You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2017/12/22 18:35:59 UTC

[airavata] 02/06: Adding repositories for ComputePref and StoragePref

This is an automated email from the ASF dual-hosted git repository.

smarru pushed a commit to branch registry-refactoring
in repository https://gitbox.apache.org/repos/asf/airavata.git

commit 034b41a8ff5255c113b7096c1f38dfdbafbfb3b9
Author: Sachin Kariyattin <sa...@gmail.com>
AuthorDate: Wed Dec 20 12:13:14 2017 -0500

    Adding repositories for ComputePref and StoragePref
---
 .../ComputeResourcePreferenceEntity.java           |  2 +-
 .../entities/appcatalog/GatewayProfileEntity.java  |  2 +-
 ...nceEntity.java => StoragePreferenceEntity.java} | 12 +--
 ...ePreferencePK.java => StoragePreferencePK.java} |  8 +-
 .../appcatalog/ComputeResourceRepository.java      | 14 ++++
 .../appcatalog/GwyResourceProfileRepository.java   | 90 ++++++++++++++++++----
 .../appcatalog/StoragePrefRepository.java          | 13 ++++
 .../airavata/registry/core/utils/DBConstants.java  | 13 ++++
 .../registry/core/utils/QueryConstants.java        | 10 +++
 .../src/main/resources/META-INF/persistence.xml    |  4 +-
 10 files changed, 140 insertions(+), 28 deletions(-)

diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePreferenceEntity.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePreferenceEntity.java
index 8b005c6..682981a 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePreferenceEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePreferenceEntity.java
@@ -32,7 +32,7 @@ import java.sql.Timestamp;
  * The persistent class for the compute_resource_preference database table.
  */
 @Entity
