Package com.linkedin.helix.messaging.handling

Examples of com.linkedin.helix.messaging.handling.HelixTaskResult


    }

    @Override
    public HelixTaskResult handleMessage() throws InterruptedException
    {
      HelixTaskResult result = new HelixTaskResult();
      result.setSuccess(true);
      // TODO : consider unify this with StatsAggregationStage.executeAlertActions()
      try
      {
        ActionOnError actionOnError
          = ActionOnError.valueOf(_message.getRecord().getSimpleField(ACTIONKEY));

        if(actionOnError == ActionOnError.DISABLE_INSTANCE)
        {
          _manager.getClusterManagmentTool().enableInstance(_manager.getClusterName(), _message.getMsgSrc(), false);
          _logger.info("Instance " + _message.getMsgSrc() + " disabled");
        }
        else if(actionOnError == ActionOnError.DISABLE_PARTITION)
        {
          _manager.getClusterManagmentTool().enablePartition(false, _manager.getClusterName(), _message.getMsgSrc(),
              _message.getResourceName(), Arrays.asList( _message.getPartitionName()));
          _logger.info("partition " + _message.getPartitionName() + " disabled");
        }
        else if (actionOnError == ActionOnError.DISABLE_RESOURCE)
        {
          // NOT IMPLEMENTED, or we can disable all partitions
          //_manager.getClusterManagmentTool().en(_manager.getClusterName(), _manager.getInstanceName(),
          //    _message.getResourceName(), _message.getPartitionName(), false);
          _logger.info("resource " + _message.getResourceName() + " disabled");
        }
      }
      catch(Exception e)
      {
        _logger.error("", e);
        result.setSuccess(false);
        result.setException(e);
      }
      return result;
    }
View Full Code Here


    @Override
    public HelixTaskResult handleMessage() throws InterruptedException
    {
      String type = _message.getMsgType();
      HelixTaskResult result = new HelixTaskResult();
      if(!type.equals(MessageType.CONTROLLER_MSG.toString()))
      {
        throw new HelixException("Unexpected msg type for message "+_message.getMsgId()
            +" type:" + _message.getMsgType());
      }
      result.getTaskResultMap().put("ControllerResult", "msg "+ _message.getMsgId() + " from "+_message.getMsgSrc() + " processed");
      result.setSuccess(true);
      return result;
    }
View Full Code Here

    @Override
    public HelixTaskResult handleMessage() throws InterruptedException
    {
      String type = _message.getMsgType();
      HelixTaskResult result = new HelixTaskResult();
      if (!type.equals(MessageType.SCHEDULER_MSG.toString()))
      {
        throw new HelixException("Unexpected msg type for message "
            + _message.getMsgId() + " type:" + _message.getMsgType());
      }
      // Parse timeout value
      int timeOut = -1;
      if (_message.getRecord().getSimpleFields().containsKey("TIMEOUT"))
      {
        try
        {
          timeOut = Integer.parseInt(_message.getRecord().getSimpleFields()
              .get("TIMEOUT"));
        } catch (Exception e)
        {
        }
      }

      // Parse the message template
      ZNRecord record = new ZNRecord("templateMessage");
      record.getSimpleFields().putAll(
          _message.getRecord().getMapField("MessageTemplate"));
      Message messageTemplate = new Message(record);

      // Parse the criteria
      StringReader sr = new StringReader(_message.getRecord().getSimpleField(
          "Criteria"));
      ObjectMapper mapper = new ObjectMapper();
      Criteria recipientCriteria;
      try
      {
        recipientCriteria = mapper.readValue(sr, Criteria.class);
      } catch (Exception e)
      {
        _logger.error("", e);
        result.setException(e);
        result.setSuccess(false);
        return result;
      }
      _logger.info("Scheduler sending message, criteria:" + recipientCriteria);
     
      boolean waitAll = false;
      if(_message.getRecord().getSimpleField(DefaultSchedulerMessageHandlerFactory.WAIT_ALL) !=null)
      {
        try
        {
          waitAll = Boolean.parseBoolean(_message.getRecord().getSimpleField(DefaultSchedulerMessageHandlerFactory.WAIT_ALL));
        }
        catch(Exception e)
        {
          _logger.warn("",e);
        }
      }
      // Send all messages.
     
      int nMsgsSent = 0;
      SchedulerAsyncCallback callback = new SchedulerAsyncCallback(_message, _manager);
      if(waitAll)
      {
        nMsgsSent = _manager.getMessagingService().sendAndWait(recipientCriteria,
            messageTemplate,
            callback,
            timeOut);
      }
      else
      {
        nMsgsSent = _manager.getMessagingService().send(recipientCriteria,
            messageTemplate,
            callback,
            timeOut);
      }
      HelixDataAccessor accessor = _manager.getHelixDataAccessor();
      Builder keyBuilder = accessor.keyBuilder();

      // Record the number of messages sent into status updates
      Map<String, String> sendSummary = new HashMap<String, String>();
      sendSummary.put("MessageCount", "" + nMsgsSent);
     
      ZNRecord statusUpdate = accessor.getProperty(
          keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.toString(),
              _message.getMsgId())).getRecord();

      statusUpdate.getMapFields().put("SentMessageCount", sendSummary);

      accessor.setProperty(keyBuilder.controllerTaskStatus(
          MessageType.SCHEDULER_MSG.toString(), _message.getMsgId()),
          new StatusUpdate(statusUpdate));

      result.getTaskResultMap().put(
          "ControllerResult",
          "msg " + _message.getMsgId() + " from " + _message.getMsgSrc()
              + " processed");
      result.getTaskResultMap().put(SCHEDULER_MSG_ID, _message.getMsgId());
      result.setSuccess(true);
      return result;
    }
View Full Code Here

      }

      @Override
      public HelixTaskResult handleMessage() throws InterruptedException
      {
        HelixTaskResult result = new HelixTaskResult();
        result.setSuccess(true);
        Thread.sleep(1000);
        System.out.println("TestMessagingHandler " + _message.getMsgId());
        _processedMsgIds.add(_message.getRecord().getSimpleField(
            "TestMessagingPara"));
        result.getTaskResultMap().put("ReplyMessage", "TestReplyMessage");
        return result;
      }
View Full Code Here

      }

      @Override
      public HelixTaskResult handleMessage() throws InterruptedException
      {
        HelixTaskResult result = new HelixTaskResult();
        return result;
      }
View Full Code Here

      }

      @Override
      public HelixTaskResult handleMessage() throws InterruptedException
      {
        HelixTaskResult result = new HelixTaskResult();
        result.setSuccess(true);
        return result;
      }
View Full Code Here

      }

      @Override
      public HelixTaskResult handleMessage() throws InterruptedException
      {
        HelixTaskResult result = new HelixTaskResult();
        result.setSuccess(true);
        String destName = _message.getTgtName();
        synchronized (_results)
        {
          if (!_results.containsKey(_message.getPartitionName()))
          {
View Full Code Here

      @Override
      public HelixTaskResult handleMessage() throws InterruptedException
      {
        String hostName;
        HelixTaskResult result = new HelixTaskResult();
        try
        {
          hostName = InetAddress.getLocalHost().getCanonicalHostName();
        } catch (UnknownHostException e)
        {
          hostName = "UNKNOWN";
        }
        String port = "2134";
        String msgSubType = _message.getMsgSubType();
        if (msgSubType.equals(REQUEST_BOOTSTRAP_URL))
        {
          result.getTaskResultMap().put(
              "BOOTSTRAP_URL",
              "http://" + hostName + ":" + port
                  + "/getFile?path=/data/bootstrap/"
                  + _message.getResourceName() + "/"
                  + _message.getPartitionName() + ".tar");

          result.getTaskResultMap().put(
              "BOOTSTRAP_TIME",
              ""+new Date().getTime());
        }

        result.setSuccess(true);
        return result;
      }
View Full Code Here

TOP

Related Classes of com.linkedin.helix.messaging.handling.HelixTaskResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.