Search in sources :

Example 1 with TaskSubmitEvent

use of org.apache.airavata.model.messaging.event.TaskSubmitEvent 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

MessageContext (org.apache.airavata.messaging.core.MessageContext)1 ExperimentStatusChangeEvent (org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent)1 JobStatusChangeEvent (org.apache.airavata.model.messaging.event.JobStatusChangeEvent)1 Message (org.apache.airavata.model.messaging.event.Message)1 ProcessStatusChangeEvent (org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent)1 TaskOutputChangeEvent (org.apache.airavata.model.messaging.event.TaskOutputChangeEvent)1 TaskStatusChangeEvent (org.apache.airavata.model.messaging.event.TaskStatusChangeEvent)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