Search in sources :

Example 6 with MessageContext

use of org.apache.airavata.messaging.core.MessageContext in project airavata by apache.

the class OrchestratorUtils method updageAndPublishExperimentStatus.

public static void updageAndPublishExperimentStatus(String experimentId, ExperimentStatus status, Publisher publisher, String gatewayId) {
    try {
        RegistryFactory.getDefaultExpCatalog().update(ExperimentCatalogModelType.EXPERIMENT_STATUS, status, experimentId);
        ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent(status.getState(), experimentId, gatewayId);
        String messageId = AiravataUtils.getId("EXPERIMENT");
        MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId);
        messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp());
        publisher.publish(messageContext);
    } catch (RegistryException e) {
        log.error("expId : " + experimentId + " Error while updating experiment status to " + status.toString(), e);
    } catch (AiravataException e) {
        log.error("expId : " + experimentId + " Error while publishing experiment status to " + status.toString(), e);
    }
}
Also used : ExperimentStatusChangeEvent(org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent) MessageContext(org.apache.airavata.messaging.core.MessageContext) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 7 with MessageContext

use of org.apache.airavata.messaging.core.MessageContext in project airavata by apache.

the class GFACPassiveJobSubmitter method submit.

/**
 * Submit the job to a shared launch.queue accross multiple gfac instances
 *
 * @param experimentId
 * @param processId
 * @param tokenId
 * @return
 * @throws OrchestratorException
 */
public boolean submit(String experimentId, String processId, String tokenId) throws OrchestratorException {
    try {
        String gatewayId = null;
        CredentialReader credentialReader = GFacUtils.getCredentialReader();
        if (credentialReader != null) {
            try {
                gatewayId = credentialReader.getGatewayID(tokenId);
            } catch (Exception e) {
                logger.error(e.getLocalizedMessage());
            }
        }
        if (gatewayId == null || gatewayId.isEmpty()) {
            gatewayId = ServerSettings.getDefaultUserGateway();
        }
        ProcessSubmitEvent processSubmitEvent = new ProcessSubmitEvent(processId, gatewayId, experimentId, tokenId);
        MessageContext messageContext = new MessageContext(processSubmitEvent, MessageType.LAUNCHPROCESS, "LAUNCH" + ".PROCESS-" + UUID.randomUUID().toString(), gatewayId);
        messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp());
        publisher.publish(messageContext);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new OrchestratorException(e);
    }
    return true;
}
Also used : CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) ProcessSubmitEvent(org.apache.airavata.model.messaging.event.ProcessSubmitEvent) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) MessageContext(org.apache.airavata.messaging.core.MessageContext) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 8 with MessageContext

use of org.apache.airavata.messaging.core.MessageContext 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);
}
Also used : ProcessStatusChangeEvent(org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent) MessageContext(org.apache.airavata.messaging.core.MessageContext) ProcessIdentifier(org.apache.airavata.model.messaging.event.ProcessIdentifier)

Example 9 with MessageContext

use of org.apache.airavata.messaging.core.MessageContext 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 10 with MessageContext

use of org.apache.airavata.messaging.core.MessageContext 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)

Aggregations

MessageContext (org.apache.airavata.messaging.core.MessageContext)20 TException (org.apache.thrift.TException)9 AiravataException (org.apache.airavata.common.exception.AiravataException)6 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)6 DBEventMessage (org.apache.airavata.model.dbevent.DBEventMessage)4 DBEventMessageContext (org.apache.airavata.model.dbevent.DBEventMessageContext)4 Message (org.apache.airavata.model.messaging.event.Message)4 URISyntaxException (java.net.URISyntaxException)3 UnknownHostException (java.net.UnknownHostException)3 ExperimentStatusChangeEvent (org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent)3 ExperimentSubmitEvent (org.apache.airavata.model.messaging.event.ExperimentSubmitEvent)3 TBase (org.apache.thrift.TBase)3 Timestamp (java.sql.Timestamp)2 CredentialReader (org.apache.airavata.credential.store.store.CredentialReader)2 DBEventSubscriber (org.apache.airavata.model.dbevent.DBEventSubscriber)2 ProcessStatusChangeEvent (org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent)2 ProcessSubmitEvent (org.apache.airavata.model.messaging.event.ProcessSubmitEvent)2 OrchestratorException (org.apache.airavata.orchestrator.core.exception.OrchestratorException)2 RegistryException (org.apache.airavata.registry.cpi.RegistryException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1