Search in sources :

Example 1 with JobStatusChangeEvent

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;
}
Also used : TaskStatusChangeEvent(org.apache.airavata.model.messaging.event.TaskStatusChangeEvent) 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) JobIdentifier(org.apache.airavata.model.messaging.event.JobIdentifier) ProcessIdentifier(org.apache.airavata.model.messaging.event.ProcessIdentifier)

Example 2 with JobStatusChangeEvent

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

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();
    }
}
Also used : TaskStatusChangeEvent(org.apache.airavata.model.messaging.event.TaskStatusChangeEvent) WorkflowIdentifier(org.apache.airavata.model.messaging.event.WorkflowIdentifier) TaskIdentifier(org.apache.airavata.model.messaging.event.TaskIdentifier) ExperimentStatusChangeEvent(org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent) JobStatusChangeEvent(org.apache.airavata.model.messaging.event.JobStatusChangeEvent) JobIdentifier(org.apache.airavata.model.messaging.event.JobIdentifier) WorkflowNodeStatusChangeEvent(org.apache.airavata.model.messaging.event.WorkflowNodeStatusChangeEvent)

Example 4 with JobStatusChangeEvent

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);
            }
        }
    };
}
Also used : MessageType(org.apache.airavata.model.messaging.event.MessageType) Type(org.apache.airavata.messaging.core.Type) Options(org.apache.commons.cli.Options) LoggerFactory(org.slf4j.LoggerFactory) TaskStatusChangeEvent(org.apache.airavata.model.messaging.event.TaskStatusChangeEvent) ArrayList(java.util.ArrayList) ServerSettings(org.apache.airavata.common.utils.ServerSettings) CommandLine(org.apache.commons.cli.CommandLine) OutputStreamWriter(java.io.OutputStreamWriter) PosixParser(org.apache.commons.cli.PosixParser) TBase(org.apache.thrift.TBase) MessagingFactory(org.apache.airavata.messaging.core.MessagingFactory) ExperimentStatusChangeEvent(org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent) Logger(org.slf4j.Logger) CommandLineParser(org.apache.commons.cli.CommandLineParser) BufferedWriter(java.io.BufferedWriter) TException(org.apache.thrift.TException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ThriftUtils(org.apache.airavata.common.utils.ThriftUtils) File(java.io.File) MessageHandler(org.apache.airavata.messaging.core.MessageHandler) List(java.util.List) JobStatusChangeEvent(org.apache.airavata.model.messaging.event.JobStatusChangeEvent) ParseException(org.apache.commons.cli.ParseException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Subscriber(org.apache.airavata.messaging.core.Subscriber) TException(org.apache.thrift.TException) TaskStatusChangeEvent(org.apache.airavata.model.messaging.event.TaskStatusChangeEvent) ExperimentStatusChangeEvent(org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent) JobStatusChangeEvent(org.apache.airavata.model.messaging.event.JobStatusChangeEvent) TBase(org.apache.thrift.TBase) IOException(java.io.IOException)

Example 5 with JobStatusChangeEvent

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();
}
Also used : TException(org.apache.thrift.TException) JobStatusChangeEvent(org.apache.airavata.model.messaging.event.JobStatusChangeEvent) ExperimentModel(org.apache.airavata.model.experiment.ExperimentModel) ExperimentState(org.apache.airavata.model.status.ExperimentState) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) ExperimentStatusChangeEvent(org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent) ErrorModel(org.apache.airavata.model.commons.ErrorModel) TBase(org.apache.thrift.TBase)

Aggregations

ExperimentStatusChangeEvent (org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent)5 JobStatusChangeEvent (org.apache.airavata.model.messaging.event.JobStatusChangeEvent)5 TaskStatusChangeEvent (org.apache.airavata.model.messaging.event.TaskStatusChangeEvent)4 TBase (org.apache.thrift.TBase)3 TException (org.apache.thrift.TException)3 JobIdentifier (org.apache.airavata.model.messaging.event.JobIdentifier)2 ProcessStatusChangeEvent (org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent)2 TaskOutputChangeEvent (org.apache.airavata.model.messaging.event.TaskOutputChangeEvent)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 ServerSettings (org.apache.airavata.common.utils.ServerSettings)1 ThriftUtils (org.apache.airavata.common.utils.ThriftUtils)1 MessageContext (org.apache.airavata.messaging.core.MessageContext)1 MessageHandler (org.apache.airavata.messaging.core.MessageHandler)1