You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ch...@apache.org on 2014/07/10 21:23:49 UTC

git commit: return empty list instead of null

Repository: airavata
Updated Branches:
  refs/heads/master 8ea2f0e98 -> 85a2c4a23


return empty list instead of null


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

Branch: refs/heads/master
Commit: 85a2c4a23d16d2f5ab08a2fdded9f710d29065e4
Parents: 8ea2f0e
Author: Chathuri Wimalasena <ka...@gmail.com>
Authored: Thu Jul 10 15:23:44 2014 -0400
Committer: Chathuri Wimalasena <ka...@gmail.com>
Committed: Thu Jul 10 15:23:44 2014 -0400

----------------------------------------------------------------------
 .../server/handler/AiravataServerHandler.java    | 15 +++++++++++++++
 .../data/impl/ApplicationDeploymentImpl.java     | 13 ++++++++-----
 .../data/impl/ApplicationInterfaceImpl.java      | 19 ++++++++-----------
 .../catalog/data/impl/ComputeResourceImpl.java   | 15 +++++++--------
 4 files changed, 38 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/85a2c4a2/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
index 1dff780..683848a 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
@@ -2211,6 +2211,21 @@ public class AiravataServerHandler implements Airavata.Iface, Watcher {
     	try {
             appCatalog = AppCatalogFactory.getAppCatalog();
             GwyResourceProfile gatewayProfile = appCatalog.getGatewayProfile();
+            ComputeResource computeResource = appCatalog.getComputeResource();
+            if (!gatewayProfile.isGatewayResourceProfileExists(gatewayID)){
+                logger.error("Given gateway profile does not exist in the system. Please provide a valid gateway id...");
+                AiravataSystemException exception = new AiravataSystemException();
+                exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+                exception.setMessage("Given gateway profile does not exist in the system. Please provide a valid gateway id...");
+                throw exception;
+            }
+            if (!computeResource.isComputeResourceExists(computeResourceId)){
+                logger.error("Given compute resource does not exist in the system. Please provide a valid compute resource id...");
+                AiravataSystemException exception = new AiravataSystemException();
+                exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+                exception.setMessage("Given compute resource does not exist in the system. Please provide a valid compute resource id...");
+                throw exception;
+            }
             return gatewayProfile.getComputeResourcePreference(gatewayID, computeResourceId);
         } catch (AppCatalogException e) {
             logger.error("Error while reading gateway compute resource preference...", e);

http://git-wip-us.apache.org/repos/asf/airavata/blob/85a2c4a2/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationDeploymentImpl.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationDeploymentImpl.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationDeploymentImpl.java
index 695e1b2..9edc226 100644
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationDeploymentImpl.java
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationDeploymentImpl.java
@@ -32,6 +32,7 @@ import org.apache.airavata.model.appcatalog.appdeployment.SetEnvPaths;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -235,18 +236,19 @@ public class ApplicationDeploymentImpl implements ApplicationDeployment {
 
     @Override
     public List<ApplicationDeploymentDescription> getApplicationDeployements(Map<String, String> filters) throws AppCatalogException {
+        List<ApplicationDeploymentDescription> deploymentDescriptions = new ArrayList<ApplicationDeploymentDescription>();
         try {
             AppDeploymentResource resource = new AppDeploymentResource();
             for (String fieldName : filters.keySet() ){
                 if (fieldName.equals(AbstractResource.ApplicationDeploymentConstants.APP_MODULE_ID)){
                     List<Resource> resources = resource.get(AbstractResource.ApplicationDeploymentConstants.APP_MODULE_ID, filters.get(fieldName));
                     if (resources != null && !resources.isEmpty()){
-                        return AppCatalogThriftConversion.getAppDepDescList(resources);
+                        deploymentDescriptions = AppCatalogThriftConversion.getAppDepDescList(resources);
                     }
                 }else if (fieldName.equals(AbstractResource.ApplicationDeploymentConstants.COMPUTE_HOST_ID)){
                     List<Resource> resources = resource.get(AbstractResource.ApplicationDeploymentConstants.COMPUTE_HOST_ID, filters.get(fieldName));
                     if (resources != null && !resources.isEmpty()){
-                        return AppCatalogThriftConversion.getAppDepDescList(resources);
+                        deploymentDescriptions = AppCatalogThriftConversion.getAppDepDescList(resources);
                     }
                 } else {
                     logger.error("Unsupported field name for app deployment.", new IllegalArgumentException());
@@ -257,23 +259,24 @@ public class ApplicationDeploymentImpl implements ApplicationDeployment {
             logger.error("Error while retrieving app deployment list...", e);
             throw new AppCatalogException(e);
         }
-        return null;
+        return deploymentDescriptions;
     }
 
     @Override
     public List<ApplicationDeploymentDescription> getAllApplicationDeployements() throws AppCatalogException {
+        List<ApplicationDeploymentDescription> deploymentDescriptions = new ArrayList<ApplicationDeploymentDescription>();
         try {
             AppDeploymentResource resource = new AppDeploymentResource();
             List<Resource> resources = resource.getAll();
             if (resources != null && !resources.isEmpty()){
-                return AppCatalogThriftConversion.getAppDepDescList(resources);
+                deploymentDescriptions = AppCatalogThriftConversion.getAppDepDescList(resources);
             }
 
         }catch (Exception e){
             logger.error("Error while retrieving app deployment list...", e);
             throw new AppCatalogException(e);
         }
-        return null;
+        return deploymentDescriptions;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/airavata/blob/85a2c4a2/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationInterfaceImpl.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationInterfaceImpl.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationInterfaceImpl.java
index d578eac..cdd1842 100644
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationInterfaceImpl.java
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationInterfaceImpl.java
@@ -33,6 +33,7 @@ import org.apache.airavata.model.appcatalog.appinterface.OutputDataObjectType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -244,13 +245,14 @@ public class ApplicationInterfaceImpl implements ApplicationInterface {
 
     @Override
     public List<ApplicationModule> getApplicationModules(Map<String, String> filters) throws AppCatalogException {
+        List<ApplicationModule> modules = new ArrayList<ApplicationModule>();
         try {
             AppModuleResource resource = new AppModuleResource();
             for (String fieldName : filters.keySet() ){
                 if (fieldName.equals(AbstractResource.ApplicationModuleConstants.MODULE_NAME)){
                     List<Resource> resources = resource.get(AbstractResource.ApplicationModuleConstants.MODULE_NAME, filters.get(fieldName));
                     if (resources != null && !resources.isEmpty()){
-                        return AppCatalogThriftConversion.getAppModules(resources);
+                        modules = AppCatalogThriftConversion.getAppModules(resources);
                     }
                 }else {
                     logger.error("Unsupported field name for app module.", new IllegalArgumentException());
@@ -261,19 +263,18 @@ public class ApplicationInterfaceImpl implements ApplicationInterface {
             logger.error("Error while retrieving app module list...", e);
             throw new AppCatalogException(e);
         }
-        return null;
+        return modules;
     }
 
     @Override
     public List<ApplicationInterfaceDescription> getApplicationInterfaces(Map<String, String> filters) throws AppCatalogException {
+        List<ApplicationInterfaceDescription> appInterfaces = new ArrayList<ApplicationInterfaceDescription>();
         try {
             AppInterfaceResource resource = new AppInterfaceResource();
             for (String fieldName : filters.keySet() ){
                 if (fieldName.equals(AbstractResource.ApplicationInterfaceConstants.APPLICATION_NAME)){
                     List<Resource> resources = resource.get(AbstractResource.ApplicationInterfaceConstants.APPLICATION_NAME, filters.get(fieldName));
-                    if (resources != null && !resources.isEmpty()){
-                        return AppCatalogThriftConversion.getAppInterfaceDescList(resources);
-                    }
+                    appInterfaces = AppCatalogThriftConversion.getAppInterfaceDescList(resources);
                 }else {
                     logger.error("Unsupported field name for app interface.", new IllegalArgumentException());
                     throw new IllegalArgumentException("Unsupported field name for app interface.");
@@ -283,7 +284,7 @@ public class ApplicationInterfaceImpl implements ApplicationInterface {
             logger.error("Error while retrieving app interface list...", e);
             throw new AppCatalogException(e);
         }
-        return null;
+        return appInterfaces;
     }
 
     @Override
@@ -291,15 +292,11 @@ public class ApplicationInterfaceImpl implements ApplicationInterface {
         try {
             AppInterfaceResource resource = new AppInterfaceResource();
             List<Resource> resources = resource.getAll();
-            if (resources != null && !resources.isEmpty()){
-                return AppCatalogThriftConversion.getAppInterfaceDescList(resources);
-            }
-
+            return AppCatalogThriftConversion.getAppInterfaceDescList(resources);
         }catch (Exception e){
             logger.error("Error while retrieving app interface list...", e);
             throw new AppCatalogException(e);
         }
-        return null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/airavata/blob/85a2c4a2/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ComputeResourceImpl.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ComputeResourceImpl.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ComputeResourceImpl.java
index add1168..0f5794a 100644
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ComputeResourceImpl.java
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ComputeResourceImpl.java
@@ -21,10 +21,7 @@
 
 package org.apache.aiaravata.application.catalog.data.impl;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 import org.airavata.appcatalog.cpi.AppCatalogException;
 import org.airavata.appcatalog.cpi.ComputeResource;
@@ -392,6 +389,7 @@ public class ComputeResourceImpl implements ComputeResource {
 
     @Override
     public List<ComputeResourceDescription> getComputeResourceList(Map<String, String> filters) throws AppCatalogException {
+        List<ComputeResourceDescription> computeResourceDescriptions = new ArrayList<ComputeResourceDescription>();
         try {
         	//TODO check if this is correct way to do this
             ComputeResourceResource resource = new ComputeResourceResource();
@@ -399,7 +397,7 @@ public class ComputeResourceImpl implements ComputeResource {
                 if (fieldName.equals(AbstractResource.ComputeResourceConstants.HOST_NAME)){
                     List<Resource> resources = resource.get(AbstractResource.ComputeResourceConstants.HOST_NAME, filters.get(fieldName));
                     if (resources != null && !resources.isEmpty()){
-                        return AppCatalogThriftConversion.getComputeDescriptionList(resources);
+                        computeResourceDescriptions = AppCatalogThriftConversion.getComputeDescriptionList(resources);
                     }
                 }else {
                     logger.error("Unsupported field name for compute resource.", new IllegalArgumentException());
@@ -410,22 +408,23 @@ public class ComputeResourceImpl implements ComputeResource {
             logger.error("Error while retrieving compute resource list...", e);
             throw new AppCatalogException(e);
         }
-        return null;
+        return computeResourceDescriptions;
     }
 
     @Override
     public List<ComputeResourceDescription> getAllComputeResourceList() throws AppCatalogException {
+        List<ComputeResourceDescription> computeResourceDescriptions = new ArrayList<ComputeResourceDescription>();
         try {
             ComputeResourceResource resource = new ComputeResourceResource();
             List<Resource> resources = resource.getAll();
             if (resources != null && !resources.isEmpty()){
-                return AppCatalogThriftConversion.getComputeDescriptionList(resources);
+                computeResourceDescriptions = AppCatalogThriftConversion.getComputeDescriptionList(resources);
             }
         }catch (Exception e){
             logger.error("Error while retrieving compute resource list...", e);
             throw new AppCatalogException(e);
         }
-        return null;
+        return computeResourceDescriptions;
     }
 
     @Override