Repository: stratos Updated Branches: refs/heads/master 2db1eeaf0 -> 7c35cc64b
fix for STRATOS-851 Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/8cbf8a92 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/8cbf8a92 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/8cbf8a92 Branch: refs/heads/master Commit: 8cbf8a922ed4fcab8b72253097eced07eed65388 Parents: 69ae307 Author: Udara Liyanage <[email protected]> Authored: Tue Sep 30 18:14:11 2014 +0530 Committer: Udara Liyanage <[email protected]> Committed: Tue Sep 30 18:19:12 2014 +0530 ---------------------------------------------------------------------- .../manager/CartridgeSubscriptionManager.java | 5 ++ .../rest/endpoint/services/ServiceUtils.java | 74 ++++++++++++++++++-- 2 files changed, 72 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/8cbf8a92/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java index fb11847..f25ad34 100644 --- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java +++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java @@ -594,4 +594,9 @@ public class CartridgeSubscriptionManager { DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager(); return dataInsertionAndRetrievalManager.getCartridgeSubscriptions(tenantId, cartridgeType); } + + public Collection<CartridgeSubscription> getCartridgeSubscriptionsForType (String cartridgeType) { + + return new DataInsertionAndRetrievalManager().getCartridgeSubscriptions(cartridgeType); + } } http://git-wip-us.apache.org/repos/asf/stratos/blob/8cbf8a92/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java index 0da5c2e..76794dc 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java @@ -143,17 +143,77 @@ public class ServiceUtils { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) { + + CartridgeInfo cartridgeInfo = null; try { - cloudControllerServiceClient.unDeployCartridgeDefinition(cartridgeType); + cartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(cartridgeType); + } catch (RemoteException e) { - log.error(e.getMessage(), e); - throw new RestAPIException(e.getMessage(), e); - } catch (CloudControllerServiceInvalidCartridgeTypeExceptionException e) { - String msg = e.getFaultMessage().getInvalidCartridgeTypeException().getMessage(); - log.error(msg, e); - throw new RestAPIException(msg, e); + log.error("Error in getting Cartridge details for type " + cartridgeType); + throw new RestAPIException(e); + + } catch (CloudControllerServiceUnregisteredCartridgeExceptionException e) { + log.error("Error in getting Cartridge details for type " + cartridgeType); + throw new RestAPIException(e); + } + + if (cartridgeInfo == null) { + String errorMsg = "Cartridge information not found for type " + cartridgeType; + log.error(errorMsg); + throw new RestAPIException(errorMsg); + } + + // check if the service is multi tenant. + if (cartridgeInfo.getMultiTenant()) { + // check if there are any deployed MT services. If so, should not allow to undeploy + try { + 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); + } else { + // can undeploy + undeployCartridgeDefinition(cloudControllerServiceClient, cartridgeType); + } + + } catch (ADCException e) { + log.error("Error in getting MT Service details for type " + cartridgeType); + throw new RestAPIException(e); + } + + } else { + // if not multi tenant, check if there are any existing Subscriptions + Collection<CartridgeSubscription> cartridgeSubscriptions = + cartridgeSubsciptionManager.getCartridgeSubscriptionsForType(cartridgeType); + if (cartridgeSubscriptions != null && !cartridgeSubscriptions.isEmpty()) { + // not allowed to undeploy! + String errorMsg = "Subscription exists for " + cartridgeType + ", cannot undeploy"; + log.error(errorMsg); + throw new RestAPIException(errorMsg); + } else { + // can undeploy + undeployCartridgeDefinition(cloudControllerServiceClient, cartridgeType); + } } + } + } + + private static void undeployCartridgeDefinition (CloudControllerServiceClient cloudControllerServiceClient, + String cartridgeType) throws RestAPIException { + try { + cloudControllerServiceClient.unDeployCartridgeDefinition(cartridgeType); + + } catch (RemoteException e) { + log.error(e.getMessage(), e); + throw new RestAPIException(e.getMessage(), e); + + } catch (CloudControllerServiceInvalidCartridgeTypeExceptionException e) { + String msg = e.getFaultMessage().getInvalidCartridgeTypeException().getMessage(); + log.error(msg, e); + throw new RestAPIException(msg, e); } }
