Return-Path: X-Original-To: apmail-stratos-dev-archive@minotaur.apache.org Delivered-To: apmail-stratos-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B9FA218A92 for ; Mon, 30 Nov 2015 01:29:31 +0000 (UTC) Received: (qmail 72644 invoked by uid 500); 30 Nov 2015 01:29:31 -0000 Delivered-To: apmail-stratos-dev-archive@stratos.apache.org Received: (qmail 72595 invoked by uid 500); 30 Nov 2015 01:29:31 -0000 Mailing-List: contact dev-help@stratos.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@stratos.apache.org Delivered-To: mailing list dev@stratos.apache.org Received: (qmail 72581 invoked by uid 99); 30 Nov 2015 01:29:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Nov 2015 01:29:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0E622DFC91; Mon, 30 Nov 2015 01:29:31 +0000 (UTC) From: nirmal070125 To: dev@stratos.apache.org Reply-To: dev@stratos.apache.org References: In-Reply-To: Subject: [GitHub] stratos pull request: Group validation for deployment policies def... Content-Type: text/plain Message-Id: <20151130012931.0E622DFC91@git1-us-west.apache.org> Date: Mon, 30 Nov 2015 01:29:31 +0000 (UTC) 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 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. ---