Github user pubudu538 commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/371#discussion_r46109989
  
    --- Diff: 
components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
 ---
    @@ -1551,14 +1552,62 @@ private static void 
validateGroupAliasesInApplicationDefinition(ApplicationBean
                                 group.getAlias();
                         throw new RestAPIException(message);
                     }
    +
    +                // Validate top level group deployment policy with 
cartridges
    +                if (group.getCartridges() != null) {
    +                    if (group.getDeploymentPolicy() != null) {
    +                        groupParentHasDP = true;
    +                    }
    +                    
validateCartridgesForDeploymentPolicy(group.getCartridges(), groupParentHasDP);
    +                }
    +
                     groupsInApplicationDefinition.put(group.getAlias(), group);
     
                     if (group.getGroups() != null) {
                         //This is to validate the groups aliases recursively
    -                    
validateGroupsRecursively(groupsInApplicationDefinition, group.getGroups());
    +                    
validateGroupsRecursively(groupsInApplicationDefinition, group.getGroups(), 
groupParentHasDP);
                     }
                 }
             }
    +
    +        if ((applicationDefinition.getComponents().getCartridges() != 
null) &&
    +                
(!applicationDefinition.getComponents().getCartridges().isEmpty())) {
    +            
validateCartridgesForDeploymentPolicy(applicationDefinition.getComponents().getCartridges(),
 false);
    +        }
    +
    +    }
    +
    +    /**
    +     * This method validates cartridges in groups
    +     * Deployment policy should not defined in cartridge if group has a 
deployment policy
    +     * If group does not have a DP, then cartridge should have one
    +     * @param cartridgeReferenceBeans - Cartridges in a group
    +     * @throws RestAPIException
    +     */
    +    private static void 
validateCartridgesForDeploymentPolicy(List<CartridgeReferenceBean> 
cartridgeReferenceBeans,
    +                                                              boolean 
hasDP) throws RestAPIException {
    +
    +        if (hasDP) {
    +            for (CartridgeReferenceBean cartridge : 
cartridgeReferenceBeans) {
    +                if (cartridge.getSubscribableInfo().getDeploymentPolicy() 
!= null) {
    +                    String message = "Group deployment policy already 
exists. Remove deployment policy from " +
    +                            "cartridge subscription : [cartridge] " + 
cartridge.getSubscribableInfo().getAlias();
    +                    throw new RestAPIException(message);
    +                }
    +            }
    +        } else {
    +            for (CartridgeReferenceBean cartridge : 
cartridgeReferenceBeans) {
    +                if (cartridge.getSubscribableInfo().getDeploymentPolicy() 
== null) {
    --- End diff --
    
    Actually hasDP is the flag to identify whether the parent group has a 
deployment policy and cartridge.getSubscribableInfo().getDeploymentPolicy() != 
null is to check within  a it has a deployment policy. Logic here is as 
follows. If the parent group has a deployment policy defined, then within the 
group it should not have the deployment policies. If the parent group does not 
have a deployment policy, then within the group every cartridge should have a 
deployment policy. It looks like variables are confusing. I will change those 
as well. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to