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

[2/2] stratos git commit: validating dependency and scaling order prefixes at group deployment

validating dependency and scaling order prefixes at group deployment


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

Branch: refs/heads/master
Commit: b0ef0ccf3491610cf5fbec10b40e955fa31823d3
Parents: ed558da
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Mon May 11 13:56:28 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Mon May 11 16:42:55 2015 +0530

----------------------------------------------------------------------
 .../services/impl/AutoscalerServiceImpl.java    |  2 ++
 .../stratos/autoscaler/util/AutoscalerUtil.java | 25 ++++++++++++++++----
 .../rest/endpoint/api/StratosApiV41.java        |  3 +++
 3 files changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/b0ef0ccf/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 f007632..8b3685c 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
@@ -621,6 +621,7 @@ public class AutoscalerServiceImpl implements AutoscalerService {
 
                 if (startupOrders != null) {
                     log.debug("StartupOrder:size  " + startupOrders.length);
+                    AutoscalerUtil.validateStartupOrders(groupName, startupOrders);
                 } else {
                     log.debug("StartupOrder: is null");
                 }
@@ -633,6 +634,7 @@ public class AutoscalerServiceImpl implements AutoscalerService {
 
                 if (scalingDependents != null) {
                     log.debug("ScalingDependents:size " + scalingDependents.length);
+                    AutoscalerUtil.validateScalingDependencies(groupName, scalingDependents);
                 } else {
                     log.debug("ScalingDependent: is null");
                 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/b0ef0ccf/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
index a5efd9d..3ac9f46 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
@@ -38,10 +38,7 @@ import org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetwo
 import org.apache.stratos.autoscaler.context.partition.network.GroupLevelNetworkPartitionContext;
 import org.apache.stratos.autoscaler.context.partition.network.NetworkPartitionContext;
 import org.apache.stratos.autoscaler.exception.AutoScalerException;
-import org.apache.stratos.autoscaler.exception.application.ApplicationDefinitionException;
-import org.apache.stratos.autoscaler.exception.application.DependencyBuilderException;
-import org.apache.stratos.autoscaler.exception.application.InvalidApplicationPolicyException;
-import org.apache.stratos.autoscaler.exception.application.TopologyInConsistentException;
+import org.apache.stratos.autoscaler.exception.application.*;
 import org.apache.stratos.autoscaler.exception.policy.ApplicatioinPolicyNotExistsException;
 import org.apache.stratos.autoscaler.exception.policy.PolicyValidationException;
 import org.apache.stratos.autoscaler.monitor.Monitor;
@@ -859,6 +856,26 @@ public class AutoscalerUtil {
         }
     }
 
+    public static void validateStartupOrders (String groupName, String[] startupOrders) throws InvalidServiceGroupException {
+        for (String startupOrder : startupOrders) {
+            if (!startupOrder.startsWith("cartridge.") && !startupOrder.startsWith("group.")) {
+                // invalid startup order; should prefixed by either 'cartridge.' or 'group.'
+                throw new InvalidServiceGroupException("Invalid Service Group: startup order [" + startupOrder +  "] for group " + groupName +
+                        ", should prefixed by either 'cartridge.' or 'group.'");
+            }
+        }
+    }
+
+    public static void validateScalingDependencies (String groupName, String[] scalingDependents) throws InvalidServiceGroupException {
+        for (String scalingDependent : scalingDependents) {
+            if (!scalingDependent.startsWith("cartridge.") && !scalingDependent.startsWith("group.")) {
+                // invalid startup order; should prefixed by either 'cartridge.' or 'group.'
+                throw new InvalidServiceGroupException("Invalid Service Group: Scaling Dependency [" + scalingDependent + "] for group " + groupName +
+                        ", should prefixed by either 'cartridge.' or 'group.'");
+            }
+        }
+    }
+
     public void updateMonitors() {
 
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/b0ef0ccf/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 8c941d5..4b932dd 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
@@ -458,6 +458,9 @@ public class StratosApiV41 extends AbstractApi {
             if (e.getCause().getMessage().contains("already exists")) {
                 return Response.status(Response.Status.CONFLICT).entity(new StatusResponseBean(
                         Response.Status.CONFLICT.getStatusCode(), "Cartridge group not found")).build();
+            } else if (e.getCause().getMessage().contains("Invalid Service Group")) {
+                return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponseBean(
+                        Response.Status.BAD_REQUEST.getStatusCode(), e.getCause().getMessage())).build();
             } else {
                 throw e;
             }