@VisibleForTesting void sendShutdownRequest() { Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); 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.helixManager.getMessagingService().send(criteria, shutdownRequest); if (messagesSent == 0) { LOGGER.error(String.format("Failed to send the %s message to the controller", shutdownRequest.getMsgSubType())); } }
@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())); } }
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("*");
@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())); } }
@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)); } } }
/** * Instantiate a message * @param record a ZNRecord corresponding to a message */ public Message(ZNRecord record) { super(record); if (getMsgState() == null) { setMsgState(MessageState.NEW); } if (getCreateTimeStamp() == 0) { _record.setLongField(Attributes.CREATE_TIMESTAMP.toString(), new Date().getTime()); } }
/** * Instantiate a message * @param record a ZNRecord corresponding to a message */ public Message(ZNRecord record) { super(record); if (getMsgState() == null) { setMsgState(MessageState.NEW); } if (getCreateTimeStamp() == 0) { _record.setLongField(Attributes.CREATE_TIMESTAMP.toString(), new Date().getTime()); } }
private void markReadMessage(Message message, NotificationContext context, HelixManager manager) { message.setMsgState(MessageState.READ); message.setReadTimeStamp(new Date().getTime()); message.setExecuteSessionId(context.getManager().getSessionId()); _statusUpdateUtil.logInfo(message, HelixStateMachineEngine.class, "New Message", manager); }
private void markReadMessage(Message message, NotificationContext context, HelixManager manager) { message.setMsgState(MessageState.READ); message.setReadTimeStamp(new Date().getTime()); message.setExecuteSessionId(context.getManager().getSessionId()); _statusUpdateUtil.logInfo(message, HelixStateMachineEngine.class, "New Message", manager); }
/** * Instantiate a message * @param type {@link MessageType} as a string or a custom message type * @param msgId unique message identifier */ public Message(String type, String msgId) { super(new ZNRecord(msgId)); _record.setSimpleField(Attributes.MSG_TYPE.toString(), type); setMsgId(msgId); setMsgState(MessageState.NEW); _record.setLongField(Attributes.CREATE_TIMESTAMP.toString(), new Date().getTime()); }
/** * Instantiate a message * @param type {@link MessageType} as a string or a custom message type * @param msgId unique message identifier */ public Message(String type, String msgId) { super(new ZNRecord(msgId)); _record.setSimpleField(Attributes.MSG_TYPE.toString(), type); setMsgId(msgId); setMsgState(MessageState.NEW); _record.setLongField(Attributes.CREATE_TIMESTAMP.toString(), new Date().getTime()); }
@VisibleForTesting void sendShutdownRequest() { Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); 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.helixManager.getMessagingService().send(criteria, shutdownRequest); if (messagesSent == 0) { LOGGER.error(String.format("Failed to send the %s message to the controller", shutdownRequest.getMsgSubType())); } }
@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())); } }
private void syncSessionToController(HelixManager manager) { if (_lastSessionSyncTime == null || System.currentTimeMillis() - _lastSessionSyncTime > SESSION_SYNC_INTERVAL) { // > delay since last sync HelixDataAccessor accessor = manager.getHelixDataAccessor(); PropertyKey key = new Builder(manager.getClusterName()).controllerMessage(SESSION_SYNC); if (accessor.getProperty(key) == null) { LOG.info(String.format("Participant %s syncs session with controller", manager.getInstanceName())); Message msg = new Message(MessageType.PARTICIPANT_SESSION_CHANGE, SESSION_SYNC); msg.setSrcName(manager.getInstanceName()); msg.setTgtSessionId("*"); msg.setMsgState(MessageState.NEW); msg.setMsgId(SESSION_SYNC); Criteria cr = new Criteria(); cr.setRecipientInstanceType(InstanceType.CONTROLLER); cr.setSessionSpecific(false); manager.getMessagingService().send(cr, msg); _lastSessionSyncTime = System.currentTimeMillis(); } } }
@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)); } } }
private void syncSessionToController(HelixManager manager) { if (_lastSessionSyncTime == null || System.currentTimeMillis() - _lastSessionSyncTime > SESSION_SYNC_INTERVAL) { // > delay since last sync HelixDataAccessor accessor = manager.getHelixDataAccessor(); PropertyKey key = new Builder(manager.getClusterName()).controllerMessage(SESSION_SYNC); if (accessor.getProperty(key) == null) { LOG.info(String.format("Participant %s syncs session with controller", manager.getInstanceName())); Message msg = new Message(MessageType.PARTICIPANT_SESSION_CHANGE, SESSION_SYNC); msg.setSrcName(manager.getInstanceName()); msg.setTgtSessionId("*"); msg.setMsgState(MessageState.NEW); msg.setMsgId(SESSION_SYNC); Criteria cr = new Criteria(); cr.setRecipientInstanceType(InstanceType.CONTROLLER); cr.setSessionSpecific(false); manager.getMessagingService().send(cr, msg); _lastSessionSyncTime = System.currentTimeMillis(); } } }
public void postTestMessage(String zkServer, String clusterName, String instanceName) { String msgSrc = "cm-instance-0"; String msgId = "TestMessageId-2"; Message message = new Message(MessageType.STATE_TRANSITION, msgId); message.setMsgId(msgId); message.setSrcName(msgSrc); message.setTgtName(instanceName); message.setMsgState(MessageState.NEW); message.setFromState("Slave"); message.setToState("Master"); message.setPartitionName("EspressoDB.partition-0." + instanceName); post(zkServer, message, clusterName, instanceName); }
public void postTestMessage(String zkServer, String clusterName, String instanceName) { String msgSrc = "cm-instance-0"; String msgId = "TestMessageId-2"; Message message = new Message(MessageType.STATE_TRANSITION, msgId); message.setMsgId(msgId); message.setSrcName(msgSrc); message.setTgtName(instanceName); message.setMsgState(MessageState.NEW); message.setFromState("Slave"); message.setToState("Master"); message.setPartitionName("EspressoDB.partition-0." + instanceName); post(zkServer, message, clusterName, instanceName); }
private Message newMessage(String resourceName, String partitionName, String instanceName, String fromState, String toState) { String uuid = UUID.randomUUID().toString(); Message message = new Message(MessageType.STATE_TRANSITION, uuid); message.setSrcName("controller"); message.setTgtName(instanceName); message.setMsgState(MessageState.NEW); message.setResourceName(resourceName); message.setPartitionName(partitionName); message.setFromState(fromState); message.setToState(toState); message.setTgtSessionId("sessionId"); message.setSrcSessionId("sessionId"); message.setStateModelDef("MasterSlave"); message.setStateModelFactoryName("DEFAULT"); message.setBucketSize(0); return message; }
private Message generateMessage(String from, String to) { String uuid = UUID.randomUUID().toString(); Message message = new Message(Message.MessageType.STATE_TRANSITION, uuid); message.setSrcName("ADMIN"); message.setTgtName(_participant.getInstanceName()); message.setMsgState(Message.MessageState.NEW); message.setPartitionName("P"); message.setResourceName(WorkflowGenerator.DEFAULT_TGT_DB); message.setFromState(from); message.setToState(to); message.setTgtSessionId(_participant.getSessionId()); message.setSrcSessionId(_manager.getSessionId()); message.setStateModelDef("OnlineOffline"); message.setStateModelFactoryName("DEFAULT"); return message; }