You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2015/02/16 18:21:11 UTC

stratos git commit: adding deployment policy validation logic

Repository: stratos
Updated Branches:
  refs/heads/4.1.0-beta-deployment-policy-fix e3d49b27b -> a94be0442


adding deployment policy validation logic


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/a94be044
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/a94be044
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/a94be044

Branch: refs/heads/4.1.0-beta-deployment-policy-fix
Commit: a94be04426e7ee2e2f717b5595a5f6de229a4483
Parents: e3d49b2
Author: R-Rajkumar <rr...@gmail.com>
Authored: Mon Feb 16 22:50:33 2015 +0530
Committer: R-Rajkumar <rr...@gmail.com>
Committed: Mon Feb 16 22:50:33 2015 +0530

----------------------------------------------------------------------
 .../InvalidDeploymentPolicyException.java       |  26 +++++
 .../impl/CloudControllerServiceUtil.java        | 112 +++++++++++++++++++
 2 files changed, 138 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/a94be044/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidDeploymentPolicyException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidDeploymentPolicyException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidDeploymentPolicyException.java
new file mode 100644
index 0000000..7bce66e
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidDeploymentPolicyException.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cloud.controller.exception;
+
+public class InvalidDeploymentPolicyException extends Exception{
+	
+	public InvalidDeploymentPolicyException(String message) {
+		super(message);
+	}
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/a94be044/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
index 01a95e0..25b901d 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
@@ -26,9 +26,14 @@ import com.google.common.net.InetAddresses;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.cloud.controller.context.CloudControllerContext;
+import org.apache.stratos.cloud.controller.domain.DeploymentPolicy;
 import org.apache.stratos.cloud.controller.domain.IaasProvider;
 import org.apache.stratos.cloud.controller.domain.MemberContext;
+import org.apache.stratos.cloud.controller.domain.NetworkPartition;
+import org.apache.stratos.cloud.controller.domain.NetworkPartitionRef;
 import org.apache.stratos.cloud.controller.domain.Partition;
+import org.apache.stratos.cloud.controller.domain.PartitionRef;
+import org.apache.stratos.cloud.controller.exception.InvalidDeploymentPolicyException;
 import org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException;
 import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
 import org.apache.stratos.cloud.controller.iaases.Iaas;
@@ -108,4 +113,111 @@ public class CloudControllerServiceUtil {
         validatePartitionAndGetIaasProvider(partition, iaasProvider);
         return true;
     }
+    
+    /**
+     * Validates deployment policy
+     * @param deploymentPolicy the {@link DeploymentPolicy} to be validated
+     * @throws InvalidDeploymentPolicyException will be thrown if the given {@link DeploymentPolicy} is not valid
+     */
+    public static void validateDeploymentPolicy(DeploymentPolicy deploymentPolicy) throws InvalidDeploymentPolicyException {
+    	
+    	// deployment policy can't be null
+    	if (null == deploymentPolicy) {
+			String msg = "Invalid deployment policy. Cause -> Deployment policy is null";
+			log.error(msg);
+			throw new InvalidDeploymentPolicyException(msg);
+		}
+    	
+    	if (log.isInfoEnabled()) {
+    		log.info(String.format("Validating deployment policy %s", deploymentPolicy.toString()));
+		}
+    	
+    	// deployment policy id can't be null or empty
+    	if (null == deploymentPolicy.getDeploymentPolicyID() || deploymentPolicy.getDeploymentPolicyID().isEmpty()) {
+			String msg = "Invalid deployment policy. Cause -> Invalid deployment policy id";
+			log.error(msg);
+			throw new InvalidDeploymentPolicyException(msg);
+		}
+    	
+    	// deployment policy should contain at least one network partition reference
+    	if (null == deploymentPolicy.getNetworkPartitionsRef() || deploymentPolicy.getNetworkPartitionsRef().length == 0) {
+			String msg = String.format("Invalid deployment policy - [deployment-policy-id] %s. "
+					+ "Cause -> Deployment policy doesn't have at least one network partition reference", 
+					deploymentPolicy.getDeploymentPolicyID());
+			log.error(msg);
+			throw new InvalidDeploymentPolicyException(msg);
+		}
+    	
+    	// validate each network partition references
+    	for (NetworkPartitionRef networkPartitionRef : deploymentPolicy.getNetworkPartitionsRef()) {
+    		
+			// network partition id can't be null or empty
+    		if (null == networkPartitionRef.getId() || networkPartitionRef.getId().isEmpty()) {
+				String msg = String.format("Invalid deployment policy - [deployment-policy-id] %s. "
+						+ "Cause -> Invalid network partition id in network partition references section", 
+						deploymentPolicy.getDeploymentPolicyID());
+				log.error(msg);
+				throw new InvalidDeploymentPolicyException(msg);
+			}
+    		
+    		// network partitions should be already deployed
+    		if (null == CloudControllerContext.getInstance().getNetworkPartition(networkPartitionRef.getId())) {
+				String msg = String.format("Invalid deployment policy - [deployment-policy-id] %s. "
+						+ "Cause -> Network partition is not deployed - [network-partition-id] %s", 
+						deploymentPolicy.getDeploymentPolicyID(), networkPartitionRef.getId());
+				log.error(msg);
+				throw new InvalidDeploymentPolicyException(msg);
+			}
+    		
+    		// partition algorithm can't be null or empty
+    		if (null == networkPartitionRef.getPartitionAlgo() || networkPartitionRef.getPartitionAlgo().isEmpty()) {
+				String msg = String.format("Invalid deployment policy - [deployment-policy-id] %s. "
+						+ "Cause -> Invalid partition algorithm - [network-partition-id] %s", 
+						deploymentPolicy.getDeploymentPolicyID(), networkPartitionRef.getId());
+				log.error(msg);
+				throw new InvalidDeploymentPolicyException(msg);
+			}
+    		
+    		// a network partition reference should contain at least one partition reference
+    		if (null == networkPartitionRef.getPartitions() || networkPartitionRef.getPartitions().length == 0) {
+				String msg = String.format("Invalid deployment policy - [deployment-policy-id] %s. "
+						+ "Cause -> Network partition reference doesn't have at lease one partition reference - "
+						+ "[network-partition-id] %s", deploymentPolicy.getDeploymentPolicyID(), networkPartitionRef.getId());
+				log.error(msg);
+				throw new InvalidDeploymentPolicyException(msg);
+			}
+    		
+    		// validate each partition reference defined in network partition reference
+    		for (PartitionRef partitionRef : networkPartitionRef.getPartitions()) {
+				
+    			// partition id can't be null or empty
+    			if (null == partitionRef.getId() || partitionRef.getId().isEmpty()) {
+    				String msg = String.format("Invalid deployment policy - [deployment-policy-id] %s. "
+    						+ "Cause -> Invalid partition id for a partition defined in the netwok partition - [network-partition-id] %s", 
+    						deploymentPolicy.getDeploymentPolicyID(), networkPartitionRef.getId());
+    				log.error(msg);
+    				throw new InvalidDeploymentPolicyException(msg);
+				}
+    			
+    			// partition should be defined in the relevant network partitions (on network partition deployment)
+    			NetworkPartition networkPartition = CloudControllerContext.getInstance().getNetworkPartition(networkPartitionRef.getId());
+    			if (null == networkPartition.getPartition(partitionRef.getId())) {
+    				String msg = String.format("Invalid deployment policy - [deployment-policy-id] %s. "
+    						+ "Cause -> Partition not found in the network partition definition - [network-partition-id] %s [partition-id] %s", 
+    						deploymentPolicy.getDeploymentPolicyID(), networkPartitionRef.getId(), partitionRef.getId());
+    				log.error(msg);
+    				throw new InvalidDeploymentPolicyException(msg);
+				}
+    			
+    			// partition reference should have a valid max value
+    			if (partitionRef.getMax() < 0) {
+    				String msg = String.format("Invalid deployment policy - [deployment-policy-id] %s. "
+    						+ "Cause -> Partition max value is not valid - [network-partition-id] %s [partition-id] %s [max-value] %s", 
+    						deploymentPolicy.getDeploymentPolicyID(), networkPartitionRef.getId(), partitionRef.getId(), partitionRef.getMax());
+    				log.error(msg);
+    				throw new InvalidDeploymentPolicyException(msg);
+				}
+			}
+		}
+    }
 }