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 2012/11/12 19:07:11 UTC

svn commit: r1408384 - in /airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest: client/ resources/

Author: chathuri
Date: Mon Nov 12 18:07:10 2012
New Revision: 1408384

URL: http://svn.apache.org/viewvc?rev=1408384&view=rev
Log:
adding user workflow registry and published workflow registry clients

Added:
    airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/PublishedWorkflowResourceClient.java
    airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/UserWorkflowResourceClient.java
Modified:
    airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/PublishWorkflowRegistryResource.java
    airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java

Added: airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/PublishedWorkflowResourceClient.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/PublishedWorkflowResourceClient.java?rev=1408384&view=auto
==============================================================================
--- airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/PublishedWorkflowResourceClient.java (added)
+++ airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/PublishedWorkflowResourceClient.java Mon Nov 12 18:07:10 2012
@@ -0,0 +1,181 @@
+/*
+ *
+ * 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.services.registry.rest.client;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.json.JSONConfiguration;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.airavata.services.registry.rest.resourcemappings.PublishWorkflowNamesList;
+import org.apache.airavata.services.registry.rest.resourcemappings.Workflow;
+import org.apache.airavata.services.registry.rest.resourcemappings.WorkflowList;
+import org.apache.airavata.services.registry.rest.utils.ResourcePathConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriBuilder;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class PublishedWorkflowResourceClient {
+    private WebResource webResource;
+    private final static Logger logger = LoggerFactory.getLogger(PublishedWorkflowResourceClient.class);
+
+    private URI getBaseURI() {
+        logger.info("Creating Base URI");
+        return UriBuilder.fromUri("http://localhost:9080/airavata-services/").build();
+    }
+
+    private WebResource getPublishedWFRegistryBaseResource (){
+        ClientConfig config = new DefaultClientConfig();
+        config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
+                Boolean.TRUE);
+        Client client = Client.create(config);
+        WebResource baseWebResource = client.resource(getBaseURI());
+        webResource = baseWebResource.path(ResourcePathConstants.PublishedWFConstants.REGISTRY_API_PUBLISHWFREGISTRY);
+        return webResource;
+    }
+
+    public boolean isPublishedWorkflowExists(String workflowName){
+        webResource = getPublishedWFRegistryBaseResource().path(ResourcePathConstants.PublishedWFConstants.PUBLISHWF_EXIST);
+        MultivaluedMap queryParams = new MultivaluedMapImpl();
+        queryParams.add("workflowname", workflowName);
+        ClientResponse response = webResource.queryParams(queryParams).type(MediaType.TEXT_PLAIN).get(ClientResponse.class);
+        int status = response.getStatus();
+
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+
+        return true;
+    }
+
+    public void publishWorkflow(String workflowName, String publishWorkflowName){
+        webResource = getPublishedWFRegistryBaseResource().path(ResourcePathConstants.PublishedWFConstants.PUBLISH_WORKFLOW);
+        MultivaluedMap formParams = new MultivaluedMapImpl();
+        formParams.add("workflowName", workflowName);
+        formParams.add("publishWorkflowName", publishWorkflowName);
+
+        ClientResponse response = webResource.type(MediaType.TEXT_PLAIN).post(ClientResponse.class, formParams);
+        int status = response.getStatus();
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+    }
+
+    public void publishWorkflow(String workflowName){
+        webResource = getPublishedWFRegistryBaseResource().path(ResourcePathConstants.PublishedWFConstants.PUBLISH_DEFAULT_WORKFLOW);
+        MultivaluedMap formParams = new MultivaluedMapImpl();
+        formParams.add("workflowName", workflowName);
+
+        ClientResponse response = webResource.type(MediaType.TEXT_PLAIN).post(ClientResponse.class, formParams);
+        int status = response.getStatus();
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+
+    }
+
+    public String getPublishedWorkflowGraphXML(String workflowName){
+        webResource = getPublishedWFRegistryBaseResource().path(ResourcePathConstants.PublishedWFConstants.GET_PUBLISHWORKFLOWGRAPH);
+        MultivaluedMap queryParams = new MultivaluedMapImpl();
+        queryParams.add("workflowname", workflowName);
+        ClientResponse response = webResource.queryParams(queryParams).type(MediaType.TEXT_PLAIN).get(ClientResponse.class);
+        int status = response.getStatus();
+
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+
+        String wfGraph = response.getEntity(String.class);
+        return wfGraph;
+
+    }
+
+    public List<String> getPublishedWorkflowNames(){
+        webResource = getPublishedWFRegistryBaseResource().path(ResourcePathConstants.PublishedWFConstants.GET_PUBLISHWORKFLOWNAMES);
+        ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+        int status = response.getStatus();
+
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+
+        PublishWorkflowNamesList workflowNamesList = response.getEntity(PublishWorkflowNamesList.class);
+        List<String> publishWorkflowNames = workflowNamesList.getPublishWorkflowNames();
+        return publishWorkflowNames;
+    }
+
+    public Map<String, String> getPublishedWorkflows(){
+        webResource = getPublishedWFRegistryBaseResource().path(ResourcePathConstants.PublishedWFConstants.GET_PUBLISHWORKFLOWS);
+        ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+        int status = response.getStatus();
+
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+
+        Map<String, String> publishWFmap = new HashMap<String, String>();
+        WorkflowList workflowList = response.getEntity(WorkflowList.class);
+        List<Workflow> workflows = workflowList.getWorkflowList();
+
+        for (Workflow workflow : workflows){
+            publishWFmap.put(workflow.getWorkflowName(), workflow.getWorkflowGraph());
+        }
+
+        return publishWFmap;
+    }
+
+    public void removePublishedWorkflow(String workflowName){
+        webResource = getPublishedWFRegistryBaseResource().path(ResourcePathConstants.PublishedWFConstants.REMOVE_PUBLISHWORKFLOW);
+        MultivaluedMap queryParams = new MultivaluedMapImpl();
+        queryParams.add("workflowname", workflowName);
+        ClientResponse response = webResource.queryParams(queryParams).type(MediaType.TEXT_PLAIN).delete(ClientResponse.class);
+        int status = response.getStatus();
+
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+
+    }
+}

Added: airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/UserWorkflowResourceClient.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/UserWorkflowResourceClient.java?rev=1408384&view=auto
==============================================================================
--- airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/UserWorkflowResourceClient.java (added)
+++ airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/UserWorkflowResourceClient.java Mon Nov 12 18:07:10 2012
@@ -0,0 +1,163 @@
+/*
+ *
+ * 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.services.registry.rest.client;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.json.JSONConfiguration;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.airavata.services.registry.rest.resourcemappings.Workflow;
+import org.apache.airavata.services.registry.rest.resourcemappings.WorkflowList;
+import org.apache.airavata.services.registry.rest.utils.ResourcePathConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriBuilder;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class UserWorkflowResourceClient {
+    private WebResource webResource;
+    private final static Logger logger = LoggerFactory.getLogger(UserWorkflowResourceClient.class);
+
+    private URI getBaseURI() {
+        logger.info("Creating Base URI");
+        return UriBuilder.fromUri("http://localhost:9080/airavata-services/").build();
+    }
+
+    private com.sun.jersey.api.client.WebResource getUserWFRegistryBaseResource (){
+        ClientConfig config = new DefaultClientConfig();
+        config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
+                Boolean.TRUE);
+        Client client = Client.create(config);
+        WebResource baseWebResource = client.resource(getBaseURI());
+        webResource = baseWebResource.path(ResourcePathConstants.UserWFConstants.REGISTRY_API_USERWFREGISTRY);
+        return webResource;
+    }
+
+    public boolean isWorkflowExists(String workflowName){
+        webResource = getUserWFRegistryBaseResource().path(ResourcePathConstants.UserWFConstants.WORKFLOW_EXIST);
+        MultivaluedMap queryParams = new MultivaluedMapImpl();
+        queryParams.add("workflowname", workflowName);
+        ClientResponse response = webResource.queryParams(queryParams).type(MediaType.TEXT_PLAIN).get(ClientResponse.class);
+        int status = response.getStatus();
+
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+
+        return true;
+    }
+
+    public void addWorkflow(String workflowName, String workflowGraphXml){
+        webResource = getUserWFRegistryBaseResource().path(ResourcePathConstants.UserWFConstants.ADD_WORKFLOW);
+        MultivaluedMap formParams = new MultivaluedMapImpl();
+        formParams.add("workflowName", workflowName);
+        formParams.add("workflowGraphXml", workflowGraphXml);
+
+        ClientResponse response = webResource.accept(MediaType.APPLICATION_FORM_URLENCODED).type(MediaType.TEXT_PLAIN).post(ClientResponse.class, formParams);
+        int status = response.getStatus();
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+    }
+
+    public void updateWorkflow(String workflowName, String workflowGraphXml){
+        webResource = getUserWFRegistryBaseResource().path(ResourcePathConstants.UserWFConstants.UPDATE_WORKFLOW);
+        MultivaluedMap formParams = new MultivaluedMapImpl();
+        formParams.add("workflowName", workflowName);
+        formParams.add("workflowGraphXml", workflowGraphXml);
+
+        ClientResponse response = webResource.accept(MediaType.APPLICATION_FORM_URLENCODED).type(MediaType.TEXT_PLAIN).post(ClientResponse.class, formParams);
+        int status = response.getStatus();
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+    }
+
+    public String getWorkflowGraphXML(String workflowName){
+        webResource = getUserWFRegistryBaseResource().path(ResourcePathConstants.UserWFConstants.GET_WORKFLOWGRAPH);
+        MultivaluedMap queryParams = new MultivaluedMapImpl();
+        queryParams.add("workflowname", workflowName);
+        ClientResponse response = webResource.queryParams(queryParams).type(MediaType.TEXT_PLAIN).get(ClientResponse.class);
+        int status = response.getStatus();
+
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+
+        String worlflowGraph = response.getEntity(String.class);
+        return worlflowGraph;
+    }
+
+    public Map<String, String> getWorkflows(){
+        webResource = getUserWFRegistryBaseResource().path(ResourcePathConstants.UserWFConstants.GET_WORKFLOWS);
+        ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+        int status = response.getStatus();
+
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+
+        Map<String, String> userWFMap = new HashMap<String, String>();
+        WorkflowList workflowList = response.getEntity(WorkflowList.class);
+        List<Workflow> workflows = workflowList.getWorkflowList();
+
+        for (Workflow workflow : workflows){
+            userWFMap.put(workflow.getWorkflowName(), workflow.getWorkflowGraph());
+        }
+
+        return userWFMap;
+    }
+
+    public void removeWorkflow(String workflowName){
+        webResource = getUserWFRegistryBaseResource().path(ResourcePathConstants.UserWFConstants.REMOVE_WORKFLOW);
+        MultivaluedMap queryParams = new MultivaluedMapImpl();
+        queryParams.add("workflowname", workflowName);
+        ClientResponse response = webResource.queryParams(queryParams).type(MediaType.TEXT_PLAIN).delete(ClientResponse.class);
+        int status = response.getStatus();
+
+        if (status != 200) {
+            logger.error("Failed : HTTP error code : " + status);
+            throw new RuntimeException("Failed : HTTP error code : "
+                    + status);
+        }
+    }
+
+}

Modified: airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/PublishWorkflowRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/PublishWorkflowRegistryResource.java?rev=1408384&r1=1408383&r2=1408384&view=diff
==============================================================================
--- airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/PublishWorkflowRegistryResource.java (original)
+++ airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/PublishWorkflowRegistryResource.java Mon Nov 12 18:07:10 2012
@@ -182,7 +182,7 @@ public class PublishWorkflowRegistryReso
      */
     @GET
     @Path(ResourcePathConstants.PublishedWFConstants.GET_PUBLISHWORKFLOWNAMES)
-    @Produces(MediaType.TEXT_PLAIN)
+    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response getPublishedWorkflowNames() {
         airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
         try{

Modified: airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java?rev=1408384&r1=1408383&r2=1408384&view=diff
==============================================================================
--- airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java (original)
+++ airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java Mon Nov 12 18:07:10 2012
@@ -88,6 +88,7 @@ public class UserWorkflowRegistryResourc
      */
     @POST
     @Path(ResourcePathConstants.UserWFConstants.ADD_WORKFLOW)
+    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     @Produces(MediaType.TEXT_PLAIN)
     public Response addWorkflow(@FormParam("workflowName") String workflowName,
                                 @FormParam("workflowGraphXml") String workflowGraphXml) {