Java Code Examples for org.apache.helix.model.Message#setMsgSubType()

The following examples show how to use org.apache.helix.model.Message#setMsgSubType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelixUtils.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public static void sendUserDefinedMessage(String messageSubType, String messageVal, String messageId,
    InstanceType instanceType, HelixManager helixManager, Logger logger) {
  Criteria criteria = new Criteria();
  criteria.setInstanceName("%");
  criteria.setResource("%");
  criteria.setPartition("%");
  criteria.setPartitionState("%");
  criteria.setRecipientInstanceType(instanceType);
  criteria.setSessionSpecific(true);

  Message message = new Message(Message.MessageType.USER_DEFINE_MSG.toString(), messageId);
  message.setMsgSubType(messageSubType);
  message.setAttribute(Message.Attributes.INNER_MESSAGE, messageVal);
  message.setMsgState(Message.MessageState.NEW);
  message.setTgtSessionId("*");

  int messagesSent = helixManager.getMessagingService().send(criteria, message);
  if (messagesSent == 0) {
    logger.error(String.format("Failed to send the %s message to the participants", message));
  }
}
 
Example 2
Source File: GobblinAWSClusterLauncher.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void sendShutdownRequest() {
  final Criteria criteria = new Criteria();
  criteria.setInstanceName("%");
  criteria.setResource("%");
  criteria.setPartition("%");
  criteria.setPartitionState("%");
  criteria.setRecipientInstanceType(InstanceType.CONTROLLER);
  criteria.setSessionSpecific(true);

  final Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE,
      HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString());
  shutdownRequest.setMsgSubType(HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString());
  shutdownRequest.setMsgState(Message.MessageState.NEW);
  shutdownRequest.setTgtSessionId("*");

  // Wait for 5 minutes
  final int timeout = 300000;

  // Send shutdown request to Cluster master, which will send shutdown request to workers
  // Upon receiving shutdown response from workers, master will shut itself down and call back shutdownASG()
  final int messagesSent = this.helixManager.getMessagingService().send(criteria, shutdownRequest,
      shutdownASG(),timeout);
  if (messagesSent == 0) {
    LOGGER.error(String.format("Failed to send the %s message to the controller", shutdownRequest.getMsgSubType()));
  }
}
 
Example 3
Source File: GobblinYarnAppLauncher.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void sendShutdownRequest() {
  Criteria criteria = new Criteria();
  criteria.setInstanceName("%");
  criteria.setPartition("%");
  criteria.setPartitionState("%");
  criteria.setResource("%");
  if (this.isHelixClusterManaged) {
    //In the managed mode, the Gobblin Yarn Application Master connects to the Helix cluster in the Participant role.
    criteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
    criteria.setInstanceName(this.helixInstanceName);
  } else {
    criteria.setRecipientInstanceType(InstanceType.CONTROLLER);
  }
  criteria.setSessionSpecific(true);

  Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE,
      HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString());
  shutdownRequest.setMsgSubType(HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString());
  shutdownRequest.setMsgState(Message.MessageState.NEW);
  shutdownRequest.setTgtSessionId("*");

  int messagesSent = this.messagingService.send(criteria, shutdownRequest);
  if (messagesSent == 0) {
    LOGGER.error(String.format("Failed to send the %s message to the controller", shutdownRequest.getMsgSubType()));
  }
}
 
Example 4
Source File: AbstractYarnAppSecurityManager.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected void sendTokenFileUpdatedMessage(InstanceType instanceType, String instanceName) {
  Criteria criteria = new Criteria();
  criteria.setInstanceName(Strings.isNullOrEmpty(instanceName) ? "%" : instanceName);
  criteria.setResource("%");
  criteria.setPartition("%");
  criteria.setPartitionState("%");
  criteria.setRecipientInstanceType(instanceType);
  /**
   * #HELIX-0.6.7-WORKAROUND
   * Add back when LIVESTANCES messaging is ported to 0.6 branch
   if (instanceType == InstanceType.PARTICIPANT) {
   criteria.setDataSource(Criteria.DataSource.LIVEINSTANCES);
   }
   **/
  criteria.setSessionSpecific(true);

  Message tokenFileUpdatedMessage = new Message(Message.MessageType.USER_DEFINE_MSG,
      HelixMessageSubTypes.TOKEN_FILE_UPDATED.toString().toLowerCase() + UUID.randomUUID().toString());
  tokenFileUpdatedMessage.setMsgSubType(HelixMessageSubTypes.TOKEN_FILE_UPDATED.toString());
  tokenFileUpdatedMessage.setMsgState(Message.MessageState.NEW);
  if (instanceType == InstanceType.CONTROLLER) {
    tokenFileUpdatedMessage.setTgtSessionId("*");
  }

  // #HELIX-0.6.7-WORKAROUND
  // Temporarily bypass the default messaging service to allow upgrade to 0.6.7 which is missing support
  // for messaging to instances
  //int messagesSent = this.helixManager.getMessagingService().send(criteria, tokenFileUpdatedMessage);
  GobblinHelixMessagingService messagingService = new GobblinHelixMessagingService(helixManager);

  int messagesSent = messagingService.send(criteria, tokenFileUpdatedMessage);
  LOGGER.info(String.format("Sent %d token file updated message(s) to the %s", messagesSent, instanceType));
}
 
