use of org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent 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;
}
use of org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent 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.ProcessStatusChangeEvent in project airavata by apache.
the class GfacServerHandler method publishProcessStatus.
private void publishProcessStatus(ProcessSubmitEvent event, ProcessStatus status) throws AiravataException {
ProcessIdentifier identifier = new ProcessIdentifier(event.getProcessId(), event.getExperimentId(), event.getGatewayId());
ProcessStatusChangeEvent processStatusChangeEvent = new ProcessStatusChangeEvent(status.getState(), identifier);
MessageContext msgCtx = new MessageContext(processStatusChangeEvent, MessageType.PROCESS, AiravataUtils.getId(MessageType.PROCESS.name()), event.getGatewayId());
msgCtx.setUpdatedTime(AiravataUtils.getCurrentTimestamp());
statusPublisher.publish(msgCtx);
}
Aggregations