Search in sources :

Example 1 with Message

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

the class RabbitMQPublisher method publish.

/**
 * This method is used only for publishing DB Events
 * @param messageContext object of message context which will include actual db event and other information
 * @param routingKey
 * @throws AiravataException
 */
@Override
public void publish(MessageContext messageContext, String routingKey) throws AiravataException {
    try {
        byte[] body = ThriftUtils.serializeThriftObject(messageContext.getEvent());
        Message message = new Message();
        message.setEvent(body);
        message.setMessageId(messageContext.getMessageId());
        message.setMessageType(messageContext.getType());
        if (messageContext.getUpdatedTime() != null) {
            message.setUpdatedTime(messageContext.getUpdatedTime().getTime());
        }
        // log.info("publish messageId:" + messageContext.getMessageId() + ", messageType:" + messageContext.getType() + ", to routingKey:" + routingKey);
        byte[] messageBody = ThriftUtils.serializeThriftObject(message);
        send(messageBody, routingKey);
    } catch (TException e) {
        String msg = "Error while deserializing the object";
        log.error(msg, e);
        throw new AiravataException(msg, e);
    } catch (Exception e) {
        String msg = "Error while sending to rabbitmq";
        log.error(msg, e);
        throw new AiravataException(msg, e);
    }
}
Also used : TException(org.apache.thrift.TException) Message(org.apache.airavata.model.messaging.event.Message) TException(org.apache.thrift.TException) IOException(java.io.IOException) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) AiravataException(org.apache.airavata.common.exception.AiravataException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 2 with Message

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

Example 3 with Message

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

the class ExperimentConsumer 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);
        long deliveryTag = envelope.getDeliveryTag();
        if (message.getMessageType() == MessageType.EXPERIMENT || message.getMessageType() == MessageType.EXPERIMENT_CANCEL) {
            TBase event = null;
            String gatewayId = null;
            ExperimentSubmitEvent experimentEvent = new ExperimentSubmitEvent();
            ThriftUtils.createThriftFromBytes(message.getEvent(), experimentEvent);
            log.info(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getMessageType() + "'  for experimentId:" + " " + experimentEvent.getExperimentId());
            event = experimentEvent;
            gatewayId = experimentEvent.getGatewayId();
            MessageContext messageContext = new MessageContext(event, message.getMessageType(), message.getMessageId(), gatewayId, deliveryTag);
            messageContext.setUpdatedTime(AiravataUtils.getTime(message.getUpdatedTime()));
            messageContext.setIsRedeliver(envelope.isRedeliver());
            handler.onMessage(messageContext);
        } else {
            log.error("{} message type is not handle in ProcessLaunch Subscriber. Sending ack for " + "delivery tag {} ", message.getMessageType().name(), deliveryTag);
            sendAck(deliveryTag);
        }
    } 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) Message(org.apache.airavata.model.messaging.event.Message) TBase(org.apache.thrift.TBase) ExperimentSubmitEvent(org.apache.airavata.model.messaging.event.ExperimentSubmitEvent) MessageContext(org.apache.airavata.messaging.core.MessageContext)

Example 4 with Message

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

the class ProcessConsumer method handleDelivery.

@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties basicProperties, byte[] body) throws IOException {
    Message message = new Message();
    try {
        ThriftUtils.createThriftFromBytes(body, message);
        TBase event = null;
        String gatewayId = null;
        long deliveryTag = envelope.getDeliveryTag();
        if (message.getMessageType().equals(MessageType.LAUNCHPROCESS)) {
            ProcessSubmitEvent processSubmitEvent = new ProcessSubmitEvent();
            ThriftUtils.createThriftFromBytes(message.getEvent(), processSubmitEvent);
            log.info(" Message Received with message id '" + message.getMessageId() + " and with message type:" + message.getMessageType() + ", for processId:" + processSubmitEvent.getProcessId() + ", expId:" + processSubmitEvent.getExperimentId());
            event = processSubmitEvent;
            gatewayId = processSubmitEvent.getGatewayId();
            MessageContext messageContext = new MessageContext(event, message.getMessageType(), message.getMessageId(), gatewayId, deliveryTag);
            messageContext.setUpdatedTime(AiravataUtils.getTime(message.getUpdatedTime()));
            messageContext.setIsRedeliver(envelope.isRedeliver());
            handler.onMessage(messageContext);
        } else {
            log.error("{} message type is not handle in ProcessLaunch Subscriber. Sending ack for " + "delivery tag {} ", message.getMessageType().name(), deliveryTag);
            sendAck(deliveryTag);
        }
    } 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) Message(org.apache.airavata.model.messaging.event.Message) ProcessSubmitEvent(org.apache.airavata.model.messaging.event.ProcessSubmitEvent) TBase(org.apache.thrift.TBase) MessageContext(org.apache.airavata.messaging.core.MessageContext)

Example 5 with Message

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

the class MessageConsumer method handleDelivery.

@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
    Message message = new Message();
    try {
        logger.info("handleDelivery() -> Handling message delivery. Consumer Tag : " + consumerTag);
        ThriftUtils.createThriftFromBytes(body, message);
        DBEventMessage dBEventMessage = new DBEventMessage();
        ThriftUtils.createThriftFromBytes(message.getEvent(), dBEventMessage);
        MessageContext messageContext = new MessageContext((TBase) dBEventMessage, message.getMessageType(), message.getMessageId(), "gatewayId", envelope.getDeliveryTag());
        handler.onMessage(messageContext);
    // sendAck(deliveryTag);
    } catch (TException e) {
        logger.error("handleDelivery() -> Error handling delivery. Consumer Tag : " + consumerTag, e);
    }
}
Also used : TException(org.apache.thrift.TException) DBEventMessage(org.apache.airavata.model.dbevent.DBEventMessage) DBEventMessage(org.apache.airavata.model.dbevent.DBEventMessage) Message(org.apache.airavata.model.messaging.event.Message) MessageContext(org.apache.airavata.messaging.core.MessageContext) DBEventMessageContext(org.apache.airavata.model.dbevent.DBEventMessageContext)

Aggregations

Message (org.apache.airavata.model.messaging.event.Message)6 TException (org.apache.thrift.TException)6 MessageContext (org.apache.airavata.messaging.core.MessageContext)4 TBase (org.apache.thrift.TBase)3 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)2 IOException (java.io.IOException)2 AiravataException (org.apache.airavata.common.exception.AiravataException)2 DBEventMessage (org.apache.airavata.model.dbevent.DBEventMessage)1 DBEventMessageContext (org.apache.airavata.model.dbevent.DBEventMessageContext)1 ExperimentStatusChangeEvent (org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent)1 ExperimentSubmitEvent (org.apache.airavata.model.messaging.event.ExperimentSubmitEvent)1 JobStatusChangeEvent (org.apache.airavata.model.messaging.event.JobStatusChangeEvent)1 ProcessStatusChangeEvent (org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent)1 ProcessSubmitEvent (org.apache.airavata.model.messaging.event.ProcessSubmitEvent)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