http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/LocalSubmissionResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/LocalSubmissionResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/LocalSubmissionResource.java new file mode 100644 index 0000000..487e5dc --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/LocalSubmissionResource.java @@ -0,0 +1,293 @@ +/* + * + * 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.aiaravata.application.catalog.data.resources; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.Query; + +import org.airavata.appcatalog.cpi.AppCatalogException; +import org.apache.aiaravata.application.catalog.data.model.LocalSubmission; +import org.apache.aiaravata.application.catalog.data.model.ResourceJobManager; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogJPAUtils; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogQueryGenerator; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogResourceType; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.AiravataUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LocalSubmissionResource extends AbstractResource { + private final static Logger logger = LoggerFactory.getLogger(LocalSubmissionResource.class); + private String resourceJobManagerId; + private ResourceJobManagerResource resourceJobManagerResource; + private String jobSubmissionInterfaceId; + private Timestamp createdTime; + private Timestamp updatedTime; + + public Timestamp getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(Timestamp createdTime) { + this.createdTime = createdTime; + } + + public Timestamp getUpdatedTime() { + return updatedTime; + } + + public void setUpdatedTime(Timestamp updatedTime) { + this.updatedTime = updatedTime; + } + + @Override + public void remove(Object identifier) throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(LOCAL_SUBMISSION); + generator.setParameter(LocalSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID, identifier); + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public Resource get(Object identifier) throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(LOCAL_SUBMISSION); + generator.setParameter(LocalSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID, identifier); + Query q = generator.selectQuery(em); + LocalSubmission localSubmission = (LocalSubmission) q.getSingleResult(); + LocalSubmissionResource localSubmissionResource = (LocalSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LOCAL_SUBMISSION, localSubmission); + em.getTransaction().commit(); + em.close(); + return localSubmissionResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public List<Resource> get(String fieldName, Object value) throws AppCatalogException { + List<Resource> localSubmissionResources = new ArrayList<Resource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(LOCAL_SUBMISSION); + Query q; + if ((fieldName.equals(LocalSubmissionConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(LocalSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List<?> results = q.getResultList(); + for (Object result : results) { + LocalSubmission localSubmission = (LocalSubmission) result; + LocalSubmissionResource localSubmissionResource = (LocalSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LOCAL_SUBMISSION, localSubmission); + localSubmissionResources.add(localSubmissionResource); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Local Submission Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Local Submission Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return localSubmissionResources; + } + + @Override + public List<Resource> getAll() throws AppCatalogException { + return null; + } + + @Override + public List<String> getAllIds() throws AppCatalogException { + return null; + } + + @Override + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> localSubmissionResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(LOCAL_SUBMISSION); + Query q; + if ((fieldName.equals(LocalSubmissionConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(LocalSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List<?> results = q.getResultList(); + for (Object result : results) { + LocalSubmission localSubmission = (LocalSubmission) result; + LocalSubmissionResource localSubmissionResource = (LocalSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LOCAL_SUBMISSION, localSubmission); + localSubmissionResourceIDs.add(localSubmissionResource.getJobSubmissionInterfaceId()); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Local Submission Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Local Submission Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return localSubmissionResourceIDs; + } + + @Override + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + LocalSubmission existingLocalSubmission = em.find(LocalSubmission.class, jobSubmissionInterfaceId); + em.close(); + LocalSubmission localSubmission; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingLocalSubmission == null) { + localSubmission = new LocalSubmission(); + localSubmission.setCreationTime(AiravataUtils.getCurrentTimestamp()); + } else { + localSubmission = existingLocalSubmission; + localSubmission.setUpdateTime(AiravataUtils.getCurrentTimestamp()); + } + localSubmission.setResourceJobManagerId(getResourceJobManagerId()); + ResourceJobManager resourceJobManager = em.find(ResourceJobManager.class, getResourceJobManagerId()); + localSubmission.setResourceJobManager(resourceJobManager); + localSubmission.setJobSubmissionInterfaceId(getJobSubmissionInterfaceId()); + if (existingLocalSubmission == null) { + em.persist(localSubmission); + } else { + em.merge(localSubmission); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public boolean isExists(Object identifier) throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + LocalSubmission localSubmission = em.find(LocalSubmission.class, identifier); + em.close(); + return localSubmission != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getResourceJobManagerId() { + return resourceJobManagerId; + } + + public ResourceJobManagerResource getResourceJobManagerResource() { + return resourceJobManagerResource; + } + + public String getJobSubmissionInterfaceId() { + return jobSubmissionInterfaceId; + } + + public void setResourceJobManagerId(String resourceJobManagerId) { + this.resourceJobManagerId=resourceJobManagerId; + } + + public void setResourceJobManagerResource(ResourceJobManagerResource resourceJobManagerResource) { + this.resourceJobManagerResource=resourceJobManagerResource; + } + + public void setJobSubmissionInterfaceId(String jobSubmissionInterfaceId) { + this.jobSubmissionInterfaceId=jobSubmissionInterfaceId; + } +}
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ModuleLoadCmdAppCatalogResourceAppCat.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ModuleLoadCmdAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ModuleLoadCmdAppCatalogResourceAppCat.java new file mode 100644 index 0000000..0cc2bde --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ModuleLoadCmdAppCatalogResourceAppCat.java @@ -0,0 +1,300 @@ +/* + * + * 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.registry.core.app.catalog.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment; +import org.apache.airavata.registry.core.app.catalog.model.ModuleLoadCmd; +import org.apache.airavata.registry.core.app.catalog.model.ModuleLoadCmd_PK; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ModuleLoadCmdAppCatalogResourceAppCat extends AppCatAbstractResource { + private final static Logger logger = LoggerFactory.getLogger(ModuleLoadCmdAppCatalogResourceAppCat.class); + private String cmd; + private String appDeploymentId; + private AppDeploymentAppCatalogResourceAppCat appDeploymentResource; + + @Override + public void remove(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map) { + ids = (HashMap<String, String>) identifier; + } else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(MODULE_LOAD_CMD); + generator.setParameter(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID, ids.get(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID)); + if (ids.get(ModuleLoadCmdConstants.CMD) != null){ + generator.setParameter(ModuleLoadCmdConstants.CMD, ids.get(ModuleLoadCmdConstants.CMD)); + } + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public AppCatalogResource get(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map) { + ids = (HashMap<String, String>) identifier; + } else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(MODULE_LOAD_CMD); + generator.setParameter(ModuleLoadCmdConstants.CMD, ids.get(ModuleLoadCmdConstants.CMD)); + generator.setParameter(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID, ids.get(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID)); + Query q = generator.selectQuery(em); + ModuleLoadCmd moduleLoadCmd = (ModuleLoadCmd) q.getSingleResult(); + ModuleLoadCmdAppCatalogResourceAppCat moduleLoadCmdResource = (ModuleLoadCmdAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.MODULE_LOAD_CMD, moduleLoadCmd); + em.getTransaction().commit(); + em.close(); + return moduleLoadCmdResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException { + List<AppCatalogResource> moduleLoadCmdResources = new ArrayList<AppCatalogResource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(MODULE_LOAD_CMD); + Query q; + if ((fieldName.equals(ModuleLoadCmdConstants.CMD)) || (fieldName.equals(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List<?> results = q.getResultList(); + for (Object result : results) { + ModuleLoadCmd moduleLoadCmd = (ModuleLoadCmd) result; + ModuleLoadCmdAppCatalogResourceAppCat moduleLoadCmdResource = (ModuleLoadCmdAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.MODULE_LOAD_CMD, moduleLoadCmd); + moduleLoadCmdResources.add(moduleLoadCmdResource); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Module Load Cmd Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Module Load Cmd Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return moduleLoadCmdResources; + } + + @Override + public List<AppCatalogResource> getAll() throws AppCatalogException { + return null; + } + + @Override + public List<String> getAllIds() throws AppCatalogException { + return null; + } + + @Override + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> moduleLoadCmdResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(MODULE_LOAD_CMD); + Query q; + if ((fieldName.equals(ModuleLoadCmdConstants.CMD)) || (fieldName.equals(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List<?> results = q.getResultList(); + for (Object result : results) { + ModuleLoadCmd moduleLoadCmd = (ModuleLoadCmd) result; + ModuleLoadCmdAppCatalogResourceAppCat moduleLoadCmdResource = (ModuleLoadCmdAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.MODULE_LOAD_CMD, moduleLoadCmd); + moduleLoadCmdResourceIDs.add(moduleLoadCmdResource.getAppDeploymentId()); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Module Load Cmd Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Module Load Cmd Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return moduleLoadCmdResourceIDs; + } + + @Override + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + ModuleLoadCmd existingModuleLoadCmd = em.find(ModuleLoadCmd.class, new ModuleLoadCmd_PK(cmd, appDeploymentId)); + em.close(); + ModuleLoadCmd moduleLoadCmd; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingModuleLoadCmd == null) { + moduleLoadCmd = new ModuleLoadCmd(); + } else { + moduleLoadCmd = existingModuleLoadCmd; + } + moduleLoadCmd.setCmd(getCmd()); + moduleLoadCmd.setAppDeploymentId(getAppDeploymentId()); + ApplicationDeployment applicationDeployment = em.find(ApplicationDeployment.class, getAppDeploymentId()); + moduleLoadCmd.setApplicationDeployment(applicationDeployment); + if (existingModuleLoadCmd == null) { + em.persist(moduleLoadCmd); + } else { + em.merge(moduleLoadCmd); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public boolean isExists(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map) { + ids = (HashMap<String, String>) identifier; + } else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + ModuleLoadCmd moduleLoadCmd = em.find(ModuleLoadCmd.class, new ModuleLoadCmd_PK(ids.get(ModuleLoadCmdConstants.CMD), ids.get(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID))); + em.close(); + return moduleLoadCmd != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getCmd() { + return cmd; + } + + public String getAppDeploymentId() { + return appDeploymentId; + } + + public AppDeploymentAppCatalogResourceAppCat getAppDeploymentResource() { + return appDeploymentResource; + } + + public void setCmd(String cmd) { + this.cmd=cmd; + } + + public void setAppDeploymentId(String appDeploymentId) { + this.appDeploymentId=appDeploymentId; + } + + public void setAppDeploymentResource(AppDeploymentAppCatalogResourceAppCat appDeploymentResource) { + this.appDeploymentResource=appDeploymentResource; + } +} + + http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ModuleLoadCmdResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ModuleLoadCmdResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ModuleLoadCmdResource.java new file mode 100644 index 0000000..99faacf --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ModuleLoadCmdResource.java @@ -0,0 +1,300 @@ +/* + * + * 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.aiaravata.application.catalog.data.resources; + +import org.airavata.appcatalog.cpi.AppCatalogException; +import org.apache.aiaravata.application.catalog.data.model.ApplicationDeployment; +import org.apache.aiaravata.application.catalog.data.model.ModuleLoadCmd; +import org.apache.aiaravata.application.catalog.data.model.ModuleLoadCmd_PK; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogJPAUtils; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogQueryGenerator; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogResourceType; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ModuleLoadCmdResource extends AbstractResource { + private final static Logger logger = LoggerFactory.getLogger(ModuleLoadCmdResource.class); + private String cmd; + private String appDeploymentId; + private AppDeploymentResource appDeploymentResource; + + @Override + public void remove(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map) { + ids = (HashMap<String, String>) identifier; + } else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(MODULE_LOAD_CMD); + generator.setParameter(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID, ids.get(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID)); + if (ids.get(ModuleLoadCmdConstants.CMD) != null){ + generator.setParameter(ModuleLoadCmdConstants.CMD, ids.get(ModuleLoadCmdConstants.CMD)); + } + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public Resource get(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map) { + ids = (HashMap<String, String>) identifier; + } else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(MODULE_LOAD_CMD); + generator.setParameter(ModuleLoadCmdConstants.CMD, ids.get(ModuleLoadCmdConstants.CMD)); + generator.setParameter(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID, ids.get(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID)); + Query q = generator.selectQuery(em); + ModuleLoadCmd moduleLoadCmd = (ModuleLoadCmd) q.getSingleResult(); + ModuleLoadCmdResource moduleLoadCmdResource = (ModuleLoadCmdResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.MODULE_LOAD_CMD, moduleLoadCmd); + em.getTransaction().commit(); + em.close(); + return moduleLoadCmdResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public List<Resource> get(String fieldName, Object value) throws AppCatalogException { + List<Resource> moduleLoadCmdResources = new ArrayList<Resource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(MODULE_LOAD_CMD); + Query q; + if ((fieldName.equals(ModuleLoadCmdConstants.CMD)) || (fieldName.equals(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List<?> results = q.getResultList(); + for (Object result : results) { + ModuleLoadCmd moduleLoadCmd = (ModuleLoadCmd) result; + ModuleLoadCmdResource moduleLoadCmdResource = (ModuleLoadCmdResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.MODULE_LOAD_CMD, moduleLoadCmd); + moduleLoadCmdResources.add(moduleLoadCmdResource); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Module Load Cmd Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Module Load Cmd Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return moduleLoadCmdResources; + } + + @Override + public List<Resource> getAll() throws AppCatalogException { + return null; + } + + @Override + public List<String> getAllIds() throws AppCatalogException { + return null; + } + + @Override + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> moduleLoadCmdResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(MODULE_LOAD_CMD); + Query q; + if ((fieldName.equals(ModuleLoadCmdConstants.CMD)) || (fieldName.equals(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List<?> results = q.getResultList(); + for (Object result : results) { + ModuleLoadCmd moduleLoadCmd = (ModuleLoadCmd) result; + ModuleLoadCmdResource moduleLoadCmdResource = (ModuleLoadCmdResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.MODULE_LOAD_CMD, moduleLoadCmd); + moduleLoadCmdResourceIDs.add(moduleLoadCmdResource.getAppDeploymentId()); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Module Load Cmd Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Module Load Cmd Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return moduleLoadCmdResourceIDs; + } + + @Override + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + ModuleLoadCmd existingModuleLoadCmd = em.find(ModuleLoadCmd.class, new ModuleLoadCmd_PK(cmd, appDeploymentId)); + em.close(); + ModuleLoadCmd moduleLoadCmd; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingModuleLoadCmd == null) { + moduleLoadCmd = new ModuleLoadCmd(); + } else { + moduleLoadCmd = existingModuleLoadCmd; + } + moduleLoadCmd.setCmd(getCmd()); + moduleLoadCmd.setAppDeploymentId(getAppDeploymentId()); + ApplicationDeployment applicationDeployment = em.find(ApplicationDeployment.class, getAppDeploymentId()); + moduleLoadCmd.setApplicationDeployment(applicationDeployment); + if (existingModuleLoadCmd == null) { + em.persist(moduleLoadCmd); + } else { + em.merge(moduleLoadCmd); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public boolean isExists(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map) { + ids = (HashMap<String, String>) identifier; + } else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + ModuleLoadCmd moduleLoadCmd = em.find(ModuleLoadCmd.class, new ModuleLoadCmd_PK(ids.get(ModuleLoadCmdConstants.CMD), ids.get(ModuleLoadCmdConstants.APP_DEPLOYMENT_ID))); + em.close(); + return moduleLoadCmd != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getCmd() { + return cmd; + } + + public String getAppDeploymentId() { + return appDeploymentId; + } + + public AppDeploymentResource getAppDeploymentResource() { + return appDeploymentResource; + } + + public void setCmd(String cmd) { + this.cmd=cmd; + } + + public void setAppDeploymentId(String appDeploymentId) { + this.appDeploymentId=appDeploymentId; + } + + public void setAppDeploymentResource(AppDeploymentResource appDeploymentResource) { + this.appDeploymentResource=appDeploymentResource; + } +} + + http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandAppCatalogResourceAppCat.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandAppCatalogResourceAppCat.java new file mode 100644 index 0000000..201b45b --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandAppCatalogResourceAppCat.java @@ -0,0 +1,333 @@ +/** + * 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.registry.core.app.catalog.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment; +import org.apache.airavata.registry.core.app.catalog.model.PostJobCommand; +import org.apache.airavata.registry.core.app.catalog.model.PostJobCommandPK; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PostJobCommandAppCatalogResourceAppCat extends AppCatAbstractResource { + private final static Logger logger = LoggerFactory.getLogger(PostJobCommandAppCatalogResourceAppCat.class); + + private String appDeploymentId; + private String command; + + private AppDeploymentAppCatalogResourceAppCat appDeploymentResource; + + + public void remove(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map){ + ids = (HashMap)identifier; + }else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(POST_JOBCOMMAND); + generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, + ids.get(PostJobCommandConstants.DEPLOYMENT_ID)); + if (ids.get(PostJobCommandConstants.COMMAND) != null){ + generator.setParameter(PostJobCommandConstants.COMMAND, ids.get(PostJobCommandConstants.COMMAND)); + } + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public AppCatalogResource get(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map){ + ids = (HashMap)identifier; + }else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND); + generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, + ids.get(PostJobCommandConstants.DEPLOYMENT_ID)); + generator.setParameter(PostJobCommandConstants.COMMAND, ids.get(PostJobCommandConstants.COMMAND)); + Query q = generator.selectQuery(em); + PostJobCommand postJobCommand = (PostJobCommand) q.getSingleResult(); + PostJobCommandAppCatalogResourceAppCat postJobCommandResource = + (PostJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand); + em.getTransaction().commit(); + em.close(); + return postJobCommandResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException { + List<AppCatalogResource> gsiSSHPostJobCommandResources = new ArrayList<AppCatalogResource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND); + List results; + if (fieldName.equals(PostJobCommandConstants.DEPLOYMENT_ID)) { + generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PostJobCommand postJobCommand = (PostJobCommand) result; + PostJobCommandAppCatalogResourceAppCat postJobCommandResource = + (PostJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand); + gsiSSHPostJobCommandResources.add(postJobCommandResource); + } + } + } else if (fieldName.equals(PostJobCommandConstants.COMMAND)) { + generator.setParameter(PostJobCommandConstants.COMMAND, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PostJobCommand postJobCommand = (PostJobCommand) result; + PostJobCommandAppCatalogResourceAppCat postJobCommandResource = + (PostJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand); + gsiSSHPostJobCommandResources.add(postJobCommandResource); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for GSISSH Post Job Command Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for GSISSH Post Job Command Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return gsiSSHPostJobCommandResources; + } + + @Override + public List<AppCatalogResource> getAll() throws AppCatalogException { + return null; + } + + @Override + public List<String> getAllIds() throws AppCatalogException { + return null; + } + + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> gsiSSHPostJobResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND); + List results; + if (fieldName.equals(PostJobCommandConstants.DEPLOYMENT_ID)) { + generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PostJobCommand postJobCommand = (PostJobCommand) result; + gsiSSHPostJobResourceIDs.add(postJobCommand.getDeploymentId()); + } + } + } else if (fieldName.equals(PostJobCommandConstants.COMMAND)) { + generator.setParameter(PostJobCommandConstants.COMMAND, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PostJobCommand postJobCommand = (PostJobCommand) result; + gsiSSHPostJobResourceIDs.add(postJobCommand.getDeploymentId()); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for GSISSH Post Job resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for GSISSH Post JOb Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return gsiSSHPostJobResourceIDs; + } + + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + PostJobCommand existingPostJobCommand = em.find(PostJobCommand.class, + new PostJobCommandPK(appDeploymentId, command)); + em.close(); + + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + ApplicationDeployment deployment = em.find(ApplicationDeployment.class, appDeploymentId); + if (existingPostJobCommand != null){ + existingPostJobCommand.setDeploymentId(appDeploymentId); + existingPostJobCommand.setCommand(command); + existingPostJobCommand.setDeployment(deployment); + em.merge(existingPostJobCommand); + }else { + PostJobCommand postJobCommand = new PostJobCommand(); + postJobCommand.setDeploymentId(appDeploymentId); + postJobCommand.setCommand(command); + postJobCommand.setDeployment(deployment); + em.persist(postJobCommand); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public boolean isExists(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map){ + ids = (HashMap)identifier; + }else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + PostJobCommand postJobCommand = em.find(PostJobCommand.class, new PostJobCommandPK( + ids.get(PostJobCommandConstants.DEPLOYMENT_ID), + ids.get(PostJobCommandConstants.COMMAND))); + + em.close(); + return postJobCommand != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getAppDeploymentId() { + return appDeploymentId; + } + + public void setAppDeploymentId(String appDeploymentId) { + this.appDeploymentId = appDeploymentId; + } + + public String getCommand() { + return command; + } + + public void setCommand(String command) { + this.command = command; + } + + public AppDeploymentAppCatalogResourceAppCat getAppDeploymentResource() { + return appDeploymentResource; + } + + public void setAppDeploymentResource(AppDeploymentAppCatalogResourceAppCat appDeploymentResource) { + this.appDeploymentResource = appDeploymentResource; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandResource.java new file mode 100644 index 0000000..7cde166 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandResource.java @@ -0,0 +1,333 @@ +/** + * 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.aiaravata.application.catalog.data.resources; + +import org.airavata.appcatalog.cpi.AppCatalogException; +import org.apache.aiaravata.application.catalog.data.model.ApplicationDeployment; +import org.apache.aiaravata.application.catalog.data.model.PostJobCommand; +import org.apache.aiaravata.application.catalog.data.model.PostJobCommandPK; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogJPAUtils; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogQueryGenerator; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogResourceType; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PostJobCommandResource extends AbstractResource { + private final static Logger logger = LoggerFactory.getLogger(PostJobCommandResource.class); + + private String appDeploymentId; + private String command; + + private AppDeploymentResource appDeploymentResource; + + + public void remove(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map){ + ids = (HashMap)identifier; + }else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(POST_JOBCOMMAND); + generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, + ids.get(PostJobCommandConstants.DEPLOYMENT_ID)); + if (ids.get(PostJobCommandConstants.COMMAND) != null){ + generator.setParameter(PostJobCommandConstants.COMMAND, ids.get(PostJobCommandConstants.COMMAND)); + } + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public Resource get(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map){ + ids = (HashMap)identifier; + }else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND); + generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, + ids.get(PostJobCommandConstants.DEPLOYMENT_ID)); + generator.setParameter(PostJobCommandConstants.COMMAND, ids.get(PostJobCommandConstants.COMMAND)); + Query q = generator.selectQuery(em); + PostJobCommand postJobCommand = (PostJobCommand) q.getSingleResult(); + PostJobCommandResource postJobCommandResource = + (PostJobCommandResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand); + em.getTransaction().commit(); + em.close(); + return postJobCommandResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public List<Resource> get(String fieldName, Object value) throws AppCatalogException { + List<Resource> gsiSSHPostJobCommandResources = new ArrayList<Resource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND); + List results; + if (fieldName.equals(PostJobCommandConstants.DEPLOYMENT_ID)) { + generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PostJobCommand postJobCommand = (PostJobCommand) result; + PostJobCommandResource postJobCommandResource = + (PostJobCommandResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand); + gsiSSHPostJobCommandResources.add(postJobCommandResource); + } + } + } else if (fieldName.equals(PostJobCommandConstants.COMMAND)) { + generator.setParameter(PostJobCommandConstants.COMMAND, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PostJobCommand postJobCommand = (PostJobCommand) result; + PostJobCommandResource postJobCommandResource = + (PostJobCommandResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand); + gsiSSHPostJobCommandResources.add(postJobCommandResource); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for GSISSH Post Job Command Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for GSISSH Post Job Command Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return gsiSSHPostJobCommandResources; + } + + @Override + public List<Resource> getAll() throws AppCatalogException { + return null; + } + + @Override + public List<String> getAllIds() throws AppCatalogException { + return null; + } + + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> gsiSSHPostJobResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND); + List results; + if (fieldName.equals(PostJobCommandConstants.DEPLOYMENT_ID)) { + generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PostJobCommand postJobCommand = (PostJobCommand) result; + gsiSSHPostJobResourceIDs.add(postJobCommand.getDeploymentId()); + } + } + } else if (fieldName.equals(PostJobCommandConstants.COMMAND)) { + generator.setParameter(PostJobCommandConstants.COMMAND, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PostJobCommand postJobCommand = (PostJobCommand) result; + gsiSSHPostJobResourceIDs.add(postJobCommand.getDeploymentId()); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for GSISSH Post Job resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for GSISSH Post JOb Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return gsiSSHPostJobResourceIDs; + } + + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + PostJobCommand existingPostJobCommand = em.find(PostJobCommand.class, + new PostJobCommandPK(appDeploymentId, command)); + em.close(); + + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + ApplicationDeployment deployment = em.find(ApplicationDeployment.class, appDeploymentId); + if (existingPostJobCommand != null){ + existingPostJobCommand.setDeploymentId(appDeploymentId); + existingPostJobCommand.setCommand(command); + existingPostJobCommand.setDeployment(deployment); + em.merge(existingPostJobCommand); + }else { + PostJobCommand postJobCommand = new PostJobCommand(); + postJobCommand.setDeploymentId(appDeploymentId); + postJobCommand.setCommand(command); + postJobCommand.setDeployment(deployment); + em.persist(postJobCommand); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public boolean isExists(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map){ + ids = (HashMap)identifier; + }else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + PostJobCommand postJobCommand = em.find(PostJobCommand.class, new PostJobCommandPK( + ids.get(PostJobCommandConstants.DEPLOYMENT_ID), + ids.get(PostJobCommandConstants.COMMAND))); + + em.close(); + return postJobCommand != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getAppDeploymentId() { + return appDeploymentId; + } + + public void setAppDeploymentId(String appDeploymentId) { + this.appDeploymentId = appDeploymentId; + } + + public String getCommand() { + return command; + } + + public void setCommand(String command) { + this.command = command; + } + + public AppDeploymentResource getAppDeploymentResource() { + return appDeploymentResource; + } + + public void setAppDeploymentResource(AppDeploymentResource appDeploymentResource) { + this.appDeploymentResource = appDeploymentResource; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandAppCatalogResourceAppCat.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandAppCatalogResourceAppCat.java new file mode 100644 index 0000000..6fe515e --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandAppCatalogResourceAppCat.java @@ -0,0 +1,333 @@ +/** + * 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.registry.core.app.catalog.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment; +import org.apache.airavata.registry.core.app.catalog.model.PreJobCommand; +import org.apache.airavata.registry.core.app.catalog.model.PreJobCommandPK; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PreJobCommandAppCatalogResourceAppCat extends AppCatAbstractResource { + private final static Logger logger = LoggerFactory.getLogger(PreJobCommandAppCatalogResourceAppCat.class); + + private String appDeploymentId; + private String command; + + private AppDeploymentAppCatalogResourceAppCat appDeploymentResource; + + + public void remove(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map){ + ids = (HashMap)identifier; + }else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(PRE_JOBCOMMAND); + generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID, + ids.get(PreJobCommandConstants.DEPLOYMENT_ID)); + if (ids.get(PreJobCommandConstants.COMMAND) != null){ + generator.setParameter(PreJobCommandConstants.COMMAND, ids.get(PreJobCommandConstants.COMMAND)); + } + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public AppCatalogResource get(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map){ + ids = (HashMap)identifier; + }else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(PRE_JOBCOMMAND); + generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID, + ids.get(PreJobCommandConstants.DEPLOYMENT_ID)); + generator.setParameter(PreJobCommandConstants.COMMAND, ids.get(PreJobCommandConstants.COMMAND)); + Query q = generator.selectQuery(em); + PreJobCommand preJobCommand = (PreJobCommand) q.getSingleResult(); + PreJobCommandAppCatalogResourceAppCat preJobCommandResource = + (PreJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.PRE_JOBCOMMAND, preJobCommand); + em.getTransaction().commit(); + em.close(); + return preJobCommandResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException { + List<AppCatalogResource> gsiSSHPreJobResources = new ArrayList<AppCatalogResource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(PRE_JOBCOMMAND); + List results; + if (fieldName.equals(PreJobCommandConstants.DEPLOYMENT_ID)) { + generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PreJobCommand preJobCommand = (PreJobCommand) result; + PreJobCommandAppCatalogResourceAppCat preJobCommandResource = + (PreJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.PRE_JOBCOMMAND, preJobCommand); + gsiSSHPreJobResources.add(preJobCommandResource); + } + } + } else if (fieldName.equals(PreJobCommandConstants.COMMAND)) { + generator.setParameter(PreJobCommandConstants.COMMAND, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PreJobCommand preJobCommand = (PreJobCommand) result; + PreJobCommandAppCatalogResourceAppCat preJobCommandResource = + (PreJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.PRE_JOBCOMMAND, preJobCommand); + gsiSSHPreJobResources.add(preJobCommandResource); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for GSISSH Pre Job Command Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for GSISSH Pre Job Command Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return gsiSSHPreJobResources; + } + + @Override + public List<AppCatalogResource> getAll() throws AppCatalogException { + return null; + } + + @Override + public List<String> getAllIds() throws AppCatalogException { + return null; + } + + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> gsiSSHPreJobResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(PRE_JOBCOMMAND); + List results; + if (fieldName.equals(PreJobCommandConstants.DEPLOYMENT_ID)) { + generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PreJobCommand preJobCommand = (PreJobCommand) result; + gsiSSHPreJobResourceIDs.add(preJobCommand.getDeploymentId()); + } + } + } else if (fieldName.equals(PreJobCommandConstants.COMMAND)) { + generator.setParameter(PreJobCommandConstants.COMMAND, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + PreJobCommand preJobCommand = (PreJobCommand) result; + gsiSSHPreJobResourceIDs.add(preJobCommand.getDeploymentId()); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for GSISSH Pre Job resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for GSISSH Pre JOb Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return gsiSSHPreJobResourceIDs; + } + + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + PreJobCommand existingGSIsshPreJobCommand = em.find(PreJobCommand.class, + new PreJobCommandPK(appDeploymentId, command)); + em.close(); + + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + ApplicationDeployment deployment = em.find(ApplicationDeployment.class, appDeploymentId); + if (existingGSIsshPreJobCommand != null){ + existingGSIsshPreJobCommand.setDeploymentId(appDeploymentId); + existingGSIsshPreJobCommand.setCommand(command); + existingGSIsshPreJobCommand.setApplicationDeployment(deployment); + em.merge(existingGSIsshPreJobCommand); + }else { + PreJobCommand preJobCommand = new PreJobCommand(); + preJobCommand.setDeploymentId(appDeploymentId); + preJobCommand.setCommand(command); + preJobCommand.setApplicationDeployment(deployment); + em.persist(preJobCommand); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public boolean isExists(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map){ + ids = (HashMap)identifier; + }else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + PreJobCommand preJobCommand = em.find(PreJobCommand.class, new PreJobCommandPK( + ids.get(PreJobCommandConstants.DEPLOYMENT_ID), + ids.get(PreJobCommandConstants.COMMAND))); + + em.close(); + return preJobCommand != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getAppDeploymentId() { + return appDeploymentId; + } + + public void setAppDeploymentId(String appDeploymentId) { + this.appDeploymentId = appDeploymentId; + } + + public String getCommand() { + return command; + } + + public void setCommand(String command) { + this.command = command; + } + + public AppDeploymentAppCatalogResourceAppCat getAppDeploymentResource() { + return appDeploymentResource; + } + + public void setAppDeploymentResource(AppDeploymentAppCatalogResourceAppCat appDeploymentResource) { + this.appDeploymentResource = appDeploymentResource; + } +}
