Search in sources :

Example 61 with Message

use of org.apache.helix.model.Message in project incubator-gobblin by apache.

the class GobblinAWSClusterLauncher method sendShutdownRequest.

@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()));
    }
}
Also used : Message(org.apache.helix.model.Message) Criteria(org.apache.helix.Criteria) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 62 with Message

use of org.apache.helix.model.Message in project incubator-gobblin by apache.

the class GobblinClusterManager method sendShutdownRequest.

@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.helixManager);
    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()));
    }
}
Also used : Message(org.apache.helix.model.Message) Criteria(org.apache.helix.Criteria) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 63 with Message

use of org.apache.helix.model.Message in project incubator-gobblin by apache.

the class YarnAppSecurityManager method sendTokenFileUpdatedMessage.

@VisibleForTesting
void sendTokenFileUpdatedMessage(InstanceType instanceType) {
    Criteria criteria = new Criteria();
    criteria.setInstanceName("%");
    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(this.helixManager);
    int messagesSent = messagingService.send(criteria, tokenFileUpdatedMessage);
    LOGGER.info(String.format("Sent %d token file updated message(s) to the %s", messagesSent, instanceType));
}
Also used : Message(org.apache.helix.model.Message) Criteria(org.apache.helix.Criteria) GobblinHelixMessagingService(org.apache.gobblin.cluster.GobblinHelixMessagingService) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 64 with Message

use of org.apache.helix.model.Message in project helix by apache.

the class HelixTask method forwardRelayMessages.

private void forwardRelayMessages(HelixDataAccessor accessor, Message message, long taskCompletionTime) {
    if (message.hasRelayMessages()) {
        Map<String, Message> relayMessages = message.getRelayMessages();
        Builder keyBuilder = accessor.keyBuilder();
        // Ignore all relay messages if participant's session has changed.
        if (!_manager.getSessionId().equals(message.getTgtSessionId())) {
            logger.info("Session id has been changed, ignore all relay messages attached with " + message.getId());
            return;
        }
        for (String instance : relayMessages.keySet()) {
            Message msg = relayMessages.get(instance);
            if (msg.getMsgSubType().equals(MessageType.RELAYED_MESSAGE.name())) {
                msg.setRelayTime(taskCompletionTime);
                if (msg.isExpired()) {
                    logger.info("Relay message expired, ignore " + msg.getId() + " to instance " + instance);
                    continue;
                }
                PropertyKey msgKey = keyBuilder.message(instance, msg.getId());
                boolean success = accessor.getBaseDataAccessor().create(msgKey.getPath(), msg.getRecord(), AccessOption.PERSISTENT);
                if (!success) {
                    logger.warn("Failed to send relay message " + msg.getId() + " to " + instance);
                } else {
                    logger.info("Send relay message " + message.getId() + " to " + instance);
                }
            }
        }
    }
}
Also used : Message(org.apache.helix.model.Message) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) PropertyKey(org.apache.helix.PropertyKey)

Example 65 with Message

use of org.apache.helix.model.Message in project helix by apache.

the class HelixTask method sendReply.

private void sendReply(HelixDataAccessor accessor, Message message, HelixTaskResult taskResult) {
    if (_message.getCorrelationId() != null && !message.getMsgType().equals(MessageType.TASK_REPLY.name())) {
        logger.info("Sending reply for message " + message.getCorrelationId());
        _statusUpdateUtil.logInfo(message, HelixTask.class, "Sending reply", _manager);
        taskResult.getTaskResultMap().put("SUCCESS", "" + taskResult.isSuccess());
        taskResult.getTaskResultMap().put("INTERRUPTED", "" + taskResult.isInterrupted());
        if (!taskResult.isSuccess()) {
            taskResult.getTaskResultMap().put("ERRORINFO", taskResult.getMessage());
        }
        Message replyMessage = Message.createReplyMessage(_message, _manager.getInstanceName(), taskResult.getTaskResultMap());
        replyMessage.setSrcInstanceType(_manager.getInstanceType());
        if (message.getSrcInstanceType() == InstanceType.PARTICIPANT) {
            Builder keyBuilder = accessor.keyBuilder();
            accessor.setProperty(keyBuilder.message(message.getMsgSrc(), replyMessage.getMsgId()), replyMessage);
        } else if (message.getSrcInstanceType() == InstanceType.CONTROLLER) {
            Builder keyBuilder = accessor.keyBuilder();
            accessor.setProperty(keyBuilder.controllerMessage(replyMessage.getMsgId()), replyMessage);
        }
        _statusUpdateUtil.logInfo(message, HelixTask.class, "1 msg replied to " + replyMessage.getTgtName(), _manager);
    }
}
Also used : Message(org.apache.helix.model.Message) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder)

Aggregations

Message (org.apache.helix.model.Message)116 Test (org.testng.annotations.Test)53 ArrayList (java.util.ArrayList)36 HelixDataAccessor (org.apache.helix.HelixDataAccessor)30 Builder (org.apache.helix.PropertyKey.Builder)28 HelixManager (org.apache.helix.HelixManager)22 ZNRecord (org.apache.helix.ZNRecord)22 Criteria (org.apache.helix.Criteria)21 Date (java.util.Date)19 HashMap (java.util.HashMap)18 Partition (org.apache.helix.model.Partition)18 PropertyKey (org.apache.helix.PropertyKey)17 LiveInstance (org.apache.helix.model.LiveInstance)13 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)12 NotificationContext (org.apache.helix.NotificationContext)11 CurrentState (org.apache.helix.model.CurrentState)10 HelixException (org.apache.helix.HelixException)9 Resource (org.apache.helix.model.Resource)9 StringWriter (java.io.StringWriter)8 List (java.util.List)8