airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chath...@apache.org
Subject airavata git commit: fixing issues with storage resource
Date Mon, 14 Dec 2015 16:11:45 GMT
Repository: airavata
Updated Branches:
  refs/heads/master d3a5a5ea6 -> 94f9af2dd


fixing issues with storage resource


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

Branch: refs/heads/master
Commit: 94f9af2ddbb2a83cdaee3c74e84280bec2501474
Parents: d3a5a5e
Author: Chathuri Wimalasena <chathuri@apache.org>
Authored: Mon Dec 14 11:11:41 2015 -0500
Committer: Chathuri Wimalasena <chathuri@apache.org>
Committed: Mon Dec 14 11:11:41 2015 -0500

----------------------------------------------------------------------
 .../app/catalog/impl/ComputeResourceImpl.java   |   4 +-
 .../app/catalog/impl/StorageResourceImpl.java   |  17 +++
 .../app/catalog/util/AppCatalogJPAUtils.java    |   2 +-
 .../util/AppCatalogThriftConversion.java        |  37 +++--
 .../catalog/StorageResourceAppCatalogTest.java  | 152 +++++++++++++++++++
 5 files changed, 199 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/94f9af2d/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/ComputeResourceImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/ComputeResourceImpl.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/ComputeResourceImpl.java
