airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chath...@apache.org
Subject git commit: adding jpa models and resources for gateway profile - AIRAVATA-1318
Date Thu, 03 Jul 2014 18:25:24 GMT
Repository: airavata
Updated Branches:
  refs/heads/master 527900b82 -> 4d109fd18


adding jpa models and resources for gateway profile - AIRAVATA-1318


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/4d109fd1
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/4d109fd1
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/4d109fd1

Branch: refs/heads/master
Commit: 4d109fd18301adbbe557e444bc25b2ce686d8413
Parents: 527900b
Author: Chathuri Wimalasena <kamalasini@gmail.com>
Authored: Thu Jul 3 14:25:17 2014 -0400
Committer: Chathuri Wimalasena <kamalasini@gmail.com>
Committed: Thu Jul 3 14:25:17 2014 -0400

----------------------------------------------------------------------
 .../airavata/api/server/AiravataAPIServer.java  |   4 +-
 .../data/model/ComputeResourcePreference.java   | 139 +++++++
 .../data/model/ComputeResourcePreferencePK.java |  64 ++++
 .../catalog/data/model/GatewayProfile.java      |  10 -
 .../data/resources/AbstractResource.java        |  13 +-
 .../ComputeHostPreferenceResource.java          | 376 +++++++++++++++++++
 .../data/resources/GatewayProfileResource.java  |  11 -
 .../catalog/data/util/AppCatalogJPAUtils.java   |  23 +-
 .../data/util/AppCatalogResourceType.java       |   3 +-
 .../src/main/resources/META-INF/persistence.xml |   1 +
 .../src/main/resources/appcatalog-derby.sql     |  16 +-
 .../src/main/resources/appcatalog-mysql.sql     |  16 +-
 .../src/test/resources/appcatalog-derby.sql     |  16 +-
 13 files changed, 663 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java
