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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations