Repository: stratos Updated Branches: refs/heads/4.0.0-grouping 5aac10ea4 -> a0e36dbe8
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/c4740c06 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c4740c06 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c4740c06 Branch: refs/heads/4.0.0-grouping Commit: c4740c0638865654fbb1e9217e3f781d69b2b897 Parents: c67af55 Author: Udara Liyanage <[email protected]> Authored: Tue Sep 30 18:14:11 2014 +0530 Committer: Udara Liyanage <[email protected]> Committed: Tue Sep 30 18:14:11 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/c4740c06/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 cfc1504..0dd09a5 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 @@ -870,4 +870,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/c4740c06/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 7ccd082..515a21a 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 @@ -345,17 +345,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); } }