Example 5
Source File: GobblinClusterManager.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void sendShutdownRequest() {
  Criteria criteria = new Criteria();
  criteria.setInstanceName("%");
  criteria.setResource("%");
  criteria.setPartition("%");
  criteria.setPartitionState("%");
  criteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
  // #HELIX-0.6.7-WORKAROUND
  // Add this back when messaging to instances is ported to 0.6 branch
  //criteria.setDataSource(Criteria.DataSource.LIVEINSTANCES);
  criteria.setSessionSpecific(true);

  Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE,
      HelixMessageSubTypes.WORK_UNIT_RUNNER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString());
  shutdownRequest.setMsgSubType(HelixMessageSubTypes.WORK_UNIT_RUNNER_SHUTDOWN.toString());
  shutdownRequest.setMsgState(Message.MessageState.NEW);

  // Wait for 5 minutes
  final int timeout = 300000;

  // #HELIX-0.6.7-WORKAROUND
  // Temporarily bypass the default messaging service to allow upgrade to 0.6.7 which is missing support
  // for messaging to instances
  //int messagesSent = this.helixManager.getMessagingService().send(criteria, shutdownRequest,
  //    new NoopReplyHandler(), timeout);
  GobblinHelixMessagingService messagingService = new GobblinHelixMessagingService(this.multiManager.getJobClusterHelixManager());

  int messagesSent = messagingService.send(criteria, shutdownRequest,
          new NoopReplyHandler(), timeout);
  if (messagesSent == 0) {
    LOGGER.error(String.format("Failed to send the %s message to the participants", shutdownRequest.getMsgSubType()));
  }
}
 
Example 6
Source File: BootstrapHandler.java    From helix with Apache License 2.0 5 votes vote down vote up
@Transition(from = "OFFLINE", to = "SLAVE")
public void offlineToSlave(Message message, NotificationContext context) {
  System.out.println("BootstrapProcess.BootstrapStateModel.offlineToSlave()");
  HelixManager manager = context.getManager();
  ClusterMessagingService messagingService = manager.getMessagingService();
  Message requestBackupUriRequest =
      new Message(MessageType.USER_DEFINE_MSG, UUID.randomUUID().toString());
  requestBackupUriRequest.setMsgSubType(BootstrapProcess.REQUEST_BOOTSTRAP_URL);
  requestBackupUriRequest.setMsgState(MessageState.NEW);
  Criteria recipientCriteria = new Criteria();
  recipientCriteria.setInstanceName("*");
  recipientCriteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
  recipientCriteria.setResource(message.getResourceName());
  recipientCriteria.setPartition(message.getPartitionName());
  recipientCriteria.setSessionSpecific(true);
  // wait for 30 seconds
  int timeout = 30000;
  BootstrapReplyHandler responseHandler = new BootstrapReplyHandler();

  int sentMessageCount =
      messagingService.sendAndWait(recipientCriteria, requestBackupUriRequest, responseHandler,
          timeout);
  if (sentMessageCount == 0) {
    // could not find any other node hosting the partition
  } else if (responseHandler.getBootstrapUrl() != null) {
    System.out.println("Got bootstrap url:" + responseHandler.getBootstrapUrl());
    System.out.println("Got backup time:" + responseHandler.getBootstrapTime());
    // Got the url fetch it
  } else {
    // Either go to error state
    // throw new Exception("Cant find backup/bootstrap data");
    // Request some node to start backup process
  }
}
 
Example 7
Source File: TestHelixTaskExecutor.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test()
public void testCreateHandlerException() throws InterruptedException {
  System.out.println("START TestCMTaskExecutor.testCreateHandlerException()");
  HelixTaskExecutor executor = new HelixTaskExecutor();
  HelixManager manager = new MockClusterManager();

  TestMessageHandlerFactory factory = new TestMessageHandlerFactory();
  for (String type : factory.getMessageTypes()) {
    executor.registerMessageHandlerFactory(type, factory);
  }

  NotificationContext changeContext = new NotificationContext(manager);
  List<Message> msgList = new ArrayList<Message>();

  int nMsgs1 = 5;
  for (int i = 0; i < nMsgs1; i++) {
    Message msg = new Message(factory.getMessageTypes().get(0), UUID.randomUUID().toString());
    msg.setTgtSessionId(manager.getSessionId());
    msg.setTgtName("Localhost_1123");
    msg.setSrcName("127.101.1.23_2234");
    msg.setCorrelationId(UUID.randomUUID().toString());
    msgList.add(msg);
  }
  Message exceptionMsg = new Message(factory.getMessageTypes().get(0), UUID.randomUUID().toString());
  exceptionMsg.setTgtSessionId(manager.getSessionId());
  exceptionMsg.setMsgSubType("EXCEPTION");
  exceptionMsg.setTgtName("Localhost_1123");
  exceptionMsg.setSrcName("127.101.1.23_2234");
  exceptionMsg.setCorrelationId(UUID.randomUUID().toString());
  msgList.add(exceptionMsg);

  changeContext.setChangeType(HelixConstants.ChangeType.MESSAGE);
  executor.onMessage("someInstance", msgList, changeContext);

  Thread.sleep(1000);

  AssertJUnit.assertTrue(factory._processedMsgIds.size() == nMsgs1);
  AssertJUnit.assertTrue(factory._handlersCreated == nMsgs1);

  AssertJUnit.assertTrue(exceptionMsg.getMsgState() == MessageState.UNPROCESSABLE);
  System.out.println("END TestCMTaskExecutor.testCreateHandlerException()");
}