You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stratos.apache.org by pubudu538 <gi...@git.apache.org> on 2015/06/18 12:00:34 UTC

[GitHub] stratos pull request: Group validation for deployment policies def...

GitHub user pubudu538 opened a pull request:

    https://github.com/apache/stratos/pull/371

    Group validation for deployment policies defined 

    1. If the parent group has a deployment policy, all the child groups and cartridges will inherit that. So we should not define deployment policies in lower level.
    
    2. If the parent group does not have a deployment policy, all the cartridges should have a deployment policy. So we need to define the deployment policy in subscribableInfo section in the cartridge. 

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/pubudu538/stratos group-validation

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/stratos/pull/371.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #371
    
----
commit 56bc4302cfcd5a33de1bab4699eb0a1a37ee9889
Author: Pubudu Gunatilaka <pu...@gmail.com>
Date:   2015-06-17T13:35:55Z

    Deployment Policy validation in groups

commit bb6e0b2b9e09715c2d32cf2e60179a2c56f1929d
Author: Pubudu Gunatilaka <pu...@gmail.com>
Date:   2015-06-18T04:40:15Z

    Change sample applications for group validation

----


---
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.
---

[GitHub] stratos pull request: Group validation for deployment policies def...

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

[GitHub] stratos pull request: Group validation for deployment policies def...

Posted by rekathiru <gi...@git.apache.org>.
Github user rekathiru commented on the pull request:

    https://github.com/apache/stratos/pull/371#issuecomment-113104689
  
    Can you use different variable in validateGroupsRecursively for hasDP when you assign value to this variable inside the method? Otherwise this variable will get overwritten by the method and the validation would get failed for rest of the groups. 


---
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.
---

[GitHub] stratos pull request: Group validation for deployment policies def...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/stratos/pull/371


---
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.
---

[GitHub] stratos pull request: Group validation for deployment policies def...

Posted by nirmal070125 <gi...@git.apache.org>.
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.
---