airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sma...@apache.org
Subject [10/19] airavata git commit: Changing Airavata API to support paginated result retrieval of Project and Experiment data
Date Fri, 01 May 2015 00:56:06 GMT
Changing Airavata API to support paginated result retrieval of Project and Experiment data


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

Branch: refs/heads/master
Commit: 0a3d857b746d27a7a8cccf4f26923b163fcb9965
Parents: 9f6e30e
Author: Supun Nakandala <supun.nakandala@gmail.com>
Authored: Mon Apr 27 20:46:56 2015 +0530
Committer: Supun Nakandala <supun.nakandala@gmail.com>
Committed: Mon Apr 27 20:46:56 2015 +0530

----------------------------------------------------------------------
 .../server/handler/AiravataServerHandler.java   |   375 +-
 .../api/server/util/DatabaseCreator.java        |    15 +-
 .../handler/AiravataServerHandlerTest.java      |   324 +
 .../java/org/apache/airavata/api/Airavata.java  | 21816 ++++++++++++++---
 .../main/resources/lib/airavata/Airavata.cpp    | 12982 ++++++----
 .../src/main/resources/lib/airavata/Airavata.h  |  2398 +-
 .../lib/airavata/Airavata_server.skeleton.cpp   |    50 +
 .../resources/lib/Airavata/API/Airavata.php     |  4756 +++-
 .../lib/apache/airavata/api/Airavata-remote     |    70 +
 .../lib/apache/airavata/api/Airavata.py         | 12786 ++++++----
 .../airavataAPI.thrift                          |   332 +-
 .../apache/airavata/registry/cpi/Registry.java  |    19 +-
 .../airavata/registry/cpi/utils/Constants.java  |     1 +
 13 files changed, 43430 insertions(+), 12494 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/0a3d857b/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 e2b402e..c3039d9 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
@@ -21,12 +21,7 @@
 
 package org.apache.airavata.api.server.handler;
 
-import org.airavata.appcatalog.cpi.AppCatalog;
-import org.airavata.appcatalog.cpi.AppCatalogException;
-import org.airavata.appcatalog.cpi.ApplicationDeployment;
-import org.airavata.appcatalog.cpi.ComputeResource;
-import org.airavata.appcatalog.cpi.GwyResourceProfile;
-import org.airavata.appcatalog.cpi.WorkflowCatalog;
+import org.airavata.appcatalog.cpi.*;
 import org.apache.aiaravata.application.catalog.data.impl.AppCatalogFactory;
 import org.apache.aiaravata.application.catalog.data.resources.*;
 import org.apache.aiaravata.application.catalog.data.util.AppCatalogThriftConversion;
@@ -50,38 +45,18 @@ import org.apache.airavata.model.appcatalog.appinterface.OutputDataObjectType;
 import org.apache.airavata.model.appcatalog.computeresource.*;
 import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
 import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
-import org.apache.airavata.model.error.AiravataClientConnectException;
-import org.apache.airavata.model.error.AiravataClientException;
-import org.apache.airavata.model.error.AiravataErrorType;
-import org.apache.airavata.model.error.AiravataSystemException;
-import org.apache.airavata.model.error.ExperimentNotFoundException;
-import org.apache.airavata.model.error.InvalidRequestException;
-import org.apache.airavata.model.error.ProjectNotFoundException;
+import org.apache.airavata.model.error.*;
 import org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent;
 import org.apache.airavata.model.messaging.event.MessageType;
 import org.apache.airavata.model.workspace.Gateway;
 import org.apache.airavata.model.workspace.Project;
-import org.apache.airavata.model.workspace.experiment.ComputationalResourceScheduling;
-import org.apache.airavata.model.workspace.experiment.DataTransferDetails;
-import org.apache.airavata.model.workspace.experiment.Experiment;
-import org.apache.airavata.model.workspace.experiment.ExperimentState;
-import org.apache.airavata.model.workspace.experiment.ExperimentStatus;
-import org.apache.airavata.model.workspace.experiment.ExperimentSummary;
-import org.apache.airavata.model.workspace.experiment.JobDetails;
-import org.apache.airavata.model.workspace.experiment.JobStatus;
-import org.apache.airavata.model.workspace.experiment.TaskDetails;
-import org.apache.airavata.model.workspace.experiment.UserConfigurationData;
-import org.apache.airavata.model.workspace.experiment.WorkflowNodeDetails;
+import org.apache.airavata.model.workspace.experiment.*;
 import org.apache.airavata.orchestrator.client.OrchestratorClientFactory;
 import org.apache.airavata.orchestrator.cpi.OrchestratorService;
 import org.apache.airavata.orchestrator.cpi.OrchestratorService.Client;
 import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
