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