You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/05/19 15:51:18 UTC

[1/2] stratos git commit: This closes #345 on GitHub

Repository: stratos
Updated Branches:
  refs/heads/master 35462838e -> 146591269


This closes #345 on GitHub


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/14659126
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/14659126
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/14659126

Branch: refs/heads/master
Commit: 146591269856a618e0c09850d71a6e4327600065
Parents: 24cd70a
Author: Imesh Gunaratne <im...@apache.org>
Authored: Tue May 19 19:21:13 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Tue May 19 19:21:13 2015 +0530

----------------------------------------------------------------------

----------------------------------------------------------------------



[2/2] stratos git commit: Validating deployment policy removal

Posted by im...@apache.org.
Validating deployment policy removal


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/24cd70ab
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/24cd70ab
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/24cd70ab

Branch: refs/heads/master
Commit: 24cd70ab89b42683d0acc7c7e61e3a72dbef03ee
Parents: 3546283
Author: Vishanth <vi...@gmail.com>
Authored: Tue May 19 19:07:24 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Tue May 19 19:21:13 2015 +0530

----------------------------------------------------------------------
 .../services/impl/AutoscalerServiceImpl.java    | 32 ++++++++++++++++++--
 .../common/client/AutoscalerServiceClient.java  |  3 +-
 .../rest/endpoint/api/StratosApiV41.java        |  4 ++-
 .../rest/endpoint/api/StratosApiV41Utils.java   |  3 +-
 4 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/24cd70ab/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 8edf8e0..083d18f 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
@@ -125,6 +125,27 @@ public class AutoscalerServiceImpl implements AutoscalerService {
         return canRemove;
     }
 
+    /**
+     * Validate the deployment policy removal
+     *
+     * @param deploymentPolicyId
+     * @return
+     */
+    private boolean removableDeploymentPolicy(String deploymentPolicyId) {
+        boolean canRemove = true;
+        Collection<ApplicationContext> appContexts = AutoscalerContext.getInstance().getApplicationContexts();
+        for (ApplicationContext app : appContexts) {
+            CartridgeContext[] cartridgeContexts = app.getComponents().getCartridgeContexts();
+            for (CartridgeContext cartridgeContext : cartridgeContexts) {
+                SubscribableInfoContext subscribableInfoContexts = cartridgeContext.getSubscribableInfoContext();
+                if (subscribableInfoContexts.getDeploymentPolicy().equals(deploymentPolicyId)) {
+                    canRemove = false;
+                }
+            }
+        }
+        return canRemove;
+    }
+
     @Override
     public AutoscalePolicy getAutoscalingPolicy(String autoscalingPolicyId) {
         return PolicyManager.getInstance().getAutoscalePolicy(autoscalingPolicyId);
@@ -1167,7 +1188,8 @@ public class AutoscalerServiceImpl implements AutoscalerService {
     }
 
     @Override
-    public boolean removeDeployementPolicy(String deploymentPolicyID) throws DeploymentPolicyNotExistsException {
+    public boolean removeDeployementPolicy(String deploymentPolicyID) throws DeploymentPolicyNotExistsException,
+            UnremovablePolicyException {
         if (log.isInfoEnabled()) {
             log.info("Removing deployment policy: [deployment-policy_id] " + deploymentPolicyID);
         }
@@ -1176,7 +1198,13 @@ public class AutoscalerServiceImpl implements AutoscalerService {
             log.error(message);
             throw new DeploymentPolicyNotExistsException(message);
         }
-        PolicyManager.getInstance().removeDeploymentPolicy(deploymentPolicyID);
+        if (removableDeploymentPolicy(deploymentPolicyID)) {
+            PolicyManager.getInstance().removeDeploymentPolicy(deploymentPolicyID);
+        }
+        else {
+            throw new UnremovablePolicyException("This deployment policy cannot be removed, since it is used in an " +
+                    "application.");
+        }
         if (log.isInfoEnabled()) {
             log.info("Successfully removed deployment policy: [deployment_policy_id] " + deploymentPolicyID);
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/24cd70ab/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/AutoscalerServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/AutoscalerServiceClient.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/AutoscalerServiceClient.java
index f6a97e7..1937cf3 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/AutoscalerServiceClient.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/AutoscalerServiceClient.java
@@ -217,7 +217,8 @@ public class AutoscalerServiceClient {
     }
 
     public void removeDeploymentPolicy(String deploymentPolicyID) throws RemoteException,
-            AutoscalerServiceDeploymentPolicyNotExistsExceptionException {
+            AutoscalerServiceDeploymentPolicyNotExistsExceptionException,
+            AutoscalerServiceUnremovablePolicyExceptionException {
         stub.removeDeployementPolicy(deploymentPolicyID);
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/24cd70ab/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 5765b26..64e9888 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
@@ -273,12 +273,14 @@ public class StratosApiV41 extends AbstractApi {
     @AuthorizationAction("/permission/admin/manage/removeDeploymentPolicy")
     public Response removeDeploymentPolicy(
             @PathParam("deploymentPolicyId") String deploymentPolicyId) throws RestAPIException {
-
         try {
             StratosApiV41Utils.removeDeploymentPolicy(deploymentPolicyId);
         } catch (AutoscalerServiceDeploymentPolicyNotExistsExceptionException e) {
             return Response.status(Response.Status.NOT_FOUND).entity(new ResponseMessageBean(
                     ResponseMessageBean.ERROR, "Deployment policy not found")).build();
+        } catch (AutoscalerServiceUnremovablePolicyExceptionException e) {
+            return Response.status(Response.Status.BAD_REQUEST).entity(new ResponseMessageBean(
+                    ResponseMessageBean.ERROR, "Deployment policy is in use")).build();
         }
         URI url = uriInfo.getAbsolutePathBuilder().path(deploymentPolicyId).build();
         return Response.ok(url).entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS,

http://git-wip-us.apache.org/repos/asf/stratos/blob/24cd70ab/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 527bdd6..58244be 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
@@ -2792,7 +2792,8 @@ public class StratosApiV41Utils {
      * @throws RestAPIException
      */
     public static void removeDeploymentPolicy(String deploymentPolicyID)
-            throws RestAPIException, AutoscalerServiceDeploymentPolicyNotExistsExceptionException {
+            throws RestAPIException, AutoscalerServiceDeploymentPolicyNotExistsExceptionException,
+            AutoscalerServiceUnremovablePolicyExceptionException {
         try {
             AutoscalerServiceClient.getInstance().removeDeploymentPolicy(deploymentPolicyID);
         } catch (RemoteException e) {