http://git-wip-us.apache.org/repos/asf/airavata/blob/e13d90da/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/TaskDetailResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/TaskDetailResource.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/TaskDetailResource.java new file mode 100644 index 0000000..791c9f9 --- /dev/null +++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/TaskDetailResource.java @@ -0,0 +1,661 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.persistance.registry.jpa.resources; + +import org.apache.airavata.persistance.registry.jpa.Resource; +import org.apache.airavata.persistance.registry.jpa.ResourceType; +import org.apache.airavata.persistance.registry.jpa.ResourceUtils; +import org.apache.airavata.persistance.registry.jpa.model.*; +import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator; +import org.apache.airavata.registry.cpi.RegistryException; +import org.apache.airavata.registry.cpi.utils.StatusType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; + +public class TaskDetailResource extends AbstractResource { + private static final Logger logger = LoggerFactory.getLogger(TaskDetailResource.class); + private String taskId; + private WorkflowNodeDetailResource workflowNodeDetailResource; + private Timestamp creationTime; + private String applicationId; + private String applicationVersion; + private String applicationDeploymentId; + private boolean enableEmailNotifications; + + public boolean isEnableEmailNotifications() { + return enableEmailNotifications; + } + + public void setEnableEmailNotifications(boolean enableEmailNotifications) { + this.enableEmailNotifications = enableEmailNotifications; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public WorkflowNodeDetailResource getWorkflowNodeDetailResource() { + return workflowNodeDetailResource; + } + + public void setWorkflowNodeDetailResource(WorkflowNodeDetailResource workflowNodeDetailResource) { + this.workflowNodeDetailResource = workflowNodeDetailResource; + } + + public Timestamp getCreationTime() { + return creationTime; + } + + public void setCreationTime(Timestamp creationTime) { + this.creationTime = creationTime; + } + + public String getApplicationId() { + return applicationId; + } + + public void setApplicationId(String applicationId) { + this.applicationId = applicationId; + } + + public String getApplicationVersion() { + return applicationVersion; + } + + public void setApplicationVersion(String applicationVersion) { + this.applicationVersion = applicationVersion; + } + + + public Resource create(ResourceType type) throws RegistryException{ + switch (type){ + case ERROR_DETAIL: + ErrorDetailResource errorDetailResource = new ErrorDetailResource(); + errorDetailResource.setTaskDetailResource(this); + return errorDetailResource; + case NOTIFICATION_EMAIL: + NotificationEmailResource emailResource = new NotificationEmailResource(); + emailResource.setTaskDetailResource(this); + return emailResource; + case APPLICATION_INPUT: + ApplicationInputResource applicationInputResource = new ApplicationInputResource(); + applicationInputResource.setTaskDetailResource(this); + return applicationInputResource; + case APPLICATION_OUTPUT: + ApplicationOutputResource applicationOutputResource = new ApplicationOutputResource(); + applicationOutputResource.setTaskDetailResource(this); + return applicationOutputResource; + case JOB_DETAIL: + JobDetailResource jobDetailResource = new JobDetailResource(); + jobDetailResource.setTaskDetailResource(this); + return jobDetailResource; + case DATA_TRANSFER_DETAIL: + DataTransferDetailResource dataTransferDetailResource = new DataTransferDetailResource(); + dataTransferDetailResource.setTaskDetailResource(this); + return dataTransferDetailResource; + case STATUS: + StatusResource statusResource = new StatusResource(); + statusResource.setTaskDetailResource(this); + return statusResource; + case COMPUTATIONAL_RESOURCE_SCHEDULING: + ComputationSchedulingResource schedulingResource = new ComputationSchedulingResource(); + schedulingResource.setTaskDetailResource(this); + return schedulingResource; + case ADVANCE_INPUT_DATA_HANDLING: + AdvanceInputDataHandlingResource inputDataHandlingResource = new AdvanceInputDataHandlingResource(); + inputDataHandlingResource.setTaskDetailResource(this); + return inputDataHandlingResource; + case ADVANCE_OUTPUT_DATA_HANDLING: + AdvancedOutputDataHandlingResource outputDataHandlingResource = new AdvancedOutputDataHandlingResource(); + outputDataHandlingResource.setTaskDetailResource(this); + return outputDataHandlingResource; + case QOS_PARAM: + QosParamResource qosParamResource = new QosParamResource(); + qosParamResource.setTaskDetailResource(this); + return qosParamResource; + default: + logger.error("Unsupported resource type for task detail resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported resource type for task detail resource."); + } + } + + + public void remove(ResourceType type, Object name) throws RegistryException{ + EntityManager em = null; + try { + em = ResourceUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + QueryGenerator generator; + switch (type) { + case ERROR_DETAIL: + generator = new QueryGenerator(ERROR_DETAIL); + generator.setParameter(ErrorDetailConstants.TASK_ID, name); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + case NOTIFICATION_EMAIL: + generator = new QueryGenerator(NOTIFICATION_EMAIL); + generator.setParameter(NotificationEmailConstants.TASK_ID, name); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + case APPLICATION_INPUT: + generator = new QueryGenerator(APPLICATION_INPUT); + generator.setParameter(ApplicationInputConstants.TASK_ID, name); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + case APPLICATION_OUTPUT: + generator = new QueryGenerator(APPLICATION_OUTPUT); + generator.setParameter(ApplicationOutputConstants.TASK_ID, name); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + case JOB_DETAIL: + generator = new QueryGenerator(JOB_DETAIL); + generator.setParameter(JobDetailConstants.TASK_ID, taskId); + generator.setParameter(JobDetailConstants.JOB_ID, name); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + case DATA_TRANSFER_DETAIL: + generator = new QueryGenerator(DATA_TRANSFER_DETAIL); + generator.setParameter(DataTransferDetailConstants.TRANSFER_ID, name); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + case STATUS: + generator = new QueryGenerator(STATUS); + generator.setParameter(StatusConstants.TASK_ID, name); + generator.setParameter(StatusConstants.STATUS_TYPE, StatusType.TASK.toString()); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + case COMPUTATIONAL_RESOURCE_SCHEDULING: + generator = new QueryGenerator(COMPUTATIONAL_RESOURCE_SCHEDULING); + generator.setParameter(ComputationalResourceSchedulingConstants.TASK_ID, name); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + case ADVANCE_INPUT_DATA_HANDLING: + generator = new QueryGenerator(ADVANCE_INPUT_DATA_HANDLING); + generator.setParameter(AdvancedInputDataHandlingConstants.TASK_ID, name); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + case ADVANCE_OUTPUT_DATA_HANDLING: + generator = new QueryGenerator(ADVANCE_OUTPUT_DATA_HANDLING); + generator.setParameter(AdvancedOutputDataHandlingConstants.TASK_ID, name); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + case QOS_PARAM: + generator = new QueryGenerator(QOS_PARAMS); + generator.setParameter(QosParamsConstants.TASK_ID, name); + q = generator.deleteQuery(em); + q.executeUpdate(); + break; + default: + logger.error("Unsupported resource type for task detail resource.", new IllegalArgumentException()); + break; + } + em.getTransaction().commit(); + 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(); + } + } + } + + + public Resource get(ResourceType type, Object name) throws RegistryException{ + EntityManager em = null; + try { + em = ResourceUtils.getEntityManager(); + em.getTransaction().begin(); + QueryGenerator generator; + Query q; + switch (type) { + case ERROR_DETAIL: + generator = new QueryGenerator(ERROR_DETAIL); + generator.setParameter(ErrorDetailConstants.TASK_ID, name); + q = generator.selectQuery(em); + ErrorDetail errorDetail = (ErrorDetail) q.getSingleResult(); + ErrorDetailResource errorDetailResource = (ErrorDetailResource) Utils.getResource(ResourceType.ERROR_DETAIL, errorDetail); + em.getTransaction().commit(); + em.close(); + return errorDetailResource; + case NOTIFICATION_EMAIL: + generator = new QueryGenerator(NOTIFICATION_EMAIL); + generator.setParameter(NotificationEmailConstants.TASK_ID, name); + q = generator.selectQuery(em); + Notification_Email notificationEmail = (Notification_Email) q.getSingleResult(); + NotificationEmailResource emailResource = (NotificationEmailResource) Utils.getResource(ResourceType.NOTIFICATION_EMAIL, notificationEmail); + em.getTransaction().commit(); + em.close(); + return emailResource; + case APPLICATION_INPUT: + generator = new QueryGenerator(APPLICATION_INPUT); + generator.setParameter(ApplicationInputConstants.TASK_ID, name); + q = generator.selectQuery(em); + ApplicationInput applicationInput = (ApplicationInput) q.getSingleResult(); + ApplicationInputResource inputResource = (ApplicationInputResource) Utils.getResource(ResourceType.APPLICATION_INPUT, applicationInput); + em.getTransaction().commit(); + em.close(); + return inputResource; + case APPLICATION_OUTPUT: + generator = new QueryGenerator(APPLICATION_OUTPUT); + generator.setParameter(ApplicationOutputConstants.TASK_ID, name); + q = generator.selectQuery(em); + ApplicationOutput applicationOutput = (ApplicationOutput) q.getSingleResult(); + ApplicationOutputResource outputResource = (ApplicationOutputResource) Utils.getResource(ResourceType.APPLICATION_OUTPUT, applicationOutput); + em.getTransaction().commit(); + em.close(); + return outputResource; + case JOB_DETAIL: + generator = new QueryGenerator(JOB_DETAIL); + generator.setParameter(JobDetailConstants.JOB_ID, name); + generator.setParameter(JobDetailConstants.TASK_ID, taskId); + q = generator.selectQuery(em); + JobDetail jobDetail = (JobDetail) q.getSingleResult(); + JobDetailResource jobDetailResource = (JobDetailResource) Utils.getResource(ResourceType.JOB_DETAIL, jobDetail); + em.getTransaction().commit(); + em.close(); + return jobDetailResource; + case DATA_TRANSFER_DETAIL: + generator = new QueryGenerator(DATA_TRANSFER_DETAIL); + generator.setParameter(DataTransferDetailConstants.TRANSFER_ID, name); + q = generator.selectQuery(em); + DataTransferDetail transferDetail = (DataTransferDetail) q.getSingleResult(); + DataTransferDetailResource transferDetailResource = (DataTransferDetailResource) Utils.getResource(ResourceType.DATA_TRANSFER_DETAIL, transferDetail); + em.getTransaction().commit(); + em.close(); + return transferDetailResource; + case STATUS: + generator = new QueryGenerator(STATUS); + generator.setParameter(StatusConstants.TASK_ID, name); + generator.setParameter(StatusConstants.STATUS_TYPE, StatusType.TASK.toString()); + q = generator.selectQuery(em); + Status status = (Status) q.getSingleResult(); + StatusResource statusResource = (StatusResource) Utils.getResource(ResourceType.STATUS, status); + em.getTransaction().commit(); + em.close(); + return statusResource; + case COMPUTATIONAL_RESOURCE_SCHEDULING: + generator = new QueryGenerator(COMPUTATIONAL_RESOURCE_SCHEDULING); + generator.setParameter(ComputationalResourceSchedulingConstants.TASK_ID, name); + q = generator.selectQuery(em); + Computational_Resource_Scheduling resourceScheduling = (Computational_Resource_Scheduling) q.getSingleResult(); + ComputationSchedulingResource schedulingResource = (ComputationSchedulingResource) Utils.getResource(ResourceType.COMPUTATIONAL_RESOURCE_SCHEDULING, resourceScheduling); + em.getTransaction().commit(); + em.close(); + return schedulingResource; + case ADVANCE_INPUT_DATA_HANDLING: + generator = new QueryGenerator(ADVANCE_INPUT_DATA_HANDLING); + generator.setParameter(AdvancedInputDataHandlingConstants.TASK_ID, name); + q = generator.selectQuery(em); + AdvancedInputDataHandling dataHandling = (AdvancedInputDataHandling) q.getSingleResult(); + AdvanceInputDataHandlingResource inputDataHandlingResource = (AdvanceInputDataHandlingResource) Utils.getResource(ResourceType.ADVANCE_INPUT_DATA_HANDLING, dataHandling); + em.getTransaction().commit(); + em.close(); + return inputDataHandlingResource; + case ADVANCE_OUTPUT_DATA_HANDLING: + generator = new QueryGenerator(ADVANCE_OUTPUT_DATA_HANDLING); + generator.setParameter(AdvancedOutputDataHandlingConstants.TASK_ID, name); + q = generator.selectQuery(em); + AdvancedOutputDataHandling outputDataHandling = (AdvancedOutputDataHandling) q.getSingleResult(); + AdvancedOutputDataHandlingResource outputDataHandlingResource = (AdvancedOutputDataHandlingResource) Utils.getResource(ResourceType.ADVANCE_OUTPUT_DATA_HANDLING, outputDataHandling); + em.getTransaction().commit(); + em.close(); + return outputDataHandlingResource; + case QOS_PARAM: + generator = new QueryGenerator(QOS_PARAMS); + generator.setParameter(QosParamsConstants.TASK_ID, name); + q = generator.selectQuery(em); + QosParam qosParam = (QosParam) q.getSingleResult(); + QosParamResource qosParamResource = (QosParamResource) Utils.getResource(ResourceType.QOS_PARAM, qosParam); + em.getTransaction().commit(); + em.close(); + return qosParamResource; + default: + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported resource type for workflow node resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported resource type for workflow node resource."); + } + } 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(); + } + } + } + + + public List<Resource> get(ResourceType type) throws RegistryException{ + List<Resource> resourceList = new ArrayList<Resource>(); + EntityManager em = null; + try { + em = ResourceUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + QueryGenerator generator; + List results; + switch (type) { + case ERROR_DETAIL: + generator = new QueryGenerator(ERROR_DETAIL); + generator.setParameter(ErrorDetailConstants.TASK_ID, taskId); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ErrorDetail errorDetail = (ErrorDetail) result; + ErrorDetailResource errorDetailResource = + (ErrorDetailResource) Utils.getResource(ResourceType.ERROR_DETAIL, errorDetail); + resourceList.add(errorDetailResource); + } + } + break; + case NOTIFICATION_EMAIL: + generator = new QueryGenerator(NOTIFICATION_EMAIL); + generator.setParameter(NotificationEmailConstants.TASK_ID, taskId); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + Notification_Email notificationEmail = (Notification_Email) result; + NotificationEmailResource emailResource = + (NotificationEmailResource) Utils.getResource(ResourceType.NOTIFICATION_EMAIL, notificationEmail); + resourceList.add(emailResource); + } + } + break; + case APPLICATION_INPUT: + generator = new QueryGenerator(APPLICATION_INPUT); + generator.setParameter(ApplicationInputConstants.TASK_ID, taskId); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationInput applicationInput = (ApplicationInput) result; + ApplicationInputResource inputResource = + (ApplicationInputResource) Utils.getResource(ResourceType.APPLICATION_INPUT, applicationInput); + resourceList.add(inputResource); + } + } + break; + case APPLICATION_OUTPUT: + generator = new QueryGenerator(APPLICATION_OUTPUT); + generator.setParameter(ApplicationOutputConstants.TASK_ID, taskId); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + ApplicationOutputResource outputResource = + (ApplicationOutputResource) Utils.getResource(ResourceType.APPLICATION_OUTPUT, applicationOutput); + resourceList.add(outputResource); + } + } + break; + case JOB_DETAIL: + generator = new QueryGenerator(JOB_DETAIL); + generator.setParameter(JobDetailConstants.TASK_ID, taskId); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + JobDetail jobDetail = (JobDetail) result; + JobDetailResource jobDetailResource = + (JobDetailResource) Utils.getResource(ResourceType.JOB_DETAIL, jobDetail); + resourceList.add(jobDetailResource); + } + } + break; + case DATA_TRANSFER_DETAIL: + generator = new QueryGenerator(DATA_TRANSFER_DETAIL); + generator.setParameter(DataTransferDetailConstants.TASK_ID, taskId); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + DataTransferDetail transferDetail = (DataTransferDetail) result; + DataTransferDetailResource transferDetailResource = + (DataTransferDetailResource) Utils.getResource(ResourceType.DATA_TRANSFER_DETAIL, transferDetail); + resourceList.add(transferDetailResource); + } + } + break; + case STATUS: + generator = new QueryGenerator(STATUS); + generator.setParameter(StatusConstants.TASK_ID, taskId); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + Status status = (Status) result; + StatusResource statusResource = + (StatusResource) Utils.getResource(ResourceType.STATUS, status); + resourceList.add(statusResource); + } + } + break; + default: + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported resource type for workflow node details resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + em.getTransaction().commit(); + 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(); + } + } + return resourceList; + } + + + public void save() throws RegistryException{ + EntityManager em = null; + try { + em = ResourceUtils.getEntityManager(); + TaskDetail taskDetail = em.find(TaskDetail.class, taskId); + em.close(); + em = ResourceUtils.getEntityManager(); + em.getTransaction().begin(); + WorkflowNodeDetail workflowNodeDetail = em.find(WorkflowNodeDetail.class, workflowNodeDetailResource.getNodeInstanceId()); + if (taskDetail != null) { + updateTaskDetail(taskDetail, workflowNodeDetail); + em.merge(taskDetail); + } else { + taskDetail = new TaskDetail(); + updateTaskDetail(taskDetail, workflowNodeDetail); + em.persist(taskDetail); + } + em.getTransaction().commit(); + } 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(); + } + } + } + + private void updateTaskDetail(TaskDetail taskDetail, + WorkflowNodeDetail workflowNodeDetail) { + taskDetail.setTaskId(taskId); + taskDetail.setNodeDetail(workflowNodeDetail); + taskDetail.setNodeId(workflowNodeDetailResource.getNodeInstanceId()); + taskDetail.setCreationTime(creationTime); + taskDetail.setAppId(applicationId); + taskDetail.setAppVersion(applicationVersion); + taskDetail.setAllowNotification(enableEmailNotifications); + taskDetail.setApplicationDeploymentId(getApplicationDeploymentId()); + } + + public List<ApplicationInputResource> getApplicationInputs() throws RegistryException{ + List<ApplicationInputResource> applicationInputResources = new ArrayList<ApplicationInputResource>(); + List<Resource> resources = get(ResourceType.APPLICATION_INPUT); + for (Resource resource : resources) { + ApplicationInputResource inputResource = (ApplicationInputResource) resource; + applicationInputResources.add(inputResource); + } + return applicationInputResources; + } + + public List<ApplicationOutputResource> getApplicationOutputs() throws RegistryException{ + List<ApplicationOutputResource> outputResources = new ArrayList<ApplicationOutputResource>(); + List<Resource> resources = get(ResourceType.APPLICATION_OUTPUT); + for (Resource resource : resources) { + ApplicationOutputResource outputResource = (ApplicationOutputResource) resource; + outputResources.add(outputResource); + } + return outputResources; + } + + public StatusResource getTaskStatus() throws RegistryException{ + List<Resource> resources = get(ResourceType.STATUS); + for (Resource resource : resources) { + StatusResource taskStatus = (StatusResource) resource; + if(taskStatus.getStatusType().equals(StatusType.TASK.toString())){ + if (taskStatus.getState() == null || taskStatus.getState().equals("") ){ + taskStatus.setState("UNKNOWN"); + } + return taskStatus; + } + } + return null; + } + + public List<JobDetailResource> getJobDetailList() throws RegistryException{ + List<JobDetailResource> jobDetailResources = new ArrayList<JobDetailResource>(); + List<Resource> resources = get(ResourceType.JOB_DETAIL); + for (Resource resource : resources) { + JobDetailResource jobDetailResource = (JobDetailResource) resource; + jobDetailResources.add(jobDetailResource); + } + return jobDetailResources; + } + + public List<DataTransferDetailResource> getDataTransferDetailList() throws RegistryException{ + List<DataTransferDetailResource> transferDetails = new ArrayList<DataTransferDetailResource>(); + List<Resource> resources = get(ResourceType.DATA_TRANSFER_DETAIL); + for (Resource resource : resources) { + DataTransferDetailResource transferDetailResource = (DataTransferDetailResource) resource; + transferDetails.add(transferDetailResource); + } + return transferDetails; + } + + public List<ErrorDetailResource> getErrorDetailList() throws RegistryException{ + List<ErrorDetailResource> errorDetailResources = new ArrayList<ErrorDetailResource>(); + List<Resource> resources = get(ResourceType.ERROR_DETAIL); + for (Resource resource : resources) { + ErrorDetailResource errorDetailResource = (ErrorDetailResource) resource; + errorDetailResources.add(errorDetailResource); + } + return errorDetailResources; + } + + public ComputationSchedulingResource getComputationScheduling (String taskId) throws RegistryException{ + return (ComputationSchedulingResource)get(ResourceType.COMPUTATIONAL_RESOURCE_SCHEDULING, taskId); + } + + public AdvanceInputDataHandlingResource getInputDataHandling (String taskId) throws RegistryException{ + return (AdvanceInputDataHandlingResource)get(ResourceType.ADVANCE_INPUT_DATA_HANDLING, taskId); + } + + public AdvancedOutputDataHandlingResource getOutputDataHandling (String taskId) throws RegistryException{ + return (AdvancedOutputDataHandlingResource)get(ResourceType.ADVANCE_OUTPUT_DATA_HANDLING, taskId); + } + + public JobDetailResource createJobDetail (String jobId) throws RegistryException{ + JobDetailResource resource = (JobDetailResource)create(ResourceType.JOB_DETAIL); + resource.setJobId(jobId); + return resource; + } + + public JobDetailResource getJobDetail (String jobId) throws RegistryException{ + return (JobDetailResource)get(ResourceType.JOB_DETAIL, jobId); + } + + public DataTransferDetailResource getDataTransferDetail (String dataTransferId) throws RegistryException{ + return (DataTransferDetailResource)get(ResourceType.DATA_TRANSFER_DETAIL, dataTransferId); + } + + public boolean isTaskStatusExist (String taskId) throws RegistryException{ + return isExists(ResourceType.STATUS, taskId); + } + + public String getApplicationDeploymentId() { + return applicationDeploymentId; + } + + public void setApplicationDeploymentId(String applicationDeploymentId) { + this.applicationDeploymentId = applicationDeploymentId; + } + + public List<NotificationEmailResource> getNotificationEmails () throws RegistryException{ + List<NotificationEmailResource> emailResources = new ArrayList<NotificationEmailResource>(); + List<Resource> resources = get(ResourceType.NOTIFICATION_EMAIL); + for (Resource resource : resources) { + emailResources.add((NotificationEmailResource) resource); + } + return emailResources; + } +}
http://git-wip-us.apache.org/repos/asf/airavata/blob/e13d90da/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java new file mode 100644 index 0000000..11f2a4f --- /dev/null +++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java @@ -0,0 +1,186 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ +package org.apache.airavata.persistance.registry.jpa.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.SecurityUtil; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.persistance.registry.jpa.Resource; +import org.apache.airavata.persistance.registry.jpa.ResourceType; +import org.apache.airavata.persistance.registry.jpa.ResourceUtils; +import org.apache.airavata.persistance.registry.jpa.model.Users; +import org.apache.airavata.registry.cpi.RegistryException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import java.security.NoSuchAlgorithmException; +import java.util.List; + +public class UserResource extends AbstractResource { + private final static Logger logger = LoggerFactory.getLogger(UserResource.class); + private String userName; + private String password; + /** + * + */ + public UserResource() { + } + + /** + * + * @param userName user name + */ + public void setUserName(String userName) { + this.userName = userName; + } + + /** + * + * @return user name + */ + public String getUserName() { + return userName; + } + + + /** + * User is a hypothical data structure. + * @param type child resource type + * @return child resource + */ + public Resource create(ResourceType type) throws RegistryException { + logger.error("Unsupported resource type for user resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + /** + * + * @param type child resource type + * @param name child resource name + */ + public void remove(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for user resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + /** + * + * @param type child resource type + * @param name child resource name + * @return UnsupportedOperationException + */ + public Resource get(ResourceType type, Object name) throws RegistryException { + logger.error("Unsupported resource type for user resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + /** + * + * @param type child resource type + * @return UnsupportedOperationException + */ + public List<Resource> get(ResourceType type) throws RegistryException{ + logger.error("Unsupported resource type for user resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + /** + * saveExperiment user to the database + */ + public void save() throws RegistryException { + EntityManager em = null; + try { + em = ResourceUtils.getEntityManager(); + Users existingUser = em.find(Users.class, userName); + em.close(); + + em = ResourceUtils.getEntityManager(); + em.getTransaction().begin(); + Users user = new Users(); + user.setUser_name(userName); + if (password != null && !password.equals("")) { + try { + user.setPassword(SecurityUtil.digestString(password, + ServerSettings.getSetting("default.registry.password.hash.method"))); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("Error hashing default admin password. Invalid hash algorithm.", e); + } catch (ApplicationSettingsException e) { + throw new RuntimeException("Error reading hash algorithm from configurations", e); + } + } + if (existingUser != null) { + if (password != null && !password.equals("")) { + try { + existingUser.setPassword(SecurityUtil.digestString(password, + ServerSettings.getSetting("default.registry.password.hash.method"))); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("Error hashing default admin password. Invalid hash algorithm.", e); + } catch (ApplicationSettingsException e) { + throw new RuntimeException("Error reading hash algorithm from configurations", e); + } + } + user = em.merge(existingUser); + } else { + em.persist(user); + } + em.getTransaction().commit(); + 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(); + } + } + } + + /** + * + * @param type child resource type + * @param name child resource name + * @return UnsupportedOperationException + */ + public boolean isExists(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for user resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + /** + * + * @return password + */ + public String getPassword() { + return password; + } + + /** + * + * @param password password + */ + public void setPassword(String password) { + this.password = password; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/e13d90da/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java ---------------------------------------------------------------------- diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java new file mode 100644 index 0000000..69ada6d --- /dev/null +++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java @@ -0,0 +1,824 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.airavata.persistance.registry.jpa.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.persistance.registry.jpa.JPAConstants; +import org.apache.airavata.persistance.registry.jpa.Resource; +import org.apache.airavata.persistance.registry.jpa.ResourceType; +import org.apache.airavata.persistance.registry.jpa.model.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.URI; + + +public class Utils { + private final static Logger logger = LoggerFactory.getLogger(Utils.class); + + public static String getJDBCFullURL(){ + String jdbcUrl = getJDBCURL(); + String jdbcUser = getJDBCUser(); + String jdbcPassword = getJDBCPassword(); + jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword; + return jdbcUrl; + } + + public static String getJDBCURL(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_URL); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static String getHost(){ + try{ + String jdbcURL = getJDBCURL(); + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getHost(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static int getPort(){ + try{ + String jdbcURL = getJDBCURL(); + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getPort(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return -1; + } + } + + public static int getJPACacheSize (){ + try { + String cache = ServerSettings.getSetting(JPAConstants.JPA_CACHE_SIZE, "5000"); + return Integer.parseInt(cache); + }catch (Exception e){ + logger.error(e.getMessage(), e); + return -1; + } + } + + public static String isCachingEnabled (){ + try { + return ServerSettings.getSetting(JPAConstants.ENABLE_CACHING, "true"); + }catch (Exception e){ + logger.error(e.getMessage(), e); + return "true"; + } + } + + public static String getDBType(){ + try{ + String jdbcURL = getJDBCURL(); + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getScheme(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static boolean isDerbyStartEnabled(){ + try { + String s = ServerSettings.getSetting(JPAConstants.KEY_DERBY_START_ENABLE); + if("true".equals(s)){ + return true; + } + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return false; + } + return false; + } + + public static String getJDBCUser(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_USER); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static String getValidationQuery(){ + try { + return ServerSettings.getSetting(JPAConstants.VALIDATION_QUERY); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static String getJDBCPassword(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_PASSWORD); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + + } + + public static String getJDBCDriver(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_DRIVER); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } + + /** + * + * @param type model type + * @param o model type instance + * @return corresponding resource object + */ + public static Resource getResource(ResourceType type, Object o) { + switch (type){ + case GATEWAY: + if (o instanceof Gateway) { + return createGateway((Gateway) o); + } else { + logger.error("Object should be a Gateway.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a Gateway."); + } + case PROJECT: + if (o instanceof Project){ + return createProject((Project) o); + } else { + logger.error("Object should be a Project.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a Project."); + } + case PROJECT_USER: + if (o instanceof ProjectUser){ + return createProjectUser((ProjectUser)o); + }else { + logger.error("Object should be a ProjectUser.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a ProjectUser."); + } + case CONFIGURATION: + if(o instanceof Configuration){ + return createConfiguration((Configuration) o); + }else { + logger.error("Object should be a Configuration.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a Configuration."); + } + case USER: + if(o instanceof Users) { + return createUser((Users) o); + }else { + logger.error("Object should be a User.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a User."); + } + case GATEWAY_WORKER: + if (o instanceof Gateway_Worker){ + return createGatewayWorker((Gateway_Worker)o); + } else { + logger.error("Object should be a Gateway Worker.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a Gateway Worker."); + } + case EXPERIMENT: + if (o instanceof Experiment){ + return createExperiment((Experiment)o); + }else { + logger.error("Object should be a Experiment.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a Experiment."); + } + case NOTIFICATION_EMAIL: + if (o instanceof Notification_Email){ + return createNotificationEmail((Notification_Email)o); + }else { + logger.error("Object should be a Experiment.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a Experiment."); + } + case EXPERIMENT_INPUT: + if (o instanceof Experiment_Input){ + return createExperimentInput((Experiment_Input)o); + }else { + logger.error("Object should be a Experiment input data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a Experiment input data."); + } + case EXPERIMENT_OUTPUT: + if (o instanceof Experiment_Output){ + return createExperimentOutput((Experiment_Output)o); + }else { + logger.error("Object should be a Experiment output data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a Experiment output data."); + } + case WORKFLOW_NODE_DETAIL: + if (o instanceof WorkflowNodeDetail){ + return createWorkflowNodeDetail((WorkflowNodeDetail)o); + }else { + logger.error("Object should be a Workflow node data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a Workflow node data."); + } + case TASK_DETAIL: + if (o instanceof TaskDetail){ + return createTaskDetail((TaskDetail)o); + }else { + logger.error("Object should be a task detail data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a task detail data."); + } + case ERROR_DETAIL: + if (o instanceof ErrorDetail){ + return createErrorDetail((ErrorDetail)o); + }else { + logger.error("Object should be a error detail data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a error detail data."); + } + case APPLICATION_INPUT: + if (o instanceof ApplicationInput){ + return createApplicationInput((ApplicationInput)o); + }else { + logger.error("Object should be a application input data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a application input data."); + } + case APPLICATION_OUTPUT: + if (o instanceof ApplicationOutput){ + return createApplicationOutput((ApplicationOutput)o); + }else { + logger.error("Object should be a application output data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a application output data."); + } + case NODE_INPUT: + if (o instanceof NodeInput){ + return createNodeInput((NodeInput)o); + }else { + logger.error("Object should be a node input data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a node input data."); + } + case NODE_OUTPUT: + if (o instanceof NodeOutput){ + return createNodeOutput((NodeOutput)o); + }else { + logger.error("Object should be a node output data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a node output data."); + } + case JOB_DETAIL: + if (o instanceof JobDetail){ + return createJobDetail((JobDetail)o); + }else { + logger.error("Object should be a job detail data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a job detail data."); + } + case DATA_TRANSFER_DETAIL: + if (o instanceof DataTransferDetail){ + return createDataTransferResource((DataTransferDetail)o); + }else { + logger.error("Object should be a data transfer detail data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a data transfer detail data."); + } + case STATUS: + if (o instanceof Status){ + return createStatusResource((Status)o); + }else { + logger.error("Object should be a status data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be a status data."); + } + case CONFIG_DATA: + if (o instanceof ExperimentConfigData){ + return createExConfigDataResource((ExperimentConfigData)o); + }else { + logger.error("Object should be a experiment config data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be experiment config data."); + } + case COMPUTATIONAL_RESOURCE_SCHEDULING: + if (o instanceof Computational_Resource_Scheduling){ + return createComputationalScheduling((Computational_Resource_Scheduling)o); + }else { + logger.error("Object should be a scheduling resource data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be scheduling resource data."); + } + case ADVANCE_INPUT_DATA_HANDLING: + if (o instanceof AdvancedInputDataHandling){ + return createAdvancedInputDataResource((AdvancedInputDataHandling)o); + }else { + logger.error("Object should be a advanced input data handling data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be advanced input data handling data."); + } + case ADVANCE_OUTPUT_DATA_HANDLING: + if (o instanceof AdvancedOutputDataHandling){ + return createAdvancedOutputDataResource((AdvancedOutputDataHandling)o); + }else { + logger.error("Object should be a advanced output data handling data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be advanced output data handling data."); + } + case QOS_PARAM: + if (o instanceof QosParam){ + return createQosParamResource((QosParam)o); + }else { + logger.error("Object should be a QOSparam data.", new IllegalArgumentException()); + throw new IllegalArgumentException("Object should be QOSparam data."); + } + default: + logger.error("Illegal data type..", new IllegalArgumentException()); + throw new IllegalArgumentException("Illegal data type.."); + } + } + + /** + * + * @param o Gateway model object + * @return GatewayResource object + */ + private static Resource createGateway(Gateway o) { + GatewayResource gatewayResource = new GatewayResource(); + gatewayResource.setGatewayName(o.getGateway_name()); + gatewayResource.setGatewayId(o.getGateway_id()); + gatewayResource.setDomain(o.getDomain()); + gatewayResource.setEmailAddress(o.getEmailAddress()); + return gatewayResource; + } + + /** + * + * @param o Project model object + * @return ProjectResource object + */ + private static Resource createProject(Project o) { + ProjectResource projectResource = new ProjectResource(); + if (o != null){ + projectResource.setId(o.getProject_id()); + projectResource.setName(o.getProject_name()); + GatewayResource gatewayResource = (GatewayResource)createGateway(o.getGateway()); + projectResource.setGateway(gatewayResource); + Gateway_Worker gateway_worker = new Gateway_Worker(); + gateway_worker.setGateway(o.getGateway()); + gateway_worker.setUser(o.getUsers()); + gateway_worker.setUser_name(o.getUsers().getUser_name()); + WorkerResource workerResource = (WorkerResource) createGatewayWorker(gateway_worker); + projectResource.setWorker(workerResource); + projectResource.setDescription(o.getDescription()); + projectResource.setCreationTime(o.getCreationTime()); + } + + return projectResource; + } + + private static Resource createProjectUser(ProjectUser o) { + ProjectUserResource projectUserResource = new ProjectUserResource(); + if (o != null){ + projectUserResource.setUserName(o.getUser().getUser_name()); + projectUserResource.setProjectId(o.getProjectId()); + } + return projectUserResource; + } + + /** + * + * @param o configuration model object + * @return configuration resource object + */ + private static Resource createConfiguration (Configuration o){ + ConfigurationResource configurationResource = new ConfigurationResource(); + if (o != null){ + configurationResource.setConfigKey(o.getConfig_key()); + configurationResource.setConfigVal(o.getConfig_val()); + configurationResource.setExpireDate(o.getExpire_date()); + configurationResource.setCategoryID(o.getCategory_id()); + } + + return configurationResource; + } + + /** + * + * @param o Gateway_Worker model object + * @return Gateway_Worker resource object + */ + private static Resource createGatewayWorker(Gateway_Worker o) { + if (o != null){ + GatewayResource gatewayResource = new GatewayResource(o.getGateway().getGateway_id()); + gatewayResource.setDomain(o.getGateway().getGateway_name()); + gatewayResource.setDomain(o.getGateway().getDomain()); + gatewayResource.setEmailAddress(o.getGateway().getEmailAddress()); + return new WorkerResource(o.getUser_name(), gatewayResource); + } + return null; + } + + /** + * + * @param o Users model object + * @return UserResource object + */ + private static Resource createUser(Users o) { + UserResource userResource = new UserResource(); + if (o != null){ + userResource.setUserName(o.getUser_name()); + userResource.setPassword(o.getPassword()); + } + + return userResource; + } + + /** + * @param o Experiment model object + * @return Experiment resource object + */ + private static Resource createExperiment(Experiment o) { + ExperimentResource experimentResource = new ExperimentResource(); + if (o != null){ + GatewayResource gatewayResource = (GatewayResource)createGateway(o.getGateway()); + experimentResource.setGateway(gatewayResource); + experimentResource.setExecutionUser(o.getExecutionUser()); + if (o.getProject() != null){ + ProjectResource projectResource = (ProjectResource)createProject(o.getProject()); + experimentResource.setProject(projectResource); + } + experimentResource.setExpID(o.getExpId()); + experimentResource.setExpName(o.getExpName()); + experimentResource.setCreationTime(o.getCreationTime()); + experimentResource.setDescription(o.getExpDesc()); + experimentResource.setApplicationId(o.getApplicationId()); + experimentResource.setApplicationVersion(o.getAppVersion()); + experimentResource.setWorkflowTemplateId(o.getWorkflowTemplateId()); + experimentResource.setWorkflowTemplateVersion(o.getWorkflowTemplateVersion()); + experimentResource.setWorkflowExecutionId(o.getWorkflowExecutionId()); + experimentResource.setEnableEmailNotifications(o.isAllowNotification()); + experimentResource.setGatewayExecutionId(o.getGatewayExecutionId()); + } + + return experimentResource; + } + + private static Resource createNotificationEmail (Notification_Email o){ + NotificationEmailResource emailResource = new NotificationEmailResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + emailResource.setExperimentResource(experimentResource); + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTaskDetail()); + emailResource.setTaskDetailResource(taskDetailResource); + emailResource.setEmailAddress(o.getEmailAddress()); + } + return emailResource; + } + + private static Resource createExperimentInput (Experiment_Input o){ + ExperimentInputResource eInputResource = new ExperimentInputResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + eInputResource.setExperimentResource(experimentResource); + eInputResource.setDataType(o.getDataType()); + eInputResource.setMetadata(o.getMetadata()); + eInputResource.setExperimentKey(o.getEx_key()); + eInputResource.setAppArgument(o.getAppArgument()); + eInputResource.setInputOrder(o.getInputOrder()); + eInputResource.setStandardInput(o.isStandardInput()); + eInputResource.setUserFriendlyDesc(o.getUserFriendlyDesc()); + eInputResource.setRequired(o.isRequired()); + eInputResource.setRequiredToCMD(o.isRequiredToCMD()); + eInputResource.setDataStaged(o.isDataStaged()); + + if (o.getValue() != null){ + eInputResource.setValue(new String(o.getValue())); + } + + } + return eInputResource; + } + + private static Resource createExperimentOutput (Experiment_Output o){ + ExperimentOutputResource eOutputResource = new ExperimentOutputResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + eOutputResource.setExperimentResource(experimentResource); + eOutputResource.setExperimentKey(o.getEx_key()); + if (o.getValue() != null){ + eOutputResource.setValue(new String(o.getValue())); + } + eOutputResource.setDataType(o.getDataType()); + eOutputResource.setRequired(o.isRequired()); + eOutputResource.setRequiredToCMD(o.isRequiredToCMD()); + eOutputResource.setDataMovement(o.isDataMovement()); + eOutputResource.setDataNameLocation(o.getDataNameLocation()); + eOutputResource.setSearchQuery(o.getSearchQuery()); + eOutputResource.setAppArgument(o.getApplicationArgument()); + } + return eOutputResource; + } + + private static Resource createWorkflowNodeDetail (WorkflowNodeDetail o){ + WorkflowNodeDetailResource nodeDetailResource = new WorkflowNodeDetailResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + nodeDetailResource.setExperimentResource(experimentResource); + nodeDetailResource.setCreationTime(o.getCreationTime()); + nodeDetailResource.setNodeInstanceId(o.getNodeId()); + nodeDetailResource.setNodeName(o.getNodeName()); + nodeDetailResource.setExecutionUnit(o.getExecutionUnit()); + nodeDetailResource.setExecutionUnitData(o.getExecutionUnitData()); + + } + return nodeDetailResource; + } + + private static Resource createTaskDetail(TaskDetail o){ + TaskDetailResource taskDetailResource = new TaskDetailResource(); + if ( o != null){ + WorkflowNodeDetailResource nodeDetailResource = (WorkflowNodeDetailResource)createWorkflowNodeDetail(o.getNodeDetail()); + taskDetailResource.setWorkflowNodeDetailResource(nodeDetailResource); + taskDetailResource.setCreationTime(o.getCreationTime()); + taskDetailResource.setTaskId(o.getTaskId()); + taskDetailResource.setApplicationId(o.getAppId()); + taskDetailResource.setApplicationVersion(o.getAppVersion()); + taskDetailResource.setApplicationDeploymentId(o.getApplicationDeploymentId()); + taskDetailResource.setEnableEmailNotifications(o.isAllowNotification()); + } + return taskDetailResource; + } + + private static Resource createErrorDetail (ErrorDetail o){ + ErrorDetailResource errorDetailResource = new ErrorDetailResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + errorDetailResource.setExperimentResource(experimentResource); + if (o.getTask() != null){ + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTask()); + errorDetailResource.setTaskDetailResource(taskDetailResource); + } + if (o.getNodeDetails() != null){ + WorkflowNodeDetailResource nodeDetailResource = (WorkflowNodeDetailResource)createWorkflowNodeDetail(o.getNodeDetails()); + errorDetailResource.setNodeDetail(nodeDetailResource); + } + errorDetailResource.setErrorId(o.getErrorId()); + errorDetailResource.setJobId(o.getJobId()); + errorDetailResource.setCreationTime(o.getCreationTime()); + if (o.getActualErrorMsg() != null){ + errorDetailResource.setActualErrorMsg(new String(o.getActualErrorMsg())); + } + errorDetailResource.setUserFriendlyErrorMsg(o.getUserFriendlyErrorMsg()); + errorDetailResource.setTransientPersistent(o.isTransientPersistent()); + errorDetailResource.setErrorCategory(o.getErrorCategory()); + errorDetailResource.setCorrectiveAction(o.getCorrectiveAction()); + errorDetailResource.setActionableGroup(o.getActionableGroup()); + } + + return errorDetailResource; + } + + private static Resource createApplicationInput (ApplicationInput o){ + ApplicationInputResource inputResource = new ApplicationInputResource(); + if (o != null){ + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTask()); + inputResource.setTaskDetailResource(taskDetailResource); + inputResource.setInputKey(o.getInputKey()); + inputResource.setDataType(o.getDataType()); + inputResource.setAppArgument(o.getAppArgument()); + inputResource.setInputOrder(o.getInputOrder()); + inputResource.setStandardInput(o.isStandardInput()); + inputResource.setUserFriendlyDesc(o.getUserFriendlyDesc()); + inputResource.setRequired(o.isRequired()); + inputResource.setRequiredToCMD(o.isRequiredToCMD()); + inputResource.setDataStaged(o.isDataStaged()); + if (o.getValue() != null){ + inputResource.setValue(new String(o.getValue())); + } + inputResource.setMetadata(o.getMetadata()); + } + return inputResource; + } + + private static Resource createApplicationOutput (ApplicationOutput o){ + ApplicationOutputResource outputResource = new ApplicationOutputResource(); + if (o != null){ + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTask()); + outputResource.setTaskDetailResource(taskDetailResource); + outputResource.setDataType(o.getDataType()); + outputResource.setOutputKey(o.getOutputKey()); + if (o.getValue() != null){ + outputResource.setValue(new String(o.getValue())); + } + outputResource.setRequired(o.isRequired()); + outputResource.setRequiredToCMD(o.isAddedToCmd()); + outputResource.setDataMovement(o.isDataMovement()); + outputResource.setDataNameLocation(o.getDataNameLocation()); + outputResource.setSearchQuery(o.getSearchQuery()); + outputResource.setAppArgument(o.getApplicationArgument()); + } + return outputResource; + } + + private static Resource createNodeInput (NodeInput o){ + NodeInputResource inputResource = new NodeInputResource(); + if (o != null){ + WorkflowNodeDetailResource nodeDetailResource = (WorkflowNodeDetailResource)createWorkflowNodeDetail(o.getNodeDetails()); + inputResource.setNodeDetailResource(nodeDetailResource); + inputResource.setInputKey(o.getInputKey()); + inputResource.setDataType(o.getDataType()); + inputResource.setValue(o.getValue()); + inputResource.setMetadata(o.getMetadata()); + inputResource.setAppArgument(o.getAppArgument()); + inputResource.setInputOrder(o.getInputOrder()); + inputResource.setStandardInput(o.isStandardInput()); + inputResource.setUserFriendlyDesc(o.getUserFriendlyDesc()); + inputResource.setRequired(o.getIsRequired()); + inputResource.setRequiredToCMD(o.getRequiredToCMD()); + inputResource.setDataStaged(o.isDataStaged()); + } + return inputResource; + } + + private static Resource createNodeOutput (NodeOutput o){ + NodeOutputResource outputResource = new NodeOutputResource(); + if (o != null){ + WorkflowNodeDetailResource nodeDetailResource = (WorkflowNodeDetailResource)createWorkflowNodeDetail(o.getNode()); + outputResource.setNodeDetailResource(nodeDetailResource); + outputResource.setDataType(o.getDataType()); + outputResource.setOutputKey(o.getOutputKey()); + outputResource.setValue(o.getValue()); + outputResource.setRequired(o.isRequired()); + outputResource.setRequiredToCMD(o.isRequiredToCMD()); + outputResource.setDataMovement(o.isDataMovement()); + outputResource.setDataNameLocation(o.getDataNameLocation()); + outputResource.setSearchQuery(o.getSearchQuery()); + outputResource.setAppArgument(o.getApplicationArgument()); + } + + return outputResource; + } + + private static Resource createJobDetail (JobDetail o){ + JobDetailResource jobDetailResource = new JobDetailResource(); + if (o != null){ + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTask()); + jobDetailResource.setTaskDetailResource(taskDetailResource); + if (o.getJobDescription() != null){ + jobDetailResource.setJobDescription(new String(o.getJobDescription())); + } + jobDetailResource.setJobId(o.getJobId()); + jobDetailResource.setCreationTime(o.getCreationTime()); + jobDetailResource.setComputeResourceConsumed(o.getComputeResourceConsumed()); + jobDetailResource.setJobName(o.getJobName()); + jobDetailResource.setWorkingDir(o.getWorkingDir()); + + } + + return jobDetailResource; + } + + private static Resource createDataTransferResource (DataTransferDetail o){ + DataTransferDetailResource transferDetailResource = new DataTransferDetailResource(); + if (o != null){ + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTask()); + transferDetailResource.setTaskDetailResource(taskDetailResource); + transferDetailResource.setTransferId(o.getTransferId()); + transferDetailResource.setCreationTime(o.getCreationTime()); + if (o.getTransferDesc() != null){ + transferDetailResource.setTransferDescription(new String(o.getTransferDesc())); + } + + } + return transferDetailResource; + } + + private static Resource createStatusResource (Status o){ + StatusResource statusResource = new StatusResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + statusResource.setExperimentResource(experimentResource); + if (o.getTask() != null){ + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTask()); + statusResource.setTaskDetailResource(taskDetailResource); + } + if (o.getNode() != null){ + WorkflowNodeDetailResource nodeDetailResource = (WorkflowNodeDetailResource)createWorkflowNodeDetail(o.getNode()); + statusResource.setWorkflowNodeDetail(nodeDetailResource); + } + if (o.getTransferDetail() != null){ + DataTransferDetailResource transferDetailResource = (DataTransferDetailResource)createDataTransferResource(o.getTransferDetail()); + statusResource.setDataTransferDetail(transferDetailResource); + } + statusResource.setStatusId(o.getStatusId()); + statusResource.setJobId(o.getJobId()); + statusResource.setState(o.getState()); + statusResource.setStatusUpdateTime(o.getStatusUpdateTime()); + statusResource.setStatusType(o.getStatusType()); + } + + return statusResource; + } + + private static Resource createExConfigDataResource (ExperimentConfigData o){ + ConfigDataResource configDataResource = new ConfigDataResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + configDataResource.setExperimentResource(experimentResource); + configDataResource.setAiravataAutoSchedule(o.isAiravataAutoSchedule()); + configDataResource.setOverrideManualParams(o.isOverrideManualParams()); + configDataResource.setShareExp(o.isShareExp()); + configDataResource.setUserDn(o.getUserDn()); + configDataResource.setGenerateCert(o.isGenerateCert()); + } + return configDataResource; + } + + private static Resource createComputationalScheduling (Computational_Resource_Scheduling o){ + ComputationSchedulingResource schedulingResource = new ComputationSchedulingResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + schedulingResource.setExperimentResource(experimentResource); + if (o.getTask() != null){ + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTask()); + schedulingResource.setTaskDetailResource(taskDetailResource); + } + schedulingResource.setSchedulingId(o.getSchedulingId()); + schedulingResource.setResourceHostId(o.getResourceHostId()); + schedulingResource.setCpuCount(o.getCpuCount()); + schedulingResource.setNodeCount(o.getNodeCount()); + schedulingResource.setNumberOfThreads(o.getNumberOfThreads()); + schedulingResource.setQueueName(o.getQueueName()); + schedulingResource.setWalltimeLimit(o.getWallTimeLimit()); + schedulingResource.setJobStartTime(o.getJobStartTime()); + schedulingResource.setPhysicalMemory(o.getTotalPhysicalmemory()); + schedulingResource.setProjectName(o.getProjectName()); + schedulingResource.setChessisName(o.getChessisName()); + } + + return schedulingResource; + } + + private static Resource createAdvancedInputDataResource (AdvancedInputDataHandling o){ + AdvanceInputDataHandlingResource dataHandlingResource = new AdvanceInputDataHandlingResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + dataHandlingResource.setExperimentResource(experimentResource); + if (o.getTask() != null){ + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTask()); + dataHandlingResource.setTaskDetailResource(taskDetailResource); + } + dataHandlingResource.setDataHandlingId(o.getDataHandlingId()); + dataHandlingResource.setWorkingDirParent(o.getParentWorkingDir()); + dataHandlingResource.setWorkingDir(o.getWorkingDir()); + dataHandlingResource.setStageInputFiles(o.isStageInputsToWorkingDir()); + dataHandlingResource.setCleanAfterJob(o.isCleanAfterJob()); + } + + return dataHandlingResource; + } + + private static Resource createAdvancedOutputDataResource (AdvancedOutputDataHandling o){ + AdvancedOutputDataHandlingResource dataHandlingResource = new AdvancedOutputDataHandlingResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + dataHandlingResource.setExperimentResource(experimentResource); + if (o.getTask() != null){ + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTask()); + dataHandlingResource.setTaskDetailResource(taskDetailResource); + } + dataHandlingResource.setOutputDataHandlingId(o.getOutputDataHandlingId()); + dataHandlingResource.setOutputDataDir(o.getOutputDataDir()); + dataHandlingResource.setDataRegUrl(o.getDataRegUrl()); + dataHandlingResource.setPersistOutputData(o.isPersistOutputData()); + } + return dataHandlingResource; + } + + private static Resource createQosParamResource (QosParam o){ + QosParamResource qosParamResource = new QosParamResource(); + if (o != null){ + ExperimentResource experimentResource = (ExperimentResource)createExperiment(o.getExperiment()); + qosParamResource.setExperimentResource(experimentResource); + if (o.getTask() != null){ + TaskDetailResource taskDetailResource = (TaskDetailResource)createTaskDetail(o.getTask()); + qosParamResource.setTaskDetailResource(taskDetailResource); + } + qosParamResource.setQosId(o.getQosId()); + qosParamResource.setExecuteBefore(o.getExecuteBefore()); + qosParamResource.setStartExecutionAt(o.getStartExecutionAt()); + qosParamResource.setNoOfRetries(o.getNoOfRetries()); + } + + return qosParamResource; + } +}
