Repository: stratos Updated Branches: refs/heads/master 2a822d99d -> db77fe036
[STRATOS-1280] - Return 409 Conflict status if cartridge group already exists Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/b65ede05 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/b65ede05 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/b65ede05 Branch: refs/heads/master Commit: b65ede0590aaaa7559f25a35927e73eab68f18c9 Parents: 2a822d9 Author: Chamila de Alwis <[email protected]> Authored: Fri Apr 17 23:16:13 2015 +0530 Committer: Chamila de Alwis <[email protected]> Committed: Fri Apr 17 23:16:13 2015 +0530 ---------------------------------------------------------------------- .../services/impl/AutoscalerServiceImpl.java | 11 ++++++----- .../stratos/rest/endpoint/api/StratosApiV41.java | 18 +++++++++++++----- .../rest/endpoint/api/StratosApiV41Utils.java | 1 + 3 files changed, 20 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/b65ede05/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java index 589af4b..a9a76a7 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java @@ -516,15 +516,15 @@ public class AutoscalerServiceImpl implements AutoscalerService { String msg = "Cartridge group can not be null service name can not be empty."; log.error(msg); throw new IllegalArgumentException(msg); - } if (log.isInfoEnabled()) { log.info(String.format("Adding cartridge group: [group-name] %s", servicegroup.getName())); } + String groupName = servicegroup.getName(); if (RegistryManager.getInstance().serviceGroupExist(groupName)) { - throw new InvalidServiceGroupException("Cartridge group with the name " + groupName + " already exist."); + throw new InvalidServiceGroupException("Cartridge group with the name " + groupName + " already exists."); } if (log.isDebugEnabled()) { @@ -533,7 +533,7 @@ public class AutoscalerServiceImpl implements AutoscalerService { String[] subGroups = servicegroup.getCartridges(); if (log.isDebugEnabled()) { - log.debug("SubGroups" + subGroups); + log.debug("SubGroups" + Arrays.toString(subGroups)); if (subGroups != null) { log.debug("subGroups:size" + subGroups.length); } else { @@ -550,7 +550,7 @@ public class AutoscalerServiceImpl implements AutoscalerService { String[] startupOrders = dependencies.getStartupOrders(); if (log.isDebugEnabled()) { - log.debug("StartupOrders " + startupOrders); + log.debug("StartupOrders " + Arrays.toString(startupOrders)); if (startupOrders != null) { log.debug("StartupOrder:size " + startupOrders.length); @@ -558,10 +558,11 @@ public class AutoscalerServiceImpl implements AutoscalerService { log.debug("StartupOrder: is null"); } } + String[] scalingDependents = dependencies.getScalingDependants(); if (log.isDebugEnabled()) { - log.debug("ScalingDependent " + scalingDependents); + log.debug("ScalingDependent " + Arrays.toString(scalingDependents)); if (scalingDependents != null) { log.debug("ScalingDependents:size " + scalingDependents.length); http://git-wip-us.apache.org/repos/asf/stratos/blob/b65ede05/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java index bf1ceec..d5fdc5a 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java @@ -422,11 +422,19 @@ public class StratosApiV41 extends AbstractApi { @SuperTenantService(true) public Response addServiceGroup( GroupBean serviceGroupDefinition) throws RestAPIException { - StratosApiV41Utils.addServiceGroup(serviceGroupDefinition); - URI url = uriInfo.getAbsolutePathBuilder().path(serviceGroupDefinition.getName()).build(); - return Response.created(url).entity(new SuccessResponseBean(Response.Status.CREATED.getStatusCode(), - String.format("Service Group added successfully: [service-group] %s", - serviceGroupDefinition.getName()))).build(); + try { + StratosApiV41Utils.addServiceGroup(serviceGroupDefinition); + URI url = uriInfo.getAbsolutePathBuilder().path(serviceGroupDefinition.getName()).build(); + return Response.created(url).entity(new SuccessResponseBean(Response.Status.CREATED.getStatusCode(), + String.format("Service Group added successfully: [service-group] %s", + serviceGroupDefinition.getName()))).build(); + } catch (RestAPIException e) { + if (e.getCause().getMessage().contains("already exists")) { + return Response.status(Response.Status.CONFLICT).build(); + } else { + throw e; + } + } } /** http://git-wip-us.apache.org/repos/asf/stratos/blob/b65ede05/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---------------------------------------------------------------------- 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 166da5b..d6a76c1 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 @@ -884,6 +884,7 @@ public class StratosApiV41Utils { StratosManagerServiceClient smServiceClient = getStratosManagerServiceClient(); smServiceClient.addUsedCartridgesInCartridgeGroups(serviceGroupDefinition.getName(), cartridgeNames); } catch (Exception e) { + // TODO: InvalidServiceGroupException is not received, only AxisFault. Need to fix get the custom exception String message = "Could not add cartridge group"; log.error(message, e); throw new RestAPIException(message, e);
