Search in sources :

Example 1 with TaskOutputChangeEvent

use of org.apache.airavata.model.messaging.event.TaskOutputChangeEvent in project airavata by apache.

the class MessagingFactory method statusRoutingkey.

private static String statusRoutingkey(MessageContext msgCtx) {
    String gatewayId = msgCtx.getGatewayId();
    String routingKey = null;
    if (msgCtx.getType() == MessageType.EXPERIMENT) {
        ExperimentStatusChangeEvent event = (ExperimentStatusChangeEvent) msgCtx.getEvent();
        routingKey = gatewayId + "." + event.getExperimentId();
    } else if (msgCtx.getType() == MessageType.TASK) {
        TaskStatusChangeEvent event = (TaskStatusChangeEvent) msgCtx.getEvent();
        routingKey = gatewayId + "." + event.getTaskIdentity().getExperimentId() + "." + event.getTaskIdentity().getProcessId() + "." + event.getTaskIdentity().getTaskId();
    } else if (msgCtx.getType() == MessageType.PROCESSOUTPUT) {
        TaskOutputChangeEvent event = (TaskOutputChangeEvent) msgCtx.getEvent();
        routingKey = gatewayId + "." + event.getTaskIdentity().getExperimentId() + "." + event.getTaskIdentity().getProcessId() + "." + event.getTaskIdentity().getTaskId();
    } else if (msgCtx.getType() == MessageType.PROCESS) {
        ProcessStatusChangeEvent event = (ProcessStatusChangeEvent) msgCtx.getEvent();
        ProcessIdentifier processIdentifier = event.getProcessIdentity();
        routingKey = gatewayId + "." + processIdentifier.getExperimentId() + "." + processIdentifier.getProcessId();
    } else if (msgCtx.getType() == MessageType.JOB) {
        JobStatusChangeEvent event = (JobStatusChangeEvent) msgCtx.getEvent();
        JobIdentifier identity = event.getJobIdentity();
        routingKey = gatewayId + "." + identity.getExperimentId() + "." + identity.getProcessId() + "." + identity.getTaskId() + "." + identity.getJobId();
    }
    return routingKey;
}
Also used : TaskStatusChangeEvent(org.apache.airavata.model.messaging.event.TaskStatusChangeEvent) TaskOutputChangeEvent(org.apache.airavata.model.messaging.event.TaskOutputChangeEvent) ExperimentStatusChangeEvent(org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent) JobStatusChangeEvent(org.apache.airavata.model.messaging.event.JobStatusChangeEvent) ProcessStatusChangeEvent(org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent) JobIdentifier(org.apache.airavata.model.messaging.event.JobIdentifier) ProcessIdentifier(org.apache.airavata.model.messaging.event.ProcessIdentifier)

Example 2 with TaskOutputChangeEvent

use of org.apache.airavata.model.messaging.event.TaskOutputChangeEvent in project airavata by apache.

the class StatusConsumer method handleDelivery.

