You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sc...@apache.org on 2016/11/10 20:08:46 UTC

[6/7] airavata git commit: AIRAVATA-2207 Add cloneExperimentByAdmin API method

AIRAVATA-2207 Add cloneExperimentByAdmin API method


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

Branch: refs/heads/develop
Commit: 5f3b778ef55a9d59bc5cc4dab23dd496e89dd65c
Parents: 0fda5a8
Author: Marcus Christie <ma...@iu.edu>
Authored: Thu Nov 10 14:47:45 2016 -0500
Committer: Marcus Christie <ma...@iu.edu>
Committed: Thu Nov 10 14:47:45 2016 -0500

----------------------------------------------------------------------
 .../server/handler/AiravataServerHandler.java   |  154 +-
 .../java/org/apache/airavata/api/Airavata.java  | 6676 +++++++++++-------
 .../resources/lib/Airavata/API/Airavata.php     |  503 ++
 .../resources/airavata-default-xacml-policy.xml |    1 +
 .../airavata-apis/airavata_api.thrift           |   54 +
 5 files changed, 4954 insertions(+), 2434 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/5f3b778e/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 2f7a014..557c777 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
@@ -1557,7 +1557,7 @@ public class AiravataServerHandler implements Airavata.Iface {
      *    This is the experiment identifier that already exists in the system. Will use this experimentID to retrieve
      *    user configuration which is used with the clone experiment.
      *
-     * @param newExperiementName
+     * @param newExperimentName
      *   experiment name that should be used in the cloned experiment
      *
      * @return
@@ -1588,84 +1588,110 @@ public class AiravataServerHandler implements Airavata.Iface {
      *
      *
      * @param existingExperimentID
-     * @param newExperiementName
+     * @param newExperimentName
      */
     @Override
     @SecurityCheck
-    public String cloneExperiment(AuthzToken authzToken, String existingExperimentID, String newExperiementName, String newExperimentProjectId)
+    public String cloneExperiment(AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId)
             throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException,
             AuthorizationException, ProjectNotFoundException, TException {
         try {
-            RegistryService.Client regClient = getRegistryServiceClient();
-            ExperimentModel existingExperiment = regClient.getExperiment(existingExperimentID);
-            if (existingExperiment == null){
-                logger.error(existingExperimentID, "Error while cloning experiment {}, experiment doesn't exist.", existingExperimentID);
-                throw new ExperimentNotFoundException("Requested experiment id " + existingExperimentID + " does not exist in the system..");
-            }
-            if (newExperimentProjectId != null) {
+            // getExperiment will apply sharing permissions
+            ExperimentModel existingExperiment = this.getExperiment(authzToken, existingExperimentID);
+            return cloneExperimentInternal(authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment);
+        } catch (Exception e) {
+            logger.error(existingExperimentID, "Error while cloning the experiment with existing configuration...", e);
+            AiravataSystemException exception = new AiravataSystemException();
+            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+            exception.setMessage("Error while cloning the experiment with existing configuration. More info : " + e.getMessage());
+            throw exception;
+        }
+    }
 
-                Project project = regClient.getProject(newExperimentProjectId);
-                if (project == null){
-                    logger.error("Error while cloning experiment {}, project {} doesn't exist.", existingExperimentID, newExperimentProjectId);
-                    throw new ProjectNotFoundException("Requested project id " + newExperimentProjectId + " does not exist in the system..");
-                }
-                existingExperiment.setProjectId(project.getProjectID());
-            }
+    @Override
+    @SecurityCheck
+    public String cloneExperimentByAdmin(AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId)
+            throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException,
+            AuthorizationException, ProjectNotFoundException, TException {
+        try {
+            // get existing experiment by bypassing normal sharing permissions for the admin user
+            ExperimentModel existingExperiment = this.getExperimentByAdmin(authzToken, existingExperimentID);
+            return cloneExperimentInternal(authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment);
+        } catch (Exception e) {
+            logger.error(existingExperimentID, "Error while cloning the experiment with existing configuration...", e);
+            AiravataSystemException exception = new AiravataSystemException();
+            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+            exception.setMessage("Error while cloning the experiment with existing configuration. More info : " + e.getMessage());
+            throw exception;
+        }
+    }
 
-            // make sure user has write access to the project
-            String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
-            String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
-            if(!sharingRegistryServerHandler.userHasAccess(gatewayId, userId + "@" + gatewayId,
-                    existingExperiment.getProjectId(), gatewayId + ":WRITE")){
-                logger.error("Error while cloning experiment {}, user doesn't have write access to project {}", existingExperimentID, existingExperiment.getProjectId());
-                throw new AuthorizationException("User does not have permission to clone an experiment in this project");
-            }
+    private String cloneExperimentInternal(AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId, ExperimentModel existingExperiment)
+            throws ExperimentNotFoundException, ProjectNotFoundException, TException, AuthorizationException, ApplicationSettingsException {
 
-            existingExperiment.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
-            if (existingExperiment.getExecutionId() != null){
-                List<OutputDataObjectType> applicationOutputs = regClient.getApplicationOutputs(existingExperiment.getExecutionId());
-                existingExperiment.setExperimentOutputs(applicationOutputs);
-            }
-            if (validateString(newExperiementName)){
-                existingExperiment.setExperimentName(newExperiementName);
-            }
-            if (existingExperiment.getErrors() != null ){
-                existingExperiment.getErrors().clear();
-            }
-            if(existingExperiment.getUserConfigurationData() != null && existingExperiment.getUserConfigurationData()
-                    .getComputationalResourceScheduling() != null){
-                String compResourceId = existingExperiment.getUserConfigurationData()
-                        .getComputationalResourceScheduling().getResourceHostId();
-
-                ComputeResourceDescription computeResourceDescription = regClient.getComputeResource(compResourceId);
-                if(!computeResourceDescription.isEnabled()){
-                    existingExperiment.getUserConfigurationData().setComputationalResourceScheduling(null);
-                }
+        RegistryService.Client regClient = getRegistryServiceClient();
+        if (existingExperiment == null){
+            logger.error(existingExperimentID, "Error while cloning experiment {}, experiment doesn't exist.", existingExperimentID);
+            throw new ExperimentNotFoundException("Requested experiment id " + existingExperimentID + " does not exist in the system..");
+        }
+        if (newExperimentProjectId != null) {
+
+            // getProject will apply sharing permissions
+            Project project = this.getProject(authzToken, newExperimentProjectId);
+            if (project == null){
+                logger.error("Error while cloning experiment {}, project {} doesn't exist.", existingExperimentID, newExperimentProjectId);
+                throw new ProjectNotFoundException("Requested project id " + newExperimentProjectId + " does not exist in the system..");
             }
-            logger.debug("Airavata cloned experiment with experiment id : " + existingExperimentID);
-            existingExperiment.setUserName(userId);
-            String expId = regClient.createExperiment(gatewayId, existingExperiment);
+            existingExperiment.setProjectId(project.getProjectID());
+        }
 
-            if(ServerSettings.isEnableSharing()){
-                Entity entity = new Entity();
-                entity.setEntityId(expId);
-                entity.setDomainId(existingExperiment.getGatewayId());
-                entity.setEntityTypeId(existingExperiment.getGatewayId()+":"+"EXPERIMENT");
-                entity.setOwnerId(existingExperiment.getUserName() + "@" + existingExperiment.getGatewayId());
-                entity.setName(existingExperiment.getExperimentName());
-                entity.setDescription(existingExperiment.getDescription());
+        // make sure user has write access to the project
+        String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
+        String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
+        if(!sharingRegistryServerHandler.userHasAccess(gatewayId, userId + "@" + gatewayId,
+                existingExperiment.getProjectId(), gatewayId + ":WRITE")){
+            logger.error("Error while cloning experiment {}, user doesn't have write access to project {}", existingExperimentID, existingExperiment.getProjectId());
+            throw new AuthorizationException("User does not have permission to clone an experiment in this project");
+        }
 
-                sharingRegistryServerHandler.createEntity(entity);
+        existingExperiment.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
+        if (existingExperiment.getExecutionId() != null){
+            List<OutputDataObjectType> applicationOutputs = regClient.getApplicationOutputs(existingExperiment.getExecutionId());
+            existingExperiment.setExperimentOutputs(applicationOutputs);
+        }
+        if (validateString(newExperimentName)){
+            existingExperiment.setExperimentName(newExperimentName);
+        }
+        if (existingExperiment.getErrors() != null ){
+            existingExperiment.getErrors().clear();
+        }
+        if(existingExperiment.getUserConfigurationData() != null && existingExperiment.getUserConfigurationData()
+                .getComputationalResourceScheduling() != null){
+            String compResourceId = existingExperiment.getUserConfigurationData()
+                    .getComputationalResourceScheduling().getResourceHostId();
+
+            ComputeResourceDescription computeResourceDescription = regClient.getComputeResource(compResourceId);
+            if(!computeResourceDescription.isEnabled()){
+                existingExperiment.getUserConfigurationData().setComputationalResourceScheduling(null);
             }
+        }
+        logger.debug("Airavata cloned experiment with experiment id : " + existingExperimentID);
+        existingExperiment.setUserName(userId);
+        String expId = regClient.createExperiment(gatewayId, existingExperiment);
 
-            return expId;
-        } catch (Exception e) {
-            logger.error(existingExperimentID, "Error while cloning the experiment with existing configuration...", e);
-            AiravataSystemException exception = new AiravataSystemException();
-            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
-            exception.setMessage("Error while cloning the experiment with existing configuration. More info : " + e.getMessage());
-            throw exception;
+        if(ServerSettings.isEnableSharing()){
+            Entity entity = new Entity();
+            entity.setEntityId(expId);
+            entity.setDomainId(existingExperiment.getGatewayId());
+            entity.setEntityTypeId(existingExperiment.getGatewayId()+":"+"EXPERIMENT");
+            entity.setOwnerId(existingExperiment.getUserName() + "@" + existingExperiment.getGatewayId());
+            entity.setName(existingExperiment.getExperimentName());
+            entity.setDescription(existingExperiment.getDescription());
+
+            sharingRegistryServerHandler.createEntity(entity);
         }
+
+        return expId;
     }
 
     /**