use of org.apache.airavata.model.messaging.event.JobStatusChangeEvent 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.JobStatusChangeEvent 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.JobStatusChangeEvent in project airavata by apache.
the class EventData method process.
private void process(MessageContext event) {
this.messageId = event.getMessageId();
if (event.getType() == MessageType.EXPERIMENT) {
ExperimentStatusChangeEvent experimentStatusChangeEvent = (ExperimentStatusChangeEvent) event.getEvent();
this.status = experimentStatusChangeEvent.getState().toString();
this.experimentId = experimentStatusChangeEvent.getExperimentId();
this.workflowNodeId = "";
this.message = "Received experiment event , expId : " + experimentStatusChangeEvent.getExperimentId() + ", status : " + experimentStatusChangeEvent.getState().toString();
} else if (event.getType() == MessageType.WORKFLOWNODE) {
WorkflowNodeStatusChangeEvent wfnStatusChangeEvent = (WorkflowNodeStatusChangeEvent) event.getEvent();
WorkflowIdentifier wfIdentifier = wfnStatusChangeEvent.getWorkflowNodeIdentity();
this.status = wfnStatusChangeEvent.getState().toString();
this.experimentId = wfIdentifier.getExperimentId();
this.workflowNodeId = wfIdentifier.getWorkflowNodeId();
this.message = "Received workflow status change event, expId : " + wfIdentifier.getExperimentId() + ", nodeId : " + wfIdentifier.getWorkflowNodeId() + " , status : " + wfnStatusChangeEvent.getState().toString();
} else if (event.getType() == MessageType.TASK) {
TaskStatusChangeEvent taskStatusChangeEvent = (TaskStatusChangeEvent) event.getEvent();
TaskIdentifier taskIdentifier = taskStatusChangeEvent.getTaskIdentity();
this.status = taskStatusChangeEvent.getState().toString();
this.experimentId = taskIdentifier.getExperimentId();
this.workflowNodeId = taskIdentifier.getWorkflowNodeId();
this.message = "Received task event , expId : " + taskIdentifier.getExperimentId() + ",taskId : " + taskIdentifier.getTaskId() + ", wfNodeId : " + taskIdentifier.getWorkflowNodeId() + ", status : " + taskStatusChangeEvent.getState().toString();
} else if (event.getType() == MessageType.JOB) {
JobStatusChangeEvent jobStatusChangeEvent = (JobStatusChangeEvent) event.getEvent();
JobIdentifier jobIdentifier = jobStatusChangeEvent.getJobIdentity();
this.status = jobStatusChangeEvent.getState().toString();
this.experimentId = jobIdentifier.getExperimentId();
this.workflowNodeId = jobIdentifier.getWorkflowNodeId();
this.message = "Received task event , expId : " + jobIdentifier.getExperimentId() + " ,taskId : " + jobIdentifier.getTaskId() + ", wfNodeId : " + jobIdentifier.getWorkflowNodeId() + ", status : " + jobStatusChangeEvent.getState().toString();
}
}
use of org.apache.airavata.model.messaging.event.JobStatusChangeEvent in project airavata by apache.
the class RabbitMQListener method getMessageHandler.
private static MessageHandler getMessageHandler(final BufferedWriter bw) {
return message -> {
try {
long latency = System.currentTimeMillis() - message.getUpdatedTime().getTime();
bw.write(message.getMessageId() + " :" + latency);
bw.newLine();
bw.flush();
} catch (IOException e) {
e.printStackTrace();
}
if (message.getType().equals(MessageType.EXPERIMENT)) {
try {
ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent();
TBase messageEvent = message.getEvent();
byte[] bytes = ThriftUtils.serializeThriftObject(messageEvent);
ThriftUtils.createThriftFromBytes(bytes, event);
System.out.println(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getType() + "' and with state : '" + event.getState().toString() + " for Gateway " + event.getGatewayId());
} catch (TException e) {
logger.error(e.getMessage(), e);
}
} else if (message.getType().equals(MessageType.PROCESS)) {
/*try {
WorkflowNodeStatusChangeEvent event = new WorkflowNodeStatusChangeEvent();
TBase messageEvent = message.getEvent();
byte[] bytes = ThriftUtils.serializeThriftObject(messageEvent);
ThriftUtils.createThriftFromBytes(bytes, event);
System.out.println(" Message Received with message id '" + message.getMessageId()
+ "' and with message type '" + message.getType() + "' and with state : '" + event.getState().toString() +
" for Gateway " + event.getWorkflowNodeIdentity().getGatewayId());
} catch (TException e) {
logger.error(e.getMessage(), e);
}*/
} else if (message.getType().equals(MessageType.TASK)) {
try {
TaskStatusChangeEvent event = new TaskStatusChangeEvent();
TBase messageEvent = message.getEvent();
byte[] bytes = ThriftUtils.serializeThriftObject(messageEvent);
ThriftUtils.createThriftFromBytes(bytes, event);
System.out.println(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getType() + "' and with state : '" + event.getState().toString() + " for Gateway " + event.getTaskIdentity().getGatewayId());
} catch (TException e) {
logger.error(e.getMessage(), e);
}
} else if (message.getType().equals(MessageType.JOB)) {
try {
JobStatusChangeEvent event = new JobStatusChangeEvent();
TBase messageEvent = message.getEvent();
byte[] bytes = ThriftUtils.serializeThriftObject(messageEvent);
ThriftUtils.createThriftFromBytes(bytes, event);
System.out.println(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getType() + "' and with state : '" + event.getState().toString() + " for Gateway " + event.getJobIdentity().getGatewayId());
} catch (TException e) {
logger.error(e.getMessage(), e);
}
}
};
}
use of org.apache.airavata.model.messaging.event.JobStatusChangeEvent in project airavata by apache.
the class ExperimentExecution method processMessage.
private void processMessage(MessageContext message) {
if (message.getType().equals(MessageType.EXPERIMENT)) {
try {
ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent();
TBase messageEvent = message.getEvent();
byte[] bytes = ThriftUtils.serializeThriftObject(messageEvent);
ThriftUtils.createThriftFromBytes(bytes, event);
ExperimentState expState = event.getState();
String expId = event.getExperimentId();
String gatewayId = event.getGatewayId();
if (expState.equals(ExperimentState.COMPLETED)) {
resultWriter.println("Results for experiment : " + expId + " of gateway Id : " + gatewayId);
resultWriter.println("=====================================================================");
resultWriter.println("Status : " + ExperimentState.COMPLETED.toString());
// check file transfers
List<OutputDataObjectType> experimentOutputs = airavata.getExperimentOutputs(authzToken, expId);
int i = 1;
for (OutputDataObjectType output : experimentOutputs) {
System.out.println("################ Experiment : " + expId + " COMPLETES ###################");
System.out.println("Output " + i + " : " + output.getValue());
resultWriter.println("Output " + i + " : " + output.getValue());
i++;
}
resultWriter.println("End of Results for Experiment : " + expId);
resultWriter.println("=====================================================================");
} else if (expState.equals(ExperimentState.FAILED)) {
resultWriter.println("Results for experiment : " + expId + " of gateway Id : " + gatewayId);
resultWriter.println("=====================================================================");
int j = 1;
resultWriter.println("Status : " + ExperimentState.FAILED.toString());
System.out.println("################ Experiment : " + expId + " FAILED ###################");
ExperimentModel experiment = airavata.getExperiment(authzToken, expId);
List<ErrorModel> errors = experiment.getErrors();
if (errors != null && !errors.isEmpty()) {
for (ErrorModel errorDetails : errors) {
System.out.println(errorDetails.getActualErrorMessage());
resultWriter.println("Actual Error : " + j + " : " + errorDetails.getActualErrorMessage());
resultWriter.println("User Friendly Message : " + j + " : " + errorDetails.getUserFriendlyMessage());
}
}
resultWriter.println("End of Results for Experiment : " + expId);
resultWriter.println("=====================================================================");
}
} catch (TException e) {
logger.error(e.getMessage(), e);
}
} else if (message.getType().equals(MessageType.JOB)) {
try {
JobStatusChangeEvent event = new JobStatusChangeEvent();
TBase messageEvent = message.getEvent();
byte[] bytes = ThriftUtils.serializeThriftObject(messageEvent);
ThriftUtils.createThriftFromBytes(bytes, event);
} catch (TException e) {
logger.error(e.getMessage(), e);
}
}
resultWriter.flush();
}
Aggregations