@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
    Message message = new Message();
    try {
        ThriftUtils.createThriftFromBytes(body, message);
        TBase event = null;
        String gatewayId = null;
        if (message.getMessageType().equals(MessageType.EXPERIMENT)) {
            ExperimentStatusChangeEvent experimentStatusChangeEvent = new ExperimentStatusChangeEvent();
            ThriftUtils.createThriftFromBytes(message.getEvent(), experimentStatusChangeEvent);
            log.debug(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getMessageType() + "'  with status " + experimentStatusChangeEvent.getState());
            event = experimentStatusChangeEvent;
            gatewayId = experimentStatusChangeEvent.getGatewayId();
        } else if (message.getMessageType().equals(MessageType.PROCESS)) {
            ProcessStatusChangeEvent processStatusChangeEvent = new ProcessStatusChangeEvent();
            ThriftUtils.createThriftFromBytes(message.getEvent(), processStatusChangeEvent);
            log.debug("Message Recieved with message id :" + message.getMessageId() + " and with " + "message type " + message.getMessageType() + " with status " + processStatusChangeEvent.getState());
            event = processStatusChangeEvent;
            gatewayId = processStatusChangeEvent.getProcessIdentity().getGatewayId();
        } else if (message.getMessageType().equals(MessageType.TASK)) {
            TaskStatusChangeEvent taskStatusChangeEvent = new TaskStatusChangeEvent();
            ThriftUtils.createThriftFromBytes(message.getEvent(), taskStatusChangeEvent);
            log.debug(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getMessageType() + "'  with status " + taskStatusChangeEvent.getState());
            event = taskStatusChangeEvent;
            gatewayId = taskStatusChangeEvent.getTaskIdentity().getGatewayId();
        } else if (message.getMessageType() == MessageType.PROCESSOUTPUT) {
            TaskOutputChangeEvent taskOutputChangeEvent = new TaskOutputChangeEvent();
            ThriftUtils.createThriftFromBytes(message.getEvent(), taskOutputChangeEvent);
            log.debug(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getMessageType());
            event = taskOutputChangeEvent;
            gatewayId = taskOutputChangeEvent.getTaskIdentity().getGatewayId();
        } else if (message.getMessageType().equals(MessageType.JOB)) {
            JobStatusChangeEvent jobStatusChangeEvent = new JobStatusChangeEvent();
            ThriftUtils.createThriftFromBytes(message.getEvent(), jobStatusChangeEvent);
            log.debug(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getMessageType() + "'  with status " + jobStatusChangeEvent.getState());
            event = jobStatusChangeEvent;
            gatewayId = jobStatusChangeEvent.getJobIdentity().getGatewayId();
        } else if (message.getMessageType().equals(MessageType.LAUNCHPROCESS)) {
            TaskSubmitEvent taskSubmitEvent = new TaskSubmitEvent();
            ThriftUtils.createThriftFromBytes(message.getEvent(), taskSubmitEvent);
            log.debug(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getMessageType() + "'  for experimentId: " + taskSubmitEvent.getExperimentId() + "and taskId: " + taskSubmitEvent.getTaskId());
            event = taskSubmitEvent;
            gatewayId = taskSubmitEvent.getGatewayId();
        } else if (message.getMessageType().equals(MessageType.TERMINATEPROCESS)) {
            TaskTerminateEvent taskTerminateEvent = new TaskTerminateEvent();
            ThriftUtils.createThriftFromBytes(message.getEvent(), taskTerminateEvent);
            log.debug(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getMessageType() + "'  for experimentId: " + taskTerminateEvent.getExperimentId() + "and taskId: " + taskTerminateEvent.getTaskId());
            event = taskTerminateEvent;
            gatewayId = null;
        }
        MessageContext messageContext = new MessageContext(event, message.getMessageType(), message.getMessageId(), gatewayId);
        messageContext.setUpdatedTime(AiravataUtils.getTime(message.getUpdatedTime()));
        messageContext.setIsRedeliver(envelope.isRedeliver());
        handler.onMessage(messageContext);
    } catch (TException e) {
        String msg = "Failed to de-serialize the thrift message, from routing keys: " + envelope.getRoutingKey();
        log.warn(msg, e);
    }
}
Also used : TException(org.apache.thrift.TException) TaskStatusChangeEvent(org.apache.airavata.model.messaging.event.TaskStatusChangeEvent) Message(org.apache.airavata.model.messaging.event.Message) TaskOutputChangeEvent(org.apache.airavata.model.messaging.event.TaskOutputChangeEvent) ExperimentStatusChangeEvent(org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent) JobStatusChangeEvent(org.apache.airavata.model.messaging.event.JobStatusChangeEvent) ProcessStatusChangeEvent(org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent) TBase(org.apache.thrift.TBase) MessageContext(org.apache.airavata.messaging.core.MessageContext) TaskSubmitEvent(org.apache.airavata.model.messaging.event.TaskSubmitEvent) TaskTerminateEvent(org.apache.airavata.model.messaging.event.TaskTerminateEvent)

Aggregations

ExperimentStatusChangeEvent (org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent)2 JobStatusChangeEvent (org.apache.airavata.model.messaging.event.JobStatusChangeEvent)2 ProcessStatusChangeEvent (org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent)2 TaskOutputChangeEvent (org.apache.airavata.model.messaging.event.TaskOutputChangeEvent)2 TaskStatusChangeEvent (org.apache.airavata.model.messaging.event.TaskStatusChangeEvent)2 MessageContext (org.apache.airavata.messaging.core.MessageContext)1 JobIdentifier (org.apache.airavata.model.messaging.event.JobIdentifier)1 Message (org.apache.airavata.model.messaging.event.Message)1 ProcessIdentifier (org.apache.airavata.model.messaging.event.ProcessIdentifier)1 TaskSubmitEvent (org.apache.airavata.model.messaging.event.TaskSubmitEvent)1 TaskTerminateEvent (org.apache.airavata.model.messaging.event.TaskTerminateEvent)1 TBase (org.apache.thrift.TBase)1 TException (org.apache.thrift.TException)1