Return-Path: X-Original-To: apmail-airavata-commits-archive@www.apache.org Delivered-To: apmail-airavata-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0EB00D33D for ; Fri, 9 Nov 2012 21:01:52 +0000 (UTC) Received: (qmail 60623 invoked by uid 500); 9 Nov 2012 21:01:51 -0000 Delivered-To: apmail-airavata-commits-archive@airavata.apache.org Received: (qmail 60585 invoked by uid 500); 9 Nov 2012 21:01:51 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 60577 invoked by uid 99); 9 Nov 2012 21:01:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Nov 2012 21:01:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Nov 2012 21:01:45 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 462EB238897F for ; Fri, 9 Nov 2012 21:01:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1407632 - in /airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest: client/ resources/ utils/ Date: Fri, 09 Nov 2012 21:01:22 -0000 To: commits@airavata.apache.org From: chathuri@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121109210123.462EB238897F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: chathuri Date: Fri Nov 9 21:01:22 2012 New Revision: 1407632 URL: http://svn.apache.org/viewvc?rev=1407632&view=rev Log: adding client methods for descriptor registry Added: airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/DescriptorResourceClient.java Modified: airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/ConfigurationResourceClient.java airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/DescriptorRegistryResource.java airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/utils/ResourcePathConstants.java Modified: airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/ConfigurationResourceClient.java URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/ConfigurationResourceClient.java?rev=1407632&r1=1407631&r2=1407632&view=diff ============================================================================== --- airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/ConfigurationResourceClient.java (original) +++ airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/ConfigurationResourceClient.java Fri Nov 9 21:01:22 2012 @@ -43,15 +43,15 @@ import java.util.ArrayList; import java.util.List; public class ConfigurationResourceClient { - private static WebResource webResource; + private WebResource webResource; private final static Logger logger = LoggerFactory.getLogger(ConfigurationResourceClient.class); - private static URI getBaseURI() { + private URI getBaseURI() { logger.info("Creating Base URI"); return UriBuilder.fromUri("http://localhost:9080/airavata-services/").build(); } - private static WebResource getConfigurationBaseResource (){ + private WebResource getConfigurationBaseResource (){ ClientConfig config = new DefaultClientConfig(); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); @@ -62,7 +62,7 @@ public class ConfigurationResourceClient } - public static Object getConfiguration(String configKey) { + public Object getConfiguration(String configKey) { webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.GET_CONFIGURATION); MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("key", configKey); @@ -78,7 +78,7 @@ public class ConfigurationResourceClient return output; } - public static List getConfigurationList (String configKey) { + public List getConfigurationList (String configKey) { webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.GET_CONFIGURATION_LIST); MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("key", configKey); @@ -103,7 +103,7 @@ public class ConfigurationResourceClient return configurationValueList; } - public static void setConfiguration (String configKey, String configVal, String date){ + public void setConfiguration (String configKey, String configVal, String date){ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.SAVE_CONFIGURATION); MultivaluedMap formData = new MultivaluedMapImpl(); formData.add("key", configKey); @@ -120,7 +120,7 @@ public class ConfigurationResourceClient } } - public static void addConfiguration(String configKey, String configVal, String date){ + public void addConfiguration(String configKey, String configVal, String date){ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.UPDATE_CONFIGURATION); MultivaluedMap formData = new MultivaluedMapImpl(); formData.add("key", configKey); @@ -137,7 +137,7 @@ public class ConfigurationResourceClient } } - public static void removeAllConfiguration(String key){ + public void removeAllConfiguration(String key){ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.DELETE_ALL_CONFIGURATION); MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("key", key); @@ -152,7 +152,7 @@ public class ConfigurationResourceClient } - public static void removeConfiguration(String key, String value){ + public void removeConfiguration(String key, String value){ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.DELETE_CONFIGURATION); MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("key", key); @@ -167,7 +167,7 @@ public class ConfigurationResourceClient } } - public static List getGFacURIs(){ + public List getGFacURIs(){ List uriList = new ArrayList(); try{ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.GET_GFAC_URI_LIST); @@ -193,7 +193,7 @@ public class ConfigurationResourceClient return uriList; } - public static List getWorkflowInterpreterURIs(){ + public List getWorkflowInterpreterURIs(){ List uriList = new ArrayList(); try{ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.GET_WFINTERPRETER_URI_LIST); @@ -219,7 +219,7 @@ public class ConfigurationResourceClient } - public static URI getEventingURI(){ + public URI getEventingURI(){ try{ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.GET_EVENTING_URI); ClientResponse response = webResource.get(ClientResponse.class); @@ -239,7 +239,7 @@ public class ConfigurationResourceClient } } - public static URI getMsgBoxURI(){ + public URI getMsgBoxURI(){ try{ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.GET_MESSAGE_BOX_URI); ClientResponse response = webResource.get(ClientResponse.class); @@ -259,7 +259,7 @@ public class ConfigurationResourceClient } } - public static void addGFacURI(String uri) { + public void addGFacURI(String uri) { webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.ADD_GFAC_URI); MultivaluedMap formData = new MultivaluedMapImpl(); formData.add("uri", uri); @@ -274,7 +274,7 @@ public class ConfigurationResourceClient } } - public static void addWFInterpreterURI(String uri) { + public void addWFInterpreterURI(String uri) { webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.ADD_WFINTERPRETER_URI); MultivaluedMap formData = new MultivaluedMapImpl(); formData.add("uri", uri); @@ -289,7 +289,7 @@ public class ConfigurationResourceClient } } - public static void setEventingURI(String uri) { + public void setEventingURI(String uri) { webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.ADD_EVENTING_URI); MultivaluedMap formData = new MultivaluedMapImpl(); formData.add("uri", uri); @@ -304,7 +304,7 @@ public class ConfigurationResourceClient } } - public static void setMessageBoxURI(String uri) { + public void setMessageBoxURI(String uri) { webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.ADD_MESSAGE_BOX_URI); MultivaluedMap formData = new MultivaluedMapImpl(); formData.add("uri", uri); @@ -319,7 +319,7 @@ public class ConfigurationResourceClient } } - public static void addGFacURIByDate(String uri, String date) { + public void addGFacURIByDate(String uri, String date) { webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.ADD_GFAC_URI_DATE); MultivaluedMap formData = new MultivaluedMapImpl(); formData.add("uri", uri); @@ -335,7 +335,7 @@ public class ConfigurationResourceClient } } - public static void addWorkflowInterpreterURI(String uri, String date) { + public void addWorkflowInterpreterURI(String uri, String date) { webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.ADD_WFINTERPRETER_URI_DATE); MultivaluedMap formData = new MultivaluedMapImpl(); formData.add("uri", uri); @@ -351,7 +351,7 @@ public class ConfigurationResourceClient } } - public static void setEventingURIByDate(String uri, String date) { + public void setEventingURIByDate(String uri, String date) { webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.ADD_EVENTING_URI_DATE); MultivaluedMap formData = new MultivaluedMapImpl(); formData.add("uri", uri); @@ -367,7 +367,7 @@ public class ConfigurationResourceClient } } - public static void setMessageBoxURIByDate(String uri, String date) { + public void setMessageBoxURIByDate(String uri, String date) { webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.ADD_MSG_BOX_URI_DATE); MultivaluedMap formData = new MultivaluedMapImpl(); formData.add("uri", uri); @@ -383,7 +383,7 @@ public class ConfigurationResourceClient } } - public static void removeGFacURI(String uri){ + public void removeGFacURI(String uri){ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.DELETE_GFAC_URI); MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("uri", uri); @@ -397,7 +397,7 @@ public class ConfigurationResourceClient } } - public static void removeAllGFacURI(){ + public void removeAllGFacURI(){ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.DELETE_ALL_GFAC_URIS); ClientResponse response = webResource.delete(ClientResponse.class); int status = response.getStatus(); @@ -409,7 +409,7 @@ public class ConfigurationResourceClient } } - public static void removeWorkflowInterpreterURI(String uri){ + public void removeWorkflowInterpreterURI(String uri){ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.DELETE_WFINTERPRETER_URI); MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("uri", uri); @@ -423,7 +423,7 @@ public class ConfigurationResourceClient } } - public static void removeAllWorkflowInterpreterURI(){ + public void removeAllWorkflowInterpreterURI(){ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.DELETE_ALL_WFINTERPRETER_URIS); ClientResponse response = webResource.delete(ClientResponse.class); int status = response.getStatus(); @@ -435,7 +435,7 @@ public class ConfigurationResourceClient } } - public static void unsetEventingURI(){ + public void unsetEventingURI(){ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.DELETE_EVENTING_URI); ClientResponse response = webResource.delete(ClientResponse.class); int status = response.getStatus(); @@ -447,7 +447,7 @@ public class ConfigurationResourceClient } } - public static void unsetMessageBoxURI(){ + public void unsetMessageBoxURI(){ webResource = getConfigurationBaseResource().path(ResourcePathConstants.ConfigResourcePathConstants.DELETE_MSG_BOX_URI); ClientResponse response = webResource.delete(ClientResponse.class); int status = response.getStatus(); Added: airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/DescriptorResourceClient.java URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/DescriptorResourceClient.java?rev=1407632&view=auto ============================================================================== --- airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/DescriptorResourceClient.java (added) +++ airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/client/DescriptorResourceClient.java Fri Nov 9 21:01:22 2012 @@ -0,0 +1,485 @@ +/* + * + * 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.commons.gfac.type.ApplicationDeploymentDescription; +import org.apache.airavata.commons.gfac.type.HostDescription; +import org.apache.airavata.commons.gfac.type.ServiceDescription; +import org.apache.airavata.services.registry.rest.resourcemappings.*; +import org.apache.airavata.services.registry.rest.utils.DescriptorUtil; +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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DescriptorResourceClient { + private WebResource webResource; + private final static Logger logger = LoggerFactory.getLogger(DescriptorResourceClient.class); + + private URI getBaseURI() { + logger.info("Creating Base URI"); + return UriBuilder.fromUri("http://localhost:9080/airavata-services/").build(); + } + + private WebResource getDescriptorRegistryBaseResource (){ + 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.DecResourcePathConstants.DESC_RESOURCE_PATH); + return webResource; + } + + public boolean isHostDescriptorExists(String hostDescriptorName){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.HOST_DESC_EXISTS); + MultivaluedMap queryParams = new MultivaluedMapImpl(); + queryParams.add("hostDescriptorName", hostDescriptorName); + ClientResponse response = webResource.queryParams(queryParams).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); + } else { + return true; + } + } + + public void addHostDescriptor (HostDescription hostDescription){ + HostDescriptor hostDescriptor = DescriptorUtil.createHostDescriptor(hostDescription); + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.HOST_DESC_SAVE); + ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, hostDescriptor); + + int status = response.getStatus(); + + if (status != 200) { + logger.error("Failed : HTTP error code : " + status); + throw new RuntimeException("Failed : HTTP error code : " + + status); + } + } + + public void updateHostDescriptor (HostDescription hostDescription){ + HostDescriptor hostDescriptor = DescriptorUtil.createHostDescriptor(hostDescription); + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.HOST_DESC_UPDATE); + ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, hostDescriptor); + + int status = response.getStatus(); + + if (status != 200) { + logger.error("Failed : HTTP error code : " + status); + throw new RuntimeException("Failed : HTTP error code : " + + status); + } + } + + public HostDescription getHostDescriptor (String hostName){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.HOST_DESC); + MultivaluedMap queryParams = new MultivaluedMapImpl(); + queryParams.add("hostName", hostName); + ClientResponse response = webResource.queryParams(queryParams).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); + } + + HostDescriptor hostDescriptor = response.getEntity(HostDescriptor.class); + HostDescription hostDescription = DescriptorUtil.createHostDescription(hostDescriptor); + return hostDescription; + } + + public void removeHostDescriptor(String hostName){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.HOST_DESC_DELETE); + MultivaluedMap queryParams = new MultivaluedMapImpl(); + queryParams.add("hostName", hostName); + ClientResponse response = webResource.queryParams(queryParams).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); + } + } + + public List getHostDescriptors() { + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.GET_HOST_DESCS); + 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); + } + + HostDescriptionList hostDescriptionList = response.getEntity(HostDescriptionList.class); + HostDescriptor[] hostDescriptors = hostDescriptionList.getHostDescriptions(); + List hostDescriptions = new ArrayList(); + for (HostDescriptor hostDescriptor : hostDescriptors){ + HostDescription hostDescription = DescriptorUtil.createHostDescription(hostDescriptor); + hostDescriptions.add(hostDescription); + } + + return hostDescriptions; + } + + public List getHostDescriptorNames(){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.GET_HOST_DESCS_NAMES); + 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); + } + + DescriptorNameList descriptorNameList = response.getEntity(DescriptorNameList.class); + return descriptorNameList.getDescriptorNames(); + } + + public boolean isServiceDescriptorExists(String serviceDescriptorName){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.SERVICE_DESC_EXISTS); + MultivaluedMap queryParams = new MultivaluedMapImpl(); + queryParams.add("serviceDescriptorName", serviceDescriptorName); + ClientResponse response = webResource.queryParams(queryParams).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); + } else { + return true; + } + } + + public void saveServiceDescriptor (ServiceDescription serviceDescription){ + ServiceDescriptor serviceDescriptor = DescriptorUtil.createServiceDescriptor(serviceDescription); + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.SERVICE_DESC_SAVE); + ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, serviceDescriptor); + + int status = response.getStatus(); + + if (status != 200) { + logger.error("Failed : HTTP error code : " + status); + throw new RuntimeException("Failed : HTTP error code : " + + status); + } + } + + public void updateServiceDescriptor(ServiceDescription serviceDescription){ + ServiceDescriptor serviceDescriptor = DescriptorUtil.createServiceDescriptor(serviceDescription); + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.SERVICE_DESC_UPDATE); + ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, serviceDescriptor); + + int status = response.getStatus(); + + if (status != 200) { + logger.error("Failed : HTTP error code : " + status); + throw new RuntimeException("Failed : HTTP error code : " + + status); + } + } + + public ServiceDescription getServiceDescriptor (String serviceName){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.SERVICE_DESC); + MultivaluedMap queryParams = new MultivaluedMapImpl(); + queryParams.add("serviceName", serviceName); + ClientResponse response = webResource.queryParams(queryParams).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); + } + + ServiceDescriptor serviceDescriptor = response.getEntity(ServiceDescriptor.class); + ServiceDescription serviceDescription = DescriptorUtil.createServiceDescription(serviceDescriptor); + return serviceDescription; + } + + public void removeServiceDescriptor(String serviceName){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.SERVICE_DESC_DELETE); + MultivaluedMap queryParams = new MultivaluedMapImpl(); + queryParams.add("serviceName", serviceName); + ClientResponse response = webResource.queryParams(queryParams).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); + } + } + + public List getServiceDescriptors (){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.GET_SERVICE_DESCS); + 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); + } + + ServiceDescriptionList serviceDescriptionList = response.getEntity(ServiceDescriptionList.class); + ServiceDescriptor[] serviceDescriptors = serviceDescriptionList.getServiceDescriptions(); + List serviceDescriptions = new ArrayList(); + for (ServiceDescriptor serviceDescriptor : serviceDescriptors){ + ServiceDescription serviceDescription = DescriptorUtil.createServiceDescription(serviceDescriptor); + serviceDescriptions.add(serviceDescription); + } + return serviceDescriptions; + } + + public boolean isApplicationDescriptorExist (String serviceName, String hostName, String appDescriptorName){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.APPL_DESC_EXIST); + MultivaluedMap queryParams = new MultivaluedMapImpl(); + queryParams.add("serviceName", serviceName); + queryParams.add("hostName", hostName); + queryParams.add("appDescName", appDescriptorName); + ClientResponse response = webResource.queryParams(queryParams).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); + } else { + return true; + } + } + + public void addApplicationDescriptor(ServiceDescription serviceDescription, + HostDescription hostDescriptor, + ApplicationDeploymentDescription descriptor){ + ApplicationDescriptor applicationDescriptor = DescriptorUtil.createApplicationDescriptor(descriptor); + applicationDescriptor.setHostdescName(hostDescriptor.getType().getHostName()); + ServiceDescriptor serviceDescriptor = DescriptorUtil.createServiceDescriptor(serviceDescription); + applicationDescriptor.setServiceDescriptor(serviceDescriptor); + + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_BUILD_SAVE); + ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, applicationDescriptor); + + int status = response.getStatus(); + + if (status != 200) { + logger.error("Failed : HTTP error code : " + status); + throw new RuntimeException("Failed : HTTP error code : " + + status); + } + } + + public void addApplicationDescriptor(String serviceName, String hostName, ApplicationDeploymentDescription descriptor){ + ServiceDescription serviceDescription = getServiceDescriptor(serviceName); + ApplicationDescriptor applicationDescriptor = DescriptorUtil.createApplicationDescriptor(descriptor); + applicationDescriptor.setHostdescName(hostName); + ServiceDescriptor serviceDescriptor = DescriptorUtil.createServiceDescriptor(serviceDescription); + applicationDescriptor.setServiceDescriptor(serviceDescriptor); + + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_BUILD_SAVE); + ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, applicationDescriptor); + + int status = response.getStatus(); + + if (status != 200) { + logger.error("Failed : HTTP error code : " + status); + throw new RuntimeException("Failed : HTTP error code : " + + status); + } + } + + public void udpateApplicationDescriptor(ServiceDescription serviceDescription, + HostDescription hostDescriptor, + ApplicationDeploymentDescription descriptor){ + ApplicationDescriptor applicationDescriptor = DescriptorUtil.createApplicationDescriptor(descriptor); + applicationDescriptor.setHostdescName(hostDescriptor.getType().getHostName()); + ServiceDescriptor serviceDescriptor = DescriptorUtil.createServiceDescriptor(serviceDescription); + applicationDescriptor.setServiceDescriptor(serviceDescriptor); + + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_UPDATE); + ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, applicationDescriptor); + + int status = response.getStatus(); + + if (status != 200) { + logger.error("Failed : HTTP error code : " + status); + throw new RuntimeException("Failed : HTTP error code : " + + status); + } + } + + public void updateApplicationDescriptor(String serviceName, String hostName, ApplicationDeploymentDescription descriptor){ + ServiceDescription serviceDescription = getServiceDescriptor(serviceName); + ApplicationDescriptor applicationDescriptor = DescriptorUtil.createApplicationDescriptor(descriptor); + applicationDescriptor.setHostdescName(hostName); + ServiceDescriptor serviceDescriptor = DescriptorUtil.createServiceDescriptor(serviceDescription); + applicationDescriptor.setServiceDescriptor(serviceDescriptor); + + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_UPDATE); + ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, applicationDescriptor); + + int status = response.getStatus(); + + if (status != 200) { + logger.error("Failed : HTTP error code : " + status); + throw new RuntimeException("Failed : HTTP error code : " + + status); + } + } + + public ApplicationDeploymentDescription getApplicationDescriptor(String serviceName, + String hostname, + String applicationName){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_DESCRIPTION); + MultivaluedMap queryParams = new MultivaluedMapImpl(); + queryParams.add("serviceName", serviceName); + queryParams.add("hostName", hostname); + queryParams.add("applicationName", applicationName); + + ClientResponse response = webResource.queryParams(queryParams).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); + } + + ApplicationDescriptor applicationDescriptor = response.getEntity(ApplicationDescriptor.class); + ApplicationDeploymentDescription applicationDeploymentDescription = DescriptorUtil.createApplicationDescription(applicationDescriptor); + return applicationDeploymentDescription; + } + + public ApplicationDeploymentDescription getApplicationDescriptors(String serviceName, String hostname){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_PER_HOST_SERVICE); + MultivaluedMap queryParams = new MultivaluedMapImpl(); + queryParams.add("serviceName", serviceName); + queryParams.add("hostName", hostname); + + ClientResponse response = webResource.queryParams(queryParams).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); + } + + ApplicationDescriptor applicationDescriptor = response.getEntity(ApplicationDescriptor.class); + ApplicationDeploymentDescription applicationDeploymentDescription = DescriptorUtil.createApplicationDescription(applicationDescriptor); + return applicationDeploymentDescription; + } + + public Map getApplicationDescriptors(String serviceName){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_ALL_DESCS_SERVICE); + MultivaluedMap queryParams = new MultivaluedMapImpl(); + queryParams.add("serviceName", serviceName); + ClientResponse response = webResource.queryParams(queryParams).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); + } + + ApplicationDescriptorList applicationDescriptorList = response.getEntity(ApplicationDescriptorList.class); + ApplicationDescriptor[] applicationDescriptors = applicationDescriptorList.getApplicationDescriptors(); + Map applicationDeploymentDescriptionMap = new HashMap(); + for (ApplicationDescriptor applicationDescriptor : applicationDescriptors){ + ApplicationDeploymentDescription applicationDeploymentDescription = DescriptorUtil.createApplicationDescription(applicationDescriptor); + applicationDeploymentDescriptionMap.put(applicationDescriptor.getHostdescName(), applicationDeploymentDescription); + } + return applicationDeploymentDescriptionMap; + } + + public Map getApplicationDescriptors(){ + Map applicationDeploymentDescriptionMap = new HashMap(); + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_ALL_DESCRIPTORS); + 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); + } + + ApplicationDescriptorList applicationDescriptorList = response.getEntity(ApplicationDescriptorList.class); + ApplicationDescriptor[] applicationDescriptors = applicationDescriptorList.getApplicationDescriptors(); + for (ApplicationDescriptor applicationDescriptor : applicationDescriptors){ + ApplicationDeploymentDescription applicationDeploymentDescription = DescriptorUtil.createApplicationDescription(applicationDescriptor); + String[] descriptors = {applicationDescriptor.getServiceDescriptor().getServiceName(), applicationDescriptor.getHostdescName()}; + applicationDeploymentDescriptionMap.put(descriptors, applicationDeploymentDescription); + } + return applicationDeploymentDescriptionMap; + } + + private List getApplicationDescriptorNames (){ + webResource = getDescriptorRegistryBaseResource().path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_NAMES); + 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); + } + + DescriptorNameList descriptorNameList = response.getEntity(DescriptorNameList.class); + return descriptorNameList.getDescriptorNames(); + } +} Modified: airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/DescriptorRegistryResource.java URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/DescriptorRegistryResource.java?rev=1407632&r1=1407631&r2=1407632&view=diff ============================================================================== --- airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/DescriptorRegistryResource.java (original) +++ airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/resources/DescriptorRegistryResource.java Fri Nov 9 21:01:22 2012 @@ -456,7 +456,7 @@ public class DescriptorRegistryResource * @return HTTP response */ @GET - @Path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_SAVE) + @Path(ResourcePathConstants.DecResourcePathConstants.APPL_DESC_EXIST) @Produces(MediaType.TEXT_PLAIN) public Response isApplicationDescriptorExists(@QueryParam("serviceName") String serviceName, @QueryParam("hostName") String hostName, @@ -633,9 +633,9 @@ public class DescriptorRegistryResource * @return HTTP response */ @GET - @Path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_ALL_DESCS_HOST_SERVICE) + @Path(ResourcePathConstants.DecResourcePathConstants.APP_DESC_PER_HOST_SERVICE) @Produces("text/xml") - public Response getApplicationDescriptors(@QueryParam("serviceName") String serviceName, + public Response getApplicationDescriptorPerServiceHost(@QueryParam("serviceName") String serviceName, @QueryParam("hostName") String hostName) { airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY); try { Modified: airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/utils/ResourcePathConstants.java URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/utils/ResourcePathConstants.java?rev=1407632&r1=1407631&r2=1407632&view=diff ============================================================================== --- airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/utils/ResourcePathConstants.java (original) +++ airavata/sandbox/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/utils/ResourcePathConstants.java Fri Nov 9 21:01:22 2012 @@ -67,11 +67,11 @@ public class ResourcePathConstants { public static final String SERVICE_DESC = "servicedescriptor/description"; public static final String SERVICE_DESC_DELETE = "servicedescriptor/delete"; public static final String GET_SERVICE_DESCS = "get/servicedescriptors"; - public static final String APP_DESC_SAVE = "applicationdescriptor/exist"; + public static final String APPL_DESC_EXIST = "applicationdescriptor/exist"; public static final String APP_DESC_BUILD_SAVE = "applicationdescriptor/build/save"; public static final String APP_DESC_UPDATE = "applicationdescriptor/update"; public static final String APP_DESC_DESCRIPTION = "applicationdescriptor/description"; - public static final String APP_DESC_ALL_DESCS_HOST_SERVICE = "applicationdescriptors/alldescriptors/host/service"; + public static final String APP_DESC_PER_HOST_SERVICE = "applicationdescriptors/alldescriptors/host/service"; public static final String APP_DESC_ALL_DESCS_SERVICE = "applicationdescriptor/alldescriptors/service"; public static final String APP_DESC_ALL_DESCRIPTORS = "applicationdescriptor/alldescriptors"; public static final String APP_DESC_NAMES = "applicationdescriptor/names";