use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class ExperimentStatusResource method save.
public void save() throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
ExperimentStatus experimentStatus;
if (experimentId == null || statusId == null) {
throw new RegistryException("Does not have the experiment id or status id");
}
ExperimentStatusPK experimentStatusPK = new ExperimentStatusPK();
experimentStatusPK.setStatusId(statusId);
experimentStatusPK.setExperimentId(experimentId);
ExperimentStatus existingStatus = em.find(ExperimentStatus.class, experimentStatusPK);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
if (existingStatus == null) {
experimentStatus = new ExperimentStatus();
} else {
experimentStatus = existingStatus;
}
experimentStatus.setStatusId(statusId);
experimentStatus.setExperimentId(experimentId);
experimentStatus.setState(state);
experimentStatus.setReason(reason);
experimentStatus.setTimeOfStateChange(timeOfStateChange);
if (existingStatus == null) {
em.persist(experimentStatus);
} else {
em.merge(experimentStatus);
}
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
use of org.apache.airavata.registry.cpi.RegistryException 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.registry.cpi.RegistryException in project airavata by apache.
the class ExperimentRegistry method removeTask.
public void removeTask(String taskId) throws RegistryException {
try {
ProcessResource process = new ProcessResource();
process.remove(ResourceType.TASK, taskId);
} catch (Exception e) {
logger.error("Error while removing task details..", e);
throw new RegistryException(e);
}
}
use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class ExperimentRegistry method addExperiment.
// CPI Add Methods
public String addExperiment(ExperimentModel experiment) throws RegistryException {
String experimentId;
try {
if (!ExpCatResourceUtils.isUserExist(experiment.getUserName(), experiment.getGatewayId())) {
ExpCatResourceUtils.addUser(experiment.getUserName(), null, experiment.getGatewayId());
}
if (!workerResource.isProjectExists(experiment.getProjectId())) {
logger.error("Project does not exist in the system..");
throw new Exception("Project does not exist in the system, Please create the project first...");
}
experimentId = AiravataUtils.getId(experiment.getExperimentName());
experiment.setExperimentId(experimentId);
ExperimentResource experimentResource = new ExperimentResource();
experimentResource.setExperimentId(experimentId);
experimentResource.setProjectId(experiment.getProjectId());
experimentResource.setGatewayId(experiment.getGatewayId());
experimentResource.setExperimentType(experiment.getExperimentType().toString());
experimentResource.setUserName(experiment.getUserName());
experimentResource.setExperimentName(experiment.getExperimentName());
experimentResource.setCreationTime(AiravataUtils.getTime(experiment.getCreationTime()));
experimentResource.setDescription(experiment.getDescription());
experimentResource.setExecutionId(experiment.getExecutionId());
experimentResource.setGatewayExecutionId(experiment.getGatewayExecutionId());
experimentResource.setGatewayInstanceId(experiment.getGatewayInstanceId());
if (experiment.isEnableEmailNotification()) {
experimentResource.setEnableEmailNotification(true);
if (experiment.getEmailAddresses() != null) {
experimentResource.setEmailAddresses(StringUtils.join(experiment.getEmailAddresses(), ","));
}
} else {
experimentResource.setEnableEmailNotification(false);
}
experimentResource.save();
if (experiment.getUserConfigurationData() != null) {
addUserConfigData(experiment.getUserConfigurationData(), experimentId);
}
if (experiment.getExperimentInputs() != null && experiment.getExperimentInputs().size() > 0) {
addExpInputs(experiment.getExperimentInputs(), experimentId);
}
if (experiment.getExperimentOutputs() != null && experiment.getExperimentOutputs().size() > 0) {
addExpOutputs(experiment.getExperimentOutputs(), experimentId);
}
ExperimentStatus experimentStatus = new ExperimentStatus();
experimentStatus.setState(ExperimentState.CREATED);
experimentStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
addExperimentStatus(experimentStatus, experimentId);
List<ErrorModel> errors = experiment.getErrors();
if (errors != null && !errors.isEmpty()) {
for (ErrorModel errror : errors) {
addExperimentError(errror, experimentId);
}
}
} catch (Exception e) {
logger.error("Error while saving experiment to registry", e);
throw new RegistryException(e);
}
return experimentId;
}
use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class ExperimentRegistry method getProcess.
public Object getProcess(String processId, String fieldName) throws RegistryException {
try {
ExperimentResource experimentResource = new ExperimentResource();
ProcessResource resource = experimentResource.getProcess(processId);
if (fieldName == null) {
return ThriftDataModelConversion.getProcessModel(resource);
} else if (fieldName.equals(Constants.FieldConstants.ProcessConstants.PROCESS_ERROR)) {
return ThriftDataModelConversion.getErrorModel(resource.getProcessError());
} else if (fieldName.equals(Constants.FieldConstants.ProcessConstants.PROCESS_STATUS)) {
return ThriftDataModelConversion.getProcessStatus(resource.getProcessStatus());
} else if (fieldName.equals(Constants.FieldConstants.ProcessConstants.PROCESS_INPUTS)) {
return ThriftDataModelConversion.getProcessInputs(resource.getProcessInputs());
} else if (fieldName.equals(Constants.FieldConstants.ProcessConstants.PROCESS_OUTPUTS)) {
return ThriftDataModelConversion.getProcessOutputs(resource.getProcessOutputs());
} else if (fieldName.equals(Constants.FieldConstants.ProcessConstants.PROCESS_RESOURCE_SCHEDULE)) {
return ThriftDataModelConversion.getProcessResourceSchedule(resource.getProcessResourceSchedule());
} else {
logger.error("Unsupported field name for process data..");
}
} catch (Exception e) {
logger.error("Error while getting process data..", e);
throw new RegistryException(e);
}
return null;
}
Aggregations