stratos-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nirmal070125 <...@git.apache.org>
Subject [GitHub] stratos pull request: Group validation for deployment policies def...
Date Mon, 30 Nov 2015 01:29:31 GMT
Github user nirmal070125 commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/371#discussion_r46102921
  
    --- 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 --
    
    What's the difference between hasDP and cartridge.getSubscribableInfo().getDeploymentPolicy()
!= null ? For me it seems like this logic can be simplified. 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message