You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by am...@apache.org on 2013/01/03 23:58:07 UTC

svn commit: r1428660 - in /airavata/trunk/modules: airavata-client/src/main/java/org/apache/airavata/client/api/ integration-tests/src/test/java/org/apache/airavata/integration/ rest/client/src/main/java/org/apache/airavata/rest/client/

Author: amilaj
Date: Thu Jan  3 22:58:07 2013
New Revision: 1428660

URL: http://svn.apache.org/viewvc?rev=1428660&view=rev
Log:
Fixing AIRAVATA-697.

Modified:
    airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/WorkflowManager.java
    airavata/trunk/modules/integration-tests/src/test/java/org/apache/airavata/integration/BaseCaseIT.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/DescriptorResourceClient.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/UserWorkflowResourceClient.java

Modified: airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/WorkflowManager.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/WorkflowManager.java?rev=1428660&r1=1428659&r2=1428660&view=diff
==============================================================================
--- airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/WorkflowManager.java (original)
+++ airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/WorkflowManager.java Thu Jan  3 22:58:07 2013
@@ -213,8 +213,7 @@ public interface WorkflowManager {
      * @param workflowAsString The workflow to update. Workflow is uniquely identified by <xgr:id> tag.
      * @throws AiravataAPIInvocationException If an error occurred while updating the workflow.
      */
-    public void updateWorkflowAsPublic (String workflowAsString) throws AiravataAPIInvocationException,
-            DescriptorRecordAlreadyExistsException;
+    public void updateWorkflowAsPublic (String workflowAsString) throws AiravataAPIInvocationException;
 
     /**
      * Adds a new workflow. Workflow is added to users private space. i.e. only user who added the
@@ -231,8 +230,7 @@ public interface WorkflowManager {
      *                    Workflow is uniquely identified by <xgr:id> tag.
      * @throws AiravataAPIInvocationException If an error occurred while updating the workflow.
      */
-    public void updateWorkflowAsPublic (URI workflowUri) throws AiravataAPIInvocationException,
-            DescriptorRecordAlreadyExistsException;
+    public void updateWorkflowAsPublic (URI workflowUri) throws AiravataAPIInvocationException;
 
 
     /**
@@ -250,8 +248,7 @@ public interface WorkflowManager {
      * @param workflowAsString The workflow to update. Workflow is uniquely identified by <xgr:id> tag..
      * @throws AiravataAPIInvocationException If an error occurred while updating the workflow.
      */
-    public void updateWorkflow (String workflowAsString) throws AiravataAPIInvocationException,
-            DescriptorRecordAlreadyExistsException;
+    public void updateWorkflow (String workflowAsString) throws AiravataAPIInvocationException;
 
     /**
      * Adds a new workflow. Workflow is added to users private space. i.e. only user who added the
@@ -268,8 +265,7 @@ public interface WorkflowManager {
      * @param workflow The workflow to update. Workflow is uniquely identified by <xgr:id> tag..
      * @throws AiravataAPIInvocationException If an error occurred while updating the workflow.
      */
-    public void updateWorkflow (Workflow workflow) throws AiravataAPIInvocationException,
-            DescriptorRecordAlreadyExistsException;
+    public void updateWorkflow (Workflow workflow) throws AiravataAPIInvocationException;
 
     /**
      * Adds a new workflow. Workflow is added to users private space. i.e. only user who added the
@@ -286,8 +282,7 @@ public interface WorkflowManager {
      * @param workflowUri The workflow to update as a URI.
      * @throws AiravataAPIInvocationException If an error occurred while updating the workflow.
      */
-    public void updateWorkflow (URI workflowUri) throws AiravataAPIInvocationException,
-            DescriptorRecordAlreadyExistsException;
+    public void updateWorkflow (URI workflowUri) throws AiravataAPIInvocationException;
 
     /**
      * Save the workflow as public

Modified: airavata/trunk/modules/integration-tests/src/test/java/org/apache/airavata/integration/BaseCaseIT.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/integration-tests/src/test/java/org/apache/airavata/integration/BaseCaseIT.java?rev=1428660&r1=1428659&r2=1428660&view=diff
==============================================================================
--- airavata/trunk/modules/integration-tests/src/test/java/org/apache/airavata/integration/BaseCaseIT.java (original)
+++ airavata/trunk/modules/integration-tests/src/test/java/org/apache/airavata/integration/BaseCaseIT.java Thu Jan  3 22:58:07 2013
@@ -14,6 +14,7 @@ import junit.framework.Assert;
 import org.apache.airavata.client.AiravataAPIFactory;
 import org.apache.airavata.client.api.AiravataAPI;
 import org.apache.airavata.client.api.AiravataAPIInvocationException;
+import org.apache.airavata.client.api.DescriptorRecordAlreadyExistsException;
 import org.apache.airavata.client.api.ExperimentAdvanceOptions;
 import org.apache.airavata.client.api.builder.DescriptorBuilder;
 import org.apache.airavata.common.utils.Version;
@@ -22,6 +23,8 @@ import org.apache.airavata.commons.gfac.
 import org.apache.airavata.commons.gfac.type.ServiceDescription;
 import org.apache.airavata.registry.api.PasswordCallback;
 import org.apache.airavata.schemas.gfac.*;
+import org.apache.airavata.workflow.model.component.ComponentException;
+import org.apache.airavata.workflow.model.graph.GraphException;
 import org.apache.airavata.workflow.model.wf.Workflow;
 import org.apache.airavata.workflow.model.wf.WorkflowInput;
 import org.apache.airavata.ws.monitor.Monitor;
@@ -269,6 +272,93 @@ public class BaseCaseIT {
         runWorkFlow(workflow, Arrays.asList("echo_output=Airavata Test"));
     }
 
+    @Test(groups = { "echoGroup" }, dependsOnMethods = { "testEchoService" })
+    public void testUpdateEchoService() throws AiravataAPIInvocationException, IOException, ComponentException, GraphException {
+
+        DescriptorBuilder descriptorBuilder = airavataAPI.getDescriptorBuilder();
+
+        HostDescription hostDescription
+                = descriptorBuilder.buildHostDescription(HostDescriptionType.type, "localhost", "127.0.0.1");
+
+        log("Trying to add host description ....");
+        try {
+            airavataAPI.getApplicationManager().addHostDescription(hostDescription);
+            Assert.fail("Host Descriptor should already exists and should go to update.");
+        } catch (DescriptorRecordAlreadyExistsException e) {
+
+            log("Updating host description ....");
+            airavataAPI.getApplicationManager().updateHostDescription(hostDescription);
+        }
+
+        Assert.assertTrue(airavataAPI.getApplicationManager().isHostDescriptorExists(hostDescription.getType()
+                .getHostName()));
+
+
+        List<InputParameterType> inputParameters = new ArrayList<InputParameterType>();
+        inputParameters.add(descriptorBuilder.buildInputParameterType("echo_input", "echo input", DataType.STRING));
+
+        List<OutputParameterType> outputParameters = new ArrayList<OutputParameterType>();
+        outputParameters.add(descriptorBuilder.buildOutputParameterType("echo_output", "Echo output", DataType.STRING));
+
+        ServiceDescription serviceDescription = descriptorBuilder.buildServiceDescription("Echo", "Echo service",
+                inputParameters, outputParameters);
+
+        log("Adding service description ...");
+        try {
+            airavataAPI.getApplicationManager().addServiceDescription(serviceDescription);
+            Assert.fail("Service Descriptor should already exists and should go to update.");
+        } catch (DescriptorRecordAlreadyExistsException e) {
+
+            log("Updating service description ....");
+            airavataAPI.getApplicationManager().updateServiceDescription(serviceDescription);
+        }
+
+        Assert.assertTrue(airavataAPI.getApplicationManager().isServiceDescriptorExists(serviceDescription.
+                getType().getName()));
+
+        // Deployment descriptor
+        ApplicationDescription applicationDeploymentDescription
+                = descriptorBuilder.buildApplicationDeploymentDescription("EchoApplication", "/bin/echo", "/tmp");
+
+        log("Adding deployment description ...");
+        try {
+            airavataAPI.getApplicationManager().addApplicationDescription(serviceDescription,
+                    hostDescription, applicationDeploymentDescription);
+            Assert.fail("Application Descriptor should already exists and should go to update.");
+        } catch (DescriptorRecordAlreadyExistsException e) {
+
+            log("Updating application description ....");
+            airavataAPI.getApplicationManager().updateApplicationDescription(serviceDescription,
+                    hostDescription, applicationDeploymentDescription);
+        }
+
+        Assert.assertTrue(airavataAPI.getApplicationManager().isApplicationDescriptorExists(serviceDescription.getType().
+                getName(), hostDescription.getType().getHostName(),
+                applicationDeploymentDescription.getType().getApplicationName().getStringValue()));
+
+        log("Saving workflow ...");
+        Workflow workflow = new Workflow(getWorkflowComposeContent("src/test/resources/EchoWorkflow.xwf"));
+
+        try {
+            airavataAPI.getWorkflowManager().addWorkflow(workflow);
+            Assert.fail("Workflow should already exists and should go to update.");
+        } catch (DescriptorRecordAlreadyExistsException e) {
+
+            log("Updating workflow...");
+            airavataAPI.getWorkflowManager().updateWorkflow(workflow);
+        }
+
+        Assert.assertTrue(airavataAPI.getWorkflowManager().isWorkflowExists(workflow.getName()));
+
+        log("Workflow setting up completed ...");
+
+        try {
+            runWorkFlow(workflow, Arrays.asList("echo_output=Airavata Test"));
+        } catch (Exception e) {
+            log.error("An error occurred while invoking workflow", e);
+        }
+    }
+
     protected void runWorkFlow(Workflow workflow, List<String> inputValues) throws Exception {
 
         AiravataAPI airavataAPI = AiravataAPIFactory.getAPI(new URI(getRegistryURL()), getGatewayName(),

Modified: airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/DescriptorResourceClient.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/DescriptorResourceClient.java?rev=1428660&r1=1428659&r2=1428660&view=diff
==============================================================================
--- airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/DescriptorResourceClient.java (original)
+++ airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/DescriptorResourceClient.java Thu Jan  3 22:58:07 2013
@@ -32,6 +32,7 @@ import org.apache.airavata.commons.gfac.
 import org.apache.airavata.commons.gfac.type.HostDescription;
 import org.apache.airavata.commons.gfac.type.ServiceDescription;
 import org.apache.airavata.registry.api.PasswordCallback;
+import org.apache.airavata.registry.api.exception.gateway.DescriptorAlreadyExistsException;
 import org.apache.airavata.rest.mappings.resourcemappings.*;
 import org.apache.airavata.rest.mappings.utils.DescriptorUtil;
 import org.apache.airavata.rest.mappings.utils.ResourcePathConstants;
@@ -129,7 +130,7 @@ public class DescriptorResourceClient {
     }
 
 
-    public void addHostDescriptor(HostDescription hostDescription) {
+    public void addHostDescriptor(HostDescription hostDescription) throws DescriptorAlreadyExistsException {
         HostDescriptor hostDescriptor = DescriptorUtil.createHostDescriptor(hostDescription);
         webResource = getDescriptorRegistryBaseResource().path(
                 ResourcePathConstants.DecResourcePathConstants.HOST_DESC_SAVE);
@@ -156,12 +157,19 @@ public class DescriptorResourceClient {
                 logger.error(response.getEntity(String.class));
                 throw new RuntimeException("Failed : HTTP error code : "
                         + status);
+            }else if (status == ClientConstant.HTTP_BAD_REQUEST){
+                logger.debug("Descriptor already exists...");
+                throw new DescriptorAlreadyExistsException(hostDescription.getType().getHostName() + " already exists !!!");
             } else {
                 if (response.getCookies().size() > 0) {
                     cookie = response.getCookies().get(0).toCookie();
                 }
             }
-        } else {
+        }else if (status == ClientConstant.HTTP_BAD_REQUEST){
+            logger.debug("Descriptor already exists...");
+            throw new DescriptorAlreadyExistsException(hostDescription.getType().getHostName() + " already exists !!!");
+        }
+        else {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
@@ -440,7 +448,7 @@ public class DescriptorResourceClient {
         }
     }
 
-    public void addServiceDescriptor(ServiceDescription serviceDescription) {
+    public void addServiceDescriptor(ServiceDescription serviceDescription) throws DescriptorAlreadyExistsException {
         ServiceDescriptor serviceDescriptor = DescriptorUtil.createServiceDescriptor(serviceDescription);
         webResource = getDescriptorRegistryBaseResource().path(
                 ResourcePathConstants.DecResourcePathConstants.SERVICE_DESC_SAVE);
@@ -464,7 +472,10 @@ public class DescriptorResourceClient {
 
             status = response.getStatus();
 
-            if (status != ClientConstant.HTTP_OK) {
+            if (status == ClientConstant.HTTP_BAD_REQUEST){
+                logger.debug("Descriptor already exists...");
+                throw new DescriptorAlreadyExistsException(serviceDescriptor.getServiceName() + " already exists !!!");
+            } else if (status != ClientConstant.HTTP_OK) {
                 logger.error(response.getEntity(String.class));
                 throw new RuntimeException("Failed : HTTP error code : "
                         + status);
@@ -473,6 +484,9 @@ public class DescriptorResourceClient {
                     cookie = response.getCookies().get(0).toCookie();
                 }
             }
+        } else if (status == ClientConstant.HTTP_BAD_REQUEST){
+            logger.debug("Descriptor already exists...");
+            throw new DescriptorAlreadyExistsException(serviceDescriptor.getServiceName() + " already exists !!!");
         } else {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
@@ -704,7 +718,7 @@ public class DescriptorResourceClient {
 
     public void addApplicationDescriptor(ServiceDescription serviceDescription,
                                          HostDescription hostDescriptor,
-                                         ApplicationDescription descriptor) {
+                                         ApplicationDescription descriptor) throws DescriptorAlreadyExistsException {
         ApplicationDescriptor applicationDescriptor = DescriptorUtil.createApplicationDescriptor(descriptor);
         applicationDescriptor.setHostdescName(hostDescriptor.getType().getHostName());
         ServiceDescriptor serviceDescriptor = DescriptorUtil.createServiceDescriptor(serviceDescription);
@@ -731,7 +745,10 @@ public class DescriptorResourceClient {
                     MediaType.APPLICATION_JSON).post(ClientResponse.class, applicationDescriptor);
             status = response.getStatus();
 
-            if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
+            if (status == ClientConstant.HTTP_BAD_REQUEST){
+                logger.debug("Descriptor already exists...");
+                throw new DescriptorAlreadyExistsException(applicationDescriptor.getName() + " already exists !!!");
+            } else if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
                 logger.error(response.getEntity(String.class));
                 throw new RuntimeException("Failed : HTTP error code : "
                         + status);
@@ -740,6 +757,9 @@ public class DescriptorResourceClient {
                     cookie = response.getCookies().get(0).toCookie();
                 }
             }
+        } else if (status == ClientConstant.HTTP_BAD_REQUEST){
+            logger.debug("Descriptor already exists...");
+            throw new DescriptorAlreadyExistsException(applicationDescriptor.getName() + " already exists !!!");
         } else {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
@@ -749,7 +769,7 @@ public class DescriptorResourceClient {
 
     public void addApplicationDescriptor(String serviceName,
                                          String hostName,
-                                         ApplicationDescription descriptor) {
+                                         ApplicationDescription descriptor) throws DescriptorAlreadyExistsException {
         ServiceDescription serviceDescription = getServiceDescriptor(serviceName);
         ApplicationDescriptor applicationDescriptor = DescriptorUtil.createApplicationDescriptor(descriptor);
         applicationDescriptor.setHostdescName(hostName);
@@ -777,7 +797,10 @@ public class DescriptorResourceClient {
                     MediaType.APPLICATION_JSON).post(ClientResponse.class, applicationDescriptor);
             status = response.getStatus();
 
-            if (status != ClientConstant.HTTP_OK) {
+            if (status == ClientConstant.HTTP_BAD_REQUEST){
+                logger.debug("Descriptor already exists...");
+                throw new DescriptorAlreadyExistsException(applicationDescriptor.getName() + " already exists !!!");
+            } else if (status != ClientConstant.HTTP_OK) {
                 logger.error(response.getEntity(String.class));
                 throw new RuntimeException("Failed : HTTP error code : "
                         + status);
@@ -786,6 +809,9 @@ public class DescriptorResourceClient {
                     cookie = response.getCookies().get(0).toCookie();
                 }
             }
+        } else if (status == ClientConstant.HTTP_BAD_REQUEST){
+            logger.debug("Descriptor already exists...");
+            throw new DescriptorAlreadyExistsException(applicationDescriptor.getName() + " already exists !!!");
         } else {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "

Modified: airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/UserWorkflowResourceClient.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/UserWorkflowResourceClient.java?rev=1428660&r1=1428659&r2=1428660&view=diff
==============================================================================
--- airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/UserWorkflowResourceClient.java (original)
+++ airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/UserWorkflowResourceClient.java Thu Jan  3 22:58:07 2013
@@ -30,6 +30,8 @@ import com.sun.jersey.api.json.JSONConfi
 import com.sun.jersey.core.util.MultivaluedMapImpl;
 import org.apache.airavata.registry.api.PasswordCallback;
 import org.apache.airavata.registry.api.ResourceMetadata;
+import org.apache.airavata.registry.api.exception.gateway.DescriptorAlreadyExistsException;
+import org.apache.airavata.registry.api.exception.worker.UserWorkflowAlreadyExistsException;
 import org.apache.airavata.rest.mappings.resourcemappings.Workflow;
 import org.apache.airavata.rest.mappings.resourcemappings.WorkflowList;
 import org.apache.airavata.rest.mappings.utils.ResourcePathConstants;
@@ -129,7 +131,7 @@ public class UserWorkflowResourceClient 
         }
     }
 
-    public void addWorkflow(String workflowName, String workflowGraphXml) {
+    public void addWorkflow(String workflowName, String workflowGraphXml) throws UserWorkflowAlreadyExistsException {
         webResource = getUserWFRegistryBaseResource().path(
                 ResourcePathConstants.UserWFConstants.ADD_WORKFLOW);
         MultivaluedMap formParams = new MultivaluedMapImpl();
@@ -153,7 +155,11 @@ public class UserWorkflowResourceClient 
             response = builder.type(MediaType.APPLICATION_FORM_URLENCODED).accept(
                     MediaType.TEXT_PLAIN).post(ClientResponse.class, formParams);
             status = response.getStatus();
-            if (status != ClientConstant.HTTP_OK) {
+            if (status == ClientConstant.HTTP_BAD_REQUEST){
+                logger.debug("Workflow already exists...");
+                throw new UserWorkflowAlreadyExistsException(workflowName + " already exists !!!");
+            }
+            else if (status != ClientConstant.HTTP_OK) {
                 logger.error(response.getEntity(String.class));
                 throw new RuntimeException("Failed : HTTP error code : "
                         + status);
@@ -162,6 +168,9 @@ public class UserWorkflowResourceClient 
                     cookie = response.getCookies().get(0).toCookie();
                 }
             }
+        } else if (status == ClientConstant.HTTP_BAD_REQUEST){
+            logger.debug("Descriptor already exists...");
+            throw new UserWorkflowAlreadyExistsException(workflowName + " already exists !!!");
         } else {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "