airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shame...@apache.org
Subject [14/55] [abbrv] airavata git commit: creating parent logical dir when creating replicas
Date Fri, 25 Mar 2016 21:22:37 GMT
creating parent logical dir when creating replicas


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

Branch: refs/heads/master
Commit: 5e9bf914c251ac5cd36f8718417bbe4d7ba4f1fe
Parents: a23cc63
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Wed Mar 23 15:56:05 2016 -0400
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Wed Mar 23 15:56:05 2016 -0400

----------------------------------------------------------------------
 .../core/data/catalog/impl/DataCatalogImpl.java | 59 +++++++++++++++++++-
 .../airavata/data/catalog/DataCatalogTest.java  |  6 +-
 .../airavata/registry/cpi/DataCatalog.java      |  2 +
 3 files changed, 62 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/5e9bf914/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/impl/DataCatalogImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/impl/DataCatalogImpl.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/impl/DataCatalogImpl.java
index 308abfc..27e6976 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/impl/DataCatalogImpl.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/impl/DataCatalogImpl.java
@@ -34,6 +34,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.persistence.EntityManager;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
@@ -54,6 +56,37 @@ public class DataCatalogImpl implements DataCatalog {
                 productModel.setLogicalPath(productModel.getLogicalPath()+"/");
             productModel.setLogicalPath(productModel.getLogicalPath()+productModel.getProductName());
         }
+        //Creating parent logical dir if not exist too
+        String parentUri = DataCatalog.schema + productModel.getOwnerName() + "@" + productModel.getGatewayId()
+ "/" ;
+        DataProductModel tempDp;
+        if(!isExists(parentUri)){
+            tempDp = new DataProductModel();
+            tempDp.setProductUri(parentUri);
+            tempDp.setLogicalPath("/");
+            tempDp.setOwnerName(productModel.getOwnerName());
+            tempDp.setGatewayId(productModel.getGatewayId());
+            tempDp.setDataProductType(DataProductType.DIR);
+            createDataProduct(tempDp);
+        }
+        String[] bits = productModel.getLogicalPath().split("/");
+        for(int i=0; i<bits.length-1;i++){
+            String dir = bits[i];
+            if(!isExists(parentUri + dir)){
+                tempDp = new DataProductModel();
+                try {
+                    tempDp.setLogicalPath((new URI(parentUri + dir)).getPath());
+                } catch (URISyntaxException e) {
+                    throw new DataCatalogException(e);
+                }
+                tempDp.setProductUri(parentUri + dir);
+                tempDp.setOwnerName(productModel.getOwnerName());
+                tempDp.setGatewayId(productModel.getGatewayId());
+                tempDp.setDataProductType(DataProductType.DIR);
+                tempDp.setParentProductUri(parentUri);
+                parentUri = createDataProduct(tempDp);
+            }
+        }
+
         String productUri = DataCatalog.schema + "://" + productModel.getOwnerName() + "@"
+ productModel.getGatewayId()
                 + productModel.getLogicalPath();
         productModel.setProductUri(productUri);
@@ -70,6 +103,10 @@ public class DataCatalogImpl implements DataCatalog {
         }
         productModel.setCreationTime(System.currentTimeMillis());
         productModel.setLastModifiedTime(System.currentTimeMillis());
+        return createDataProduct(productModel);
+    }
+
+    private String createDataProduct(DataProductModel productModel) throws DataCatalogException
{
         DataProduct dataProduct = ThriftDataModelConversion.getDataProduct(productModel);
         EntityManager em = null;
         try {
@@ -89,7 +126,7 @@ public class DataCatalogImpl implements DataCatalog {
                 em.close();
             }
         }
-        return productUri;
+        return dataProduct.getProductUri();
     }
 
     @Override
@@ -167,6 +204,26 @@ public class DataCatalogImpl implements DataCatalog {
     }
 
     @Override
+    public boolean isExists(String productUri) throws DataCatalogException {
+        EntityManager em = null;
+        try {
+            em = DataCatalogJPAUtils.getEntityManager();
+            DataProduct dataProduct = em.find(DataProduct.class, productUri);
+            return dataProduct != null;
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new DataCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    @Override
     public String registerReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel)
throws DataCatalogException {
         String replicaId = UUID.randomUUID().toString();
         dataReplicaLocationModel.setReplicaId(replicaId);

http://git-wip-us.apache.org/repos/asf/airavata/blob/5e9bf914/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/DataCatalogTest.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/DataCatalogTest.java
b/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/DataCatalogTest.java
index 287a400..627a6e6 100644
--- a/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/DataCatalogTest.java
+++ b/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/DataCatalogTest.java
@@ -21,10 +21,7 @@
 package org.apache.airavata.data.catalog;
 
 import org.apache.airavata.data.catalog.util.Initialize;
-import org.apache.airavata.model.data.product.DataProductModel;
-import org.apache.airavata.model.data.product.DataReplicaLocationModel;
-import org.apache.airavata.model.data.product.ReplicaLocationCategory;
-import org.apache.airavata.model.data.product.ReplicaPersistentType;
+import org.apache.airavata.model.data.product.*;
 import org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory;
 import org.apache.airavata.registry.cpi.DataCatalog;
 import org.apache.airavata.registry.cpi.DataCatalogException;
@@ -56,6 +53,7 @@ public class DataCatalogTest {
             dataProductModel.setOwnerName("scnakandala");
             dataProductModel.setGatewayId("default");
             dataProductModel.setLogicalPath("/test/test/test");
+            dataProductModel.setDataProductType(DataProductType.FILE);
             HashMap<String, String> resMetadata = new HashMap<>();
             resMetadata.put("name", "name");
             dataProductModel.setProductMetadata(resMetadata);

http://git-wip-us.apache.org/repos/asf/airavata/blob/5e9bf914/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalog.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalog.java
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalog.java
index 2ddda7c..42eff2a 100644
--- a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalog.java
+++ b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalog.java
@@ -36,6 +36,8 @@ public interface DataCatalog {
 
     DataProductModel getDataProduct(String productUri) throws DataCatalogException;
 
+    boolean isExists(String productUri) throws DataCatalogException;
+
     String registerReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws
DataCatalogException;
 
     boolean removeReplicaLocation(String replicaId) throws DataCatalogException;


Mime
View raw message