Return-Path: X-Original-To: apmail-airavata-commits-archive@www.apache.org Delivered-To: apmail-airavata-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1DFA818B58 for ; Thu, 4 Jun 2015 20:36:49 +0000 (UTC) Received: (qmail 23299 invoked by uid 500); 4 Jun 2015 20:36:48 -0000 Delivered-To: apmail-airavata-commits-archive@airavata.apache.org Received: (qmail 23146 invoked by uid 500); 4 Jun 2015 20:36:48 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 22236 invoked by uid 99); 4 Jun 2015 20:36:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Jun 2015 20:36:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 21719E10DF; Thu, 4 Jun 2015 20:36:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: shameera@apache.org To: commits@airavata.apache.org Date: Thu, 04 Jun 2015 20:37:01 -0000 Message-Id: In-Reply-To: <27990c52cdb74065a551c421d4d751d4@git.apache.org> References: <27990c52cdb74065a551c421d4d751d4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [15/52] [abbrv] [partial] airavata git commit: registry refactoring 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/ApplicationInputResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputResource.java new file mode 100644 index 0000000..3dcb6b4 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputResource.java @@ -0,0 +1,454 @@ +/** + * 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.AppInput_PK; +import org.apache.aiaravata.application.catalog.data.model.ApplicationInput; +import org.apache.aiaravata.application.catalog.data.model.ApplicationInterface; +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 ApplicationInputResource extends AbstractResource { + + private final static Logger logger = LoggerFactory.getLogger(ApplicationInputResource.class); + + private String interfaceID; + private String inputKey; + private String dataType; + private String inputVal; + private String metadata; + private String appArgument; + private String userFriendlyDesc; + private int inputOrder; + private boolean standardInput; + private boolean isRequired; + private boolean requiredToCMD; + private boolean dataStaged; + + private AppInterfaceResource appInterfaceResource; + + public void remove(Object identifier) throws AppCatalogException { + HashMap 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(APPLICATION_INPUT); + generator.setParameter(AppInputConstants.INTERFACE_ID, ids.get(AppInputConstants.INTERFACE_ID)); + if (ids.get(AppInputConstants.INPUT_KEY) != null){ + generator.setParameter(AppInputConstants.INPUT_KEY, ids.get(AppInputConstants.INPUT_KEY)); + } + 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 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(APPLICATION_INPUT); + generator.setParameter(AppInputConstants.INTERFACE_ID, ids.get(AppInputConstants.INTERFACE_ID)); + generator.setParameter(AppInputConstants.INPUT_KEY, ids.get(AppInputConstants.INPUT_KEY)); + Query q = generator.selectQuery(em); + ApplicationInput applicationInput = (ApplicationInput) q.getSingleResult(); + ApplicationInputResource applicationInputResource = + (ApplicationInputResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_INPUT + , applicationInput); + em.getTransaction().commit(); + em.close(); + return applicationInputResource; + } 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 get(String fieldName, Object value) throws AppCatalogException { + List appInputResources = new ArrayList(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_INPUT); + List results; + if (fieldName.equals(AppInputConstants.INTERFACE_ID)) { + generator.setParameter(AppInputConstants.INTERFACE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationInput applicationInput = (ApplicationInput) result; + ApplicationInputResource applicationInputResource = + (ApplicationInputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.APPLICATION_INPUT, applicationInput); + appInputResources.add(applicationInputResource); + } + } + } else if (fieldName.equals(AppInputConstants.INPUT_KEY)) { + generator.setParameter(AppInputConstants.INPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationInput applicationInput = (ApplicationInput) result; + ApplicationInputResource applicationInputResource = + (ApplicationInputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.APPLICATION_INPUT, applicationInput); + appInputResources.add(applicationInputResource); + } + } + } else if (fieldName.equals(AppInputConstants.DATA_TYPE)) { + generator.setParameter(AppInputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationInput applicationInput = (ApplicationInput) result; + ApplicationInputResource applicationInputResource = + (ApplicationInputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.APPLICATION_INPUT, applicationInput); + appInputResources.add(applicationInputResource); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for AppInput Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for AppInput 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 appInputResources; + } + + @Override + public List getAll() throws AppCatalogException { + return null; + } + + @Override + public List getAllIds() throws AppCatalogException { + return null; + } + + public List getIds(String fieldName, Object value) throws AppCatalogException { + List appInputResourceIDs = new ArrayList(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_INPUT); + List results; + if (fieldName.equals(AppInputConstants.INTERFACE_ID)) { + generator.setParameter(AppInputConstants.INTERFACE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationInput applicationInput = (ApplicationInput) result; + appInputResourceIDs.add(applicationInput.getInterfaceID()); + } + } + } else if (fieldName.equals(AppInputConstants.INPUT_KEY)) { + generator.setParameter(AppInputConstants.INPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationInput applicationInput = (ApplicationInput) result; + appInputResourceIDs.add(applicationInput.getInterfaceID()); + } + } + } else if (fieldName.equals(AppInputConstants.DATA_TYPE)) { + generator.setParameter(AppInputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationInput applicationInput = (ApplicationInput) result; + appInputResourceIDs.add(applicationInput.getInterfaceID()); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for AppInput resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for AppInput 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 appInputResourceIDs; + } + + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + ApplicationInput existingApplicationInput = em.find(ApplicationInput.class, new AppInput_PK(interfaceID, inputKey)); + em.close(); + ApplicationInput applicationInput; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingApplicationInput == null) { + applicationInput = new ApplicationInput(); + } else { + applicationInput=existingApplicationInput; + } + ApplicationInterface applicationInterface = em.find(ApplicationInterface.class, interfaceID); + applicationInput.setApplicationInterface(applicationInterface); + applicationInput.setInterfaceID(applicationInterface.getInterfaceID()); + applicationInput.setDataType(dataType); + applicationInput.setInputKey(inputKey); + applicationInput.setInputVal(inputVal); + applicationInput.setMetadata(metadata); + applicationInput.setAppArgument(appArgument); + applicationInput.setUserFriendlyDesc(userFriendlyDesc); + applicationInput.setStandardInput(standardInput); + applicationInput.setInputOrder(inputOrder); + applicationInput.setRequiredToCMD(requiredToCMD); + applicationInput.setRequired(isRequired); + applicationInput.setDataStaged(dataStaged); + if (existingApplicationInput == null) { + em.persist(applicationInput); + } else { + em.merge(applicationInput); + } + 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 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(); + ApplicationInput applicationInput = em.find(ApplicationInput.class, new AppInput_PK( + ids.get(AppInputConstants.INTERFACE_ID), + ids.get(AppInputConstants.INPUT_KEY))); + + em.close(); + return applicationInput != 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 getInterfaceID() { + return interfaceID; + } + + public void setInterfaceID(String interfaceID) { + this.interfaceID = interfaceID; + } + + public String getInputKey() { + return inputKey; + } + + public void setInputKey(String inputKey) { + this.inputKey = inputKey; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getInputVal() { + return inputVal; + } + + public void setInputVal(String inputVal) { + this.inputVal = inputVal; + } + + public String getMetadata() { + return metadata; + } + + public void setMetadata(String metadata) { + this.metadata = metadata; + } + + public String getAppArgument() { + return appArgument; + } + + public void setAppArgument(String appArgument) { + this.appArgument = appArgument; + } + + public String getUserFriendlyDesc() { + return userFriendlyDesc; + } + + public void setUserFriendlyDesc(String userFriendlyDesc) { + this.userFriendlyDesc = userFriendlyDesc; + } + + public AppInterfaceResource getAppInterfaceResource() { + return appInterfaceResource; + } + + public void setAppInterfaceResource(AppInterfaceResource appInterfaceResource) { + this.appInterfaceResource = appInterfaceResource; + } + + public boolean isStandardInput() { + return standardInput; + } + + public void setStandardInput(boolean standardInput) { + this.standardInput = standardInput; + } + + public int getInputOrder() { + return inputOrder; + } + + public void setInputOrder(int inputOrder) { + this.inputOrder = inputOrder; + } + + public boolean getRequired() { + return isRequired; + } + + public void setRequired(boolean required) { + this.isRequired = required; + } + + public boolean getRequiredToCMD() { + return requiredToCMD; + } + + public void setRequiredToCMD(boolean requiredToCMD) { + this.requiredToCMD = requiredToCMD; + } + + public boolean isDataStaged() { + return dataStaged; + } + + public void setDataStaged(boolean dataStaged) { + this.dataStaged = dataStaged; + } +} 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/ApplicationOutputAppCatalogResourceAppCat.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationOutputAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationOutputAppCatalogResourceAppCat.java new file mode 100644 index 0000000..e383c1c --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationOutputAppCatalogResourceAppCat.java @@ -0,0 +1,433 @@ +/** + * 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.AppOutput_PK; +import org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface; +import org.apache.airavata.registry.core.app.catalog.model.ApplicationOutput; +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 ApplicationOutputAppCatalogResourceAppCat extends AppCatAbstractResource { + private final static Logger logger = LoggerFactory.getLogger(ApplicationOutputAppCatalogResourceAppCat.class); + + private String interfaceID; + private String outputKey; + private String outputVal; + private String dataType; + private boolean isRequired; + private boolean dataMovement; + private String dataNameLocation; + private boolean requiredToCMD; + private String searchQuery; + private String appArgument; + + private AppInterfaceAppCatalogResourceAppCat appInterfaceResource; + + public void remove(Object identifier) throws AppCatalogException { + HashMap 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(APPLICATION_OUTPUT); + generator.setParameter(AppOutputConstants.INTERFACE_ID, ids.get(AppOutputConstants.INTERFACE_ID)); + if (ids.get(AppOutputConstants.OUTPUT_KEY) != null){ + generator.setParameter(AppOutputConstants.OUTPUT_KEY, ids.get(AppOutputConstants.OUTPUT_KEY)); + } + 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 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(APPLICATION_OUTPUT); + generator.setParameter(AppOutputConstants.INTERFACE_ID, ids.get(AppOutputConstants.INTERFACE_ID)); + generator.setParameter(AppOutputConstants.OUTPUT_KEY, ids.get(AppOutputConstants.OUTPUT_KEY)); + Query q = generator.selectQuery(em); + ApplicationOutput applicationOutput = (ApplicationOutput) q.getSingleResult(); + ApplicationOutputAppCatalogResourceAppCat applicationOutputResource = + (ApplicationOutputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_OUTPUT + , applicationOutput); + em.getTransaction().commit(); + em.close(); + return applicationOutputResource; + } 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 get(String fieldName, Object value) throws AppCatalogException { + List appInputResources = new ArrayList(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_OUTPUT); + List results; + if (fieldName.equals(AppOutputConstants.INTERFACE_ID)) { + generator.setParameter(AppOutputConstants.INTERFACE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + ApplicationOutputAppCatalogResourceAppCat applicationOutputResource = + (ApplicationOutputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.APPLICATION_OUTPUT, applicationOutput); + appInputResources.add(applicationOutputResource); + } + } + } else if (fieldName.equals(AppOutputConstants.OUTPUT_KEY)) { + generator.setParameter(AppOutputConstants.OUTPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + ApplicationOutputAppCatalogResourceAppCat applicationOutputResource = + (ApplicationOutputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.APPLICATION_OUTPUT, applicationOutput); + appInputResources.add(applicationOutputResource); + } + } + } else if (fieldName.equals(AppOutputConstants.DATA_TYPE)) { + generator.setParameter(AppOutputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + ApplicationOutputAppCatalogResourceAppCat applicationOutputResource = + (ApplicationOutputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.APPLICATION_OUTPUT, applicationOutput); + appInputResources.add(applicationOutputResource); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for App Output Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for App Output 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 appInputResources; + } + + @Override + public List getAll() throws AppCatalogException { + return null; + } + + @Override + public List getAllIds() throws AppCatalogException { + return null; + } + + public List getIds(String fieldName, Object value) throws AppCatalogException { + List appOutputResourceIDs = new ArrayList(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_OUTPUT); + List results; + if (fieldName.equals(AppOutputConstants.INTERFACE_ID)) { + generator.setParameter(AppOutputConstants.INTERFACE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + appOutputResourceIDs.add(applicationOutput.getInterfaceID()); + } + } + } + if (fieldName.equals(AppOutputConstants.OUTPUT_KEY)) { + generator.setParameter(AppOutputConstants.OUTPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + appOutputResourceIDs.add(applicationOutput.getInterfaceID()); + } + } + } else if (fieldName.equals(AppOutputConstants.DATA_TYPE)) { + generator.setParameter(AppOutputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + appOutputResourceIDs.add(applicationOutput.getInterfaceID()); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for App Output resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for App Output 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 appOutputResourceIDs; + } + + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + ApplicationOutput existingApplicationOutput = em.find(ApplicationOutput.class, + new AppOutput_PK(interfaceID, outputKey)); + em.close(); + + ApplicationOutput applicationOutput; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingApplicationOutput == null) { + applicationOutput = new ApplicationOutput(); + } else { + applicationOutput = existingApplicationOutput; + } + ApplicationInterface applicationInterface = em.find(ApplicationInterface.class, interfaceID); + applicationOutput.setApplicationInterface(applicationInterface); + applicationOutput.setInterfaceID(applicationInterface.getInterfaceID()); + applicationOutput.setDataType(dataType); + applicationOutput.setOutputKey(outputKey); + applicationOutput.setOutputVal(outputVal); + applicationOutput.setRequired(isRequired); + applicationOutput.setRequiredToCMD(requiredToCMD); + applicationOutput.setDataMovement(dataMovement); + applicationOutput.setDataNameLocation(dataNameLocation); + applicationOutput.setSearchQuery(searchQuery); + applicationOutput.setApplicationArgument(appArgument); + em.merge(applicationOutput); + 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 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(); + ApplicationOutput applicationOutput = em.find(ApplicationOutput.class, new AppOutput_PK( + ids.get(AppOutputConstants.INTERFACE_ID), + ids.get(AppOutputConstants.OUTPUT_KEY))); + + em.close(); + return applicationOutput != 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 getInterfaceID() { + return interfaceID; + } + + public void setInterfaceID(String interfaceID) { + this.interfaceID = interfaceID; + } + + public String getOutputKey() { + return outputKey; + } + + public void setOutputKey(String outputKey) { + this.outputKey = outputKey; + } + + public String getOutputVal() { + return outputVal; + } + + public void setOutputVal(String outputVal) { + this.outputVal = outputVal; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public AppInterfaceAppCatalogResourceAppCat getAppInterfaceResource() { + return appInterfaceResource; + } + + public void setAppInterfaceResource(AppInterfaceAppCatalogResourceAppCat appInterfaceResource) { + this.appInterfaceResource = appInterfaceResource; + } + + public boolean getRequired() { + return isRequired; + } + + public void setRequired(boolean required) { + this.isRequired = required; + } + + public boolean isDataMovement() { + return dataMovement; + } + + public void setDataMovement(boolean dataMovement) { + this.dataMovement = dataMovement; + } + + public String getDataNameLocation() { + return dataNameLocation; + } + + public void setDataNameLocation(String dataNameLocation) { + this.dataNameLocation = dataNameLocation; + } + + public boolean getRequiredToCMD() { + return requiredToCMD; + } + + public void setRequiredToCMD(boolean requiredToCMD) { + this.requiredToCMD = requiredToCMD; + } + + public String getSearchQuery() { + return searchQuery; + } + + public void setSearchQuery(String searchQuery) { + this.searchQuery = searchQuery; + } + + public String getAppArgument() { + return appArgument; + } + + public void setAppArgument(String appArgument) { + this.appArgument = appArgument; + } +} 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/ApplicationOutputResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationOutputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationOutputResource.java new file mode 100644 index 0000000..feac711 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationOutputResource.java @@ -0,0 +1,432 @@ +/** + * 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.AppOutput_PK; +import org.apache.aiaravata.application.catalog.data.model.ApplicationInterface; +import org.apache.aiaravata.application.catalog.data.model.ApplicationOutput; +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 ApplicationOutputResource extends AbstractResource { + private final static Logger logger = LoggerFactory.getLogger(ApplicationOutputResource.class); + + private String interfaceID; + private String outputKey; + private String outputVal; + private String dataType; + private boolean isRequired; + private boolean dataMovement; + private String dataNameLocation; + private boolean requiredToCMD; + private String searchQuery; + private String appArgument; + + private AppInterfaceResource appInterfaceResource; + + public void remove(Object identifier) throws AppCatalogException { + HashMap 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(APPLICATION_OUTPUT); + generator.setParameter(AppOutputConstants.INTERFACE_ID, ids.get(AppOutputConstants.INTERFACE_ID)); + if (ids.get(AppOutputConstants.OUTPUT_KEY) != null){ + generator.setParameter(AppOutputConstants.OUTPUT_KEY, ids.get(AppOutputConstants.OUTPUT_KEY)); + } + 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 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(APPLICATION_OUTPUT); + generator.setParameter(AppOutputConstants.INTERFACE_ID, ids.get(AppOutputConstants.INTERFACE_ID)); + generator.setParameter(AppOutputConstants.OUTPUT_KEY, ids.get(AppOutputConstants.OUTPUT_KEY)); + Query q = generator.selectQuery(em); + ApplicationOutput applicationOutput = (ApplicationOutput) q.getSingleResult(); + ApplicationOutputResource applicationOutputResource = + (ApplicationOutputResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_OUTPUT + , applicationOutput); + em.getTransaction().commit(); + em.close(); + return applicationOutputResource; + } 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 get(String fieldName, Object value) throws AppCatalogException { + List appInputResources = new ArrayList(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_OUTPUT); + List results; + if (fieldName.equals(AppOutputConstants.INTERFACE_ID)) { + generator.setParameter(AppOutputConstants.INTERFACE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + ApplicationOutputResource applicationOutputResource = + (ApplicationOutputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.APPLICATION_OUTPUT, applicationOutput); + appInputResources.add(applicationOutputResource); + } + } + } else if (fieldName.equals(AppOutputConstants.OUTPUT_KEY)) { + generator.setParameter(AppOutputConstants.OUTPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + ApplicationOutputResource applicationOutputResource = + (ApplicationOutputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.APPLICATION_OUTPUT, applicationOutput); + appInputResources.add(applicationOutputResource); + } + } + } else if (fieldName.equals(AppOutputConstants.DATA_TYPE)) { + generator.setParameter(AppOutputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + ApplicationOutputResource applicationOutputResource = + (ApplicationOutputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.APPLICATION_OUTPUT, applicationOutput); + appInputResources.add(applicationOutputResource); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for App Output Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for App Output 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 appInputResources; + } + + @Override + public List getAll() throws AppCatalogException { + return null; + } + + @Override + public List getAllIds() throws AppCatalogException { + return null; + } + + public List getIds(String fieldName, Object value) throws AppCatalogException { + List appOutputResourceIDs = new ArrayList(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_OUTPUT); + List results; + if (fieldName.equals(AppOutputConstants.INTERFACE_ID)) { + generator.setParameter(AppOutputConstants.INTERFACE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + appOutputResourceIDs.add(applicationOutput.getInterfaceID()); + } + } + } + if (fieldName.equals(AppOutputConstants.OUTPUT_KEY)) { + generator.setParameter(AppOutputConstants.OUTPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + appOutputResourceIDs.add(applicationOutput.getInterfaceID()); + } + } + } else if (fieldName.equals(AppOutputConstants.DATA_TYPE)) { + generator.setParameter(AppOutputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ApplicationOutput applicationOutput = (ApplicationOutput) result; + appOutputResourceIDs.add(applicationOutput.getInterfaceID()); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for App Output resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for App Output 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 appOutputResourceIDs; + } + + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + ApplicationOutput existingApplicationOutput = em.find(ApplicationOutput.class, + new AppOutput_PK(interfaceID, outputKey)); + em.close(); + + ApplicationOutput applicationOutput; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingApplicationOutput == null) { + applicationOutput = new ApplicationOutput(); + } else { + applicationOutput = existingApplicationOutput; + } + ApplicationInterface applicationInterface = em.find(ApplicationInterface.class, interfaceID); + applicationOutput.setApplicationInterface(applicationInterface); + applicationOutput.setInterfaceID(applicationInterface.getInterfaceID()); + applicationOutput.setDataType(dataType); + applicationOutput.setOutputKey(outputKey); + applicationOutput.setOutputVal(outputVal); + applicationOutput.setRequired(isRequired); + applicationOutput.setRequiredToCMD(requiredToCMD); + applicationOutput.setDataMovement(dataMovement); + applicationOutput.setDataNameLocation(dataNameLocation); + applicationOutput.setSearchQuery(searchQuery); + applicationOutput.setApplicationArgument(appArgument); + em.merge(applicationOutput); + 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 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(); + ApplicationOutput applicationOutput = em.find(ApplicationOutput.class, new AppOutput_PK( + ids.get(AppOutputConstants.INTERFACE_ID), + ids.get(AppOutputConstants.OUTPUT_KEY))); + + em.close(); + return applicationOutput != 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 getInterfaceID() { + return interfaceID; + } + + public void setInterfaceID(String interfaceID) { + this.interfaceID = interfaceID; + } + + public String getOutputKey() { + return outputKey; + } + + public void setOutputKey(String outputKey) { + this.outputKey = outputKey; + } + + public String getOutputVal() { + return outputVal; + } + + public void setOutputVal(String outputVal) { + this.outputVal = outputVal; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public AppInterfaceResource getAppInterfaceResource() { + return appInterfaceResource; + } + + public void setAppInterfaceResource(AppInterfaceResource appInterfaceResource) { + this.appInterfaceResource = appInterfaceResource; + } + + public boolean getRequired() { + return isRequired; + } + + public void setRequired(boolean required) { + this.isRequired = required; + } + + public boolean isDataMovement() { + return dataMovement; + } + + public void setDataMovement(boolean dataMovement) { + this.dataMovement = dataMovement; + } + + public String getDataNameLocation() { + return dataNameLocation; + } + + public void setDataNameLocation(String dataNameLocation) { + this.dataNameLocation = dataNameLocation; + } + + public boolean getRequiredToCMD() { + return requiredToCMD; + } + + public void setRequiredToCMD(boolean requiredToCMD) { + this.requiredToCMD = requiredToCMD; + } + + public String getSearchQuery() { + return searchQuery; + } + + public void setSearchQuery(String searchQuery) { + this.searchQuery = searchQuery; + } + + public String getAppArgument() { + return appArgument; + } + + public void setAppArgument(String appArgument) { + this.appArgument = appArgument; + } +} 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/BatchQueueAppCatalogResourceAppCat.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/BatchQueueAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/BatchQueueAppCatalogResourceAppCat.java new file mode 100644 index 0000000..6ba1762 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/BatchQueueAppCatalogResourceAppCat.java @@ -0,0 +1,357 @@ +/* + * + * 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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.EntityManager; +import javax.persistence.Query; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.registry.core.app.catalog.model.BatchQueue; +import org.apache.airavata.registry.core.app.catalog.model.BatchQueue_PK; +import org.apache.airavata.registry.core.app.catalog.model.ComputeResource; +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; + +public class BatchQueueAppCatalogResourceAppCat extends AppCatAbstractResource { + private final static Logger logger = LoggerFactory.getLogger(BatchQueueAppCatalogResourceAppCat.class); + private String computeResourceId; + private ComputeResourceAppCatalogResourceAppCat computeHostResource; + private int maxRuntime; + private int maxJobInQueue; + private String queueDescription; + private String queueName; + private int maxProcessors; + private int maxNodes; + private int maxMemory; + + @Override + public void remove(Object identifier) throws AppCatalogException { + HashMap 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(BATCH_QUEUE); + generator.setParameter(BatchQueueConstants.COMPUTE_RESOURCE_ID, ids.get(BatchQueueConstants.COMPUTE_RESOURCE_ID)); + generator.setParameter(BatchQueueConstants.QUEUE_NAME, ids.get(BatchQueueConstants.QUEUE_NAME)); + 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 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(BATCH_QUEUE); + generator.setParameter(BatchQueueConstants.COMPUTE_RESOURCE_ID, ids.get(BatchQueueConstants.COMPUTE_RESOURCE_ID)); + generator.setParameter(BatchQueueConstants.QUEUE_NAME, ids.get(BatchQueueConstants.QUEUE_NAME)); + Query q = generator.selectQuery(em); + BatchQueue batchQueue = (BatchQueue) q.getSingleResult(); + BatchQueueAppCatalogResourceAppCat batchQueueResource = (BatchQueueAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.BATCH_QUEUE, batchQueue); + em.getTransaction().commit(); + em.close(); + return batchQueueResource; + } 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 get(String fieldName, Object value) throws AppCatalogException { + List batchQueueResources = new ArrayList(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(BATCH_QUEUE); + Query q; + if ((fieldName.equals(BatchQueueConstants.COMPUTE_RESOURCE_ID)) || (fieldName.equals(BatchQueueConstants.MAX_RUNTIME)) || (fieldName.equals(BatchQueueConstants.MAX_JOB_IN_QUEUE)) || (fieldName.equals(BatchQueueConstants.QUEUE_DESCRIPTION)) || (fieldName.equals(BatchQueueConstants.QUEUE_NAME)) || (fieldName.equals(BatchQueueConstants.MAX_PROCESSORS)) || (fieldName.equals(BatchQueueConstants.MAX_NODES))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List results = q.getResultList(); + for (Object result : results) { + BatchQueue batchQueue = (BatchQueue) result; + BatchQueueAppCatalogResourceAppCat batchQueueResource = (BatchQueueAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.BATCH_QUEUE, batchQueue); + batchQueueResources.add(batchQueueResource); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Batch Queue Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Batch Queue 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 batchQueueResources; + } + + @Override + public List getAll() throws AppCatalogException { + return null; + } + + @Override + public List getAllIds() throws AppCatalogException { + return null; + } + + @Override + public List getIds(String fieldName, Object value) throws AppCatalogException { + List batchQueueResourceIDs = new ArrayList(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(BATCH_QUEUE); + Query q; + if ((fieldName.equals(BatchQueueConstants.COMPUTE_RESOURCE_ID)) || (fieldName.equals(BatchQueueConstants.MAX_RUNTIME)) || (fieldName.equals(BatchQueueConstants.MAX_JOB_IN_QUEUE)) || (fieldName.equals(BatchQueueConstants.QUEUE_DESCRIPTION)) || (fieldName.equals(BatchQueueConstants.QUEUE_NAME)) || (fieldName.equals(BatchQueueConstants.MAX_PROCESSORS)) || (fieldName.equals(BatchQueueConstants.MAX_NODES))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List results = q.getResultList(); + for (Object result : results) { + BatchQueue batchQueue = (BatchQueue) result; + BatchQueueAppCatalogResourceAppCat batchQueueResource = (BatchQueueAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.BATCH_QUEUE, batchQueue); + batchQueueResourceIDs.add(batchQueueResource.getComputeResourceId()); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Batch Queue Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Batch Queue 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 batchQueueResourceIDs; + } + + @Override + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + BatchQueue existingBatchQueue = em.find(BatchQueue.class, new BatchQueue_PK(computeResourceId, queueName)); + em.close(); + BatchQueue batchQueue; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingBatchQueue == null) { + batchQueue = new BatchQueue(); + } else { + batchQueue = existingBatchQueue; + } + batchQueue.setComputeResourceId(getComputeResourceId()); + ComputeResource computeResource = em.find(ComputeResource.class, getComputeResourceId()); + batchQueue.setComputeResource(computeResource); + batchQueue.setMaxRuntime(getMaxRuntime()); + batchQueue.setMaxJobInQueue(getMaxJobInQueue()); + batchQueue.setQueueDescription(getQueueDescription()); + batchQueue.setQueueName(getQueueName()); + batchQueue.setMaxProcessors(getMaxProcessors()); + batchQueue.setMaxNodes(getMaxNodes()); + batchQueue.setMaxMemory(getMaxMemory()); + if (existingBatchQueue == null) { + em.persist(batchQueue); + } else { + em.merge(batchQueue); + } + 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 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(); + BatchQueue batchQueue = em.find(BatchQueue.class, new BatchQueue_PK(ids.get(BatchQueueConstants.COMPUTE_RESOURCE_ID), ids.get(BatchQueueConstants.QUEUE_NAME))); + em.close(); + return batchQueue != 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 getComputeResourceId() { + return computeResourceId; + } + + public ComputeResourceAppCatalogResourceAppCat getComputeHostResource() { + return computeHostResource; + } + + public int getMaxRuntime() { + return maxRuntime; + } + + public int getMaxJobInQueue() { + return maxJobInQueue; + } + + public String getQueueDescription() { + return queueDescription; + } + + public String getQueueName() { + return queueName; + } + + public int getMaxProcessors() { + return maxProcessors; + } + + public int getMaxNodes() { + return maxNodes; + } + + public void setComputeResourceId(String computeResourceId) { + this.computeResourceId=computeResourceId; + } + + public void setComputeHostResource(ComputeResourceAppCatalogResourceAppCat computeHostResource) { + this.computeHostResource=computeHostResource; + } + + public void setMaxRuntime(int maxRuntime) { + this.maxRuntime=maxRuntime; + } + + public void setMaxJobInQueue(int maxJobInQueue) { + this.maxJobInQueue=maxJobInQueue; + } + + public void setQueueDescription(String queueDescription) { + this.queueDescription=queueDescription; + } + + public void setQueueName(String queueName) { + this.queueName=queueName; + } + + public void setMaxProcessors(int maxProcessors) { + this.maxProcessors=maxProcessors; + } + + public void setMaxNodes(int maxNodes) { + this.maxNodes=maxNodes; + } + + public int getMaxMemory() { + return maxMemory; + } + + public void setMaxMemory(int maxMemory) { + this.maxMemory = maxMemory; + } +} \ No newline at end of file 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/BatchQueueResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/BatchQueueResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/BatchQueueResource.java new file mode 100644 index 0000000..e7f5bff --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/BatchQueueResource.java @@ -0,0 +1,357 @@ +/* + * + * 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.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.EntityManager; +import javax.persistence.Query; + +import org.airavata.appcatalog.cpi.AppCatalogException; +import org.apache.aiaravata.application.catalog.data.model.BatchQueue; +import org.apache.aiaravata.application.catalog.data.model.BatchQueue_PK; +import org.apache.aiaravata.application.catalog.data.model.ComputeResource; +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; + +public class BatchQueueResource extends AbstractResource { + private final static Logger logger = LoggerFactory.getLogger(BatchQueueResource.class); + private String computeResourceId; + private ComputeResourceResource computeHostResource; + private int maxRuntime; + private int maxJobInQueue; + private String queueDescription; + private String queueName; + private int maxProcessors; + private int maxNodes; + private int maxMemory; + + @Override + public void remove(Object identifier) throws AppCatalogException { + HashMap 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(BATCH_QUEUE); + generator.setParameter(BatchQueueConstants.COMPUTE_RESOURCE_ID, ids.get(BatchQueueConstants.COMPUTE_RESOURCE_ID)); + generator.setParameter(BatchQueueConstants.QUEUE_NAME, ids.get(BatchQueueConstants.QUEUE_NAME)); + 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 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(BATCH_QUEUE); + generator.setParameter(BatchQueueConstants.COMPUTE_RESOURCE_ID, ids.get(BatchQueueConstants.COMPUTE_RESOURCE_ID)); + generator.setParameter(BatchQueueConstants.QUEUE_NAME, ids.get(BatchQueueConstants.QUEUE_NAME)); + Query q = generator.selectQuery(em); + BatchQueue batchQueue = (BatchQueue) q.getSingleResult(); + BatchQueueResource batchQueueResource = (BatchQueueResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.BATCH_QUEUE, batchQueue); + em.getTransaction().commit(); + em.close(); + return batchQueueResource; + } 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 get(String fieldName, Object value) throws AppCatalogException { + List batchQueueResources = new ArrayList(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(BATCH_QUEUE); + Query q; + if ((fieldName.equals(BatchQueueConstants.COMPUTE_RESOURCE_ID)) || (fieldName.equals(BatchQueueConstants.MAX_RUNTIME)) || (fieldName.equals(BatchQueueConstants.MAX_JOB_IN_QUEUE)) || (fieldName.equals(BatchQueueConstants.QUEUE_DESCRIPTION)) || (fieldName.equals(BatchQueueConstants.QUEUE_NAME)) || (fieldName.equals(BatchQueueConstants.MAX_PROCESSORS)) || (fieldName.equals(BatchQueueConstants.MAX_NODES))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List results = q.getResultList(); + for (Object result : results) { + BatchQueue batchQueue = (BatchQueue) result; + BatchQueueResource batchQueueResource = (BatchQueueResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.BATCH_QUEUE, batchQueue); + batchQueueResources.add(batchQueueResource); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Batch Queue Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Batch Queue 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 batchQueueResources; + } + + @Override + public List getAll() throws AppCatalogException { + return null; + } + + @Override + public List getAllIds() throws AppCatalogException { + return null; + } + + @Override + public List getIds(String fieldName, Object value) throws AppCatalogException { + List batchQueueResourceIDs = new ArrayList(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(BATCH_QUEUE); + Query q; + if ((fieldName.equals(BatchQueueConstants.COMPUTE_RESOURCE_ID)) || (fieldName.equals(BatchQueueConstants.MAX_RUNTIME)) || (fieldName.equals(BatchQueueConstants.MAX_JOB_IN_QUEUE)) || (fieldName.equals(BatchQueueConstants.QUEUE_DESCRIPTION)) || (fieldName.equals(BatchQueueConstants.QUEUE_NAME)) || (fieldName.equals(BatchQueueConstants.MAX_PROCESSORS)) || (fieldName.equals(BatchQueueConstants.MAX_NODES))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List results = q.getResultList(); + for (Object result : results) { + BatchQueue batchQueue = (BatchQueue) result; + BatchQueueResource batchQueueResource = (BatchQueueResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.BATCH_QUEUE, batchQueue); + batchQueueResourceIDs.add(batchQueueResource.getComputeResourceId()); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Batch Queue Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Batch Queue 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 batchQueueResourceIDs; + } + + @Override + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + BatchQueue existingBatchQueue = em.find(BatchQueue.class, new BatchQueue_PK(computeResourceId, queueName)); + em.close(); + BatchQueue batchQueue; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingBatchQueue == null) { + batchQueue = new BatchQueue(); + } else { + batchQueue = existingBatchQueue; + } + batchQueue.setComputeResourceId(getComputeResourceId()); + ComputeResource computeResource = em.find(ComputeResource.class, getComputeResourceId()); + batchQueue.setComputeResource(computeResource); + batchQueue.setMaxRuntime(getMaxRuntime()); + batchQueue.setMaxJobInQueue(getMaxJobInQueue()); + batchQueue.setQueueDescription(getQueueDescription()); + batchQueue.setQueueName(getQueueName()); + batchQueue.setMaxProcessors(getMaxProcessors()); + batchQueue.setMaxNodes(getMaxNodes()); + batchQueue.setMaxMemory(getMaxMemory()); + if (existingBatchQueue == null) { + em.persist(batchQueue); + } else { + em.merge(batchQueue); + } + 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 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(); + BatchQueue batchQueue = em.find(BatchQueue.class, new BatchQueue_PK(ids.get(BatchQueueConstants.COMPUTE_RESOURCE_ID), ids.get(BatchQueueConstants.QUEUE_NAME))); + em.close(); + return batchQueue != 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 getComputeResourceId() { + return computeResourceId; + } + + public ComputeResourceResource getComputeHostResource() { + return computeHostResource; + } + + public int getMaxRuntime() { + return maxRuntime; + } + + public int getMaxJobInQueue() { + return maxJobInQueue; + } + + public String getQueueDescription() { + return queueDescription; + } + + public String getQueueName() { + return queueName; + } + + public int getMaxProcessors() { + return maxProcessors; + } + + public int getMaxNodes() { + return maxNodes; + } + + public void setComputeResourceId(String computeResourceId) { + this.computeResourceId=computeResourceId; + } + + public void setComputeHostResource(ComputeResourceResource computeHostResource) { + this.computeHostResource=computeHostResource; + } + + public void setMaxRuntime(int maxRuntime) { + this.maxRuntime=maxRuntime; + } + + public void setMaxJobInQueue(int maxJobInQueue) { + this.maxJobInQueue=maxJobInQueue; + } + + public void setQueueDescription(String queueDescription) { + this.queueDescription=queueDescription; + } + + public void setQueueName(String queueName) { + this.queueName=queueName; + } + + public void setMaxProcessors(int maxProcessors) { + this.maxProcessors=maxProcessors; + } + + public void setMaxNodes(int maxNodes) { + this.maxNodes=maxNodes; + } + + public int getMaxMemory() { + return maxMemory; + } + + public void setMaxMemory(int maxMemory) { + this.maxMemory = maxMemory; + } +} \ No newline at end of file