b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java
index 361408d..4786e52 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java
@@ -67,10 +67,10 @@ public class AiravataAPIServer implements IServer{
 			TServerTransport serverTransport;
 			
 			if(serverHost == null){
-				serverTransport = new TServerSocket(serverPort);
+				serverTransport = new TServerSocket(serverPort, 10000);
 			}else{
 				InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
-				serverTransport = new TServerSocket(inetSocketAddress);
+				serverTransport = new TServerSocket(inetSocketAddress, 10000);
 			}
 			
             TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/ComputeResourcePreference.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/ComputeResourcePreference.java
b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/ComputeResourcePreference.java
new file mode 100644
index 0000000..751cfcb
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/ComputeResourcePreference.java
@@ -0,0 +1,139 @@
+/*
+ *
+ * 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.model;
+
+
+import org.apache.aiaravata.application.catalog.data.resources.ComputeHostResource;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name = "GATEWAY_PROFILE")
+@IdClass(ComputeResourcePreferencePK.class)
+public class ComputeResourcePreference {
+    @Id
+    @Column(name = "GATEWAY_ID")
+    private String gatewayId;
+    @Id
+    @Column(name = "RESOURCE_ID")
+    private String resourceId;
+    @Column(name = "OVERRIDE_BY_AIRAVATA")
+    private boolean overrideByAiravata;
+    @Column(name = "PREFERED_JOB_SUB_PROTOCOL")
+    private String preferedJobSubmissionProtocol;
+    @Column(name = "PREFERED_DATA_MOVE_PROTOCOL")
+    private String preferedDataMoveProtocol;
+    @Column(name = "PREFERED_BATCH_QUEUE")
+    private String batchQueue;
+    @Column(name = "SCRATCH_LOCATION")
+    private String scratchLocation;
+    @Column(name = "ALLOCATION_PROJECT_NUMBER")
+    private String projectNumber;
+
+    @ManyToOne(cascade= CascadeType.MERGE)
+    @JoinColumn(name = "RESOURCE_ID")
+    private ComputeResource computeHostResource;
+
+    @ManyToOne(cascade= CascadeType.MERGE)
+    @JoinColumn(name = "GATEWAY_ID")
+    private GatewayProfile gatewayProfile;
+
+    public String getGatewayId() {
+        return gatewayId;
+    }
+
+    public void setGatewayId(String gatewayId) {
+        this.gatewayId = gatewayId;
+    }
+
+    public String getResourceId() {
+        return resourceId;
+    }
+
+    public void setResourceId(String resourceId) {
+        this.resourceId = resourceId;
+    }
+
+    public boolean isOverrideByAiravata() {
+        return overrideByAiravata;
+    }
+
+    public void setOverrideByAiravata(boolean overrideByAiravata) {
+        this.overrideByAiravata = overrideByAiravata;
+    }
+
+    public String getPreferedJobSubmissionProtocol() {
+        return preferedJobSubmissionProtocol;
+    }
+
+    public void setPreferedJobSubmissionProtocol(String preferedJobSubmissionProtocol) {
+        this.preferedJobSubmissionProtocol = preferedJobSubmissionProtocol;
+    }
+
+    public String getPreferedDataMoveProtocol() {
+        return preferedDataMoveProtocol;
+    }
+
+    public void setPreferedDataMoveProtocol(String preferedDataMoveProtocol) {
+        this.preferedDataMoveProtocol = preferedDataMoveProtocol;
+    }
+
+    public String getBatchQueue() {
+        return batchQueue;
+    }
+
+    public void setBatchQueue(String batchQueue) {
+        this.batchQueue = batchQueue;
+    }
+
+    public String getScratchLocation() {
+        return scratchLocation;
+    }
+
+    public void setScratchLocation(String scratchLocation) {
+        this.scratchLocation = scratchLocation;
+    }
+
+    public String getProjectNumber() {
+        return projectNumber;
+    }
+
+    public void setProjectNumber(String projectNumber) {
+        this.projectNumber = projectNumber;
+    }
+
+    public ComputeResource getComputeHostResource() {
+        return computeHostResource;
+    }
+
+    public void setComputeHostResource(ComputeResource computeHostResource) {
+        this.computeHostResource = computeHostResource;
+    }
+
+    public GatewayProfile getGatewayProfile() {
+        return gatewayProfile;
+    }
+
+    public void setGatewayProfile(GatewayProfile gatewayProfile) {
+        this.gatewayProfile = gatewayProfile;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/ComputeResourcePreferencePK.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/ComputeResourcePreferencePK.java
b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/ComputeResourcePreferencePK.java
new file mode 100644
index 0000000..5e2c0b7
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/ComputeResourcePreferencePK.java
@@ -0,0 +1,64 @@
+/*
+ *
+ * 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.model;
+
+import java.io.Serializable;
+
+public class ComputeResourcePreferencePK implements Serializable {
+    private String gatewayId;
+    private String resourceId;
+
+    public ComputeResourcePreferencePK(String gatewayId, String resourceId) {
+        this.gatewayId = gatewayId;
+        this.resourceId = resourceId;
+    }
+
+    public ComputeResourcePreferencePK() {
+        ;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return 1;
+    }
+
+    public String getGatewayId() {
+        return gatewayId;
+    }
+
+    public void setGatewayId(String gatewayId) {
+        this.gatewayId = gatewayId;
+    }
+
+    public String getResourceId() {
+        return resourceId;
+    }
+
+    public void setResourceId(String resourceId) {
+        this.resourceId = resourceId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/GatewayProfile.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/GatewayProfile.java
b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/GatewayProfile.java
index 858cfc8..2809b53 100644
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/GatewayProfile.java
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/model/GatewayProfile.java
@@ -37,8 +37,6 @@ public class GatewayProfile implements Serializable {
     private String gatewayName;
     @Column(name = "GATEWAY_DESC")
     private String gatewayDesc;
-    @Column(name = "PREFERED_RESOURCE")
-    private String preferedResource;
 
     public String getGatewayID() {
         return gatewayID;
@@ -63,12 +61,4 @@ public class GatewayProfile implements Serializable {
     public void setGatewayDesc(String gatewayDesc) {
         this.gatewayDesc = gatewayDesc;
     }
-
-    public String getPreferedResource() {
-        return preferedResource;
-    }
-
-    public void setPreferedResource(String preferedResource) {
-        this.preferedResource = preferedResource;
-    }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/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
index 059aba6..78edf60 100644
--- 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
@@ -48,6 +48,7 @@ public abstract class AbstractResource implements Resource {
     public static final String APPLICATION_INPUT = "ApplicationInput";
     public static final String APPLICATION_OUTPUT = "ApplicationOutput";
     public static final String GATEWAY_PROFILE = "GatewayProfile";
+    public static final String COMPUTE_RESOURCE_PREFERENCE = "ComputeResourcePreference";
 
     // Compute Resource Table
     public final class ComputeResourceConstants {
@@ -212,7 +213,17 @@ public abstract class AbstractResource implements Resource {
         public static final String GATEWAY_ID = "gatewayID";
         public static final String GATEWAY_NAME = "gatewayName";
         public static final String GATEWAY_DESC = "gatewayDesc";
-        public static final String PREFERED_RESOURCE = "preferedResource";
+    }
+
+    public final class ComputeResourcePreferenceConstants {
+        public static final String GATEWAY_ID = "gatewayID";
+        public static final String RESOURCE_ID = "resourceId";
+        public static final String OVERRIDE_BY_AIRAVATA = "overrideByAiravata";
+        public static final String PREFERED_JOB_SUB_PROTOCOL = "preferedJobSubmissionProtocol";
+        public static final String PREFERED_DATA_MOVE_PROTOCOL = "preferedDataMoveProtocol";
+        public static final String PREFERED_BATCH_QUEUE = "batchQueue";
+        public static final String SCRATCH_LOCATION = "scratchLocation";
+        public static final String ALLOCATION_PROJECT_NUMBER = "projectNumber";
     }
 
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostPreferenceResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostPreferenceResource.java
b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostPreferenceResource.java
new file mode 100644
index 0000000..925f6b2
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostPreferenceResource.java
@@ -0,0 +1,376 @@
+/*
+ *
+ * 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.model.ComputeResourcePreference;
+import org.apache.aiaravata.application.catalog.data.model.ComputeResourcePreferencePK;
+import org.apache.aiaravata.application.catalog.data.model.GatewayProfile;
+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 ComputeHostPreferenceResource extends AbstractResource {
+    private final static Logger logger = LoggerFactory.getLogger(ComputeHostPreferenceResource.class);
+    private String gatewayId;
+    private String resourceId;
+    private boolean overrideByAiravata;
+    private String preferredJobProtocol;
+    private String preferedDMProtocol;
+    private String batchQueue;
+    private String scratchLocation;
+    private String projectNumber;
+
+    private GatewayProfileResource gatewayProfile;
+    private ComputeHostResource computeHostResource;
+
+    public String getGatewayId() {
+        return gatewayId;
+    }
+
+    public void setGatewayId(String gatewayId) {
+        this.gatewayId = gatewayId;
+    }
+
+    public String getResourceId() {
+        return resourceId;
+    }
+
+    public void setResourceId(String resourceId) {
+        this.resourceId = resourceId;
+    }
+
+    public boolean getOverrideByAiravata() {
+        return overrideByAiravata;
+    }
+
+    public void setOverrideByAiravata(boolean overrideByAiravata) {
+        this.overrideByAiravata = overrideByAiravata;
+    }
+
+    public String getPreferredJobProtocol() {
+        return preferredJobProtocol;
+    }
+
+    public void setPreferredJobProtocol(String preferredJobProtocol) {
+        this.preferredJobProtocol = preferredJobProtocol;
+    }
+
+    public String getPreferedDMProtocol() {
+        return preferedDMProtocol;
+    }
+
+    public void setPreferedDMProtocol(String preferedDMProtocol) {
+        this.preferedDMProtocol = preferedDMProtocol;
+    }
+
+    public String getBatchQueue() {
+        return batchQueue;
+    }
+
+    public void setBatchQueue(String batchQueue) {
+        this.batchQueue = batchQueue;
+    }
+
+    public String getScratchLocation() {
+        return scratchLocation;
+    }
+
+    public void setScratchLocation(String scratchLocation) {
+        this.scratchLocation = scratchLocation;
+    }
+
+    public String getProjectNumber() {
+        return projectNumber;
+    }
+
+    public void setProjectNumber(String projectNumber) {
+        this.projectNumber = projectNumber;
+    }
+
+    public GatewayProfileResource getGatewayProfile() {
+        return gatewayProfile;
+    }
+
+    public void setGatewayProfile(GatewayProfileResource gatewayProfile) {
+        this.gatewayProfile = gatewayProfile;
+    }
+
+    public ComputeHostResource getComputeHostResource() {
+        return computeHostResource;
+    }
+
+    public void setComputeHostResource(ComputeHostResource computeHostResource) {
+        this.computeHostResource = computeHostResource;
+    }
+
+    @Override
+    public void remove(Object identifier) throws AppCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap) identifier;
+        } else {
+            logger.error("Identifier should be a map with the field name and it's value");
+            throw new AppCatalogException("Identifier should be a map with the field name
and it's value");
+        }
+
+        EntityManager em = null;
+        try {
+            em = AppCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(COMPUTE_RESOURCE_PREFERENCE);
+            generator.setParameter(ComputeResourcePreferenceConstants.RESOURCE_ID, ids.get(ComputeResourcePreferenceConstants.RESOURCE_ID));
+            generator.setParameter(ComputeResourcePreferenceConstants.GATEWAY_ID, ids.get(ComputeResourcePreferenceConstants.GATEWAY_ID));
+
+            Query q = generator.deleteQuery(em);
+            q.executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new AppCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    @Override
+    public Resource get(Object identifier) throws AppCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap) 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(COMPUTE_RESOURCE_PREFERENCE);
+            generator.setParameter(ComputeResourcePreferenceConstants.GATEWAY_ID, ids.get(ComputeResourcePreferenceConstants.GATEWAY_ID));
+            generator.setParameter(ComputeResourcePreferenceConstants.RESOURCE_ID, ids.get(ComputeResourcePreferenceConstants.RESOURCE_ID));
+            Query q = generator.selectQuery(em);
+            ComputeResourcePreference preference = (ComputeResourcePreference) q.getSingleResult();
+            ComputeHostPreferenceResource preferenceResource =
+                    (ComputeHostPreferenceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE_PREFERENCE,
preference);
+            em.getTransaction().commit();
+            em.close();
+            return preferenceResource;
+        } 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> preferenceResourceList = new ArrayList<Resource>();
+        EntityManager em = null;
+        try {
+            em = AppCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query q;
+            AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(COMPUTE_RESOURCE_PREFERENCE);
+            List results;
+            if (fieldName.equals(ComputeResourcePreferenceConstants.RESOURCE_ID)) {
+                generator.setParameter(ComputeResourcePreferenceConstants.RESOURCE_ID, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        ComputeResourcePreference preference = (ComputeResourcePreference)
result;
+                        ComputeHostPreferenceResource preferenceResource =
+                                (ComputeHostPreferenceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE_PREFERENCE,
preference);
+                        preferenceResourceList.add(preferenceResource);
+                    }
+                }
+            } else if (fieldName.equals(ComputeResourcePreferenceConstants.GATEWAY_ID)) {
+                generator.setParameter(ComputeResourcePreferenceConstants.GATEWAY_ID, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        ComputeResourcePreference preference = (ComputeResourcePreference)
result;
+                        ComputeHostPreferenceResource preferenceResource =
+                                (ComputeHostPreferenceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE_PREFERENCE,
preference);
+                        preferenceResourceList.add(preferenceResource);
+                    }
+                }
+            } else if (fieldName.equals(ComputeResourcePreferenceConstants.PREFERED_JOB_SUB_PROTOCOL))
{
+                generator.setParameter(ComputeResourcePreferenceConstants.PREFERED_JOB_SUB_PROTOCOL,
value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        ComputeResourcePreference preference = (ComputeResourcePreference)
result;
+                        ComputeHostPreferenceResource preferenceResource =
+                                (ComputeHostPreferenceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE_PREFERENCE,
preference);
+                        preferenceResourceList.add(preferenceResource);
+                    }
+                }
+            } else if (fieldName.equals(ComputeResourcePreferenceConstants.PREFERED_DATA_MOVE_PROTOCOL))
{
+                generator.setParameter(ComputeResourcePreferenceConstants.PREFERED_DATA_MOVE_PROTOCOL,
value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        ComputeResourcePreference preference = (ComputeResourcePreference)
result;
+                        ComputeHostPreferenceResource preferenceResource =
+                                (ComputeHostPreferenceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE_PREFERENCE,
preference);
+                        preferenceResourceList.add(preferenceResource);
+                    }
+                }
+            } else {
+                em.getTransaction().commit();
+                em.close();
+                logger.error("Unsupported field name for Compute host preference Resource.",
new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported field name for Compute host
preference 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 preferenceResourceList;
+    }
+
+    @Override
+    public List<String> getIds(String fieldName, Object value) throws AppCatalogException
{
+        logger.error("Unsupported for objects with a composite identifier");
+        throw new AppCatalogException("Unsupported for objects with a composite identifier");
+    }
+
+    @Override
+    public void save() throws AppCatalogException {
+        EntityManager em = null;
+        try {
+            em = AppCatalogJPAUtils.getEntityManager();
+            ComputeResourcePreference existingPreference = em.find(ComputeResourcePreference.class,
new ComputeResourcePreferencePK(gatewayId, resourceId));
+            em.close();
+
+            em = AppCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            ComputeResource computeResource = em.find(ComputeResource.class, resourceId);
+            GatewayProfile gatewayProf = em.find(GatewayProfile.class, gatewayId);
+            if (existingPreference != null) {
+                existingPreference.setResourceId(resourceId);
+                existingPreference.setGatewayId(gatewayId);
+                existingPreference.setComputeHostResource(computeResource);
+                existingPreference.setGatewayProfile(gatewayProf);
+                existingPreference.setOverrideByAiravata(overrideByAiravata);
+                existingPreference.setPreferedJobSubmissionProtocol(preferredJobProtocol);
+                existingPreference.setPreferedDataMoveProtocol(preferedDMProtocol);
+                existingPreference.setScratchLocation(scratchLocation);
+                existingPreference.setProjectNumber(projectNumber);
+                em.merge(existingPreference);
+            } else {
+                ComputeResourcePreference resourcePreference = new ComputeResourcePreference();
+                resourcePreference.setResourceId(resourceId);
+                resourcePreference.setGatewayId(gatewayId);
+                resourcePreference.setComputeHostResource(computeResource);
+                resourcePreference.setGatewayProfile(gatewayProf);
+                resourcePreference.setOverrideByAiravata(overrideByAiravata);
+                resourcePreference.setPreferedJobSubmissionProtocol(preferredJobProtocol);
+                resourcePreference.setPreferedDataMoveProtocol(preferedDMProtocol);
+                resourcePreference.setScratchLocation(scratchLocation);
+                resourcePreference.setProjectNumber(projectNumber);
+                em.persist(resourcePreference);
+            }
+            em.getTransaction().commit();
+            em.close();
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new AppCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    @Override
+    public boolean isExists(Object identifier) throws AppCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap) 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();
+            ComputeResourcePreference existingPreference = em.find(ComputeResourcePreference.class,
+                    new ComputeResourcePreferencePK(ids.get(ComputeResourcePreferenceConstants.GATEWAY_ID),
+                            ids.get(ComputeResourcePreferenceConstants.RESOURCE_ID)));
+            em.close();
+            return existingPreference != null;
+        }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();
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/GatewayProfileResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/GatewayProfileResource.java
b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/GatewayProfileResource.java
index 9a2ac65..8ce60eb 100644
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/GatewayProfileResource.java
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/GatewayProfileResource.java
@@ -20,7 +20,6 @@ public class GatewayProfileResource extends AbstractResource {
     private String gatewayID;
     private String gatewayName;
     private String gatewayDesc;
-    private String preferedResource;
 
     public void remove(Object identifier) throws AppCatalogException {
         EntityManager em = null;
@@ -192,14 +191,12 @@ public class GatewayProfileResource extends AbstractResource {
             if (existingGatewayProfile != null) {
                 existingGatewayProfile.setGatewayDesc(gatewayDesc);
                 existingGatewayProfile.setGatewayName(gatewayName);
-                existingGatewayProfile.setPreferedResource(preferedResource);
                 em.merge(existingGatewayProfile);
             } else {
                 GatewayProfile gatewayProfile = new GatewayProfile();
                 gatewayProfile.setGatewayID(gatewayID);
                 gatewayProfile.setGatewayName(gatewayName);
                 gatewayProfile.setGatewayDesc(gatewayDesc);
-                gatewayProfile.setPreferedResource(preferedResource);
                 em.persist(gatewayProfile);
             }
             em.getTransaction().commit();
@@ -260,12 +257,4 @@ public class GatewayProfileResource extends AbstractResource {
     public void setGatewayDesc(String gatewayDesc) {
         this.gatewayDesc = gatewayDesc;
     }
-
-    public String getPreferedResource() {
-        return preferedResource;
-    }
-
-    public void setPreferedResource(String preferedResource) {
-        this.preferedResource = preferedResource;
-    }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/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
index a293f33..160083a 100644
--- 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
@@ -253,6 +253,13 @@ public class AppCatalogJPAUtils {
                     logger.error("Object should be a GatewayProfile.", new IllegalArgumentException());
                     throw new IllegalArgumentException("Object should be a GatewayProfile.");
                 }
+            case COMPUTE_RESOURCE_PREFERENCE:
+                if (o instanceof ComputeResourcePreference){
+                    return createComputeResourcePref((ComputeResourcePreference) o);
+                }else {
+                    logger.error("Object should be a Compute Resource Preference.", new IllegalArgumentException());
+                    throw new IllegalArgumentException("Object should be a Compute Resource
Preference.");
+                }
             case APPLICATION_INPUT:
                 if (o instanceof ApplicationInput){
                     return createApplicationInput((ApplicationInput) o);
@@ -483,7 +490,21 @@ public class AppCatalogJPAUtils {
         resource.setGatewayID(o.getGatewayID());
         resource.setGatewayName(o.getGatewayName());
         resource.setGatewayDesc(o.getGatewayDesc());
-        resource.setPreferedResource(o.getPreferedResource());
+        return resource;
+    }
+
+    private static Resource createComputeResourcePref(ComputeResourcePreference o) {
+        ComputeHostPreferenceResource resource = new ComputeHostPreferenceResource();
+        resource.setGatewayId(o.getGatewayId());
+        resource.setResourceId(o.getResourceId());
+        resource.setOverrideByAiravata(o.isOverrideByAiravata());
+        resource.setPreferredJobProtocol(o.getPreferedJobSubmissionProtocol());
+        resource.setPreferedDMProtocol(o.getPreferedDataMoveProtocol());
+        resource.setBatchQueue(o.getBatchQueue());
+        resource.setScratchLocation(o.getScratchLocation());
+        resource.setProjectNumber(o.getProjectNumber());
+        resource.setComputeHostResource((ComputeHostResource)createComputeResource(o.getComputeHostResource()));
+        resource.setGatewayProfile((GatewayProfileResource)createGatewayProfile(o.getGatewayProfile()));
         return resource;
     }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/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
index 7e48250..174dfa5 100644
--- 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
@@ -46,5 +46,6 @@ public enum AppCatalogResourceType {
     APP_MODULE_MAPPING,
     APPLICATION_INPUT,
     APPLICATION_OUTPUT,
-    GATEWAY_PROFILE
+    GATEWAY_PROFILE,
+    COMPUTE_RESOURCE_PREFERENCE
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/modules/app-catalog/app-catalog-data/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/resources/META-INF/persistence.xml
b/modules/app-catalog/app-catalog-data/src/main/resources/META-INF/persistence.xml
index 167e08c..c7ca38d 100644
--- a/modules/app-catalog/app-catalog-data/src/main/resources/META-INF/persistence.xml
+++ b/modules/app-catalog/app-catalog-data/src/main/resources/META-INF/persistence.xml
@@ -48,6 +48,7 @@
         <class>org.apache.aiaravata.application.catalog.data.model.ApplicationInput</class>
         <class>org.apache.aiaravata.application.catalog.data.model.ApplicationOutput</class>
         <class>org.apache.aiaravata.application.catalog.data.model.GatewayProfile</class>
+        <class>org.apache.aiaravata.application.catalog.data.model.ComputeResourcePreference</class>
         <exclude-unlisted-classes>true</exclude-unlisted-classes>
     </persistence-unit>
 </persistence>

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/modules/app-catalog/app-catalog-data/src/main/resources/appcatalog-derby.sql
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/resources/appcatalog-derby.sql
b/modules/app-catalog/app-catalog-data/src/main/resources/appcatalog-derby.sql
index 4c23c09..765c50b 100644
--- a/modules/app-catalog/app-catalog-data/src/main/resources/appcatalog-derby.sql
+++ b/modules/app-catalog/app-catalog-data/src/main/resources/appcatalog-derby.sql
@@ -237,10 +237,24 @@ CREATE TABLE GATEWAY_PROFILE
          GATEWAY_ID VARCHAR(255),
          GATEWAY_NAME VARCHAR(255),
          GATEWAY_DESC VARCHAR(255),
-         PREFERED_RESOURCE VARCHAR(255),
          PRIMARY KEY(GATEWAY_ID)
 );
 
+CREATE TABLE COMPUTE_RESOURCE_PREFERENCE
+(
+        GATEWAY_ID VARCHAR(255),
+        RESOURCE_ID VARCHAR(255),
+        OVERRIDE_BY_AIRAVATA SMALLINT(255),
+        PREFERED_JOB_SUB_PROTOCOL VARCHAR(255),
+        PREFERED_DATA_MOVE_PROTOCOL VARCHAR(255),
+        PREFERED_BATCH_QUEUE VARCHAR(255),
+        SCRATCH_LOCATION VARCHAR(255),
+        ALLOCATION_PROJECT_NUMBER VARCHAR(255),
+        PRIMARY KEY(GATEWAY_ID,RESOURCE_ID),
+        FOREIGN KEY (RESOURCE_ID) REFERENCES COMPUTE_RESOURCE(RESOURCE_ID) ON DELETE CASCADE,
+        FOREIGN KEY (GATEWAY_ID) REFERENCES GATEWAY_PROFILE(GATEWAY_ID) ON DELETE CASCADE
+);
+
 
 
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/modules/app-catalog/app-catalog-data/src/main/resources/appcatalog-mysql.sql
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/resources/appcatalog-mysql.sql
b/modules/app-catalog/app-catalog-data/src/main/resources/appcatalog-mysql.sql
index 6877ca4..dcc8dc9 100644
--- a/modules/app-catalog/app-catalog-data/src/main/resources/appcatalog-mysql.sql
+++ b/modules/app-catalog/app-catalog-data/src/main/resources/appcatalog-mysql.sql
@@ -239,7 +239,21 @@ CREATE TABLE GATEWAY_PROFILE
          GATEWAY_ID VARCHAR(255),
          GATEWAY_NAME VARCHAR(255),
          GATEWAY_DESC VARCHAR(255),
-         PREFERED_RESOURCE VARCHAR(255),
          PRIMARY KEY(GATEWAY_ID)
 );
 
+CREATE TABLE COMPUTE_RESOURCE_PREFERENCE
+(
+        GATEWAY_ID VARCHAR(255),
+        RESOURCE_ID VARCHAR(255),
+        OVERRIDE_BY_AIRAVATA SMALLINT(255),
+        PREFERED_JOB_SUB_PROTOCOL VARCHAR(255),
+        PREFERED_DATA_MOVE_PROTOCOL VARCHAR(255),
+        PREFERED_BATCH_QUEUE VARCHAR(255),
+        SCRATCH_LOCATION VARCHAR(255),
+        ALLOCATION_PROJECT_NUMBER VARCHAR(255),
+        PRIMARY KEY(GATEWAY_ID,RESOURCE_ID),
+        FOREIGN KEY (RESOURCE_ID) REFERENCES COMPUTE_RESOURCE(RESOURCE_ID) ON DELETE CASCADE,
+        FOREIGN KEY (GATEWAY_ID) REFERENCES GATEWAY_PROFILE(GATEWAY_ID) ON DELETE CASCADE
+);
+

http://git-wip-us.apache.org/repos/asf/airavata/blob/4d109fd1/modules/app-catalog/app-catalog-data/src/test/resources/appcatalog-derby.sql
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/test/resources/appcatalog-derby.sql
b/modules/app-catalog/app-catalog-data/src/test/resources/appcatalog-derby.sql
index 4c23c09..765c50b 100644
--- a/modules/app-catalog/app-catalog-data/src/test/resources/appcatalog-derby.sql
+++ b/modules/app-catalog/app-catalog-data/src/test/resources/appcatalog-derby.sql
@@ -237,10 +237,24 @@ CREATE TABLE GATEWAY_PROFILE
          GATEWAY_ID VARCHAR(255),
          GATEWAY_NAME VARCHAR(255),
          GATEWAY_DESC VARCHAR(255),
-         PREFERED_RESOURCE VARCHAR(255),
          PRIMARY KEY(GATEWAY_ID)
 );
 
+CREATE TABLE COMPUTE_RESOURCE_PREFERENCE
+(
+        GATEWAY_ID VARCHAR(255),
+        RESOURCE_ID VARCHAR(255),
+        OVERRIDE_BY_AIRAVATA SMALLINT(255),
+        PREFERED_JOB_SUB_PROTOCOL VARCHAR(255),
+        PREFERED_DATA_MOVE_PROTOCOL VARCHAR(255),
+        PREFERED_BATCH_QUEUE VARCHAR(255),
+        SCRATCH_LOCATION VARCHAR(255),
+        ALLOCATION_PROJECT_NUMBER VARCHAR(255),
+        PRIMARY KEY(GATEWAY_ID,RESOURCE_ID),
+        FOREIGN KEY (RESOURCE_ID) REFERENCES COMPUTE_RESOURCE(RESOURCE_ID) ON DELETE CASCADE,
+        FOREIGN KEY (GATEWAY_ID) REFERENCES GATEWAY_PROFILE(GATEWAY_ID) ON DELETE CASCADE
+);
+
 
 
 


Mime
View raw message