-@Table(name = "compute_resource_preference")
+@Table(name = "COMPUTE_RESOURCE_PREFERENCE")
 public class ComputeResourcePreferenceEntity implements Serializable {
     private static final long serialVersionUID = 1L;
 
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GatewayProfileEntity.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GatewayProfileEntity.java
index 4dbb95a..71fcd71 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GatewayProfileEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GatewayProfileEntity.java
@@ -32,7 +32,7 @@ import java.sql.Timestamp;
  * The persistent class for the gateway_profile database table.
  */
 @Entity
-@Table(name = "gateway_profile")
+@Table(name = "GATEWAY_PROFILE")
 public class GatewayProfileEntity implements Serializable {
     private static final long serialVersionUID = 1L;
 
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/DataStoragePreferenceEntity.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/StoragePreferenceEntity.java
similarity index 87%
rename from modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/DataStoragePreferenceEntity.java
rename to modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/StoragePreferenceEntity.java
index 0798cad..631657c 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/DataStoragePreferenceEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/StoragePreferenceEntity.java
@@ -30,12 +30,12 @@ import java.io.Serializable;
  * The persistent class for the data_storage_preference database table.
  */
 @Entity
-@Table(name = "data_storage_preference")
-public class DataStoragePreferenceEntity implements Serializable {
+@Table(name = "STORAGE_PREFERENCE")
+public class StoragePreferenceEntity implements Serializable {
     private static final long serialVersionUID = 1L;
 
     @EmbeddedId
-    private DataStoragePreferencePK id;
+    private StoragePreferencePK id;
 
     @Column(name = "FS_ROOT_LOCATION")
     private String fsRootLocation;
@@ -46,14 +46,14 @@ public class DataStoragePreferenceEntity implements Serializable {
     @Column(name = "RESOURCE_CS_TOKEN")
     private String resourceCsToken;
 
-    public DataStoragePreferenceEntity() {
+    public StoragePreferenceEntity() {
     }
 
-    public DataStoragePreferencePK getId() {
+    public StoragePreferencePK getId() {
         return id;
     }
 
-    public void setId(DataStoragePreferencePK id) {
+    public void setId(StoragePreferencePK id) {
         this.id = id;
     }
 
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/DataStoragePreferencePK.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/StoragePreferencePK.java
similarity index 90%
rename from modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/DataStoragePreferencePK.java
rename to modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/StoragePreferencePK.java
index a03c62c..7002540 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/DataStoragePreferencePK.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/StoragePreferencePK.java
@@ -28,7 +28,7 @@ import java.io.Serializable;
  * The primary key class for the data_storage_preference database table.
  */
 @Embeddable
-public class DataStoragePreferencePK implements Serializable {
+public class StoragePreferencePK implements Serializable {
     //default serial version id, required for serializable classes.
     private static final long serialVersionUID = 1L;
 
@@ -38,7 +38,7 @@ public class DataStoragePreferencePK implements Serializable {
     @Column(name = "STORAGE_RESOURCE_ID")
     private String storageResourceId;
 
-    public DataStoragePreferencePK() {
+    public StoragePreferencePK() {
     }
 
     public String getGatewayId() {
@@ -61,10 +61,10 @@ public class DataStoragePreferencePK implements Serializable {
         if (this == other) {
             return true;
         }
-        if (!(other instanceof DataStoragePreferencePK)) {
+        if (!(other instanceof StoragePreferencePK)) {
             return false;
         }
-        DataStoragePreferencePK castOther = (DataStoragePreferencePK) other;
+        StoragePreferencePK castOther = (StoragePreferencePK) other;
         return
                 this.gatewayId.equals(castOther.gatewayId)
                         && this.storageResourceId.equals(castOther.storageResourceId);
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ComputeResourceRepository.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ComputeResourceRepository.java
new file mode 100644
index 0000000..6add69f
--- /dev/null
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ComputeResourceRepository.java
@@ -0,0 +1,14 @@
+package org.apache.airavata.registry.core.repositories.appcatalog;
+
+import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
+import org.apache.airavata.registry.core.entities.appcatalog.ComputeResourceEntity;
+import org.apache.airavata.registry.core.entities.appcatalog.ComputeResourcePreferencePK;
+import org.apache.airavata.registry.core.repositories.AbstractRepository;
+
+public class ComputeResourceRepository extends AbstractRepository<ComputeResourcePreference, ComputeResourceEntity, ComputeResourcePreferencePK> {
+
+    public ComputeResourceRepository() {
+        super(ComputeResourcePreference.class, ComputeResourceEntity.class);
+    }
+
+}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GwyResourceProfileRepository.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GwyResourceProfileRepository.java
index 98bc194..07055d9 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GwyResourceProfileRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GwyResourceProfileRepository.java
@@ -1,23 +1,32 @@
 package org.apache.airavata.registry.core.repositories.appcatalog;
 
 import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
 import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
+import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference;
+import org.apache.airavata.registry.core.entities.appcatalog.ComputeResourcePreferencePK;
+import org.apache.airavata.registry.core.entities.appcatalog.StoragePreferencePK;
 import org.apache.airavata.registry.core.entities.appcatalog.GatewayProfileEntity;
 import org.apache.airavata.registry.core.repositories.AbstractRepository;
+import org.apache.airavata.registry.core.utils.DBConstants;
 import org.apache.airavata.registry.core.utils.JPAUtils;
 import org.apache.airavata.registry.core.utils.ObjectMapperSingleton;
+import org.apache.airavata.registry.core.utils.QueryConstants;
 import org.dozer.Mapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 public class GwyResourceProfileRepository extends AbstractRepository<GatewayResourceProfile, GatewayProfileEntity, String>{
 
     private final static Logger logger = LoggerFactory.getLogger(GwyResourceProfileRepository.class);
 
-    public GwyResourceProfileRepository(Class<GatewayResourceProfile> thriftGenericClass, Class<GatewayProfileEntity> dbEntityGenericClass) {
-        super(thriftGenericClass, dbEntityGenericClass);
+    public GwyResourceProfileRepository() {
+        super(GatewayResourceProfile.class, GatewayProfileEntity.class);
     }
 
     public String addGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) {
@@ -25,29 +34,41 @@ public class GwyResourceProfileRepository extends AbstractRepository<GatewayReso
     }
 
     public String updateGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) {
+        String gatewayId = gatewayResourceProfile.getGatewayID();
         Mapper mapper = ObjectMapperSingleton.getInstance();
         GatewayProfileEntity gatewayProfileEntity = mapper.map(gatewayResourceProfile, GatewayProfileEntity.class);
         gatewayProfileEntity.setUpdateTime(AiravataUtils.getCurrentTimestamp());
         GatewayProfileEntity persistedCopy = JPAUtils.execute(entityManager -> entityManager.merge(gatewayProfileEntity));
 
-        //TODO ComputeResourcePreference
-        //TODO StoragePreference
-
+        List<ComputeResourcePreference> computeResourcePreferences = gatewayResourceProfile.getComputeResourcePreferences();
+        if (computeResourcePreferences != null && !computeResourcePreferences.isEmpty()) {
+            for (ComputeResourcePreference preference : computeResourcePreferences ) {
+                (new ComputeResourceRepository()).create(preference);
+            }
+        }
+
+        List<StoragePreference> dataStoragePreferences = gatewayResourceProfile.getStoragePreferences();
+        if (dataStoragePreferences != null && !dataStoragePreferences.isEmpty()) {
+            for (StoragePreference storagePreference : dataStoragePreferences) {
+                (new StoragePrefRepository()).create(storagePreference);
+            }
+        }
         return persistedCopy.getGatewayId();
-
     }
 
     public GatewayResourceProfile getGatewayProfile(String gatewayId) {
-        //TODO ComputeResourcePreference
-        //TODO StoragePreference
+        GatewayResourceProfile gatewayResourceProfile = (new GwyResourceProfileRepository()).getGatewayProfile(gatewayId);
+        gatewayResourceProfile.setComputeResourcePreferences(getAllComputeResourcePreferences(gatewayId));
+        gatewayResourceProfile.setStoragePreferences(getAllStoragePreferences(gatewayId));
+        return gatewayResourceProfile;
     }
 
     public boolean removeGatewayResourceProfile(String gatewayId) {
-        // TODO - Call from handler
+        //return delete(gatewayId);
     }
 
     public boolean isGatewayResourceProfileExists(String gatewayId) {
-        // TODO - Call isExists from handler
+        //return isExists(gatewayId);
     }
 
     public List<String> getGatewayProfileIds(String gatewayName) {
@@ -56,15 +77,56 @@ public class GwyResourceProfileRepository extends AbstractRepository<GatewayReso
 
     public List<GatewayResourceProfile> getAllGatewayProfiles() {
 
-        String queryString = "SELECT * FROM GATEWAY_PROFILE";
+        List<GatewayResourceProfile> gwyResourceProfileList = new ArrayList<GatewayResourceProfile>();
+        List<GatewayResourceProfile> gatewayResourceProfileList = select(QueryConstants.FIND_ALL_GATEWAY_PROFILES,-1, 0);
+        if (gatewayResourceProfileList != null && !gatewayResourceProfileList.isEmpty()) {
+            for (GatewayResourceProfile gatewayResourceProfile: gatewayResourceProfileList) {
+                gatewayResourceProfile.setComputeResourcePreferences(getAllComputeResourcePreferences(gatewayResourceProfile.getGatewayID()));
+                gatewayResourceProfile.setStoragePreferences(getAllStoragePreferences(gatewayResourceProfile.getGatewayID()));
+            }
+        }
+        return gwyResourceProfileList;
+    }
 
-        List<GatewayResourceProfile> gatewayResourceProfileList = select(queryString,-1, 0);
+    public boolean removeComputeResourcePreferenceFromGateway(String gatewayId, String preferenceId) {
+        ComputeResourcePreferencePK computeResourcePreferencePK = new ComputeResourcePreferencePK();
+        computeResourcePreferencePK.setGatewayId(gatewayId);
+        computeResourcePreferencePK.setResourceId(preferenceId);
+        (new ComputeResourceRepository()).delete(computeResourcePreferencePK);
+        return true;
+    }
 
-        //TODO ComputeResourcePreference
-        //TODO StoragePreference
+    public boolean removeDataStoragePreferenceFromGateway(String gatewayId, String preferenceId) {
+        StoragePreferencePK storagePreferencePK = new StoragePreferencePK();
+        storagePreferencePK.setGatewayId(gatewayId);
+        storagePreferencePK.setStorageResourceId(preferenceId);
+        (new StoragePrefRepository()).delete(storagePreferencePK);
+        return true;
     }
 
+    public ComputeResourcePreference getComputeResourcePreference(String gatewayId, String hostId) {
+        ComputeResourcePreferencePK computeResourcePreferencePK = new ComputeResourcePreferencePK();
+        computeResourcePreferencePK.setGatewayId(gatewayId);
+        computeResourcePreferencePK.setResourceId(hostId);
+        return (new ComputeResourceRepository()).get(computeResourcePreferencePK);
+    }
 
+    public StoragePreference getStoragePreference(String gatewayId, String storageId){
+        StoragePreferencePK storagePreferencePK = new StoragePreferencePK();
+        storagePreferencePK.setStorageResourceId(storageId);
+        storagePreferencePK.setGatewayId(gatewayId);
+        return (new StoragePrefRepository()).get(storagePreferencePK);
+    }
 
+    public List<ComputeResourcePreference> getAllComputeResourcePreferences(String gatewayId) {
+        Map<String,Object> queryParameters = new HashMap<>();
+        queryParameters.put(DBConstants.ComputeResourcePreference.GATEWAY_ID, gatewayId);
+        return (new ComputeResourceRepository()).select(QueryConstants.FIND_ALL_COMPUTE_RESOURCE_PREFERENCES, -1, 0, queryParameters);
+    }
 
+    public List<StoragePreference> getAllStoragePreferences(String gatewayId) {
+        Map<String,Object> queryParameters = new HashMap<>();
+        queryParameters.put(DBConstants.StorageResourcePreference.GATEWAY_ID, gatewayId);
+        return (new StoragePrefRepository()).select(QueryConstants.FIND_ALL_STORAGE_RESOURCE_PREFERENCES, -1, 0, queryParameters);
+    }
 }
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/StoragePrefRepository.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/StoragePrefRepository.java
new file mode 100644
index 0000000..d5b054a
--- /dev/null
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/StoragePrefRepository.java
@@ -0,0 +1,13 @@
+package org.apache.airavata.registry.core.repositories.appcatalog;
+
+import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference;
+import org.apache.airavata.registry.core.entities.appcatalog.StoragePreferenceEntity;
+import org.apache.airavata.registry.core.entities.appcatalog.StoragePreferencePK;
+import org.apache.airavata.registry.core.repositories.AbstractRepository;
+
+public class StoragePrefRepository extends AbstractRepository<StoragePreference, StoragePreferenceEntity, StoragePreferencePK> {
+
+    public StoragePrefRepository() {
+        super(StoragePreference.class, StoragePreferenceEntity.class);
+    }
+}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/DBConstants.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/DBConstants.java
new file mode 100644
index 0000000..752b556
--- /dev/null
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/DBConstants.java
@@ -0,0 +1,13 @@
+package org.apache.airavata.registry.core.utils;
+
+public class DBConstants {
+
+    public static class ComputeResourcePreference {
+        public static final String GATEWAY_ID = "gatewayId";
+    }
+
+    public static class StorageResourcePreference {
+        public static final String GATEWAY_ID = "gatewayId";
+    }
+
+}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
index 250c461..244f9d6 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
@@ -2,6 +2,10 @@ package org.apache.airavata.registry.core.utils;
 
 import org.apache.airavata.model.user.UserProfile;
 
+import org.apache.airavata.registry.core.entities.appcatalog.ComputeResourcePreferenceEntity;
+import org.apache.airavata.registry.core.entities.appcatalog.StoragePreferenceEntity;
+import org.apache.airavata.registry.core.entities.appcatalog.GatewayProfileEntity;
+
 public interface QueryConstants {
 
     String FIND_USER_PROFILE_BY_USER_ID = "SELECT u FROM UserProfileEntity u " +
@@ -10,4 +14,10 @@ public interface QueryConstants {
 
     String FIND_ALL_USER_PROFILES_BY_GATEWAY_ID = "SELECT u FROM UserProfileEntity u " +
             "where u.gatewayId LIKE :"+ UserProfile._Fields.GATEWAY_ID.getFieldName() + "";
+
+    String FIND_ALL_GATEWAY_PROFILES = "SELECT G FROM " + GatewayProfileEntity.class.getSimpleName() + "G";
+    String FIND_ALL_COMPUTE_RESOURCE_PREFERENCES = "SELECT DISTINCT CR FROM " + ComputeResourcePreferenceEntity.class.getSimpleName() + "CR " +
+            "WHERE CR.gatewayId LIKE : " + DBConstants.ComputeResourcePreference.GATEWAY_ID;
+    String FIND_ALL_STORAGE_RESOURCE_PREFERENCES = "SELECT DISTINCT S FROM " + StoragePreferenceEntity.class.getSimpleName() + "S " +
+            "WHERE S.gatewayId LIKE : " + DBConstants.StorageResourcePreference.GATEWAY_ID;
 }
diff --git a/modules/registry-refactoring/src/main/resources/META-INF/persistence.xml b/modules/registry-refactoring/src/main/resources/META-INF/persistence.xml
index 68861e4..645165d 100644
--- a/modules/registry-refactoring/src/main/resources/META-INF/persistence.xml
+++ b/modules/registry-refactoring/src/main/resources/META-INF/persistence.xml
@@ -97,7 +97,7 @@
         <class>org.apache.airavata.registry.core.entities.appcatalog.JobManagerCommandEntity</class>
         <class>org.apache.airavata.registry.core.entities.appcatalog.ParallelismCommandEntity</class>
         <class>org.apache.airavata.registry.core.entities.appcatalog.LocalDataMovementEntity</class>
-        <class>org.apache.airavata.registry.core.entities.appcatalog.DataStoragePreferenceEntity</class>
+        <class>org.apache.airavata.registry.core.entities.appcatalog.StoragePreferenceEntity</class>
         <class>org.apache.airavata.registry.core.entities.appcatalog.GlobusGkEndpointPK</class>
         <class>org.apache.airavata.registry.core.entities.appcatalog.GsisshPostjobcommandPK</class>
         <class>org.apache.airavata.registry.core.entities.appcatalog.GsisshPrejobcommandPK</class>
@@ -124,7 +124,7 @@
         <class>org.apache.airavata.registry.core.entities.appcatalog.StorageInterfacePK</class>
         <class>org.apache.airavata.registry.core.entities.appcatalog.JobManagerCommandPK</class>
         <class>org.apache.airavata.registry.core.entities.appcatalog.ParallelismCommandPK</class>
-        <class>org.apache.airavata.registry.core.entities.appcatalog.DataStoragePreferencePK</class>
+        <class>org.apache.airavata.registry.core.entities.appcatalog.StoragePreferencePK</class>
 
         <exclude-unlisted-classes>true</exclude-unlisted-classes>
     </persistence-unit>

-- 
To stop receiving notification emails like this one, please contact
"commits@airavata.apache.org" <co...@airavata.apache.org>.