You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/06/18 13:20:51 UTC
[3/3] stratos git commit: Deployment Policy validation in groups
Deployment Policy validation in groups
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/5120d584
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/5120d584
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/5120d584
Branch: refs/heads/master
Commit: 5120d58400d2d76d652727bf2e0e77e10e8d621c
Parents: 4e97b3e
Author: Pubudu Gunatilaka <pu...@gmail.com>
Authored: Wed Jun 17 19:05:55 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Thu Jun 18 16:50:44 2015 +0530
----------------------------------------------------------------------
.../rest/endpoint/api/StratosApiV41Utils.java | 72 +++++++++++++++++++-
.../single-group-app/artifacts/application.json | 2 -
2 files changed, 69 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/5120d584/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 7964e1c..2d79bb1 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
@@ -1540,6 +1540,7 @@ public class StratosApiV41Utils {
private static void validateGroupAliasesInApplicationDefinition(ApplicationBean applicationDefinition) throws RestAPIException {
ConcurrentHashMap<String, CartridgeGroupReferenceBean> groupsInApplicationDefinition = new ConcurrentHashMap<String, CartridgeGroupReferenceBean>();
+ boolean groupParentHasDP = false;
if ((applicationDefinition.getComponents().getGroups() != null) &&
(!applicationDefinition.getComponents().getGroups().isEmpty())) {
@@ -1551,14 +1552,62 @@ public class StratosApiV41Utils {
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
+ *
+ * @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) {
+ String message = String.format("Deployment policy is not defined for cartridge [cartridge] %s." +
+ "It has not inherited any deployment policies.",
+ cartridge.getSubscribableInfo().getAlias());
+ throw new RestAPIException(message);
}
}
+
}
+
+
}
/**
@@ -1570,17 +1619,34 @@ public class StratosApiV41Utils {
*/
private static void validateGroupsRecursively(ConcurrentHashMap<String, CartridgeGroupReferenceBean> groupsSet,
- Collection<CartridgeGroupReferenceBean> groups) throws RestAPIException {
+ Collection<CartridgeGroupReferenceBean> groups, boolean hasDP)
+ throws RestAPIException {
+
for (CartridgeGroupReferenceBean group : groups) {
if (groupsSet.get(group.getAlias()) != null) {
String message = "Cartridge group alias exists more than once: [group-alias] " +
group.getAlias();
throw new RestAPIException(message);
}
+
+ if (group.getDeploymentPolicy() != null) {
+ if (hasDP) {
+ 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;
+ }
+ }
+
+ if (group.getCartridges() != null) {
+ validateCartridgesForDeploymentPolicy(group.getCartridges(), hasDP);
+ }
+
groupsSet.put(group.getAlias(), group);
if (group.getGroups() != null) {
- validateGroupsRecursively(groupsSet, group.getGroups());
+ validateGroupsRecursively(groupsSet, group.getGroups(), hasDP);
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5120d584/samples/applications/simple/single-group-app/artifacts/application.json
----------------------------------------------------------------------
diff --git a/samples/applications/simple/single-group-app/artifacts/application.json b/samples/applications/simple/single-group-app/artifacts/application.json
index 59c1398..c16a3f3 100644
--- a/samples/applications/simple/single-group-app/artifacts/application.json
+++ b/samples/applications/simple/single-group-app/artifacts/application.json
@@ -17,7 +17,6 @@
"subscribableInfo": {
"alias": "my-esb",
"autoscalingPolicy": "autoscaling-policy-1",
- "deploymentPolicy": "deployment-policy-1",
"artifactRepository": {
"privateRepo": false,
"repoUrl": "https://github.com/imesh/stratos-esb-applications.git",
@@ -33,7 +32,6 @@
"subscribableInfo": {
"alias": "my-php",
"autoscalingPolicy": "autoscaling-policy-1",
- "deploymentPolicy": "deployment-policy-1",
"artifactRepository": {
"privateRepo": false,
"repoUrl": "https://github.com/imesh/stratos-php-applications.git",