You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ch...@apache.org on 2014/06/27 17:29:03 UTC
git commit: adding app-catalog resource layer implementation for
compute resource
Repository: airavata
Updated Branches:
refs/heads/master e7bb56595 -> 37df1e0a6
adding app-catalog resource layer implementation for compute resource
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/37df1e0a
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/37df1e0a
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/37df1e0a
Branch: refs/heads/master
Commit: 37df1e0a6dddc1205f2e3196b42e6f9c82e7d665
Parents: e7bb565
Author: Chathuri Wimalasena <ka...@gmail.com>
Authored: Fri Jun 27 11:28:59 2014 -0400
Committer: Chathuri Wimalasena <ka...@gmail.com>
Committed: Fri Jun 27 11:28:59 2014 -0400
----------------------------------------------------------------------
.../data/resources/AbstractResource.java | 60 ++++
.../data/resources/ComputeHostResource.java | 307 +++++++++++++++++++
.../catalog/data/resources/Resource.java | 71 +++--
.../catalog/data/util/AppCatalogJPAUtils.java | 111 +++++++
.../data/util/AppCatalogQueryGenerator.java | 90 ++++++
.../data/util/AppCatalogResourceType.java | 48 +++
.../application/catalog/data/util/JPAUtils.java | 79 -----
7 files changed, 655 insertions(+), 111 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/airavata/blob/37df1e0a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AbstractResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AbstractResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AbstractResource.java
new file mode 100644
index 0000000..e6729f7
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AbstractResource.java
@@ -0,0 +1,60 @@
+/*
+ *
+ * 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;
+
+public abstract class AbstractResource implements Resource{
+ // table names
+ public static final String COMPUTE_RESOURCE = "ComputeResource";
+ public static final String HOST_ALIAS = "HostAlias";
+ public static final String HOST_IPADDRESS = "HostIPAddress";
+ public static final String GSISSH_SUBMISSION = "GSISSHSubmission";
+ public static final String GSISSH_EXPORT = "GSISSHExport";
+ public static final String GSISSH_PREJOBCOMMAND = "GSISSHPreJobCommand";
+ public static final String GSISSH_POSTJOBCOMMAND = "GSISSHPostJobCommand";
+ public static final String GLOBUS_SUBMISSION = "GlobusJobSubmission";
+ public static final String SSH_SUBMISSION = "SSHSubmission";
+ public static final String SCP_DATAMOVEMENT = "SCPDataMovement";
+ public static final String GRID_FTP_DATAMOVEMENT = "GridFTPDataMovement";
+ public static final String JOB_SUBMISSION_PROTOCOL = "JobSubmissionProtocol";
+ public static final String DATA_MOVEMENT_PROTOCOL = "DataMovementProtocol";
+ public static final String APPLICATION_MODULE = "ApplicationModule";
+ public static final String APPLICATION_DEPLOYMENT = "ApplicationDeployment";
+ public static final String LIBRARY_PREPAND_PATH = "LibraryPrepandPath";
+ public static final String LIBRARY_APEND_PATH = "LibraryApendPath";
+ public static final String APP_ENVIRONMENT = "AppEnvironment";
+ public static final String APPLICATION_INTERFACE = "ApplicationInterface";
+ public static final String APP_MODULE_MAPPING = "AppModuleMapping";
+ public static final String APPLICATION_INPUT = "ApplicationInput";
+ public static final String APPLICATION_OUTPUT = "ApplicationOutput";
+ public static final String GATEWAY_PROFILE = "GatewayProfile";
+
+ // Gateway Table
+ public final class ComputeResourceConstants {
+ public static final String RESOURCE_ID = "resourceID";
+ public static final String HOST_NAME = "hostName";
+ public static final String DESCRIPTION = "description";
+ public static final String SCRATCH_LOC = "scratchLocation";
+ public static final String PREFERED_SUBMISSION_PROTOCOL = "preferredJobSubProtocol";
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/37df1e0a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostResource.java
new file mode 100644
index 0000000..9b915dd
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostResource.java
@@ -0,0 +1,307 @@
+/*
+ *
+ * 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.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;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ComputeHostResource extends AbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(ComputeHostResource.class);
+ private String resoureId;
+ private String hostName;
+ private String description;
+ private String scratchLocation;
+ private String preferredJobSubmissionProtocol;
+
+ public String getResoureId() {
+ return resoureId;
+ }
+
+ public void setResoureId(String resoureId) {
+ this.resoureId = resoureId;
+ }
+
+ public String getHostName() {
+ return hostName;
+ }
+
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getScratchLocation() {
+ return scratchLocation;
+ }
+
+ public void setScratchLocation(String scratchLocation) {
+ this.scratchLocation = scratchLocation;
+ }
+
+ public String getPreferredJobSubmissionProtocol() {
+ return preferredJobSubmissionProtocol;
+ }
+
+ public void setPreferredJobSubmissionProtocol(String preferredJobSubmissionProtocol) {
+ this.preferredJobSubmissionProtocol = preferredJobSubmissionProtocol;
+ }
+
+ @Override
+ public void remove(Object identifier) throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(COMPUTE_RESOURCE);
+ generator.setParameter(ComputeResourceConstants.RESOURCE_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(COMPUTE_RESOURCE);
+ generator.setParameter(ComputeResourceConstants.RESOURCE_ID, identifier);
+ Query q = generator.selectQuery(em);
+ ComputeResource computeResource = (ComputeResource) q.getSingleResult();
+ ComputeHostResource workerResource =
+ (ComputeHostResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE, computeResource);
+ em.getTransaction().commit();
+ em.close();
+ return workerResource;
+ } 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> computeHostResources = new ArrayList<Resource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(COMPUTE_RESOURCE);
+ List results;
+ if (fieldName.equals(ComputeResourceConstants.HOST_NAME)) {
+ generator.setParameter(ComputeResourceConstants.HOST_NAME, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ComputeResource computeResource = (ComputeResource) result;
+ ComputeHostResource projectResource =
+ (ComputeHostResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE, computeResource);
+ computeHostResources.add(projectResource);
+ }
+ }
+ } else if (fieldName.equals(ComputeResourceConstants.PREFERED_SUBMISSION_PROTOCOL)) {
+ generator.setParameter(ComputeResourceConstants.PREFERED_SUBMISSION_PROTOCOL, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ComputeResource computeResource = (ComputeResource) result;
+ ComputeHostResource projectResource =
+ (ComputeHostResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE, computeResource);
+ computeHostResources.add(projectResource);
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for compute resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for compute 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 computeHostResources;
+ }
+
+ @Override
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> computeHostResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(COMPUTE_RESOURCE);
+ List results;
+ if (fieldName.equals(ComputeResourceConstants.HOST_NAME)) {
+ generator.setParameter(ComputeResourceConstants.HOST_NAME, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ComputeResource computeResource = (ComputeResource) result;
+ computeHostResourceIDs.add(computeResource.getResourceID());
+ }
+ }
+ } else if (fieldName.equals(ComputeResourceConstants.PREFERED_SUBMISSION_PROTOCOL)) {
+ generator.setParameter(ComputeResourceConstants.PREFERED_SUBMISSION_PROTOCOL, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ComputeResource computeResource = (ComputeResource) result;
+ computeHostResourceIDs.add(computeResource.getResourceID());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for compute resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for compute 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 computeHostResourceIDs;
+ }
+
+ @Override
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ ComputeResource existingComputeResource = em.find(ComputeResource.class, resoureId);
+ em.close();
+
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingComputeResource != null){
+ existingComputeResource.setHostName(hostName);
+ existingComputeResource.setDescription(description);
+ existingComputeResource.setPreferredJobSubProtocol(preferredJobSubmissionProtocol);
+ existingComputeResource.setScratchLocation(scratchLocation);
+ em.merge(existingComputeResource);
+ }else {
+ ComputeResource computeResource = new ComputeResource();
+ computeResource.setResourceID(resoureId);
+ computeResource.setHostName(hostName);
+ computeResource.setDescription(description);
+ computeResource.setPreferredJobSubProtocol(preferredJobSubmissionProtocol);
+ computeResource.setScratchLocation(scratchLocation);
+ em.persist(computeResource);
+ }
+ 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();
+ ComputeHostResource computeHostResource = em.find(ComputeHostResource.class, identifier);
+ em.close();
+ return computeHostResource != 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();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/37df1e0a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/Resource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/Resource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/Resource.java
index a25933e..8250138 100644
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/Resource.java
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/Resource.java
@@ -26,43 +26,50 @@ import java.util.List;
public interface Resource {
- /**
- * This method will create associate resource objects for the given resource type.
- * @return associated resource
- */
- Resource create() throws AppCatalogException;
+ /**
+ * This method will remove the given resource from the database
+ *
+ * @param identifier identifier that can uniquely identify a single instance of the resource
+ */
+ void remove(Object identifier) throws AppCatalogException;
- /**
- * This method will remove the given resource from the database
- * @param name resource name
- */
- void remove(Object name) throws AppCatalogException;
+ /**
+ * This method will return the given resource from the database
+ *
+ * @param identifier identifier that can uniquely identify a single instance of the resource
+ * @return associate resource
+ */
+ Resource get(Object identifier) throws AppCatalogException;
- /**
- * This method will return the given resource from the database
- * @param name resource name
- * @return associate resource
- */
- Resource get(Object name) throws AppCatalogException;
+ /**
+ * This method will list all the resources according to the filtering criteria
+ * @param fieldName field name
+ * @param value value of the field
+ * @return list of resources
+ */
+ List<Resource> get(String fieldName, Object value) throws AppCatalogException;
- /**
- * This method will list all the child resources for the given resource type
- * @return list of child resources of the given child resource type
- */
- List<Resource> get() throws AppCatalogException;
+ /** This method will return list of resource ids according to given criteria
+ * @param fieldName field name
+ * @param value value of the field
+ * @return list of resource Ids
+ * @throws AppCatalogException
+ */
+ List<String> getIds(String fieldName, Object value) throws AppCatalogException;
- /**
- * This method will save the resource to the database.
- */
- void save() throws AppCatalogException;
+ /**
+ * This method will save the resource to the database.
+ */
+ void save() throws AppCatalogException;
- /**
- * This method will check whether an entry from the given resource type and resource name
- * exists in the database
- * @param name resource name
- * @return whether the entry exists in the database or not
- */
- boolean isExists(Object name) throws AppCatalogException;
+ /**
+ * This method will check whether an entry from the given resource and resource name
+ * exists in the database
+ *
+ * @param identifier identifier that can uniquely identify a single instance of the resource
+ * @return whether the entry exists in the database or not
+ */
+ boolean isExists(Object identifier) throws AppCatalogException;
}
http://git-wip-us.apache.org/repos/asf/airavata/blob/37df1e0a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogJPAUtils.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogJPAUtils.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogJPAUtils.java
new file mode 100644
index 0000000..6b763e5
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogJPAUtils.java
@@ -0,0 +1,111 @@
+/*
+ *
+ * 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.util;
+
+import org.apache.aiaravata.application.catalog.data.resources.ComputeHostResource;
+import org.apache.aiaravata.application.catalog.data.resources.Resource;
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import java.util.HashMap;
+import java.util.Map;
+
+public class AppCatalogJPAUtils {
+ private final static Logger logger = LoggerFactory.getLogger(AppCatalogJPAUtils.class);
+ private static final String PERSISTENCE_UNIT_NAME = "appcatalog_data";
+ private static final String APPCATALOG_JDBC_DRIVER = "appcatalog.jdbc.driver";
+ private static final String APPCATALOG_JDBC_URL = "appcatalog.jdbc.url";
+ private static final String APPCATALOG_JDBC_USER = "appcatalog.jdbc.user";
+ private static final String APPCATALOG_JDBC_PWD = "appcatalog.jdbc.password";
+ private static final String APPCATALOG_VALIDATION_QUERY = "appcatalog.validationQuery";
+ private static final String JPA_CACHE_SIZE = "jpa.cache.size";
+ protected static EntityManagerFactory factory;
+
+ public static EntityManager getEntityManager() throws ApplicationSettingsException {
+ if (factory == null) {
+ String connectionProperties = "DriverClassName=" + readServerProperties(APPCATALOG_JDBC_DRIVER) + "," +
+ "Url=" + readServerProperties(APPCATALOG_JDBC_URL) + "," +
+ "Username=" + readServerProperties(APPCATALOG_JDBC_USER) + "," +
+ "Password=" + readServerProperties(APPCATALOG_JDBC_PWD) +
+ ",validationQuery=" + readServerProperties(APPCATALOG_VALIDATION_QUERY);
+ System.out.println(connectionProperties);
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource");
+ properties.put("openjpa.ConnectionProperties", connectionProperties);
+ properties.put("openjpa.DynamicEnhancementAgent", "true");
+ properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported");
+ properties.put("openjpa.DataCache","true(CacheSize=" + Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", SoftReferenceSize=0)");
+ properties.put("openjpa.QueryCache","true(CacheSize=" + Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", SoftReferenceSize=0)");
+ properties.put("openjpa.RemoteCommitProvider","sjvm");
+ properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
+ properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
+ properties.put("openjpa.jdbc.QuerySQLCache", "false");
+ factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
+ }
+ return factory.createEntityManager();
+ }
+
+ private static String readServerProperties (String propertyName) throws ApplicationSettingsException {
+ try {
+ return ServerSettings.getSetting(propertyName);
+ } catch (ApplicationSettingsException e) {
+ logger.error("Unable to read airavata-server.properties...", e);
+ throw new ApplicationSettingsException("Unable to read airavata-server.properties...");
+ }
+ }
+
+ /**
+ *
+ * @param type model type
+ * @param o model type instance
+ * @return corresponding resource object
+ */
+ public static Resource getResource(AppCatalogResourceType type, Object o) {
+ switch (type){
+ case COMPUTE_RESOURCE:
+ if (o instanceof ComputeHostResource){
+ return createComputeResource((ComputeHostResource)o);
+ }else {
+ logger.error("Object should be a Compute Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Object should be a Compute Resource.");
+ }
+ default:
+ logger.error("Illegal data type..", new IllegalArgumentException());
+ throw new IllegalArgumentException("Illegal data type..");
+ }
+ }
+
+ private static Resource createComputeResource(ComputeHostResource o) {
+ ComputeHostResource hostResource = new ComputeHostResource();
+ hostResource.setResoureId(o.getResoureId());
+ hostResource.setHostName(o.getHostName());
+ hostResource.setDescription(o.getDescription());
+ hostResource.setScratchLocation(o.getScratchLocation());
+ hostResource.setPreferredJobSubmissionProtocol(o.getPreferredJobSubmissionProtocol());
+ return hostResource;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/37df1e0a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogQueryGenerator.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogQueryGenerator.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogQueryGenerator.java
new file mode 100644
index 0000000..8f41538
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogQueryGenerator.java
@@ -0,0 +1,90 @@
+/*
+ *
+ * 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.util;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.util.HashMap;
+import java.util.Map;
+
+public class AppCatalogQueryGenerator {
+ private String tableName;
+ private Map<String,Object> matches=new HashMap<String, Object>();
+ private static final String SELECT_OBJ="p";
+ private static final String DELETE_OBJ="p";
+ private static final String TABLE_OBJ="p";
+
+ public AppCatalogQueryGenerator(String tableName, Object[]...params) {
+ setTableName(tableName);
+ for (Object[] param : params) {
+ addMatch(param[0].toString(), param[1]);
+ }
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+ public void setTableName(String tableName) {
+ this.tableName = tableName;
+ }
+ public void addMatch(String colName, Object matchValue){
+ matches.put(colName, matchValue);
+ }
+
+ public void setParameter(String colName, Object matchValue){
+ addMatch(colName, matchValue);
+ }
+
+ public Query selectQuery(EntityManager entityManager){
+ String queryString="SELECT "+ SELECT_OBJ + " FROM " +getTableName()+" "+TABLE_OBJ;
+ return generateQueryWithParameters(entityManager, queryString);
+ }
+
+ public Query deleteQuery(EntityManager entityManager){
+ String queryString="Delete FROM "+getTableName()+" "+TABLE_OBJ;
+ return generateQueryWithParameters(entityManager, queryString);
+ }
+
+ private Query generateQueryWithParameters(EntityManager entityManager,
+ String queryString) {
+ Map<String,Object> queryParameters=new HashMap<String, Object>();
+ if (matches.size()>0){
+ String matchString = "";
+ int paramCount=0;
+ for (String colName : matches.keySet()) {
+ String paramName="param"+paramCount;
+ queryParameters.put(paramName, matches.get(colName));
+ if (!matchString.equals("")){
+ matchString+=" AND ";
+ }
+ matchString+=TABLE_OBJ+"."+colName+" =:"+paramName;
+ paramCount++;
+ }
+ queryString+=" WHERE "+matchString;
+ }
+ Query query = entityManager.createQuery(queryString);
+ for (String paramName : queryParameters.keySet()) {
+ query.setParameter(paramName, queryParameters.get(paramName));
+ }
+ return query;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/37df1e0a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogResourceType.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogResourceType.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogResourceType.java
new file mode 100644
index 0000000..bc8d0ef
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogResourceType.java
@@ -0,0 +1,48 @@
+/*
+ *
+ * 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.util;
+
+public enum AppCatalogResourceType {
+ COMPUTE_RESOURCE,
+ HOST_ALIAS,
+ HOST_IPADDRESS,
+ GSISSH_SUBMISSION,
+ GSISSH_EXPORT,
+ GSISSH_PREJOBCOMMAND,
+ GSISSH_POSTJOBCOMMAND,
+ GLOBUS_SUBMISSION,
+ SSH_SUBMISSION,
+ SCP_DATAMOVEMENT,
+ GRID_FTP_DATAMOVEMENT,
+ JOB_SUBMISSION_PROTOCOL,
+ DATA_MOVEMENT_PROTOCOL,
+ APPLICATION_MODULE,
+ APPLICATION_DEPLOYMENT,
+ LIBRARY_PREPAND_PATH,
+ LIBRARY_APEND_PATH,
+ APP_ENVIRONMENT,
+ APPLICATION_INTERFACE,
+ APP_MODULE_MAPPING,
+ APPLICATION_INPUT,
+ APPLICATION_OUTPUT,
+ GATEWAY_PROFILE
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/37df1e0a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/JPAUtils.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/JPAUtils.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/JPAUtils.java
deleted file mode 100644
index 7bad1a6..0000000
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/JPAUtils.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- *
- * 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.util;
-
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import java.util.HashMap;
-import java.util.Map;
-
-public class JPAUtils {
- private final static Logger logger = LoggerFactory.getLogger(JPAUtils.class);
- private static final String PERSISTENCE_UNIT_NAME = "appcatalog_data";
- private static final String APPCATALOG_JDBC_DRIVER = "appcatalog.jdbc.driver";
- private static final String APPCATALOG_JDBC_URL = "appcatalog.jdbc.url";
- private static final String APPCATALOG_JDBC_USER = "appcatalog.jdbc.user";
- private static final String APPCATALOG_JDBC_PWD = "appcatalog.jdbc.password";
- private static final String APPCATALOG_VALIDATION_QUERY = "appcatalog.validationQuery";
- private static final String JPA_CACHE_SIZE = "jpa.cache.size";
- protected static EntityManagerFactory factory;
-
- public static EntityManager getEntityManager() throws ApplicationSettingsException {
- if (factory == null) {
- String connectionProperties = "DriverClassName=" + readServerProperties(APPCATALOG_JDBC_DRIVER) + "," +
- "Url=" + readServerProperties(APPCATALOG_JDBC_URL) + "," +
- "Username=" + readServerProperties(APPCATALOG_JDBC_USER) + "," +
- "Password=" + readServerProperties(APPCATALOG_JDBC_PWD) +
- ",validationQuery=" + readServerProperties(APPCATALOG_VALIDATION_QUERY);
- System.out.println(connectionProperties);
- Map<String, String> properties = new HashMap<String, String>();
- properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource");
- properties.put("openjpa.ConnectionProperties", connectionProperties);
- properties.put("openjpa.DynamicEnhancementAgent", "true");
- properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported");
- properties.put("openjpa.DataCache","true(CacheSize=" + Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", SoftReferenceSize=0)");
- properties.put("openjpa.QueryCache","true(CacheSize=" + Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", SoftReferenceSize=0)");
- properties.put("openjpa.RemoteCommitProvider","sjvm");
- properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
- properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
- properties.put("openjpa.jdbc.QuerySQLCache", "false");
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
- }
- return factory.createEntityManager();
- }
-
- private static String readServerProperties (String propertyName) throws ApplicationSettingsException {
- try {
- return ServerSettings.getSetting(propertyName);
- } catch (ApplicationSettingsException e) {
- logger.error("Unable to read airavata-server.properties...", e);
- throw new ApplicationSettingsException("Unable to read airavata-server.properties...");
- }
-
- }
-}