index 5df3270..8ce13a3 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/ComputeResourceImpl.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/ComputeResourceImpl.java
@@ -79,7 +79,7 @@ public class ComputeResourceImpl implements ComputeResource {
 		List<DataMovementInterface> dataMovemenetInterfaces = description.getDataMovementInterfaces();
 		if (dataMovemenetInterfaces != null && !dataMovemenetInterfaces.isEmpty()) {
 		    for (DataMovementInterface dataMovementInterface : dataMovemenetInterfaces) {
-		    	DataMovementInterfaceResource dmir = AppCatalogThriftConversion.getDataMovementInterface(dataMovementInterface);
+		    	DataMovementInterfaceResource dmir = AppCatalogThriftConversion.getDataMovementInterfaceResource(dataMovementInterface);
 		    	dmir.setComputeHostResource(computeHostResource);
 		    	dmir.setComputeResourceId(computeHostResource.getResourceId());
 				dmir.save();
@@ -372,7 +372,7 @@ public class ComputeResourceImpl implements ComputeResource {
         try {
             String dmId = null;
             if (dmType.equals(DMType.COMPUTE_RESOURCE)){
-                DataMovementInterfaceResource dmi = AppCatalogThriftConversion.getDataMovementInterface(dataMovementInterface);
+                DataMovementInterfaceResource dmi = AppCatalogThriftConversion.getDataMovementInterfaceResource(dataMovementInterface);
                 dmi.setComputeResourceId(resourceId);
                 ComputeResourceResource computeResourceResource = new ComputeResourceResource();
                 computeResourceResource=(ComputeResourceResource)computeResourceResource.get(resourceId);

http://git-wip-us.apache.org/repos/asf/airavata/blob/94f9af2d/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/StorageResourceImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/StorageResourceImpl.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/StorageResourceImpl.java
index bc0bcc7..c761e5d 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/StorageResourceImpl.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/StorageResourceImpl.java
@@ -23,8 +23,10 @@ package org.apache.airavata.registry.core.app.catalog.impl;
 
 import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription;
 import org.apache.airavata.model.commons.airavata_commonsConstants;
+import org.apache.airavata.model.data.movement.DataMovementInterface;
 import org.apache.airavata.registry.core.app.catalog.resources.AppCatAbstractResource;
 import org.apache.airavata.registry.core.app.catalog.resources.AppCatalogResource;
+import org.apache.airavata.registry.core.app.catalog.resources.StorageInterfaceResource;
 import org.apache.airavata.registry.core.app.catalog.resources.StorageResourceResource;
 import org.apache.airavata.registry.core.app.catalog.util.AppCatalogThriftConversion;
 import org.apache.airavata.registry.core.app.catalog.util.AppCatalogUtils;
@@ -53,9 +55,24 @@ public class StorageResourceImpl implements StorageResource {
 			StorageResourceDescription description) throws AppCatalogException {
         StorageResourceResource storageResourceResource = AppCatalogThriftConversion.getStorageResource(description);
         storageResourceResource.save();
+        saveDataMovementInterfaces(description, storageResourceResource);
 		return storageResourceResource;
 	}
 
+    protected void saveDataMovementInterfaces(
+            StorageResourceDescription description,
+            StorageResourceResource storageResourceResource)
+            throws AppCatalogException {
+        List<DataMovementInterface> dataMovemenetInterfaces = description.getDataMovementInterfaces();
+        if (dataMovemenetInterfaces != null && !dataMovemenetInterfaces.isEmpty())
{
+            for (DataMovementInterface dataMovementInterface : dataMovemenetInterfaces) {
+                StorageInterfaceResource storageInterface = AppCatalogThriftConversion.getStorageInterface(dataMovementInterface);
+                storageInterface.setStorageResourceResource(storageResourceResource);
+                storageInterface.setStorageResourceId(storageResourceResource.getStorageResourceId());
+                storageInterface.save();
+            }
+        }
+    }
     /**
      * This function will add a storage resource description to the database
      *

http://git-wip-us.apache.org/repos/asf/airavata/blob/94f9af2d/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java
index 50af371..09f2467 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java
@@ -941,7 +941,7 @@ public class AppCatalogJPAUtils {
         if (o != null) {
             resource.setStorageResourceId(o.getStorageResourceId());
             resource.setDataMovementInterfaceId(o.getDataMovementInterfaceId());
-            resource.setDataMovementInterfaceId(o.getDataMovementInterfaceId());
+            resource.setDataMovementProtocol(o.getDataMovementProtocol());
             resource.setStorageResourceResource((StorageResourceResource)createStorageResource(o.getStorageResource()));
         }
         return resource;

http://git-wip-us.apache.org/repos/asf/airavata/blob/94f9af2d/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogThriftConversion.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogThriftConversion.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogThriftConversion.java
index a634d72..4a094a6 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogThriftConversion.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogThriftConversion.java
@@ -118,9 +118,11 @@ public class AppCatalogThriftConversion {
         description.setHostName(resource.getHostName());
         description.setStorageResourceDescription(resource.getResourceDescription());
         description.setEnabled(resource.isEnabled());
-        List<AppCatalogResource> dmiList = resource.get(AppCatAbstractResource.StorageInterfaceConstants.STORAGE_RESOURCE_ID,
resource.getStorageResourceId());
-        if (dmiList != null && !dmiList.isEmpty()){
-            description.setDataMovementInterfaces(getDataMovementInterfaces(dmiList));
+        StorageInterfaceResource interfaceResource = new StorageInterfaceResource();
+        interfaceResource.setStorageResourceId(resource.getStorageResourceId());
+        List<AppCatalogResource> resources = interfaceResource.get(AppCatAbstractResource.StorageResourceConstants.RESOURCE_ID,
resource.getStorageResourceId());
+        if (resources != null && !resources.isEmpty()){
+            description.setDataMovementInterfaces(getDataMovementInterfacesForStorageResource(resources));
         }
         return description;
     }
@@ -164,31 +166,46 @@ public class AppCatalogThriftConversion {
         }
         return batchQueues;
     }
-    
+
     public static List<DataMovementInterface> getDataMovementInterfaces(List<AppCatalogResource>
resources){
+        List<DataMovementInterface> dataMovementInterfaces = new ArrayList<DataMovementInterface>();
+        for (AppCatalogResource resource : resources){
+            dataMovementInterfaces.add(getDataMovementInterface((DataMovementInterfaceResource)resource));
+        }
+        return dataMovementInterfaces;
+    }
+
+    public static List<DataMovementInterface> getDataMovementInterfacesForStorageResource(List<AppCatalogResource>
resources){
     	List<DataMovementInterface> dataMovementInterfaces = new ArrayList<DataMovementInterface>();
         for (AppCatalogResource resource : resources){
-        	dataMovementInterfaces.add(getDataMovementInterface((DataMovementInterfaceResource)resource));
+        	dataMovementInterfaces.add(getDataMovementInterfaceForStorageResource((StorageInterfaceResource)resource));
         }
         return dataMovementInterfaces;
     }
     
-    public static DataMovementInterface getDataMovementInterface(DataMovementInterfaceResource
resource){
+    public static DataMovementInterface getDataMovementInterfaceForStorageResource(StorageInterfaceResource
resource){
     	DataMovementInterface dmi = new DataMovementInterface();
     	dmi.setDataMovementInterfaceId(resource.getDataMovementInterfaceId());
     	dmi.setDataMovementProtocol(DataMovementProtocol.valueOf(resource.getDataMovementProtocol()));
-    	dmi.setPriorityOrder(resource.getPriorityOrder());
         return dmi;
     }
     
-    public static DataMovementInterfaceResource getDataMovementInterface(DataMovementInterface
resource){
-    	DataMovementInterfaceResource dmi = new DataMovementInterfaceResource();
+    public static DataMovementInterface getDataMovementInterface(DataMovementInterfaceResource
resource){
+        DataMovementInterface dmi = new DataMovementInterface();
     	dmi.setDataMovementInterfaceId(resource.getDataMovementInterfaceId());
-    	dmi.setDataMovementProtocol(resource.getDataMovementProtocol().toString());
+    	dmi.setDataMovementProtocol(DataMovementProtocol.valueOf(resource.getDataMovementProtocol()));
     	dmi.setPriorityOrder(resource.getPriorityOrder());
         return dmi;
     }
 
+    public static DataMovementInterfaceResource getDataMovementInterfaceResource(DataMovementInterface
dataMovementInterface){
+        DataMovementInterfaceResource dmi = new DataMovementInterfaceResource();
+        dmi.setDataMovementInterfaceId(dataMovementInterface.getDataMovementInterfaceId());
+        dmi.setDataMovementProtocol(dataMovementInterface.getDataMovementProtocol().toString());
+        dmi.setPriorityOrder(dataMovementInterface.getPriorityOrder());
+        return dmi;
+    }
+
     public static StorageInterfaceResource getStorageInterface(DataMovementInterface resource){
         StorageInterfaceResource storageInterfaceResource = new StorageInterfaceResource();
         storageInterfaceResource.setDataMovementInterfaceId(resource.getDataMovementInterfaceId());

http://git-wip-us.apache.org/repos/asf/airavata/blob/94f9af2d/modules/registry/registry-core/src/test/java/org/apache/airavata/app/catalog/StorageResourceAppCatalogTest.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/test/java/org/apache/airavata/app/catalog/StorageResourceAppCatalogTest.java
b/modules/registry/registry-core/src/test/java/org/apache/airavata/app/catalog/StorageResourceAppCatalogTest.java
new file mode 100644
index 0000000..981a204
--- /dev/null
+++ b/modules/registry/registry-core/src/test/java/org/apache/airavata/app/catalog/StorageResourceAppCatalogTest.java
@@ -0,0 +1,152 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.app.catalog;
+
+
+import org.apache.airavata.app.catalog.util.Initialize;
+import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription;
+import org.apache.airavata.model.data.movement.*;
+import org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory;
+import org.apache.airavata.registry.cpi.AppCatalog;
+import org.apache.airavata.registry.cpi.AppCatalogException;
+import org.apache.airavata.registry.cpi.StorageResource;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+
+public class StorageResourceAppCatalogTest {
+    private static Initialize initialize;
+    private static AppCatalog appcatalog;
+    private static final Logger logger = LoggerFactory.getLogger(StorageResourceAppCatalogTest.class);
+
+    @Before
+    public void setUp() {
+        try {
+            initialize = new Initialize("appcatalog-derby.sql");
+            initialize.initializeDB();
+            appcatalog = RegistryFactory.getAppCatalog();
+        } catch (AppCatalogException e) {
+            logger.error(e.getMessage(), e);
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        System.out.println("********** TEAR DOWN ************");
+        initialize.stopDerbyServer();
+
+    }
+
+    @Test
+    public void testAddStorageResource(){
+        try {
+            StorageResource storageResource = appcatalog.getStorageResource();
+            StorageResourceDescription description = new StorageResourceDescription();
+
+            description.setHostName("localhost");
+            description.setEnabled(true);
+            description.setStorageResourceDescription("testDescription");
+
+
+            String scpDataMoveId = addSCPDataMovement();
+            System.out.println("**** SCP DataMoveId****** :" + scpDataMoveId);
+            String gridFTPDataMoveId = addGridFTPDataMovement();
+            System.out.println("**** grid FTP DataMoveId****** :" + gridFTPDataMoveId);
+
+            List<DataMovementInterface> dataMovementInterfaces = new ArrayList<DataMovementInterface>();
+            DataMovementInterface scpInterface = new DataMovementInterface();
+            scpInterface.setDataMovementInterfaceId(scpDataMoveId);
+            scpInterface.setDataMovementProtocol(DataMovementProtocol.SCP);
+            scpInterface.setPriorityOrder(1);
+
+            DataMovementInterface gridFTPMv = new DataMovementInterface();
+            gridFTPMv.setDataMovementInterfaceId(gridFTPDataMoveId);
+            gridFTPMv.setDataMovementProtocol(DataMovementProtocol.GridFTP);
+            gridFTPMv.setPriorityOrder(2);
+
+            dataMovementInterfaces.add(scpInterface);
+            dataMovementInterfaces.add(gridFTPMv);
+            description.setDataMovementInterfaces(dataMovementInterfaces);
+
+            String resourceId = storageResource.addStorageResource(description);
+            System.out.println("**********Resource id ************* : " +  resourceId);
+            StorageResourceDescription storageResourceDescription = null;
+            if (storageResource.isStorageResourceExists(resourceId)){
+                storageResourceDescription = storageResource.getStorageResource(resourceId);
+                List<DataMovementInterface> movementInterfaces = storageResourceDescription.getDataMovementInterfaces();
+                if (movementInterfaces != null && !movementInterfaces.isEmpty()){
+                    for (DataMovementInterface dataMovementInterface : movementInterfaces){
+                        System.out.println("Data Movement Interface Id :" + dataMovementInterface.getDataMovementInterfaceId());
+                        System.out.println("Data Movement Protocol :" + dataMovementInterface.getDataMovementProtocol().toString());
+                    }
+                }
+            }
+
+            description.setHostName("localhost2");
+            storageResource.updateStorageResource(resourceId, description);
+            if (storageResource.isStorageResourceExists(resourceId)){
+                storageResourceDescription = storageResource.getStorageResource(resourceId);
+                System.out.println("**********Updated Resource name ************* : " + storageResourceDescription.getHostName());
+            }
+            assertTrue("Compute resource save successfully", storageResourceDescription !=
null);
+        } catch (AppCatalogException e) {
+            logger.error(e.getMessage(), e);
+        }
+    }
+
+    public String addSCPDataMovement (){
+        try {
+            SCPDataMovement dataMovement = new SCPDataMovement();
+            dataMovement.setSshPort(22);
+            dataMovement.setSecurityProtocol(SecurityProtocol.SSH_KEYS);
+            return appcatalog.getComputeResource().addScpDataMovement(dataMovement);
+        }catch (AppCatalogException e) {
+            logger.error(e.getMessage(), e);
+        }
+        return null;
+    }
+
+    public String addGridFTPDataMovement (){
+        try {
+            GridFTPDataMovement dataMovement = new GridFTPDataMovement();
+            dataMovement.setSecurityProtocol(SecurityProtocol.SSH_KEYS);
+            List<String> endPoints = new ArrayList<String>();
+            endPoints.add("222.33.43.444");
+            endPoints.add("23.344.44.454");
+            dataMovement.setGridFTPEndPoints(endPoints);
+            return appcatalog.getComputeResource().addGridFTPDataMovement(dataMovement);
+        }catch (AppCatalogException e) {
+            logger.error(e.getMessage(), e);
+        }
+        return null;
+    }
+
+
+}
+


Mime
View raw message