-import org.apache.airavata.registry.cpi.ChildDataType;
-import org.apache.airavata.registry.cpi.ParentDataType;
-import org.apache.airavata.registry.cpi.Registry;
-import org.apache.airavata.registry.cpi.RegistryException;
-import org.apache.airavata.registry.cpi.RegistryModelType;
+import org.apache.airavata.registry.cpi.*;
 import org.apache.airavata.registry.cpi.utils.Constants;
 import org.apache.thrift.TException;
 
@@ -343,10 +318,34 @@ public class AiravataServerHandler implements Airavata.Iface {
     /**
      * Get all Project by user
      *
+     * @param gatewayId
+     *    The identifier for the requested gateway.
      * @param userName
+     *    The identifier of the user
+     * @deprecated  Instead use getAllUserProjectsWithPagination method
      */
+    @Deprecated
     @Override
     public List<Project> getAllUserProjects(String gatewayId, String userName) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        return getAllUserProjectsWithPagination(gatewayId, userName, -1, -1);
+    }
+
+    /**
+     * Get all Project by user with pagination. Results will be ordered based
+     * on creation time DESC
+     *
+     * @param gatewayId
+     *    The identifier for the requested gateway.
+     * @param userName
+     *    The identifier of the user
+     * @param limit
+     *    The amount results to be fetched
+     * @param offset
+     *    The starting point of the results to be fetched
+     **/
+    @Override
+    public List<Project> getAllUserProjectsWithPagination(String gatewayId, String userName,
+                                                          int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
         if (!validateString(userName)){
             logger.error("Username cannot be empty. Please provide a valid user..");
             AiravataSystemException exception = new AiravataSystemException();
@@ -371,7 +370,8 @@ public class AiravataServerHandler implements Airavata.Iface {
             Map<String, String> filters = new HashMap<String, String>();
             filters.put(Constants.FieldConstants.ProjectConstants.OWNER, userName);
             filters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId);
-            List<Object> list = registry.search(RegistryModelType.PROJECT,filters);
+            List<Object> list = registry.search(RegistryModelType.PROJECT, filters, limit, offset,
+                    Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC);
             if (list != null && !list.isEmpty()){
                 for (Object o : list){
                     projects.add((Project) o);
@@ -387,10 +387,43 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
+    /**
+     * Get all Project for user by project name
+     *
+     * @param gatewayId
+     *    The identifier for the requested gateway.
+     * @param userName
+     *    The identifier of the user
+     * @param projectName
+     *    The name of the project on which the results to be fetched
+     * @deprecated Instead use searchProjectsByProjectNameWithPagination
+     */
+    @Deprecated
+    @Override
     public List<Project> searchProjectsByProjectName(String gatewayId, String userName, String projectName) throws InvalidRequestException,
                                                                                                  AiravataClientException,
                                                                                                  AiravataSystemException,
                                                                                                  TException {
+        return searchProjectsByProjectNameWithPagination(gatewayId, userName, projectName, -1, -1);
+    }
+
+    /**
+     * Get all Project for user by project name with pagination. Results will be ordered based
+     * on creation time DESC
+     *
+     * @param gatewayId
+     *    The identifier for the requested gateway.
+     * @param userName
+     *    The identifier of the user
+     * @param projectName
+     *    The name of the project on which the results to be fetched
+     * @param limit
+     *    The amount results to be fetched
+     * @param offset
+     *    The starting point of the results to be fetched
+     */
+    @Override
+    public List<Project> searchProjectsByProjectNameWithPagination(String gatewayId, String userName, String projectName, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
         if (!validateString(userName)){
             logger.error("Username cannot be empty. Please provide a valid user..");
             AiravataSystemException exception = new AiravataSystemException();
@@ -416,7 +449,8 @@ public class AiravataServerHandler implements Airavata.Iface {
             filters.put(Constants.FieldConstants.ProjectConstants.OWNER, userName);
             filters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId);
             filters.put(Constants.FieldConstants.ProjectConstants.PROJECT_NAME, projectName);
-            List<Object> results = registry.search(RegistryModelType.PROJECT, filters);
+            List<Object> results = registry.search(RegistryModelType.PROJECT, filters, limit, offset,
+                    Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC);
             for (Object object : results) {
                 projects.add((Project)object);
             }
@@ -430,10 +464,42 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
+    /**
+     * Get all Project for user by project description
+     * @param gatewayId
+     *    The identifier for the requested gateway.
+     * @param userName
+     *    The identifier of the user
+     * @param description
+     *    The description to be matched
+     * @deprecated Instead use searchProjectsByProjectDescWithPagination
+     */
+    @Deprecated
+    @Override
     public List<Project> searchProjectsByProjectDesc(String gatewayId, String userName, String description) throws InvalidRequestException,
                                                                                                  AiravataClientException,
                                                                                                  AiravataSystemException,
                                                                                                  TException {
+        return searchProjectsByProjectDescWithPagination(gatewayId, userName, description, -1, -1);
+    }
+
+    /**
+     * Search and get all Projects for user by project description with pagination. Results
+     * will be ordered based on creation time DESC
+     *
+     * @param gatewayId
+     *    The identifier for the requested gateway.
+     * @param userName
+     *    The identifier of the user
+     * @param description
+     *    The description to be matched
+     * @param limit
+     *    The amount results to be fetched
+     * @param offset
+     *    The starting point of the results to be fetched
+     */
+    @Override
+    public List<Project> searchProjectsByProjectDescWithPagination(String gatewayId, String userName, String description, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
         if (!validateString(userName)){
             logger.error("Username cannot be empty. Please provide a valid user..");
             AiravataSystemException exception = new AiravataSystemException();
@@ -459,7 +525,8 @@ public class AiravataServerHandler implements Airavata.Iface {
             filters.put(Constants.FieldConstants.ProjectConstants.OWNER, userName);
             filters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId);
             filters.put(Constants.FieldConstants.ProjectConstants.DESCRIPTION, description);
-            List<Object> results = registry.search(RegistryModelType.PROJECT, filters);
+            List<Object> results = registry.search(RegistryModelType.PROJECT, filters, limit, offset,
+                    Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC);
             for (Object object : results) {
                 projects.add((Project)object);
             }
@@ -473,10 +540,45 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
+    /**
+     * Search Experiments by experiment name
+     *
+     * @param gatewayId
+     *       Identifier of the requested gateway
+     * @param userName
+     *       Username of the requested user
+     * @param expName
+     *       Experiment name to be matched
+     * @deprecated
+     *       Instead use searchExperimentsByNameWithPagination
+     *
+     */
+    @Deprecated
+    @Override
     public List<ExperimentSummary> searchExperimentsByName(String gatewayId, String userName, String expName) throws InvalidRequestException,
                                                                                                    AiravataClientException,
                                                                                                    AiravataSystemException,
                                                                                                    TException {
+        return searchExperimentsByNameWithPagination(gatewayId, userName, expName, -1, -1);
+    }
+
+    /**
+     * Search Experiments by experiment name with pagination. Results will be sorted
+     * based on creation time DESC
+     *
+     * @param gatewayId
+     *       Identifier of the requested gateway
+     * @param userName
+     *       Username of the requested user
+     * @param expName
+     *       Experiment name to be matched
+     * @param limit
+     *       Amount of results to be fetched
+     * @param offset
+     *       The starting point of the results to be fetched
+     */
+    @Override
+    public List<ExperimentSummary> searchExperimentsByNameWithPagination(String gatewayId, String userName, String expName, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
         if (!validateString(userName)){
             logger.error("Username cannot be empty. Please provide a valid user..");
             AiravataSystemException exception = new AiravataSystemException();
@@ -502,7 +604,8 @@ public class AiravataServerHandler implements Airavata.Iface {
             filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName);
             filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY, gatewayId);
             filters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_NAME, expName);
-            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters);
+            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters, limit,
+                    offset, Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
             for (Object object : results) {
                 summaries.add((ExperimentSummary) object);
             }
@@ -516,10 +619,44 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
+    /**
+     * Search Experiments by experiment name
+     *
+     * @param gatewayId
+     *       Identifier of the requested gateway
+     * @param userName
+     *       Username of the requested user
+     * @param description
+     *       Experiment description to be matched
+     * @deprecated
+     *       Instead use searchExperimentsByDescWithPagination
+     */
+    @Deprecated
+    @Override
     public List<ExperimentSummary> searchExperimentsByDesc(String gatewayId, String userName, String description) throws InvalidRequestException,
                                                                                                        AiravataClientException,
                                                                                                        AiravataSystemException,
                                                                                                        TException {
+        return searchExperimentsByDescWithPagination(gatewayId, userName, description, -1, -1);
+    }
+
+    /**
+     * Search Experiments by experiment name with pagination. Results will be sorted
+     * based on creation time DESC
+     *
+     * @param gatewayId
+     *       Identifier of the requested gateway
+     * @param userName
+     *       Username of the requested user
+     * @param description
+     *       Experiment description to be matched
+     * @param limit
+     *       Amount of results to be fetched
+     * @param offset
+     *       The starting point of the results to be fetched
+     */
+    @Override
+    public List<ExperimentSummary> searchExperimentsByDescWithPagination(String gatewayId, String userName, String description, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
         if (!validateString(userName)){
             logger.error("Username cannot be empty. Please provide a valid user..");
             AiravataSystemException exception = new AiravataSystemException();
@@ -545,7 +682,8 @@ public class AiravataServerHandler implements Airavata.Iface {
             filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName);
             filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY, gatewayId);
             filters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_DESC, description);
-            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters);
+            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters, limit,
+                    offset, Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
             for (Object object : results) {
                 summaries.add((ExperimentSummary) object);
             }
@@ -559,7 +697,41 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
+    /**
+     * Search Experiments by application id
+     *
+     * @param gatewayId
+     *       Identifier of the requested gateway
+     * @param userName
+     *       Username of the requested user
+     * @param applicationId
+     *       Application id to be matched
+     * @deprecated
+     *       Instead use searchExperimentsByApplication
+     */
+    @Deprecated
+    @Override
     public List<ExperimentSummary> searchExperimentsByApplication(String gatewayId, String userName, String applicationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        return searchExperimentsByApplicationWithPagination(gatewayId, userName, applicationId, -1, -1);
+    }
+
+    /**
+     * Search Experiments by application id with pagination. Results will be sorted
+     * based on creation time DESC
+     *
+     * @param gatewayId
+     *       Identifier of the requested gateway
+     * @param userName
+     *       Username of the requested user
+     * @param applicationId
+     *       Application id to be matched
+     * @param limit
+     *       Amount of results to be fetched
+     * @param offset
+     *       The starting point of the results to be fetched
+     */
+    @Override
+    public List<ExperimentSummary> searchExperimentsByApplicationWithPagination(String gatewayId, String userName, String applicationId, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
         if (!validateString(userName)){
             logger.error("Username cannot be empty. Please provide a valid user..");
             AiravataSystemException exception = new AiravataSystemException();
@@ -585,7 +757,8 @@ public class AiravataServerHandler implements Airavata.Iface {
             filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName);
             filters.put(Constants.FieldConstants.ExperimentConstants.APPLICATION_ID, applicationId);
             filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY, gatewayId);
-            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters);
+            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters, limit,
+                    offset, Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
             for (Object object : results) {
                 summaries.add((ExperimentSummary) object);
             }
@@ -599,8 +772,41 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
+    /**
+     * Search Experiments by experiment status
+     *
+     * @param gatewayId
+     *       Identifier of the requested gateway
+     * @param userName
+     *       Username of the requested user
+     * @param experimentState
+     *       Experiment state to be matched
+     * @deprecated
+     *       Instead use searchExperimentsByStatusWithPagination
+     */
+    @Deprecated
     @Override
     public List<ExperimentSummary> searchExperimentsByStatus(String gatewayId, String userName, ExperimentState experimentState) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        return searchExperimentsByStatusWithPagination(gatewayId, userName, experimentState, -1, -1);
+    }
+
+    /**
+     * Search Experiments by experiment status with pagination. Results will be sorted
+     * based on creation time DESC
+     *
+     * @param gatewayId
+     *       Identifier of the requested gateway
+     * @param userName
+     *       Username of the requested user
+     * @param experimentState
+     *       Experiement state to be matched
+     * @param limit
+     *       Amount of results to be fetched
+     * @param offset
+     *       The starting point of the results to be fetched
+     */
+    @Override
+    public List<ExperimentSummary> searchExperimentsByStatusWithPagination(String gatewayId, String userName, ExperimentState experimentState, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
         if (!validateString(userName)){
             logger.error("Username cannot be empty. Please provide a valid user..");
             AiravataSystemException exception = new AiravataSystemException();
@@ -626,7 +832,8 @@ public class AiravataServerHandler implements Airavata.Iface {
             filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName);
             filters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_STATUS, experimentState.toString());
             filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY, gatewayId);
-            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters);
+            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters, limit,
+                    offset, Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
             for (Object object : results) {
                 summaries.add((ExperimentSummary) object);
             }
@@ -640,8 +847,45 @@ public class AiravataServerHandler implements Airavata.Iface {
         }
     }
 
+    /**
+     * Search Experiments by experiment creation time
+     *
+     * @param gatewayId
+     *       Identifier of the requested gateway
+     * @param userName
+     *       Username of the requested user
+     * @param fromTime
+     *       Start time of the experiments creation time
+     * @param toTime
+     *       End time of the  experiement creation time
+     * @deprecated
+     *       Instead use searchExperimentsByCreationTime
+     */
+    @Deprecated
     @Override
     public List<ExperimentSummary> searchExperimentsByCreationTime(String gatewayId, String userName, long fromTime, long toTime) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        return searchExperimentsByCreationTimeWithPagination(gatewayId, userName, fromTime, toTime, -1, -1);
+    }
+
+    /**
+     * Search Experiments by experiment creation time with pagination. Results will be sorted
+     * based on creation time DESC
+     *
+     * @param gatewayId
+     *       Identifier of the requested gateway
+     * @param userName
+     *       Username of the requested user
+     * @param fromTime
+     *       Start time of the experiments creation time
+     * @param toTime
+     *       End time of the  experiement creation time
+     * @param limit
+     *       Amount of results to be fetched
+     * @param offset
+     *       The starting point of the results to be fetched
+     */
+    @Override
+    public List<ExperimentSummary> searchExperimentsByCreationTimeWithPagination(String gatewayId, String userName, long fromTime, long toTime, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
         if (!validateString(userName)){
             logger.error("Username cannot be empty. Please provide a valid user..");
             AiravataSystemException exception = new AiravataSystemException();
@@ -668,7 +912,8 @@ public class AiravataServerHandler implements Airavata.Iface {
             filters.put(Constants.FieldConstants.ExperimentConstants.FROM_DATE, String.valueOf(fromTime));
             filters.put(Constants.FieldConstants.ExperimentConstants.TO_DATE, String.valueOf(toTime));
             filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY, gatewayId);
-            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters);
+            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters, limit,
+                    offset, Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
             for (Object object : results) {
                 summaries.add((ExperimentSummary) object);
             }
@@ -686,13 +931,34 @@ public class AiravataServerHandler implements Airavata.Iface {
      * Get all Experiments within a Project
      *
      * @param projectId
+     *       Identifier of the project
+     * @deprecated
+     *       Instead use getAllExperimentsInProjectWithPagination
      */
+    @Deprecated
     @Override
     public List<Experiment> getAllExperimentsInProject(String projectId) throws InvalidRequestException,
                                                                                 AiravataClientException,
                                                                                 AiravataSystemException,
                                                                                 ProjectNotFoundException,
                                                                                 TException {
+        return getAllExperimentsInProjectWithPagination(projectId, -1, -1);
+    }
+
+    /**
+     * Get all Experiments within project with pagination. Results will be sorted
+     * based on creation time DESC
+     *
+     * @param projectId
+     *       Identifier of the project
+     * @param limit
+     *       Amount of results to be fetched
+     * @param offset
+     *       The starting point of the results to be fetched
+     */
+    @Override
+    public List<Experiment> getAllExperimentsInProjectWithPagination(String projectId, int limit, int offset)
+            throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, TException {
         if (!validateString(projectId)){
             logger.error("Project id cannot be empty. Please provide a valid project ID...");
             AiravataSystemException exception = new AiravataSystemException();
@@ -709,7 +975,9 @@ public class AiravataServerHandler implements Airavata.Iface {
                 throw exception;
             }
             List<Experiment> experiments = new ArrayList<Experiment>();
-            List<Object> list = registry.get(RegistryModelType.EXPERIMENT, Constants.FieldConstants.ExperimentConstants.PROJECT_ID, projectId);
+            List<Object> list = registry.get(RegistryModelType.EXPERIMENT,
+                    Constants.FieldConstants.ExperimentConstants.PROJECT_ID, projectId, limit, offset,
+                    Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
             if (list != null && !list.isEmpty()) {
                 for (Object o : list) {
                     experiments.add((Experiment) o);
@@ -728,10 +996,34 @@ public class AiravataServerHandler implements Airavata.Iface {
     /**
      * Get all Experiments by user
      *
+     * @param gatewayId
+     *       Identifier of the requesting gateway
      * @param userName
+     *       Username of the requested user
+     * @deprecated
+     *       Instead use getAllUserExperimentsWithPagination
      */
+    @Deprecated
     @Override
     public List<Experiment> getAllUserExperiments(String gatewayId, String userName) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        return getAllUserExperimentsWithPagination(gatewayId, userName, -1, -1);
+    }
+
+    /**
+     * Get all Experiments by user pagination. Results will be sorted
+     * based on creation time DESC
+     *
+     * @param gatewayId
+     *       Identifier of the requesting gateway
+     * @param userName
+     *       Username of the requested user
+     * @param limit
+     *       Amount of results to be fetched
+     * @param offset
+     *       The starting point of the results to be fetched
+     */
+    @Override
+    public List<Experiment> getAllUserExperimentsWithPagination(String gatewayId, String userName, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
         if (!validateString(userName)){
             logger.error("Username cannot be empty. Please provide a valid user..");
             AiravataSystemException exception = new AiravataSystemException();
@@ -753,10 +1045,9 @@ public class AiravataServerHandler implements Airavata.Iface {
             }
             List<Experiment> experiments = new ArrayList<Experiment>();
             registry = RegistryFactory.getRegistry(gatewayId);
-            Map<String, String> filters = new HashMap<String, String>();
-            filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName);
-            filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY, gatewayId);
-            List<Object> list = registry.search(RegistryModelType.EXPERIMENT, filters);
+            List<Object> list = registry.get(RegistryModelType.EXPERIMENT,
+                    Constants.FieldConstants.ExperimentConstants.USER_NAME, userName, limit, offset,
+                    Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
             if (list != null && !list.isEmpty()){
                 for (Object o : list){
                     experiments.add((Experiment)o);

http://git-wip-us.apache.org/repos/asf/airavata/blob/0a3d857b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/DatabaseCreator.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/DatabaseCreator.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/DatabaseCreator.java
index 4833f2c..4bc3c72 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/DatabaseCreator.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/DatabaseCreator.java
@@ -23,7 +23,10 @@ package org.apache.airavata.api.server.util;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.sql.*;
 import java.util.StringTokenizer;
 
@@ -33,6 +36,7 @@ import java.util.StringTokenizer;
  * properties files.
  */
 public class DatabaseCreator {
+    private final static Logger logger = LoggerFactory.getLogger(DatabaseCreator.class);
 
     public enum DatabaseType {
         derby("(?i).*derby.*"), mysql("(?i).*mysql.*"), other("");
@@ -257,6 +261,15 @@ public class DatabaseCreator {
 
         try {
             InputStream is = DatabaseCreator.class.getClassLoader().getResourceAsStream(dbscriptName);
+            if(is == null) {
+                logger.info("Script file not found at " + dbscriptName + ". Uses default database script file");
+                DatabaseType databaseType = DatabaseCreator.getDatabaseType(conn);
+                if(databaseType.equals(DatabaseType.derby)){
+                    is = DatabaseCreator.class.getClassLoader().getResourceAsStream("registry-derby.sql");
+                }else if(databaseType.equals(DatabaseType.derby)){
+                    is = DatabaseCreator.class.getClassLoader().getResourceAsStream("registry-mysql.sql");
+                }
+            }
             reader = new BufferedReader(new InputStreamReader(is));
             String line;
             while ((line = reader.readLine()) != null) {

http://git-wip-us.apache.org/repos/asf/airavata/blob/0a3d857b/airavata-api/airavata-api-server/src/test/java/org/apache/airavata/api/server/handler/AiravataServerHandlerTest.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/test/java/org/apache/airavata/api/server/handler/AiravataServerHandlerTest.java b/airavata-api/airavata-api-server/src/test/java/org/apache/airavata/api/server/handler/AiravataServerHandlerTest.java
new file mode 100644
index 0000000..799f8e9
--- /dev/null
+++ b/airavata-api/airavata-api-server/src/test/java/org/apache/airavata/api/server/handler/AiravataServerHandlerTest.java
@@ -0,0 +1,324 @@
+/*
+ *
+ * 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.api.server.handler;
+
+import junit.framework.Assert;
+import org.apache.airavata.api.server.util.RegistryInitUtil;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.model.appcatalog.appinterface.InputDataObjectType;
+import org.apache.airavata.model.appcatalog.appinterface.OutputDataObjectType;
+import org.apache.airavata.model.workspace.Gateway;
+import org.apache.airavata.model.workspace.Project;
+import org.apache.airavata.model.workspace.experiment.*;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * Test methods for Airavata Service Handler
+ */
+public class AiravataServerHandlerTest {
+    private final static Logger logger = LoggerFactory.getLogger(AiravataServerHandlerTest.class);
+
+    private static AiravataServerHandler airavataServerHandler;
+    private static String gatewayId = "default";
+
+    @BeforeClass
+    public static void setupBeforeClass() throws Exception{
+        AiravataUtils.setExecutionAsServer();
+        RegistryInitUtil.initializeDB();
+        airavataServerHandler = new AiravataServerHandler();
+
+        Gateway gateway = new Gateway();
+        gateway.setGatewayId(gatewayId);
+        airavataServerHandler.addGateway(gateway);
+    }
+
+    @AfterClass
+    public static void tearDown(){
+        RegistryInitUtil.stopDerbyInServerMode();
+    }
+
+    /**
+     * Testing for project related API methods
+     */
+    @Test
+    public void testProject(){
+        try {
+            String TAG = System.currentTimeMillis() + "";
+
+            //testing the creation of a project
+            Project project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("TestProject"+TAG);
+            project.setDescription("This is a test project"+TAG);
+            String projectId1 = airavataServerHandler.createProject(gatewayId, project);
+            Assert.assertNotNull(projectId1);
+
+            //testing the update of a project
+            Project updatedProject = new Project();
+            updatedProject.setProjectID(projectId1);
+            updatedProject.setOwner("TestUser"+TAG);
+            updatedProject.setName("UpdatedTestProject"+TAG);
+            updatedProject.setDescription("This is an updated test project"+TAG);
+            airavataServerHandler.updateProject(projectId1, updatedProject);
+
+            //testing project retrieval
+            Project retrievedProject = airavataServerHandler.getProject(projectId1);
+            Assert.assertEquals(updatedProject.getProjectID(), retrievedProject.getProjectID());
+            Assert.assertEquals(updatedProject.getOwner(), retrievedProject.getOwner());
+            Assert.assertEquals(updatedProject.getName(), retrievedProject.getName());
+            Assert.assertEquals(updatedProject.getDescription(), retrievedProject.getDescription());
+            Assert.assertNotNull(retrievedProject.getCreationTime());
+            //created user should be in the shared users list
+            Assert.assertTrue(retrievedProject.getSharedUsers().size()==1);
+
+            //creating more projects for the same user
+            project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("Project Terrible"+TAG);
+            project.setDescription("This is a test project_2"+TAG);
+            String projectId2 = airavataServerHandler.createProject(gatewayId, project);
+            Assert.assertNotNull(projectId2);
+
+            project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("Project Funny"+TAG);
+            project.setDescription("This is a test project_3"+TAG);
+            String projectId3 = airavataServerHandler.createProject(gatewayId, project);
+            Assert.assertNotNull(projectId3);
+
+            project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("Project Stupid"+TAG);
+            project.setDescription("This is a test project_4"+TAG);
+            String projectId4 = airavataServerHandler.createProject(gatewayId, project);
+            Assert.assertNotNull(projectId4);
+
+            project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("Project Boring"+TAG);
+            project.setDescription("This is a test project_5"+TAG);
+            String projectId5 = airavataServerHandler.createProject(gatewayId, project);
+            Assert.assertNotNull(projectId5);
+
+            //search project by project name
+            List<Project> list = airavataServerHandler.searchProjectsByProjectName(gatewayId,
+                    "TestUser"+TAG, "Terrible"+TAG);
+            Assert.assertTrue(list.size()==1);
+            //with pagination
+            list = airavataServerHandler.searchProjectsByProjectNameWithPagination(gatewayId,
+                    "TestUser" + TAG, "Project", 2, 1);
+            Assert.assertTrue(list.size()==2);
+
+            //search project by project description
+            list = airavataServerHandler.searchProjectsByProjectDesc(gatewayId, "TestUser"+TAG,
+                    "test project_2"+TAG);
+            Assert.assertTrue(list.size()==1);
+            //with pagination
+            list = airavataServerHandler.searchProjectsByProjectDescWithPagination(gatewayId,
+                    "TestUser" + TAG, "test", 2, 1);
+            Assert.assertTrue(list.size()==2);
+
+            //get all projects of user
+            list = airavataServerHandler.getAllUserProjects(gatewayId, "TestUser"+TAG);
+            Assert.assertTrue(list.size()==5);
+            //with pagination
+            list = airavataServerHandler.getAllUserProjectsWithPagination(gatewayId, "TestUser" + TAG, 2, 2);
+            Assert.assertTrue(list.size()==2);
+            Project project1 = list.get(0);
+            Project project2 = list.get(1);
+            Assert.assertTrue(project1.getCreationTime()-project2.getCreationTime() > 0);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    /**
+     * Testing for project related API methods
+     */
+    @Test
+    public void testExperiment(){
+        try {
+            String TAG = System.currentTimeMillis() + "";
+
+            String applicationId = "Echo_" + UUID.randomUUID().toString();
+
+            //creating project
+            Project project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("TestProject"+TAG);
+            project.setDescription("This is a test project"+TAG);
+            String projectId1 = airavataServerHandler.createProject(gatewayId,project);
+            Assert.assertNotNull(projectId1);
+
+            //creating sample echo experiment. assumes echo application is already defined
+            InputDataObjectType inputDataObjectType = new InputDataObjectType();
+            inputDataObjectType.setName("Input_to_Echo");
+            inputDataObjectType.setValue("Hello World");
+
+            ComputationalResourceScheduling scheduling = new ComputationalResourceScheduling();
+            scheduling.setResourceHostId(UUID.randomUUID().toString());
+            scheduling.setComputationalProjectAccount("TG-STA110014S");
+            scheduling.setTotalCPUCount(1);
+            scheduling.setNodeCount(1);
+            scheduling.setWallTimeLimit(15);
+            scheduling.setQueueName("normal");
+
+            UserConfigurationData userConfigurationData = new UserConfigurationData();
+            userConfigurationData.setAiravataAutoSchedule(false);
+            userConfigurationData.setOverrideManualScheduledParams(false);
+            userConfigurationData.setComputationalResourceScheduling(scheduling);
+
+            Experiment experiment = new Experiment();
+            experiment.setProjectID(projectId1);
+            experiment.setUserName("TestUser" + TAG);
+            experiment.setName("TestExperiment"+TAG);
+            experiment.setDescription("experiment");
+            experiment.setApplicationId(applicationId);
+            experiment.setUserConfigurationData(userConfigurationData);
+            experiment.addToExperimentInputs(inputDataObjectType);
+
+            String experimentId1 = airavataServerHandler.createExperiment(gatewayId, experiment);
+            Assert.assertNotNull(experimentId1);
+
+            //retrieving the stored experiment
+            Experiment retrievedExperiment = airavataServerHandler.getExperiment(experimentId1);
+            Assert.assertNotNull(retrievedExperiment);
+            Assert.assertEquals(retrievedExperiment.getProjectID(), experiment.getProjectID());
+            Assert.assertEquals(retrievedExperiment.getDescription(), experiment.getDescription());
+            Assert.assertEquals(retrievedExperiment.getName(), experiment.getName());
+            Assert.assertEquals(retrievedExperiment.getApplicationId(), experiment.getApplicationId());
+            Assert.assertNotNull(retrievedExperiment.getUserConfigurationData());
+            Assert.assertNotNull(retrievedExperiment.getExperimentInputs());
+
+            //updating an existing experiment
+            experiment.setName("NewExperimentName"+TAG);
+            OutputDataObjectType outputDataObjectType = new OutputDataObjectType();
+            outputDataObjectType.setName("Output_to_Echo");
+            outputDataObjectType.setValue("Hello World");
+            experiment.addToExperimentOutputs(outputDataObjectType);
+            airavataServerHandler.updateExperiment(experimentId1, experiment);
+
+            //creating more experiments
+            experiment = new Experiment();
+            experiment.setProjectID(projectId1);
+            experiment.setUserName("TestUser" + TAG);
+            experiment.setName("TestExperiment2" + TAG);
+            experiment.setDescription("experiment");
+            experiment.setApplicationId(applicationId);
+            experiment.setUserConfigurationData(userConfigurationData);
+            experiment.addToExperimentInputs(inputDataObjectType);
+
+            String experimentId2 = airavataServerHandler.createExperiment(gatewayId, experiment);
+            Assert.assertNotNull(experimentId2);
+
+            experiment = new Experiment();
+            experiment.setProjectID(projectId1);
+            experiment.setUserName("TestUser" + TAG);
+            experiment.setName("TestExperiment3"+TAG);
+            experiment.setDescription("experiment");
+            experiment.setApplicationId(applicationId);
+            experiment.setUserConfigurationData(userConfigurationData);
+            experiment.addToExperimentInputs(inputDataObjectType);
+
+            String experimentId3 = airavataServerHandler.createExperiment(gatewayId, experiment);
+            Assert.assertNotNull(experimentId3);
+
+            //searching experiments by name
+            List<ExperimentSummary> results = airavataServerHandler.searchExperimentsByName(gatewayId,
+                    "TestUser" + TAG, "Experiment2");
+            Assert.assertTrue(results.size()==1);
+            //with pagination
+            results = airavataServerHandler.searchExperimentsByNameWithPagination(gatewayId,
+                    "TestUser" + TAG, "Experi", 2, 0);
+            Assert.assertTrue(results.size()==2);
+
+            //searching experiments by creation time
+            long time = System.currentTimeMillis();
+            results = airavataServerHandler.searchExperimentsByCreationTime(
+                    gatewayId, "TestUser" + TAG, time-10000, time+1000);
+            Assert.assertTrue(results.size()==3);
+            //with pagination
+            results = airavataServerHandler.searchExperimentsByCreationTimeWithPagination(
+                    gatewayId, "TestUser" + TAG, time-10000, time+1000, 2, 1);
+            Assert.assertTrue(results.size()==2);
+
+            //searching based on experiment state
+            ExperimentState experimentState = ExperimentState.findByValue(0);
+            results = airavataServerHandler.searchExperimentsByStatus(
+                    gatewayId, "TestUser" + TAG, experimentState);
+            Assert.assertTrue(results.size() > 0);
+            //with pagination
+            results = airavataServerHandler.searchExperimentsByStatusWithPagination(
+                    gatewayId, "TestUser" + TAG, experimentState, 2, 0);
+            Assert.assertTrue(results.size()==2);
+
+            //searching based on application
+            results = airavataServerHandler.searchExperimentsByApplication(
+                    gatewayId, "TestUser" + TAG, "Ech");
+            Assert.assertTrue(results.size() > 0);
+            //with pagination
+            results = airavataServerHandler.searchExperimentsByApplicationWithPagination(
+                    gatewayId, "TestUser" + TAG, "Ech", 2, 0);
+            Assert.assertTrue(results.size()==2);
+
+            //searching experiments by description
+            results = airavataServerHandler.searchExperimentsByDesc(
+                    gatewayId, "TestUser" + TAG, "exp");
+            Assert.assertTrue(results.size() > 0);
+            //with pagination
+            results = airavataServerHandler.searchExperimentsByDescWithPagination(
+                    gatewayId, "TestUser" + TAG, "exp", 2, 0);
+            Assert.assertTrue(results.size()==2);
+
+
+            //retrieving all experiments in project
+            List<Experiment> list = airavataServerHandler.getAllExperimentsInProject(projectId1);
+            Assert.assertTrue(list.size()==3);
+            //with pagination
+            list = airavataServerHandler.getAllExperimentsInProjectWithPagination(projectId1, 2, 1);
+            Assert.assertTrue(list.size()==2);
+
+            //getting all user experiments
+            list = airavataServerHandler.getAllUserExperiments(gatewayId, "TestUser" + TAG);
+            Assert.assertTrue(list.size() == 3);
+            //with pagination
+            list = airavataServerHandler.getAllUserExperimentsWithPagination(
+                    gatewayId, "TestUser" + TAG, 2, 0);
+            //testing time ordering
+            Assert.assertTrue(list.size()==2);
+            Experiment exp1 = list.get(0);
+            Experiment exp2 = list.get(1);
+            Assert.assertTrue(exp1.getCreationTime()-exp2.getCreationTime() > 0);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+}
\ No newline at end of file


Mime
View raw message