stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject [2/2] stratos git commit: Adding changes for group validation
Date Mon, 22 Jun 2015 06:06:53 GMT
Adding changes for group validation


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

Branch: refs/heads/master
Commit: 656c9825f1d31296e36babbb1511693edd5a90c6
Parents: 1c21daa
Author: Pubudu Gunatilaka <pubudu538@gmail.com>
Authored: Sun Jun 21 15:53:03 2015 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Mon Jun 22 11:36:45 2015 +0530

----------------------------------------------------------------------
 .../rest/endpoint/api/StratosApiV41Utils.java   | 39 ++++++++++++--------
 1 file changed, 23 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/656c9825/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 05e824a..f644a26 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
@@ -1325,9 +1325,10 @@ public class StratosApiV41Utils {
      * @param tenantDomain  Tenant Domain
      * @throws RestAPIException
      */
-    public static void addApplication(ApplicationBean appDefinition, ConfigurationContext
ctxt,
-                                      String userName, String tenantDomain)
-            throws RestAPIException, AutoscalerServiceCartridgeNotFoundExceptionException,
AutoscalerServiceCartridgeGroupNotFoundExceptionException {
+    public static void addApplication(ApplicationBean appDefinition, ConfigurationContext
ctxt, String userName,
+                                      String tenantDomain) throws RestAPIException,
+            AutoscalerServiceCartridgeNotFoundExceptionException,
+            AutoscalerServiceCartridgeGroupNotFoundExceptionException {
 
         if (StringUtils.isBlank(appDefinition.getApplicationId())) {
             String message = "Please specify the application name";
@@ -1347,7 +1348,7 @@ public class StratosApiV41Utils {
         validateApplication(appDefinition);
 
         // To validate groups have unique alias in the application definition
-        validateGroupAliasesInApplicationDefinition(appDefinition);
+        validateGroupsInApplicationDefinition(appDefinition);
 
 
         ApplicationContext applicationContext = ObjectConverter.convertApplicationDefinitionToStubApplicationContext(
@@ -1532,10 +1533,10 @@ public class StratosApiV41Utils {
      * @param applicationDefinition - the application definition
      * @throws RestAPIException
      */
-    private static void validateGroupAliasesInApplicationDefinition(ApplicationBean applicationDefinition)
throws RestAPIException {
+    private static void validateGroupsInApplicationDefinition(ApplicationBean applicationDefinition)
throws RestAPIException {
 
         ConcurrentHashMap<String, CartridgeGroupReferenceBean> groupsInApplicationDefinition
= new ConcurrentHashMap<String, CartridgeGroupReferenceBean>();
-        boolean groupParentHasDP = false;
+        boolean groupParentHasDeploymentPolicy = false;
 
         if ((applicationDefinition.getComponents().getGroups() != null) &&
                 (!applicationDefinition.getComponents().getGroups().isEmpty())) {
@@ -1551,16 +1552,18 @@ public class StratosApiV41Utils {
                 // Validate top level group deployment policy with cartridges
                 if (group.getCartridges() != null) {
                     if (group.getDeploymentPolicy() != null) {
-                        groupParentHasDP = true;
+                        groupParentHasDeploymentPolicy = true;
+                    } else {
+                        groupParentHasDeploymentPolicy = false;
                     }
-                    validateCartridgesForDeploymentPolicy(group.getCartridges(), groupParentHasDP);
+                    validateCartridgesForDeploymentPolicy(group.getCartridges(), groupParentHasDeploymentPolicy);
                 }
 
                 groupsInApplicationDefinition.put(group.getAlias(), group);
 
                 if (group.getGroups() != null) {
                     //This is to validate the groups aliases recursively
-                    validateGroupsRecursively(groupsInApplicationDefinition, group.getGroups(),
groupParentHasDP);
+                    validateGroupsRecursively(groupsInApplicationDefinition, group.getGroups(),
groupParentHasDeploymentPolicy);
                 }
             }
         }
@@ -1581,9 +1584,9 @@ public class StratosApiV41Utils {
      * @throws RestAPIException
      */
     private static void validateCartridgesForDeploymentPolicy(List<CartridgeReferenceBean>
cartridgeReferenceBeans,
-                                                              boolean hasDP) throws RestAPIException
{
+                                                              boolean hasDeploymentPolicy)
throws RestAPIException {
 
-        if (hasDP) {
+        if (hasDeploymentPolicy) {
             for (CartridgeReferenceBean cartridge : cartridgeReferenceBeans) {
                 if (cartridge.getSubscribableInfo().getDeploymentPolicy() != null) {
                     String message = "Group deployment policy already exists. Remove deployment
policy from " +
@@ -1615,9 +1618,11 @@ public class StratosApiV41Utils {
      */
 
     private static void validateGroupsRecursively(ConcurrentHashMap<String, CartridgeGroupReferenceBean>
groupsSet,
-                                                  Collection<CartridgeGroupReferenceBean>
groups, boolean hasDP)
+                                                  Collection<CartridgeGroupReferenceBean>
groups, boolean hasDeploymentPolicy)
             throws RestAPIException {
 
+        boolean groupHasDeploymentPolicy = false;
+
         for (CartridgeGroupReferenceBean group : groups) {
             if (groupsSet.get(group.getAlias()) != null) {
                 String message = "Cartridge group alias exists more than once: [group-alias]
" +
@@ -1626,23 +1631,25 @@ public class StratosApiV41Utils {
             }
 
             if (group.getDeploymentPolicy() != null) {
-                if (hasDP) {
+                if (hasDeploymentPolicy) {
                     String message = "Parent Group has a deployment policy. Remove deployment
policy from the" +
                             " group: [group-alias] " + group.getAlias();
                     throw new RestAPIException(message);
                 } else {
-                    hasDP = true;
+                    groupHasDeploymentPolicy = true;
                 }
+            } else {
+                groupHasDeploymentPolicy = hasDeploymentPolicy;
             }
 
             if (group.getCartridges() != null) {
-                validateCartridgesForDeploymentPolicy(group.getCartridges(), hasDP);
+                validateCartridgesForDeploymentPolicy(group.getCartridges(), groupHasDeploymentPolicy);
             }
 
             groupsSet.put(group.getAlias(), group);
 
             if (group.getGroups() != null) {
-                validateGroupsRecursively(groupsSet, group.getGroups(), hasDP);
+                validateGroupsRecursively(groupsSet, group.getGroups(), groupHasDeploymentPolicy);
             }
         }
     }


Mime
View raw message