From 3d2ddda352cf3f6dba2677b066f6c74f2f51cd1b Mon Sep 17 00:00:00 2001 From: gayan Date: Fri, 19 Dec 2014 13:51:29 +0530 Subject: [PATCH 1/8] Update the class with String format for string generation and method doc comments Conflicts: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java --- .../rest/endpoint/api/StratosApiV41Utils.java | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java index ad7cbff998..164a5f5859 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java @@ -90,27 +90,27 @@ public class StratosApiV41Utils { private static ServiceDeploymentManager serviceDeploymentManager = new ServiceDeploymentManager(); // Util methods for cartridges - public static void addCartridge(CartridgeDefinitionBean cartridgeDefinitionBean, ConfigurationContext ctxt, - String userName, String tenantDomain) throws RestAPIException { + public static void createCartridgeDefinition(CartridgeDefinitionBean cartridgeDefinitionBean, ConfigurationContext ctxt, + String userName, String tenantDomain) throws RestAPIException { - log.info("Starting to add cartridge: [cartridge-type] " + cartridgeDefinitionBean.getType()); + log.info(String.format("Starting to deploy a cartridge: [type] %s " , cartridgeDefinitionBean.getType())); CartridgeConfig cartridgeConfig = ObjectConverter.convertCartridgeDefinitionBeanToStubCartridgeConfig(cartridgeDefinitionBean); if (cartridgeConfig == null) { throw new RestAPIException("Could not read cartridge definition, cartridge deployment failed"); } if (StringUtils.isEmpty(cartridgeConfig.getCategory())) { - throw new RestAPIException("Category is not specified, cartridge deployment failed"); + throw new RestAPIException(String.format("Category is not specified %s , hence cartridge deployment failed",cartridgeConfig.getDisplayName())); } try { CartridgeDeploymentManager.getDeploymentManager(cartridgeDefinitionBean.getDeployerType()).deploy(cartridgeConfig); } catch (ADCException e) { throw new RestAPIException(e); } - log.info("Successfully added cartridge: [cartridge-type] " + cartridgeDefinitionBean.getType()); + log.info(String.format("Successfully deployed cartridge: [type] %s " , cartridgeDefinitionBean.getType())); } - public static void removeCartridge(String cartridgeType) throws RestAPIException { + public static void deleteCartridgeDefinition(String cartridgeType) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) { @@ -119,16 +119,16 @@ public static void removeCartridge(String cartridgeType) throws RestAPIException try { cartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(cartridgeType); } catch (RemoteException e) { - log.error("Could not find cartridge: [type] " + cartridgeType); + log.error(String.format("Could not find cartridge: [type] %s ", cartridgeType)); throw new RestAPIException(e); } catch (CloudControllerServiceUnregisteredCartridgeExceptionException e) { - log.error("Could not find cartridge: [type] " + cartridgeType); + log.error(String.format("Could not find cartridge: [type] %s " , cartridgeType)); throw new RestAPIException(e); } if (cartridgeInfo == null) { - String errorMsg = "Could not find cartridge: [type] " + cartridgeType; + String errorMsg = String.format("Could not find cartridge: [type] %s ", cartridgeType); log.error(errorMsg); throw new RestAPIException(errorMsg); } @@ -140,16 +140,18 @@ public static void removeCartridge(String cartridgeType) throws RestAPIException Service service = serviceDeploymentManager.getService(cartridgeType); if (service != null) { // not allowed to undeploy! - String errorMsg = "Multi tenant Service already exists for " + cartridgeType + ", cannot undeploy"; - log.error(errorMsg); - throw new RestAPIException(errorMsg); + String errorMsg = + String.format("Multi tenant Service already exists for %s ,hence cannot undeploy", + cartridgeType); + log.error(errorMsg); + throw new RestAPIException(errorMsg); } else { // can undeploy undeployCartridgeDefinition(cloudControllerServiceClient, cartridgeType); } } catch (ADCException e) { - log.error("Error in getting MT Service details for type " + cartridgeType); + log.error(String.format("Error in getting MT Service details for type %S " , cartridgeType)); throw new RestAPIException(e); } @@ -159,7 +161,7 @@ public static void removeCartridge(String cartridgeType) throws RestAPIException cartridgeSubsciptionManager.getCartridgeSubscriptionsForType(cartridgeType); if (cartridgeSubscriptions != null && !cartridgeSubscriptions.isEmpty()) { // not allowed to undeploy! - String errorMsg = "Subscription exists for " + cartridgeType + ", cannot undeploy"; + String errorMsg =String.format("Subscription exists for %s, cannot undeploy",cartridgeType); log.error(errorMsg); throw new RestAPIException(errorMsg); } else { @@ -174,7 +176,7 @@ private static void undeployCartridgeDefinition(CloudControllerServiceClient clo String cartridgeType) throws RestAPIException { try { - cloudControllerServiceClient.removeCartridge(cartridgeType); + cloudControllerServiceClient.unDeployCartridgeDefinition(cartridgeType); } catch (RemoteException e) { log.error(e.getMessage(), e); @@ -231,6 +233,13 @@ private static List getAvailableLbCartridges(Boolean mu return lbCartridges; } + /** + * Get the available cartridges by provider + * @param provider provide name + * @param configurationContext configuration context + * @return List of the cartridge definitions + * @throws RestAPIException + */ private static List getAvailableCartridgesByProvider(String provider, ConfigurationContext configurationContext) throws RestAPIException { List cartridges = new ArrayList(); @@ -521,7 +530,7 @@ private static AutoscalerServiceClient getAutoscalerServiceClient() throws RestA // Util methods for Autoscaling policies - public static void addAutoscalingPolicy(AutoscalePolicy autoscalePolicyBean) throws RestAPIException { + public static void createAutoscalingPolicy(AutoscalePolicy autoscalePolicyBean) throws RestAPIException { log.info(String.format("Deploying autoscaling policy: [id] %s", autoscalePolicyBean.getId())); @@ -849,7 +858,7 @@ public static void synchronizeRepository(CartridgeSubscription cartridgeSubscrip // Util methods for service groups - public static void addServiceGroup(ServiceGroupDefinition serviceGroupDefinition) throws RestAPIException { + public static void createServiceGroupDefinition(ServiceGroupDefinition serviceGroupDefinition) throws RestAPIException { try { serviceGropingManager.deployServiceGroupDefinition(serviceGroupDefinition); @@ -889,7 +898,7 @@ public static ServiceGroupDefinition[] getServiceGroupDefinitions() throws RestA } } - public static void removeServiceGroup(String serviceGroupDefinitionName) throws RestAPIException { + public static void deleteServiceGroupDefinition(String serviceGroupDefinitionName) throws RestAPIException { try { serviceGropingManager.undeployServiceGroupDefinition(serviceGroupDefinitionName); @@ -1019,7 +1028,7 @@ public static ApplicationSubscription getApplicationSubscriptions(String appId, } } - public static void removeApplication(String applicationId) throws RestAPIException { + public static void deleteApplication(String applicationId) throws RestAPIException { try { AutoscalerServiceClient.getServiceClient().deleteApplication(applicationId); @@ -1157,7 +1166,7 @@ private static void addClustersToGroupBean(Group group, GroupBean groupBean) { // Util methods for Kubernetes clusters - public static boolean addKubernetesGroup(KubernetesGroup kubernetesGroupBean) throws RestAPIException { + public static boolean deployKubernetesGroup(KubernetesGroup kubernetesGroupBean) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) { @@ -1178,7 +1187,7 @@ public static boolean addKubernetesGroup(KubernetesGroup kubernetesGroupBean) th return false; } - public static boolean addKubernetesHost(String kubernetesGroupId, KubernetesHost kubernetesHostBean) + public static boolean deployKubernetesHost(String kubernetesGroupId, KubernetesHost kubernetesHostBean) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); @@ -1267,7 +1276,7 @@ public static KubernetesGroup getKubernetesGroup(String kubernetesGroupId) throw return null; } - public static boolean removeKubernetesGroup(String kubernetesGroupId) throws RestAPIException { + public static boolean undeployKubernetesGroup(String kubernetesGroupId) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) { @@ -1286,7 +1295,7 @@ public static boolean removeKubernetesGroup(String kubernetesGroupId) throws Res return false; } - public static boolean removeKubernetesHost(String kubernetesHostId) throws RestAPIException { + public static boolean undeployKubernetesHost(String kubernetesHostId) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) { From 5fe201565ab5835b232321293a228f18a074ac0e Mon Sep 17 00:00:00 2001 From: gayan Date: Fri, 19 Dec 2014 13:56:04 +0530 Subject: [PATCH 2/8] Update the class with String format for string generation and method doc comments --- .../apache/stratos/rest/endpoint/api/StratosApiV41Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java index 164a5f5859..660afecda5 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java @@ -151,7 +151,7 @@ public static void deleteCartridgeDefinition(String cartridgeType) throws RestAP } } catch (ADCException e) { - log.error(String.format("Error in getting MT Service details for type %S " , cartridgeType)); + log.error(String.format("Error in getting MT Service details for type %s " , cartridgeType)); throw new RestAPIException(e); } From 61a3045e21ff2bb6594e81694b157a8a065835c9 Mon Sep 17 00:00:00 2001 From: gayan Date: Fri, 19 Dec 2014 15:43:04 +0530 Subject: [PATCH 3/8] Update error handling in rest API and meta data service --- .../registry/CarbonRegistry.java | 2 +- .../services/MetaDataAdmin.java | 29 ++++++++++++------- .../rest/endpoint/api/StratosApiV41Utils.java | 20 ++++++++----- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java index 5c3495d429..bab037b4b7 100644 --- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java +++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java @@ -113,7 +113,7 @@ public void addPropertyToCluster(String applicationId, String clusterId, NewProp * @throws RegistryException */ public boolean deleteApplication(String applicationId) throws RegistryException { - if(StringUtils.isEmpty(applicationId)){ + if(StringUtils.isBlank(applicationId)){ throw new IllegalArgumentException("Application ID can not be null"); } Registry tempRegistry = DataHolder.getRegistryService().getRegistry(); diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java index fc688f9b17..6f527e5ddb 100644 --- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java +++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java @@ -63,7 +63,7 @@ public MetaDataAdmin(){ @Produces("application/json") @Consumes("application/json") @AuthorizationAction("/permission/protected/manage/monitor/tenants") - public Response getClusterProperties(@PathParam("application_id") String applicationId, @PathParam("cluster_id") String clusterId){ + public Response getClusterProperties(@PathParam("application_id") String applicationId, @PathParam("cluster_id") String clusterId) throws RestAPIException{ List properties; NewProperty[] propertiesArr = null; @@ -74,8 +74,10 @@ public Response getClusterProperties(@PathParam("application_id") String applica propertiesArr = new NewProperty[properties.size()]; propertiesArr = properties.toArray(propertiesArr); } - } catch (Exception e) { - log.error("Error occurred while getting properties ", e); + } catch (RegistryException e) { + String msg = "Error occurred while getting properties "; + log.error(msg, e); + throw new RestAPIException(msg, e); } Response.ResponseBuilder rb; @@ -92,8 +94,7 @@ public Response getClusterProperties(@PathParam("application_id") String applica @Produces("application/json") @Consumes("application/json") @AuthorizationAction("/permission/protected/manage/monitor/tenants") - - public Response getClusterProperty(@PathParam("application_id") String applicationId, @PathParam("cluster_id") String clusterId, @PathParam("property_name") String propertyName){ + public Response getClusterProperty(@PathParam("application_id") String applicationId, @PathParam("cluster_id") String clusterId, @PathParam("property_name") String propertyName) throws RestAPIException{ List properties; @@ -111,8 +112,10 @@ public Response getClusterProperty(@PathParam("application_id") String applicati break; } } - } catch (Exception e) { - log.error("Error occurred while getting property ", e); + } catch (RegistryException e) { + String msg = "Error occurred while adding property"; + log.error(msg, e); + throw new RestAPIException(msg, e); } Response.ResponseBuilder rb; @@ -137,7 +140,9 @@ public Response addPropertyToACluster(@PathParam("application_id") String applic try { registry.addPropertyToCluster(applicationId, clusterId, property); } catch (RegistryException e) { - log.error("Error occurred while adding property", e); + String msg = "Error occurred while adding property"; + log.error(msg, e); + throw new RestAPIException(msg, e); } return Response.created(url).build(); @@ -154,8 +159,10 @@ public Response addPropertiesToACluster(@PathParam("application_id") String appl try { registry.addPropertiesToCluster(applicationId, clusterId, properties); - } catch (Exception e) { - log.error("Error occurred while adding properties ", e); + } catch (RegistryException e) { + String msg = "Error occurred while adding properties "; + log.error(msg, e); + throw new RestAPIException(msg, e); } return Response.created(url).build(); @@ -177,7 +184,7 @@ public Response deleteApplicationProperties(@PathParam("application_id") String } catch (RegistryException e) { String msg= "Resource attached with appId could not be deleted"; log.error(msg, e); - throw new RestAPIException(" ", e); + throw new RestAPIException(msg, e); } return Response.ok().build(); diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java index 660afecda5..a4037f6af7 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java @@ -139,7 +139,7 @@ public static void deleteCartridgeDefinition(String cartridgeType) throws RestAP try { Service service = serviceDeploymentManager.getService(cartridgeType); if (service != null) { - // not allowed to undeploy! + // not allowed to undeploy! String errorMsg = String.format("Multi tenant Service already exists for %s ,hence cannot undeploy", cartridgeType); @@ -282,14 +282,20 @@ private static List getAvailableCartridgesByProvider(St log.debug("There are no available cartridges"); } } - } catch (Exception e) { - String msg = "Error while getting available cartridges. Cause: " + e.getMessage(); - log.error(msg, e); - throw new RestAPIException(msg, e); + } catch (AxisFault axisFault) { + String errorMsg = String.format( + "Error while getting CloudControllerServiceClient instance to connect to the Cloud Controller. " + + "Cause: %s ", axisFault.getMessage()); + log.error(errorMsg, axisFault); + throw new RestAPIException(errorMsg, axisFault); + } catch (RemoteException e) { + String errorMsg = + String.format("Error while getting cartridge information for provider %s Cause: %s ", provider, + e.getMessage()); + log.error(errorMsg, e); + throw new RestAPIException(errorMsg, e); } - //Collections.sort(cartridges); - if (log.isDebugEnabled()) { log.debug("Returning available cartridges " + cartridges.size()); } From 8a1cd3df9832627910c7c5beecc7da45178463ac Mon Sep 17 00:00:00 2001 From: gayan Date: Fri, 19 Dec 2014 15:54:58 +0530 Subject: [PATCH 4/8] Update the messaging model util with apache commons isNumber util method --- .../apache/stratos/messaging/util/Util.java | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java index d5df69dfc9..bae0a35f03 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.stratos.messaging.event.Event; import org.apache.stratos.messaging.message.JsonMessage; +import org.apache.commons.lang3.math.NumberUtils; import java.io.File; import java.io.FileInputStream; @@ -122,11 +123,11 @@ public static void validateTenantRange(String tenantRange) { String[] array = tenantRange.split(TENANT_RANGE_DELIMITER); if (array.length == 2) { // Integer-Integer - if (isNumber(array[0]) && (isNumber(array[1]))) { + if (NumberUtils.isNumber(array[0]) && (NumberUtils.isNumber(array[1]))) { valid = true; } // Integer-* - else if (isNumber(array[0]) && "*".equals(array[1])) { + else if (NumberUtils.isNumber(array[0]) && "*".equals(array[1])) { valid = true; } } @@ -137,21 +138,6 @@ else if (isNumber(array[0]) && "*".equals(array[1])) { throw new RuntimeException(String.format("Tenant range %s is not valid", tenantRange)); } - /** - * Check given string is a number - * - * @param inputStr String to be checked - * @return Boolean of given string is a number - */ - public static boolean isNumber(String inputStr) { - try { - Integer.parseInt(inputStr); - return true; - } catch (NumberFormatException ignore) { - // Not a valid number - } - return false; - } /** * Transform json into an object of given type. From 7db5fb5b247cc3e9d07900c1aea868cb99e01963 Mon Sep 17 00:00:00 2001 From: gayan Date: Fri, 19 Dec 2014 15:56:59 +0530 Subject: [PATCH 5/8] Update the messaging model util with apache commons isNumber util method --- .../src/main/java/org/apache/stratos/messaging/util/Util.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java index bae0a35f03..94e8807476 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java @@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.stratos.messaging.event.Event; import org.apache.stratos.messaging.message.JsonMessage; -import org.apache.commons.lang3.math.NumberUtils; +import org.apache.commons.lang.math.NumberUtils; import java.io.File; import java.io.FileInputStream; From 668f923c5b6889c11756786e72c0c645c76caa72 Mon Sep 17 00:00:00 2001 From: gayan Date: Fri, 19 Dec 2014 16:03:20 +0530 Subject: [PATCH 6/8] Update the messaging model util with apache commons isNumber util method --- .../services/MetaDataAdmin.java | 109 +++++++++--------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java index 6f527e5ddb..8282516e93 100644 --- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java +++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java @@ -29,7 +29,6 @@ import org.apache.stratos.metadataservice.util.ConfUtil; import org.wso2.carbon.registry.api.RegistryException; -import javax.servlet.http.HttpServletRequest; import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; @@ -67,18 +66,18 @@ public Response getClusterProperties(@PathParam("application_id") String applica List properties; NewProperty[] propertiesArr = null; - try { - properties = registry - .getPropertiesOfCluster(applicationId, clusterId); - if (properties != null) { - propertiesArr = new NewProperty[properties.size()]; - propertiesArr = properties.toArray(propertiesArr); - } - } catch (RegistryException e) { - String msg = "Error occurred while getting properties "; - log.error(msg, e); - throw new RestAPIException(msg, e); - } + try { + properties = registry + .getPropertiesOfCluster(applicationId, clusterId); + if (properties != null) { + propertiesArr = new NewProperty[properties.size()]; + propertiesArr = properties.toArray(propertiesArr); + } + } catch (RegistryException e) { + String msg = "Error occurred while getting properties "; + log.error(msg, e); + throw new RestAPIException(msg, e); + } Response.ResponseBuilder rb; if (propertiesArr == null) { @@ -100,23 +99,23 @@ public Response getClusterProperty(@PathParam("application_id") String applicati NewProperty property = null; - try { - properties = registry - .getPropertiesOfCluster(applicationId, clusterId); - if (properties == null) { - return Response.status(Response.Status.NOT_FOUND).build(); - } - for (NewProperty p : properties) { - if (propertyName.equals(p.getKey())) { - property = p; - break; - } - } - } catch (RegistryException e) { - String msg = "Error occurred while adding property"; - log.error(msg, e); - throw new RestAPIException(msg, e); - } + try { + properties = registry + .getPropertiesOfCluster(applicationId, clusterId); + if (properties == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } + for (NewProperty p : properties) { + if (propertyName.equals(p.getKey())) { + property = p; + break; + } + } + } catch (RegistryException e) { + String msg = "Error occurred while adding property"; + log.error(msg, e); + throw new RestAPIException(msg, e); + } Response.ResponseBuilder rb; if (property == null) { @@ -137,13 +136,13 @@ public Response addPropertyToACluster(@PathParam("application_id") String applic URI url = uriInfo.getAbsolutePathBuilder().path(applicationId + "/" + clusterId + "/" + property.getKey()).build(); - try { - registry.addPropertyToCluster(applicationId, clusterId, property); - } catch (RegistryException e) { - String msg = "Error occurred while adding property"; - log.error(msg, e); - throw new RestAPIException(msg, e); - } + try { + registry.addPropertyToCluster(applicationId, clusterId, property); + } catch (RegistryException e) { + String msg = "Error occurred while adding property"; + log.error(msg, e); + throw new RestAPIException(msg, e); + } return Response.created(url).build(); } @@ -157,13 +156,13 @@ public Response addPropertiesToACluster(@PathParam("application_id") String appl throws RestAPIException { URI url = uriInfo.getAbsolutePathBuilder().path(applicationId + "/" + clusterId).build(); - try { - registry.addPropertiesToCluster(applicationId, clusterId, properties); - } catch (RegistryException e) { - String msg = "Error occurred while adding properties "; - log.error(msg, e); - throw new RestAPIException(msg, e); - } + try { + registry.addPropertiesToCluster(applicationId, clusterId, properties); + } catch (RegistryException e) { + String msg = "Error occurred while adding properties "; + log.error(msg, e); + throw new RestAPIException(msg, e); + } return Response.created(url).build(); } @@ -176,16 +175,18 @@ public Response addPropertiesToACluster(@PathParam("application_id") String appl public Response deleteApplicationProperties(@PathParam("application_id") String applicationId) throws RestAPIException { - try { - boolean deleted = registry.deleteApplication(applicationId); - if(!deleted){ - log.warn(String.format("Either no metadata is associated with given appId %s Or resources could not be deleted", applicationId)); - } - } catch (RegistryException e) { - String msg= "Resource attached with appId could not be deleted"; - log.error(msg, e); - throw new RestAPIException(msg, e); - } + try { + boolean deleted = registry.deleteApplication(applicationId); + if (!deleted) { + log.warn(String.format( + "Either no metadata is associated with given appId %s Or resources could not be deleted", + applicationId)); + } + } catch (RegistryException e) { + String msg = "Resource attached with appId could not be deleted"; + log.error(msg, e); + throw new RestAPIException(msg, e); + } return Response.ok().build(); } From 56218a431412738b758e89c51e96c49eff9491c2 Mon Sep 17 00:00:00 2001 From: gayan Date: Fri, 19 Dec 2014 16:04:47 +0530 Subject: [PATCH 7/8] Update the messaging model util with apache commons isNumber util method --- .../apache/stratos/metadataservice/services/MetaDataAdmin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java index 8282516e93..8e0448adad 100644 --- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java +++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java @@ -112,7 +112,7 @@ public Response getClusterProperty(@PathParam("application_id") String applicati } } } catch (RegistryException e) { - String msg = "Error occurred while adding property"; + String msg = "Error occurred while getting property"; log.error(msg, e); throw new RestAPIException(msg, e); } From b698805f7cde3dd74264134cfa0efa66b01538ef Mon Sep 17 00:00:00 2001 From: gayan Date: Fri, 19 Dec 2014 18:07:14 +0530 Subject: [PATCH 8/8] Merge the changes --- .../rest/endpoint/api/StratosApiV41Utils.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java index a4037f6af7..718e1d8edc 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java @@ -90,7 +90,7 @@ public class StratosApiV41Utils { private static ServiceDeploymentManager serviceDeploymentManager = new ServiceDeploymentManager(); // Util methods for cartridges - public static void createCartridgeDefinition(CartridgeDefinitionBean cartridgeDefinitionBean, ConfigurationContext ctxt, + public static void addCartridge(CartridgeDefinitionBean cartridgeDefinitionBean, ConfigurationContext ctxt, String userName, String tenantDomain) throws RestAPIException { log.info(String.format("Starting to deploy a cartridge: [type] %s " , cartridgeDefinitionBean.getType())); @@ -107,10 +107,10 @@ public static void createCartridgeDefinition(CartridgeDefinitionBean cartridgeDe } catch (ADCException e) { throw new RestAPIException(e); } - log.info(String.format("Successfully deployed cartridge: [type] %s " , cartridgeDefinitionBean.getType())); + log.info(String.format("Successfully deployed cartridge: [cartridge-type] %s " , cartridgeDefinitionBean.getType())); } - public static void deleteCartridgeDefinition(String cartridgeType) throws RestAPIException { + public static void removeCartridge(String cartridgeType) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) { @@ -176,7 +176,7 @@ private static void undeployCartridgeDefinition(CloudControllerServiceClient clo String cartridgeType) throws RestAPIException { try { - cloudControllerServiceClient.unDeployCartridgeDefinition(cartridgeType); + cloudControllerServiceClient.removeCartridge(cartridgeType); } catch (RemoteException e) { log.error(e.getMessage(), e); @@ -536,7 +536,7 @@ private static AutoscalerServiceClient getAutoscalerServiceClient() throws RestA // Util methods for Autoscaling policies - public static void createAutoscalingPolicy(AutoscalePolicy autoscalePolicyBean) throws RestAPIException { + public static void addAutoscalingPolicy(AutoscalePolicy autoscalePolicyBean) throws RestAPIException { log.info(String.format("Deploying autoscaling policy: [id] %s", autoscalePolicyBean.getId())); @@ -864,7 +864,7 @@ public static void synchronizeRepository(CartridgeSubscription cartridgeSubscrip // Util methods for service groups - public static void createServiceGroupDefinition(ServiceGroupDefinition serviceGroupDefinition) throws RestAPIException { + public static void addServiceGroup(ServiceGroupDefinition serviceGroupDefinition) throws RestAPIException { try { serviceGropingManager.deployServiceGroupDefinition(serviceGroupDefinition); @@ -904,7 +904,7 @@ public static ServiceGroupDefinition[] getServiceGroupDefinitions() throws RestA } } - public static void deleteServiceGroupDefinition(String serviceGroupDefinitionName) throws RestAPIException { + public static void removeServiceGroup(String serviceGroupDefinitionName) throws RestAPIException { try { serviceGropingManager.undeployServiceGroupDefinition(serviceGroupDefinitionName); @@ -1034,7 +1034,7 @@ public static ApplicationSubscription getApplicationSubscriptions(String appId, } } - public static void deleteApplication(String applicationId) throws RestAPIException { + public static void removeApplication(String applicationId) throws RestAPIException { try { AutoscalerServiceClient.getServiceClient().deleteApplication(applicationId); @@ -1172,7 +1172,7 @@ private static void addClustersToGroupBean(Group group, GroupBean groupBean) { // Util methods for Kubernetes clusters - public static boolean deployKubernetesGroup(KubernetesGroup kubernetesGroupBean) throws RestAPIException { + public static boolean addKubernetesGroup(KubernetesGroup kubernetesGroupBean) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) { @@ -1193,7 +1193,7 @@ public static boolean deployKubernetesGroup(KubernetesGroup kubernetesGroupBean) return false; } - public static boolean deployKubernetesHost(String kubernetesGroupId, KubernetesHost kubernetesHostBean) + public static boolean addKubernetesHost(String kubernetesGroupId, KubernetesHost kubernetesHostBean) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); @@ -1282,7 +1282,7 @@ public static KubernetesGroup getKubernetesGroup(String kubernetesGroupId) throw return null; } - public static boolean undeployKubernetesGroup(String kubernetesGroupId) throws RestAPIException { + public static boolean removeKubernetesGroup(String kubernetesGroupId) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) { @@ -1301,7 +1301,7 @@ public static boolean undeployKubernetesGroup(String kubernetesGroupId) throws R return false; } - public static boolean undeployKubernetesHost(String kubernetesHostId) throws RestAPIException { + public static boolean removeKubernetesHost(String kubernetesHostId) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) {