You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ud...@apache.org on 2013/11/30 10:19:46 UTC

[1/9] git commit: changing memberCountToBeIncreased in rool file

Updated Branches:
  refs/heads/master faca01666 -> 560b1c5fc


changing memberCountToBeIncreased in rool file


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

Branch: refs/heads/master
Commit: 174700322f835438f41280f4060b26b4265ed12f
Parents: eacb65f
Author: Udara Liyanage <ud...@wso2.com>
Authored: Wed Nov 27 12:17:21 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Wed Nov 27 12:17:21 2013 -0500

----------------------------------------------------------------------
 .../distribution/src/main/conf/autoscaler.drl   | 89 +++++++++-----------
 1 file changed, 41 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/17470032/products/autoscaler/modules/distribution/src/main/conf/autoscaler.drl
----------------------------------------------------------------------
diff --git a/products/autoscaler/modules/distribution/src/main/conf/autoscaler.drl b/products/autoscaler/modules/distribution/src/main/conf/autoscaler.drl
index e824444..c551d9a 100644
--- a/products/autoscaler/modules/distribution/src/main/conf/autoscaler.drl
+++ b/products/autoscaler/modules/distribution/src/main/conf/autoscaler.drl
@@ -25,7 +25,6 @@ import org.apache.stratos.autoscaler.AutoscalerContext;
 import org.apache.stratos.autoscaler.ClusterContext;
 import org.apache.stratos.autoscaler.Constants;
 import org.apache.stratos.autoscaler.policy.PolicyManager;
-import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
 import org.apache.stratos.autoscaler.policy.model.Partition;
 import org.apache.stratos.autoscaler.policy.model.PartitionGroup;
 import org.apache.stratos.autoscaler.policy.model.DeploymentPolicy;
@@ -59,7 +58,7 @@ dialect "mvel"
 
 
        then
-	       int memberCountToBeIncreased = 1;
+	       int memberCountToBeIncreased = $partition.getPartitionMembersMin() - $clusterContext.getMemberCount($partition.getId());
 	       if($evaluator.delegateSpawn($partition,$cluster.getClusterId(), memberCountToBeIncreased)){
 		   $clusterContext.increaseMemberCountInPartitionBy($partition.getId(), memberCountToBeIncreased);
 	       }
@@ -68,57 +67,51 @@ end
 rule "Scaler-up Rule"
 dialect "mvel"
 	when
-        $service : Service ()
-        $cluster : Cluster () from  $service.getClusters()
-        $autoScalingPolicy : AutoscalePolicy(id == $cluster.getAutoscalePolicyName() ) from $manager.getAutoscalePolicyList()
-        $deploymentPolicy : DeploymentPolicy(id == $cluster.getDeploymentPolicyName() ) from $manager.getDeploymentPolicyList()
-        $partitionGroup : PartitionGroup () from  $deploymentPolicy.getPartitionGroups()
-        $clusterContext : ClusterContext() from $context.getClusterContext($cluster.getClusterId())
-        $loadThresholds :LoadThresholds() from  $autoScalingPolicy.getLoadThresholds()
-
-        autoscaleAlgorithm : AutoscaleAlgorithm() from  $evaluator.getAutoscaleAlgorithm($partitionGroup.getPartitionAlgo())
-        lbStatAverage : Float() from  $clusterContext.getAverageRequestsInFlight()
-        lbStatGradient : Float() from  $clusterContext.getRequestsInFlightGradient()
-        lbStatSecondDerivative : Float() from  $clusterContext.getRequestsInFlightSecondDerivative()
-        averageLimit : Float() from  $loadThresholds.getRequestsInFlight().getAverage()
-        gradientLimit : Float() from  $loadThresholds.getRequestsInFlight().getGradient()
-        secondDerivative  : Float() from  $loadThresholds.getRequestsInFlight().getSecondDerivative()
-        partition :  Partition() from autoscaleAlgorithm.getNextScaleUpPartition($partitionGroup, $cluster.getClusterId())
-        eval (lbStatAverage > averageLimit && lbStatGradient > gradientLimit)
+		$service : Service ()
+		$cluster : Cluster () from  $service.getClusters()
+		$policy : AutoscalePolicy(id == $cluster.autoscalePolicyName ) from $manager.getPolicyList()
+		$clusterContext : ClusterContext() from $context.getClusterContext($cluster.getClusterId())
+		$loadThresholds :LoadThresholds() from  $policy.getLoadThresholds()
+		autoscaleAlgorithm : AutoscaleAlgorithm() from  $evaluator.getAutoscaleAlgorithm($policy.getHAPolicy().getPartitionAlgo())
+		lbStatAverage : Float() from  $clusterContext.getAverageRequestsInFlight()
+		lbStatGradient : Float() from  $clusterContext.getRequestsInFlightGradient()
+		lbStatSecondDerivative : Float() from  $clusterContext.getRequestsInFlightSecondDerivative()
+		averageLimit : Float() from  $loadThresholds.getRequestsInFlight().getAverage()
+		gradientLimit : Float() from  $loadThresholds.getRequestsInFlight().getGradient()
+		secondDerivative  : Float() from  $loadThresholds.getRequestsInFlight().getSecondDerivative()
+		partition :  Partition() from autoscaleAlgorithm.getNextScaleUpPartition($cluster.getClusterId())
+		eval (lbStatAverage > averageLimit && lbStatGradient > gradientLimit)
 	then
-        int numberOfInstancesToBeSpawned = (lbStatSecondDerivative > secondDerivative) ? 2 : 1; //  take from a config
-        $evaluator.delegateSpawn(partition,$cluster.getClusterId(), numberOfInstancesToBeSpawned);
-        $clusterContext.setRequestsInFlightGradient(gradientLimit);
-        $clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
-        $clusterContext.setAverageRequestsInFlight(averageLimit);
+		int numberOfInstancesToBeSpawned = (lbStatSecondDerivative > secondDerivative) ? 2 : 1; //  take from a config
+		$evaluator.delegateSpawn(partition,$cluster.getClusterId(), numberOfInstancesToBeSpawned);
+		$clusterContext.setRequestsInFlightGradient(gradientLimit);
+		$clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
+		$clusterContext.setAverageRequestsInFlight(averageLimit);
 end
 
 rule "Scaler-down Rule"
 dialect "mvel"
 	when
-	    $service : Service ()
-	    $cluster : Cluster () from  $service.getClusters()
-	    $autoScalingPolicy : AutoscalePolicy(id == $cluster.getAutoscalePolicyName() ) from $manager.getAutoscalePolicyList()
-        $deploymentPolicy : DeploymentPolicy(id == $cluster.getDeploymentPolicyName() ) from $manager.getDeploymentPolicyList()
-        $partitionGroup : PartitionGroup () from  $deploymentPolicy.getPartitionGroups()
-	    $clusterContext : ClusterContext() from $context.getClusterContext($cluster.getClusterId())
-        $loadThresholds :LoadThresholds() from  $autoScalingPolicy.getLoadThresholds()
-
-        autoscaleAlgorithm : AutoscaleAlgorithm() from  $evaluator.getAutoscaleAlgorithm($partitionGroup.getPartitionAlgo())
-        lbStatAverage : Float() from  $clusterContext.getAverageRequestsInFlight()
-        lbStatGradient : Float() from  $clusterContext.getRequestsInFlightGradient()
-        lbStatSecondDerivative : Float() from  $clusterContext.getRequestsInFlightSecondDerivative()
-        averageLimit : Float() from  $loadThresholds.getRequestsInFlight().getAverage()
-        gradientLimit : Float() from  $loadThresholds.getRequestsInFlight().getGradient()
-        secondDerivative  : Float() from  $loadThresholds.getRequestsInFlight().getSecondDerivative()
-        scaleDownSlowerMarginOfGradient : Float() from  $loadThresholds.getRequestsInFlight().getScaleDownMarginOfGradient()
-        scaleDownSlowerMarginOfSecondDerivative : Float() from  $loadThresholds.getRequestsInFlight().getScaleDownMarginOfSecondDerivative()
-        partition : Partition() from autoscaleAlgorithm.getNextScaleDownPartition($partitionGroup, $cluster.getClusterId())
-        eval(lbStatAverage < averageLimit  && lbStatGradient < gradientLimit - scaleDownSlowerMarginOfSecondDerivative
-                         && lbStatSecondDerivative < secondDerivative - scaleDownSlowerMarginOfSecondDerivative)
+		$service : Service ()
+		$cluster : Cluster () from  $service.getClusters()
+		$policy : AutoscalePolicy(id == $cluster.autoscalePolicyName ) from $manager.getPolicyList()
+		$clusterContext : ClusterContext() from $context.getClusterContext($cluster.getClusterId())
+		$loadThresholds :LoadThresholds() from  $policy.getLoadThresholds()
+		autoscaleAlgorithm : AutoscaleAlgorithm() from  $evaluator.getAutoscaleAlgorithm($policy.getHAPolicy().getPartitionAlgo())
+		lbStatAverage : Float() from  $clusterContext.getAverageRequestsInFlight()
+		lbStatGradient : Float() from  $clusterContext.getRequestsInFlightGradient()
+		lbStatSecondDerivative : Float() from  $clusterContext.getRequestsInFlightSecondDerivative()
+		averageLimit : Float() from  $loadThresholds.getRequestsInFlight().getAverage()
+		gradientLimit : Float() from  $loadThresholds.getRequestsInFlight().getGradient()
+		secondDerivative  : Float() from  $loadThresholds.getRequestsInFlight().getSecondDerivative()
+		scaleDownSlowerMarginOfGradient : Float() from  $loadThresholds.getRequestsInFlight().getScaleDownMarginOfGradient()
+		scaleDownSlowerMarginOfSecondDerivative : Float() from  $loadThresholds.getRequestsInFlight().getScaleDownMarginOfSecondDerivative()
+		partition : Partition() from autoscaleAlgorithm.getNextScaleDownPartition($cluster.getClusterId())
+		eval(lbStatAverage < averageLimit  && lbStatGradient < gradientLimit - scaleDownSlowerMarginOfSecondDerivative
+				 && lbStatSecondDerivative < secondDerivative - scaleDownSlowerMarginOfSecondDerivative)
 	then
-        $evaluator.delegateTerminate(partition,$cluster.getClusterId());
-        $clusterContext.setRequestsInFlightGradient(gradientLimit);
-        $clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
-        $clusterContext.setAverageRequestsInFlight(averageLimit);
+		$evaluator.delegateTerminate(partition,$cluster.getClusterId());
+		$clusterContext.setRequestsInFlightGradient(gradientLimit);
+		$clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
+		$clusterContext.setAverageRequestsInFlight(averageLimit);
 end


[5/9] git commit: Merge branch 'm4' Add partition deployer Conflicts: components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java components/org.apache.stratos.autoscaler/src/main/java/org/apache/

Posted by ud...@apache.org.
Merge branch 'm4'
Add partition deployer
Conflicts:
	components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
	components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java
	components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
	components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java


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

Branch: refs/heads/master
Commit: 0a06ba28662283e191b26f7f74b2f915e8ce9288
Parents: 7afbe41 dca46e3
Author: Udara Liyanage <ud...@wso2.com>
Authored: Fri Nov 29 14:01:47 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Fri Nov 29 14:10:31 2013 -0500

----------------------------------------------------------------------
 .../exception/InvalidPartitionException.java    |  40 +++++
 .../partition/deployers/PartitionDeployer.java  | 103 +++++++++++
 .../partition/deployers/PartitionReader.java    | 174 +++++++++++++++++++
 .../autoscaler/util/AutoScalerConstants.java    |  33 ++++
 .../src/main/resources/META-INF/component.xml   |   5 +
 5 files changed, 355 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0a06ba28/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
index 0000000,6bba10e..e14f332
mode 000000,100644..100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
@@@ -1,0 -1,103 +1,103 @@@
+ /*
+  * 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.autoscaler.partition.deployers;
+ 
+ import java.io.File;
++import java.util.List;
++
+ import org.apache.axis2.context.ConfigurationContext;
+ import org.apache.axis2.deployment.AbstractDeployer;
+ import org.apache.axis2.deployment.DeploymentException;
+ import org.apache.axis2.deployment.repository.util.DeploymentFileData;
+ import org.apache.commons.logging.Log;
+ import org.apache.commons.logging.LogFactory;
++import org.apache.stratos.cloud.controller.deployment.partition.Partition;
+ 
+ /**
+  * 
+  * The Axis2 deployer class for party definitions definitions.
+  */
+ public class PartitionDeployer extends AbstractDeployer {
+ 	
+ 	 private static final Log log = LogFactory.getLog(PartitionDeployer.class);
+ 	 
+ 	 private static String fileExt="xml"; //default
+ 	 private static String deployDirectory=null;
+ 
+ 	@Override
+ 	public void init(ConfigurationContext context) {
 -		System.out.println("********Deploying init");
+ 		if(deployDirectory!=null){
+ 			File deployDir = new File(new File(context.getAxisConfiguration().getRepository().getPath()),deployDirectory);
+ 			if(!deployDir.exists()){
+ 				//create policies deployment directory if not exist 
+ 				try {
+ 					deployDir.mkdirs();
+ 				} catch (Exception e) {
+ 					log.error("Unable to create policies deployment directory", e);
+ 				}
+ 			}
+ 		}
+ 	}
+ 
+ 	@Override
+ 	public void setDirectory(String dir) {
+ 		deployDirectory = dir;
+ 	}
+ 
+ 	@Override
+ 	public void setExtension(String ext) {
+ 		fileExt = ext;
+ 	}
+ 	
+ 	@Override
+ 	public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
+ 
+ 		File partitionFile = deploymentFileData.getFile();
+ 		log.debug("Started to deploy the policy: " + partitionFile);
 -		System.out.println("********Deploying stated " + partitionFile);
+ 
+ 		try {
 -			/*
++			
+ 			PartitionReader reader = new PartitionReader(partitionFile);
+ 			
+ 			List<Partition> partitionList = reader.getPartitionList();
+ 			
+ 
+ 			log.info("Successfully deployed the partition specified at "
+ 					+ deploymentFileData.getAbsolutePath());
 -			 */
++			 
+ 		} catch (Exception e) {
+ 			String msg = "Invalid partition artifact at " + deploymentFileData.getAbsolutePath();
+ 			// back up the file
+ 			File fileToBeRenamed = partitionFile;
+ 			fileToBeRenamed.renameTo(new File(deploymentFileData.getAbsolutePath() + ".back"));
+ 			log.error(msg, e);
+ 			throw new DeploymentException(msg, e);
+ 		}
+ 	}
+ 	
+ 	@Override
+ 	public void undeploy(String fileName) throws DeploymentException {
 -		System.out.println("****************************************************");
 -
++		//TODO undeploy logic
+ 	}
+ 	
+ 	
+ 	
+ 
+ }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0a06ba28/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
index 0000000,a6c45f1..4f635e7
mode 000000,100644..100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
@@@ -1,0 -1,144 +1,174 @@@
+ /*
+  * 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.autoscaler.partition.deployers;
+ 
+ import java.io.File;
+ import java.util.ArrayList;
+ import java.util.Iterator;
+ import java.util.List;
 -
+ import javax.xml.namespace.QName;
+ 
+ import org.apache.axiom.om.OMElement;
+ import org.apache.axiom.om.OMNode;
+ import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+ import org.apache.axiom.om.xpath.AXIOMXPath;
 -import org.apache.axis2.deployment.DeploymentException;
+ import org.apache.commons.logging.Log;
+ import org.apache.commons.logging.LogFactory;
+ import org.apache.stratos.autoscaler.exception.InvalidPartitionException;
 -import org.apache.stratos.autoscaler.policy.InvalidPolicyException;
 -import org.apache.stratos.autoscaler.policy.model.DeploymentPolicy;
 -import org.apache.stratos.autoscaler.policy.model.Partition;
++import org.apache.stratos.cloud.controller.deployment.partition.Partition;
++import org.apache.stratos.cloud.controller.pojo.Properties;
++import org.apache.stratos.cloud.controller.pojo.Property;
+ import org.apache.stratos.autoscaler.util.AutoScalerConstants;
+ import org.jaxen.JaxenException;
+ 
+ /**
+  * 
+  * The Reader class for Deployment-policy definitions.
+  */
+ public class PartitionReader{
+ 	
+ 	private static final Log log = LogFactory.getLog(PartitionReader.class);
+ 	private static OMElement documentElement;
+ 	private File partitionFIle;
+ 	
+ 	public PartitionReader(File partitionFile){
+ 		this.partitionFIle = partitionFile;
+ 	}
+ 	
+ 	public List<Partition> getPartitionList() throws InvalidPartitionException{
+ 			this.parse(this.partitionFIle);
 -			List<OMNode> partitionXMLNodes = getMatchingNodes("/partitions/partition");
++			String partitionXpath = AutoScalerConstants.PARTITIONS_ELEMENT + "/"+AutoScalerConstants.PARTITION_ELEMENT;
++			List<OMNode> partitionXMLNodes = getMatchingNodes(partitionXpath);
+ 			Iterator<OMNode> itr = partitionXMLNodes.iterator();
+ 			List<Partition> partitonList = new ArrayList<Partition>();
+ 			while(itr.hasNext()){
+ 				 OMNode node  = itr.next();
+ 				 //System.out.println("node " + node);
+ 				 partitonList.add(this.getPartition(node));
+ 			 }
+ 		return partitonList;
+ 	}
+ 	
+ 	private  Partition getPartition(final OMNode item) {
+         Partition partition = null;
+         String id = null;
+ 
+         if (item.getType() == OMNode.ELEMENT_NODE) {
+ 
+             OMElement iaasElt = (OMElement) item;
+             Iterator<?> it =
+                     iaasElt.getChildrenWithName(new QName(AutoScalerConstants.ID_ELEMENT));
+ 
+             if (it.hasNext()) {
+                 OMElement providerElt = (OMElement) it.next();
+                 id = providerElt.getText();
+             }
+ 
+             if (it.hasNext()) {
+                 log.warn( " contains more than one " + AutoScalerConstants.ID_ELEMENT +
+                         " elements!" + " Elements other than the first will be neglected.");
+             }
+ 
+             if (id == null) {
+                 String msg ="Essential " + AutoScalerConstants.ID_ELEMENT + "element " +
+                                 "has not specified in ";
+                 // handleException(msg);
+             }
 -            //boolean partitionExist = TopologyManager.getInstance().getTopology().partitionExist(id);
++            // boolean partitionExist = TopologyManager.getInstance().getTopology().partitionExist(id);
+             boolean partitionExist =false;
+             if(!partitionExist){
+             	partition = new Partition();
+                 partition.setId(id);
 -                //loadProperties(iaasElt, partition.getProperties());
 -                //handle partition created event
 -                //TopologyBuilder.handlePartitionCreated(partition);
++                partition.setProperties(getProperties(iaasElt)); 
++                
+             }            
+         }
+         return partition;
+     }
+ 	
+ 	public void parse(File xmlSource) {
+ 
+         if (xmlSource.exists()) {
+             try {
+                 documentElement = new StAXOMBuilder(xmlSource.getPath()).getDocumentElement();
+ 
+             } catch (Exception ex) {
+                 String msg = "Error occurred when parsing the " + xmlSource.getPath() + ".";
+                 //handleException(msg, ex);
+             }
+         } else {
+             String msg = "Configuration file cannot be found : " + xmlSource.getPath();
+             //handleException(msg);
+         }
+     }
+ 	/**
+      * @param xpath XPATH expression to be read.
+      * @return List matching OMNode list
+      */
+     @SuppressWarnings("unchecked")
 -    public static List<OMNode> getMatchingNodes(final String xpath) {
++    public List<OMNode> getMatchingNodes(final String xpath) {
+ 
+         AXIOMXPath axiomXpath;
+         List<OMNode> nodeList = null;
+         try {
+             axiomXpath = new AXIOMXPath(xpath);
+             nodeList = axiomXpath.selectNodes(documentElement);
+         } catch (JaxenException e) {
+             String msg = "Error occurred while reading the Xpath (" + xpath + ")";
+             //log.error(msg, e);
 -            //throw new CloudControllerException(msg, e);
+         }
+ 
+         return nodeList;
+     }
++    
++    private Properties getProperties(final OMElement elt) {
++    	
++    	        Iterator<?> it = elt.getChildrenWithName(new QName(AutoScalerConstants.PROPERTY_ELEMENT));
++    	        ArrayList<Property> propertyList = new ArrayList<Property>();
++    	        
++    	        while (it.hasNext()) {
++    	            OMElement prop = (OMElement) it.next();
++    	
++    	            if (prop.getAttribute(new QName(AutoScalerConstants.PROPERTY_NAME_ATTR)) == null ||
++    	                    prop.getAttribute(new QName(AutoScalerConstants.PROPERTY_VALUE_ATTR)) == null) {
++    	
++    	                String msg =
++    	                        "Property element's, name and value attributes should be specified " +
++    	                                "in ";
++    	
++    	                //handleException(msg);
++    	            }
++    	            
++    	            String name = prop.getAttribute(new QName(AutoScalerConstants.PROPERTY_NAME_ATTR)).getAttributeValue();
++    	            String value = prop.getAttribute(new QName(AutoScalerConstants.PROPERTY_VALUE_ATTR)).getAttributeValue();
++    	            
++    	            Property property = new Property();
++    	            property.setName(name);
++    	            property.setValue(value);    	            
++    	            propertyList.add(property);
++    	        }
++
++    	        Property[] propertyArray = propertyList.toArray(new Property[propertyList.size()]);    	        
++    	        Properties preoperties = new Properties();
++    	        preoperties.setProperties(propertyArray);
++    	        return preoperties;
++    	    }
+ 
+ }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0a06ba28/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
index 0000000,b1fd9c5..de51f9b
mode 000000,100644..100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
@@@ -1,0 -1,30 +1,33 @@@
+ /*
+  * 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.autoscaler.util;
+ 
+ public final class AutoScalerConstants {
+ 
+     /**
+      * Constant values for Auto Scaler
+      */
+     public static final String ID_ELEMENT = "id";
+     public static final String PARTITION_ELEMENT = "partition";
+     public static final String PARTITIONS_ELEMENT = "partitions";
++    public static final String PROPERTY_ELEMENT = "property";
++    public static final String PROPERTY_NAME_ATTR= "name";
++    public static final String PROPERTY_VALUE_ATTR = "value";
+        
+ }


[4/9] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos

Posted by ud...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos


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

Branch: refs/heads/master
Commit: 7afbe41345928a5cc74f7f73b289fd9f4de03519
Parents: 3596c3b b361230
Author: Udara Liyanage <ud...@wso2.com>
Authored: Fri Nov 29 11:18:08 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Fri Nov 29 11:18:08 2013 -0500

----------------------------------------------------------------------
 .../org.apache.stratos.load.balancer.extension.api/pom.xml     | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------



[6/9] git commit: Added partition validation

Posted by ud...@apache.org.
Added partition validation


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

Branch: refs/heads/master
Commit: 9199018bc765bd475cbf59c62ca60d0be79fadb5
Parents: 0a06ba2
Author: Udara Liyanage <ud...@wso2.com>
Authored: Sat Nov 30 09:35:45 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Sat Nov 30 09:35:45 2013 -0500

----------------------------------------------------------------------
 .../cloud/controller/CloudControllerClient.java     | 16 ++++++++++++++++
 .../partition/deployers/PartitionDeployer.java      |  7 +++++++
 .../partition/deployers/PartitionReader.java        |  4 ++--
 3 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9199018b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
index 17ad1c7..3da8269 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
@@ -23,6 +23,7 @@ import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.Constants;
+import org.apache.stratos.autoscaler.exception.InvalidPartitionException;
 import org.apache.stratos.autoscaler.exception.PolicyValidationException;
 import org.apache.stratos.autoscaler.exception.SpawningException;
 import org.apache.stratos.autoscaler.exception.TerminationException;
@@ -101,6 +102,21 @@ public class CloudControllerClient {
             throw new PolicyValidationException(e);
         }
     }
+    
+    /*
+     * Calls the CC to validate the partition.
+     */
+    public boolean validatePartition(Partition partition) throws InvalidPartitionException{
+        
+        try {
+            return stub.validatePartition(partition);
+        } catch (RemoteException e) {
+            log.error(e.getMessage());
+            throw new InvalidPartitionException(e);
+        } catch (CloudControllerServiceInvalidPartitionExceptionException e) {
+        	throw new InvalidPartitionException(e);
+		}
+    }
 
     public void spawnAnInstance(Partition partition, String clusterId) throws SpawningException {
         try {

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9199018b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
index e14f332..df8ae29 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
@@ -20,6 +20,7 @@
 package org.apache.stratos.autoscaler.partition.deployers;
 
 import java.io.File;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.axis2.context.ConfigurationContext;
@@ -28,6 +29,7 @@ import org.apache.axis2.deployment.DeploymentException;
 import org.apache.axis2.deployment.repository.util.DeploymentFileData;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClient;
 import org.apache.stratos.cloud.controller.deployment.partition.Partition;
 
 /**
@@ -77,7 +79,12 @@ public class PartitionDeployer extends AbstractDeployer {
 			PartitionReader reader = new PartitionReader(partitionFile);
 			
 			List<Partition> partitionList = reader.getPartitionList();
+			Iterator<Partition> it = partitionList.iterator();
 			
+			while(it.hasNext()){
+				// validate the partition with CC
+				CloudControllerClient.getInstance().validatePartition(it.next());
+			}			
 
 			log.info("Successfully deployed the partition specified at "
 					+ deploymentFileData.getAbsolutePath());

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9199018b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
index 4f635e7..2246e56 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
@@ -52,7 +52,7 @@ public class PartitionReader{
 		this.partitionFIle = partitionFile;
 	}
 	
-	public List<Partition> getPartitionList() throws InvalidPartitionException{
+	public List<Partition> getPartitionList(){
 			this.parse(this.partitionFIle);
 			String partitionXpath = AutoScalerConstants.PARTITIONS_ELEMENT + "/"+AutoScalerConstants.PARTITION_ELEMENT;
 			List<OMNode> partitionXMLNodes = getMatchingNodes(partitionXpath);
@@ -103,7 +103,7 @@ public class PartitionReader{
         return partition;
     }
 	
-	public void parse(File xmlSource) {
+	public void parse(File xmlSource){
 
         if (xmlSource.exists()) {
             try {


[7/9] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos

Posted by ud...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos


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

Branch: refs/heads/master
Commit: 8e58eccc07b740eb60d835465fb803fd95cad715
Parents: 9199018 d9ca9e3
Author: Udara Liyanage <ud...@wso2.com>
Authored: Sat Nov 30 10:27:22 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Sat Nov 30 10:27:22 2013 -0500

----------------------------------------------------------------------
 .../load/balancer/LoadBalancerContext.java      |   28 +-
 .../conf/LoadBalancerConfiguration.java         | 1358 ++++--------------
 .../load/balancer/conf/domain/Algorithm.java    |   49 +
 .../load/balancer/conf/structure/Node.java      |   15 +-
 .../balancer/conf/structure/NodeBuilder.java    |   80 +-
 .../load/balancer/conf/util/Constants.java      |   46 +-
 .../load/balancer/conf/util/HostContext.java    |  161 ---
 .../conf/util/LoadBalancerConfigUtil.java       |  305 ----
 .../balancer/conf/util/TenantDomainContext.java |   80 --
 .../InvalidConfigurationException.java          |   33 +
 .../internal/LoadBalancerServiceComponent.java  |   57 +-
 .../test/LoadBalancerConfigUtilTest.java        |   48 -
 .../test/LoadBalancerConfigurationTest.java     |  179 +--
 .../load/balancer/test/NodeBuilderTest.java     |  123 --
 .../src/test/resources/loadbalancer.conf        |   84 --
 .../src/test/resources/loadbalancer1.conf       |   60 -
 .../src/test/resources/loadbalancer2.conf       |   50 -
 .../sample/configuration/loadbalancer1.conf     |   66 +
 .../sample/configuration/loadbalancer2.conf     |  118 ++
 .../sample/configuration/loadbalancer3.conf     |   66 +
 .../load-balancer/haproxy-extension/INSTALL.txt |   16 +-
 products/load-balancer/README.txt               |   19 +-
 .../distribution/src/main/assembly/bin.xml      |    1 +
 .../distribution/src/main/bin/stratos.bat       |    2 +-
 .../distribution/src/main/bin/stratos.sh        |    2 +-
 .../src/main/conf/loadbalancer.conf             |   45 +
 26 files changed, 801 insertions(+), 2290 deletions(-)
----------------------------------------------------------------------



[2/9] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos

Posted by ud...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos


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

Branch: refs/heads/master
Commit: 3596c3b998387503a416ae7eeb0734b32a57af43
Parents: 1747003 9f69444
Author: Udara Liyanage <ud...@wso2.com>
Authored: Fri Nov 29 09:02:58 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Fri Nov 29 09:02:58 2013 -0500

----------------------------------------------------------------------
 .../client/CloudControllerServiceClient.java    |   53 +-
 .../stratos/adc/mgt/dto/SubscriptionInfo.java   |    2 +
 .../manager/CartridgeSubscriptionManager.java   |    4 +-
 .../adc/mgt/payload/NonCarbonPayload.java       |    6 +-
 .../stratos/adc/mgt/payload/PayloadArg.java     |    2 +-
 .../DatabaseBasedPersistenceManager.java        |    2 +-
 .../service/ApplicationManagementService.java   |    2 +-
 .../adc/mgt/service/RepositoryInfoBean.java     |    3 +-
 .../mgt/subscription/CartridgeSubscription.java |    2 +-
 .../subscription/DataCartridgeSubscription.java |    2 +-
 .../MultiTenantCartridgeSubscription.java       |    2 +-
 .../SingleTenantCartridgeSubscription.java      |    2 +-
 .../factory/CartridgeSubscriptionFactory.java   |    2 +-
 .../mgt/utils/ApplicationManagementUtil.java    |  524 ++-
 .../adc/mgt/test/CartridgeSubscriptionTest.java |    3 +-
 .../stratos/adc/mgt/test/PayloadTest.java       |    5 +-
 .../stratos/autoscaler/ClusterContext.java      |   62 +-
 .../stratos/autoscaler/ClusterMonitor.java      |  163 +
 .../stratos/autoscaler/PartitionContext.java    |   78 +
 .../algorithm/AutoscaleAlgorithm.java           |   16 +-
 .../autoscaler/algorithm/OneAfterAnother.java   |  106 +-
 .../PartitionGroupOneAfterAnother.java          |  120 +-
 .../autoscaler/algorithm/RoundRobin.java        |  110 +-
 .../cloud/controller/CloudControllerClient.java |  102 +-
 .../exception/PolicyValidationException.java    |   19 +
 .../autoscaler/exception/SpawningException.java |   12 +-
 .../exception/TerminationException.java         |    4 +
 .../internal/AutoscalerServerComponent.java     |   26 +-
 .../health/HealthEventMessageDelegator.java     |   61 +-
 .../autoscaler/policy/PolicyManager.java        |    2 +-
 .../deployers/DeploymentPolicyDeployer.java     |    2 +-
 .../deployers/DeploymentPolicyReader.java       |   39 +-
 .../policy/model/DeploymentPolicy.java          |   67 -
 .../autoscaler/policy/model/Partition.java      |   87 -
 .../autoscaler/policy/model/PartitionGroup.java |   81 -
 .../rule/AutoscalerRuleEvaluator.java           |  134 +-
 .../autoscaler/rule/ExecutorTaskScheduler.java  |   58 +-
 .../processors/AutoscalerTopologyReceiver.java  |  267 ++
 .../topology/processors/TopologyReceiver.java   |   80 +
 .../stratos/autoscaler/util/AutoscalerUtil.java |   75 +-
 .../stratos/autoscaler/TestKnowledgeBase.java   |   58 +-
 .../policy/DeploymentPolicyDeployerTest.java    |   53 +
 .../src/test/resources/autoscaler.drl           |  124 +
 .../src/test/resources/deployment-policy.xml    |   16 +
 .../test/resources/minimum-autoscaler-rule.drl  |   62 +
 .../resources/test-minimum-autoscaler-rule.drl  |   34 +
 .../org.apache.stratos.cloud.controller/pom.xml |   10 +-
 .../controller/axiom/AxiomXpathParser.java      | 3431 +++++++++---------
 .../controller/axiom/AxiomXpathParserUtil.java  |  263 ++
 .../axiom/parser/CartridgeConfigParser.java     |  384 ++
 .../parser/CloudControllerConfigParser.java     |  205 ++
 .../axiom/parser/IaasProviderConfigParser.java  |  308 ++
 .../axiom/parser/ServiceConfigParser.java       |  563 +++
 .../controller/concurrent/ThreadExecutor.java   |    4 +-
 .../controller/deployers/CartridgeDeployer.java |   46 +-
 .../deployers/CloudControllerDeployer.java      |   94 +-
 .../controller/deployers/ServiceDeployer.java   |  216 +-
 .../deployment/partition/Partition.java         |  130 +
 .../deployment/partition/PartitionGroup.java    |   87 +
 .../deployment/policy/DeploymentPolicy.java     |   93 +
 .../InvalidCartridgeTypeException.java          |   38 +
 .../exception/InvalidClusterException.java      |   38 +
 .../exception/InvalidHostException.java         |   38 +
 .../exception/InvalidIaasProviderException.java |   39 +
 .../exception/InvalidMemberException.java       |   38 +
 .../exception/InvalidPartitionException.java    |   38 +
 .../exception/InvalidRegionException.java       |   38 +
 .../exception/InvalidZoneException.java         |   38 +
 .../exception/UnregisteredClusterException.java |   33 +
 .../exception/UnregisteredServiceException.java |   33 -
 .../hector/CassandraDataRetriever.java          |    6 +-
 .../controller/hive/HiveQueryExecutor.java      |   12 +-
 .../cloud/controller/iaases/AWSEC2Iaas.java     |  113 +-
 .../controller/iaases/OpenstackNovaIaas.java    |   96 +-
 .../cloud/controller/iaases/VCloudIaas.java     |   27 +-
 .../impl/CloudControllerServiceImpl.java        | 1245 ++++---
 .../interfaces/CloudControllerService.java      |  127 +-
 .../cloud/controller/interfaces/Iaas.java       |   44 +-
 .../jcloud/ComputeServiceBuilderUtil.java       |    3 +-
 .../stratos/cloud/controller/pojo/AppType.java  |   62 +
 .../cloud/controller/pojo/Cartridge.java        |  288 ++
 .../cloud/controller/pojo/CartridgeInfo.java    |  163 +
 .../controller/pojo/CartridgeInstanceData.java  |  130 +
 .../cloud/controller/pojo/ClusterContext.java   |   76 +
 .../controller/pojo/DataPublisherConfig.java    |   82 +
 .../stratos/cloud/controller/pojo/Host.java     |   73 +
 .../cloud/controller/pojo/IaasContext.java      |  162 +
 .../cloud/controller/pojo/IaasProvider.java     |  271 ++
 .../cloud/controller/pojo/LocationScope.java    |   70 +
 .../cloud/controller/pojo/MemberContext.java    |   89 +
 .../cloud/controller/pojo/PortMapping.java      |   64 +
 .../cloud/controller/pojo/Properties.java       |   37 +
 .../stratos/cloud/controller/pojo/Property.java |   54 +
 .../stratos/cloud/controller/pojo/Region.java   |  125 +
 .../cloud/controller/pojo/Registrant.java       |   79 +
 .../cloud/controller/pojo/ServiceContext.java   |  366 ++
 .../cloud/controller/pojo/TopologyConfig.java   |   59 +
 .../stratos/cloud/controller/pojo/Zone.java     |   90 +
 .../CartridgeInstanceDataPublisherTask.java     |    9 +-
 .../runtime/FasterLookUpDataHolder.java         |  187 +-
 .../controller/topology/TopologyBuilder.java    |  192 +-
 .../topology/TopologyEventSender.java           |  107 +-
 .../stratos/cloud/controller/util/AppType.java  |   62 -
 .../cloud/controller/util/Cartridge.java        |  255 --
 .../cloud/controller/util/CartridgeInfo.java    |  163 -
 .../controller/util/CartridgeInstanceData.java  |  130 -
 .../util/CloudControllerConstants.java          |    8 +
 .../controller/util/CloudControllerUtil.java    |   26 +
 .../stratos/cloud/controller/util/Host.java     |   73 -
 .../cloud/controller/util/IaasContext.java      |  162 -
 .../cloud/controller/util/IaasProvider.java     |  271 --
 .../cloud/controller/util/LocationScope.java    |   70 -
 .../cloud/controller/util/PortMapping.java      |   64 -
 .../cloud/controller/util/Properties.java       |   37 -
 .../stratos/cloud/controller/util/Property.java |   53 -
 .../stratos/cloud/controller/util/Region.java   |  125 -
 .../cloud/controller/util/ServiceContext.java   |  382 --
 .../cloud/controller/util/TopologyConfig.java   |   59 -
 .../stratos/cloud/controller/util/Zone.java     |   90 -
 .../validate/AWSEC2PartitionValidator.java      |   94 +
 .../OpenstackNovaPartitionValidator.java        |   97 +
 .../validate/interfaces/PartitionValidator.java |   47 +
 .../src/main/resources/META-INF/component.xml   |    4 +-
 .../service/axiom/AxiomValidationTest.java      |   57 +-
 .../service/axiom/AxiomXpathParserTest.java     |   21 +-
 .../service/util/ServiceContextTest.java        |    3 +-
 components/org.apache.stratos.messaging/pom.xml |    6 +
 .../messaging/domain/topology/Cluster.java      |    2 +-
 .../messaging/domain/topology/Member.java       |    8 -
 .../messaging/domain/topology/Partition.java    |   67 -
 .../stratos/messaging/domain/topology/Port.java |    5 +-
 .../messaging/domain/topology/Scope.java        |    2 +-
 .../messaging/domain/topology/Service.java      |    7 +-
 .../messaging/domain/topology/Topology.java     |   36 +-
 .../event/topology/ClusterCreatedEvent.java     |    9 +
 .../event/topology/InstanceSpawnedEvent.java    |   10 +-
 .../event/topology/PartitionCreatedEvent.java   |   60 +-
 .../CompleteTopologyEventProcessor.java         |    3 -
 .../topology/InstanceSpawnedEventProcessor.java |    1 -
 .../stratos/messaging/util/Properties.java      |   37 +
 .../apache/stratos/messaging/util/Property.java |   54 +
 .../org.apache.stratos.rest.endpoint/pom.xml    |    6 +
 .../rest/endpoint/services/ServiceUtils.java    |    2 +-
 .../executionplans/AverageHeathRequest.xml      |    3 +
 .../src/main/bin/health-publisher.sh            |    2 +-
 .../health/publisher/HealthPublisherClient.java |   25 +
 .../pom.xml                                     |   11 +-
 .../main/resources/CloudControllerService.wsdl  |  458 +--
 148 files changed, 10855 insertions(+), 5759 deletions(-)
----------------------------------------------------------------------



[3/9] git commit: Commiting partition deployer

Posted by ud...@apache.org.
Commiting partition deployer


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

Branch: refs/heads/master
Commit: dca46e39ff818bea1d8c074ae36f18effab5ee89
Parents: 1747003
Author: Udara Liyanage <ud...@wso2.com>
Authored: Fri Nov 29 09:02:31 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Fri Nov 29 11:06:18 2013 -0500

----------------------------------------------------------------------
 .../org.apache.stratos.autoscaler/pom.xml       |  47 +-----
 .../stratos/autoscaler/ClusterContext.java      |  24 +---
 .../autoscaler/algorithm/OneAfterAnother.java   |   4 +-
 .../autoscaler/algorithm/RoundRobin.java        |   4 +-
 .../exception/InvalidPartitionException.java    |  40 ++++++
 .../partition/deployers/PartitionDeployer.java  | 103 +++++++++++++
 .../partition/deployers/PartitionReader.java    | 144 +++++++++++++++++++
 .../policy/InvalidPolicyException.java          |   4 +-
 .../autoscaler/util/AutoScalerConstants.java    |  30 ++++
 .../stratos/autoscaler/util/AutoscalerUtil.java |  12 +-
 .../src/main/resources/META-INF/component.xml   |   5 +
 .../messaging/domain/topology/Cluster.java      |  27 ++--
 .../messaging/domain/topology/Topology.java     |   4 +
 .../pom.xml                                     |  13 +-
 products/pom.xml                                |   4 +-
 15 files changed, 373 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/pom.xml b/components/org.apache.stratos.autoscaler/pom.xml
index b92fc94..7d898d7 100644
--- a/components/org.apache.stratos.autoscaler/pom.xml
+++ b/components/org.apache.stratos.autoscaler/pom.xml
@@ -36,15 +36,11 @@
 
 	<dependencies>
 		<dependency>
-			<groupId>org.drools</groupId>
-			<artifactId>drools-core</artifactId>
-			<version>${drools.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.drools</groupId>
-			<artifactId>drools-compiler</artifactId>
-			<version>${drools.version}</version>
-		</dependency>
+                        <groupId>org.drools</groupId>
+                        <artifactId>knowledge-api</artifactId>
+                        <version>${drools.version}</version>
+                </dependency>
+
 		<dependency>
 			<groupId>com.thoughtworks.xstream</groupId>
 			<artifactId>xstream</artifactId>
@@ -61,11 +57,6 @@
 			<version>3.3</version>
 		</dependency>
 		<dependency>
-			<groupId>org.drools</groupId>
-			<artifactId>drools-decisiontables</artifactId>
-			<version>${drools.version}</version>
-		</dependency>
-		<dependency>
 			<groupId>org.antlr</groupId>
 			<artifactId>antlr-runtime</artifactId>
 			<version>3.3</version>
@@ -76,21 +67,6 @@
 			<version>3.2.1</version>
 		</dependency>
 		<dependency>
-			<groupId>org.drools</groupId>
-			<artifactId>drools-jsr94</artifactId>
-			<version>${drools.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.drools</groupId>
-			<artifactId>knowledge-internal-api</artifactId>
-			<version>${drools.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.drools</groupId>
-			<artifactId>knowledge-api</artifactId>
-			<version>${drools.version}</version>
-		</dependency>
-		<dependency>
 			<groupId>org.mvel</groupId>
 			<artifactId>mvel2</artifactId>
 			<version>2.1.3.Final</version>
@@ -106,16 +82,6 @@
 			<version>1.6.4</version>
 		</dependency-->
 		<dependency>
-			<groupId>org.drools</groupId>
-			<artifactId>drools-verifier</artifactId>
-			<version>${drools.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.drools</groupId>
-			<artifactId>drools-templates</artifactId>
-			<version>${drools.version}</version>
-		</dependency>
-		<dependency>
 			<groupId>org.eclipse.jdt.core.compiler</groupId>
 			<artifactId>ecj</artifactId>
 			<version>3.5.1</version>
@@ -185,8 +151,9 @@
 							*;resolution:=optional
                         </Import-Package>
 						<DynamicImport-Package>*</DynamicImport-Package>
-						<Axis2Deployer>AutoscalerPolicyDeployer</Axis2Deployer>
 						<Axis2Deployer>DeploymentPolicyDeployer</Axis2Deployer>
+						<Axis2Deployer>AutoscalerPolicyDeployer</Axis2Deployer>
+						<Axis2Deployer>PartitionDeployer</Axis2Deployer>
 						<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
 						<Embed-Directory>lib</Embed-Directory>
 					</instructions>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContext.java
index 10e09f7..c28a237 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContext.java
@@ -65,12 +65,10 @@ public class ClusterContext {
     }
 
     public Properties getProperties() {
-
         return properties;
     }
 
     public void setProperties(Properties properties) {
-
         this.properties = properties;
     }
 
@@ -79,27 +77,22 @@ public class ClusterContext {
     }
 
     public void setAverageRequestsInFlight(float averageRequestsInFlight) {
-
         this.averageRequestsInFlight = averageRequestsInFlight;
     }
 
     public float getRequestsInFlightSecondDerivative() {
-
         return requestsInFlightSecondDerivative;
     }
 
     public void setRequestsInFlightSecondDerivative(float requestsInFlightSecondDerivative) {
-
         this.requestsInFlightSecondDerivative = requestsInFlightSecondDerivative;
     }
 
     public float getRequestsInFlightGradient() {
-
         return requestsInFlightGradient;
     }
 
     public void setRequestsInFlightGradient(float requestsInFlightGradient) {
-
         this.requestsInFlightGradient = requestsInFlightGradient;
     }
 
@@ -108,7 +101,6 @@ public class ClusterContext {
      * @param memberContext will be added to map
      */
     public void addMemberContext(MemberContext memberContext) {
-
         memberContextMap.put(memberContext.getMemberId(), memberContext);
     }
 
@@ -117,27 +109,23 @@ public class ClusterContext {
      * @param memberId
      */
     public void removeMemberContext(String memberId){
-
         memberContextMap.remove(memberId);
     }
 
     public void increaseMemberCount(int count){
         memberCount += count;
-
     }
+    
     public void decreaseMemberCount(){
         memberCount --;
-
     }
 
-   public void increaseMemberCountInPartitionBy(String partitionId, int count){
-
-        partitionCountMap.put(partitionId, getMemberCount(partitionId) + count);
+    public void increaseMemberCountInPartitionBy(String partitionId, int count){
+        partitionCountMap.put(partitionId, getMemberCountInPartition(partitionId) + count);
     }
 
     public void decreaseMemberCountInPartitionBy(String partitionId, int count){
-
-        partitionCountMap.put(partitionId, getMemberCount(partitionId) - count);
+        partitionCountMap.put(partitionId, getMemberCountInPartition(partitionId) - count);
     }
 
     public void addPartitionCount(String partitionId, int count){    	
@@ -145,7 +133,6 @@ public class ClusterContext {
     }
 
     public void removePartitionCount(String partitionId){
-
         partitionCountMap.remove(partitionId);
     }
 
@@ -153,7 +140,7 @@ public class ClusterContext {
         return partitionCountMap.containsKey(partitionId);
     }
 
-    public int getMemberCount(String partitionId){
+    public int getMemberCountInPartition(String partitionId){
         if(partitionCountMap.containsKey(partitionId)) {
             return partitionCountMap.get(partitionId);
         }
@@ -161,7 +148,6 @@ public class ClusterContext {
     }
 
     public void setMemberContextMap(Map<String, MemberContext> memberContextMap) {
-
         this.memberContextMap = memberContextMap;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
index 3c06c13..71f3180 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
@@ -52,7 +52,7 @@ public class OneAfterAnother implements AutoscaleAlgorithm {
     			clusterContext.addPartitionCount(currentPartitionId, 0);
     		}
     		
-    		 if(clusterContext.getMemberCount(currentPartitionId) < currentPartition.getPartitionMembersMax()){
+    		 if(clusterContext.getMemberCountInPartition(currentPartitionId) < currentPartition.getPartitionMembersMax()){
  	        	// current partition is free    	        	
  	        	clusterContext.increaseMemberCountInPartitionBy(currentPartitionId, 1);
  	        	if(log.isDebugEnabled()) 	        		
@@ -91,7 +91,7 @@ public class OneAfterAnother implements AutoscaleAlgorithm {
 	        String currentPartitionId =  currentPartition.getId();
 	        	            
 	        // has more than minimum instances.
-	        if(clusterContext.getMemberCount(currentPartitionId) > currentPartition.getPartitionMembersMin()){
+	        if(clusterContext.getMemberCountInPartition(currentPartitionId) > currentPartition.getPartitionMembersMin()){
 	        	// current partition is free    	        	
 	        	clusterContext.decreaseMemberCountInPartitionBy(currentPartitionId, 1);
 	        	if(log.isDebugEnabled())

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java
index d75f11a..f925b47 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java
@@ -55,7 +55,7 @@ public class RoundRobin implements AutoscaleAlgorithm{
 	        	if(!clusterContext.partitionCountExists(currentPartitionId))    	        		
 	        		AutoscalerContext.getInstance().getClusterContext(clusterId).addPartitionCount(currentPartitionId, 0);
 	        	
-    	        if(clusterContext.getMemberCount(currentPartitionId) < currentPartition.getPartitionMembersMax()){
+    	        if(clusterContext.getMemberCountInPartition(currentPartitionId) < currentPartition.getPartitionMembersMax()){
     	        	// current partition is free    	        	
     	        	clusterContext.increaseMemberCountInPartitionBy(currentPartitionId, 1);
     	        	if(log.isDebugEnabled())
@@ -102,7 +102,7 @@ public class RoundRobin implements AutoscaleAlgorithm{
     	        if(!clusterContext.partitionCountExists(currentPartitionId))    	        		
 	        		AutoscalerContext.getInstance().getClusterContext(clusterId).addPartitionCount(currentPartitionId, 0);
     	        // has more than minimum instances.
-    	        if(clusterContext.getMemberCount(currentPartitionId) > currentPartition.getPartitionMembersMin()){
+    	        if(clusterContext.getMemberCountInPartition(currentPartitionId) > currentPartition.getPartitionMembersMin()){
     	        	// current partition is free    	        	
     	        	clusterContext.decreaseMemberCountInPartitionBy(currentPartitionId, 1);
     	        	if(log.isDebugEnabled())

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/InvalidPartitionException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/InvalidPartitionException.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/InvalidPartitionException.java
new file mode 100644
index 0000000..c02824d
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/InvalidPartitionException.java
@@ -0,0 +1,40 @@
+/*
+ * 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.autoscaler.exception;
+
+public class InvalidPartitionException extends Exception {
+
+	private static final long serialVersionUID = -4914522749282514366L;
+	
+	public InvalidPartitionException(String message) {
+		super(message);
+	}
+	
+	public InvalidPartitionException(String message,Throwable e) {
+		super(message,e);
+	}
+	
+	public InvalidPartitionException(Throwable e) {
+		super(e);
+	}
+	
+	
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
new file mode 100644
index 0000000..6bba10e
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
@@ -0,0 +1,103 @@
+/*
+ * 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.autoscaler.partition.deployers;
+
+import java.io.File;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.deployment.AbstractDeployer;
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.axis2.deployment.repository.util.DeploymentFileData;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * 
+ * The Axis2 deployer class for party definitions definitions.
+ */
+public class PartitionDeployer extends AbstractDeployer {
+	
+	 private static final Log log = LogFactory.getLog(PartitionDeployer.class);
+	 
+	 private static String fileExt="xml"; //default
+	 private static String deployDirectory=null;
+
+	@Override
+	public void init(ConfigurationContext context) {
+		System.out.println("********Deploying init");
+		if(deployDirectory!=null){
+			File deployDir = new File(new File(context.getAxisConfiguration().getRepository().getPath()),deployDirectory);
+			if(!deployDir.exists()){
+				//create policies deployment directory if not exist 
+				try {
+					deployDir.mkdirs();
+				} catch (Exception e) {
+					log.error("Unable to create policies deployment directory", e);
+				}
+			}
+		}
+	}
+
+	@Override
+	public void setDirectory(String dir) {
+		deployDirectory = dir;
+	}
+
+	@Override
+	public void setExtension(String ext) {
+		fileExt = ext;
+	}
+	
+	@Override
+	public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
+
+		File partitionFile = deploymentFileData.getFile();
+		log.debug("Started to deploy the policy: " + partitionFile);
+		System.out.println("********Deploying stated " + partitionFile);
+
+		try {
+			/*
+			PartitionReader reader = new PartitionReader(partitionFile);
+			
+			List<Partition> partitionList = reader.getPartitionList();
+			
+
+			log.info("Successfully deployed the partition specified at "
+					+ deploymentFileData.getAbsolutePath());
+			 */
+		} catch (Exception e) {
+			String msg = "Invalid partition artifact at " + deploymentFileData.getAbsolutePath();
+			// back up the file
+			File fileToBeRenamed = partitionFile;
+			fileToBeRenamed.renameTo(new File(deploymentFileData.getAbsolutePath() + ".back"));
+			log.error(msg, e);
+			throw new DeploymentException(msg, e);
+		}
+	}
+	
+	@Override
+	public void undeploy(String fileName) throws DeploymentException {
+		System.out.println("****************************************************");
+
+	}
+	
+	
+	
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
new file mode 100644
index 0000000..a6c45f1
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
@@ -0,0 +1,144 @@
+/*
+ * 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.autoscaler.partition.deployers;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.exception.InvalidPartitionException;
+import org.apache.stratos.autoscaler.policy.InvalidPolicyException;
+import org.apache.stratos.autoscaler.policy.model.DeploymentPolicy;
+import org.apache.stratos.autoscaler.policy.model.Partition;
+import org.apache.stratos.autoscaler.util.AutoScalerConstants;
+import org.jaxen.JaxenException;
+
+/**
+ * 
+ * The Reader class for Deployment-policy definitions.
+ */
+public class PartitionReader{
+	
+	private static final Log log = LogFactory.getLog(PartitionReader.class);
+	private static OMElement documentElement;
+	private File partitionFIle;
+	
+	public PartitionReader(File partitionFile){
+		this.partitionFIle = partitionFile;
+	}
+	
+	public List<Partition> getPartitionList() throws InvalidPartitionException{
+			this.parse(this.partitionFIle);
+			List<OMNode> partitionXMLNodes = getMatchingNodes("/partitions/partition");
+			Iterator<OMNode> itr = partitionXMLNodes.iterator();
+			List<Partition> partitonList = new ArrayList<Partition>();
+			while(itr.hasNext()){
+				 OMNode node  = itr.next();
+				 //System.out.println("node " + node);
+				 partitonList.add(this.getPartition(node));
+			 }
+		return partitonList;
+	}
+	
+	private  Partition getPartition(final OMNode item) {
+        Partition partition = null;
+        String id = null;
+
+        if (item.getType() == OMNode.ELEMENT_NODE) {
+
+            OMElement iaasElt = (OMElement) item;
+            Iterator<?> it =
+                    iaasElt.getChildrenWithName(new QName(AutoScalerConstants.ID_ELEMENT));
+
+            if (it.hasNext()) {
+                OMElement providerElt = (OMElement) it.next();
+                id = providerElt.getText();
+            }
+
+            if (it.hasNext()) {
+                log.warn( " contains more than one " + AutoScalerConstants.ID_ELEMENT +
+                        " elements!" + " Elements other than the first will be neglected.");
+            }
+
+            if (id == null) {
+                String msg ="Essential " + AutoScalerConstants.ID_ELEMENT + "element " +
+                                "has not specified in ";
+                // handleException(msg);
+            }
+            //boolean partitionExist = TopologyManager.getInstance().getTopology().partitionExist(id);
+            boolean partitionExist =false;
+            if(!partitionExist){
+            	partition = new Partition();
+                partition.setId(id);
+                //loadProperties(iaasElt, partition.getProperties());
+                //handle partition created event
+                //TopologyBuilder.handlePartitionCreated(partition);
+            }            
+        }
+        return partition;
+    }
+	
+	public void parse(File xmlSource) {
+
+        if (xmlSource.exists()) {
+            try {
+                documentElement = new StAXOMBuilder(xmlSource.getPath()).getDocumentElement();
+
+            } catch (Exception ex) {
+                String msg = "Error occurred when parsing the " + xmlSource.getPath() + ".";
+                //handleException(msg, ex);
+            }
+        } else {
+            String msg = "Configuration file cannot be found : " + xmlSource.getPath();
+            //handleException(msg);
+        }
+    }
+	/**
+     * @param xpath XPATH expression to be read.
+     * @return List matching OMNode list
+     */
+    @SuppressWarnings("unchecked")
+    public static List<OMNode> getMatchingNodes(final String xpath) {
+
+        AXIOMXPath axiomXpath;
+        List<OMNode> nodeList = null;
+        try {
+            axiomXpath = new AXIOMXPath(xpath);
+            nodeList = axiomXpath.selectNodes(documentElement);
+        } catch (JaxenException e) {
+            String msg = "Error occurred while reading the Xpath (" + xpath + ")";
+            //log.error(msg, e);
+            //throw new CloudControllerException(msg, e);
+        }
+
+        return nodeList;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/InvalidPolicyException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/InvalidPolicyException.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/InvalidPolicyException.java
index 5df3b24..9b73179 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/InvalidPolicyException.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/InvalidPolicyException.java
@@ -21,8 +21,8 @@ package org.apache.stratos.autoscaler.policy;
 
 public class InvalidPolicyException extends Exception {
 
-	private static final long serialVersionUID = -4914522749282514366L;
-	
+	private static final long serialVersionUID = 1L;
+
 	public InvalidPolicyException(String message) {
 		super(message);
 	}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
new file mode 100644
index 0000000..b1fd9c5
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
@@ -0,0 +1,30 @@
+/*
+ * 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.autoscaler.util;
+
+public final class AutoScalerConstants {
+
+    /**
+     * Constant values for Auto Scaler
+     */
+    public static final String ID_ELEMENT = "id";
+    public static final String PARTITION_ELEMENT = "partition";
+    public static final String PARTITIONS_ELEMENT = "partitions";
+       
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
index 16143f9..10c6a9e 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
@@ -60,19 +60,9 @@ public class AutoscalerUtil {
                 float gradientLimit = loadThresholds.getRequestsInFlight().getGradient();
                 float secondDerivative  = loadThresholds.getRequestsInFlight().getSecondDerivative();
 
-
                 clusterContext.setRequestsInFlightGradient(gradientLimit);
                 clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
-                clusterContext.setAverageRequestsInFlight(averageLimit);
-                DeploymentPolicy deploymentPolicy = PolicyManager.getInstance().getDeploymentPolicy(cluster.getDeploymentPolicyName());
-                if(deploymentPolicy!=null){
-                	for(PartitionGroup group :deploymentPolicy.getPartitionGroups()){
-                		for (Partition partition : group.getPartitions()) {
-                            clusterContext.addPartitionCount(partition.getId(), 0);
-                    }
-                	}
-                }
-                
+                clusterContext.setAverageRequestsInFlight(averageLimit);                                
              }
 
 			context.addClusterContext(clusterContext);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.autoscaler/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.autoscaler/src/main/resources/META-INF/component.xml
index cbab84f..ba5fc5a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/resources/META-INF/component.xml
+++ b/components/org.apache.stratos.autoscaler/src/main/resources/META-INF/component.xml
@@ -28,5 +28,10 @@
             <extension>xml</extension>
             <class>org.apache.stratos.autoscaler.policy.deployers.DeploymentPolicyDeployer</class>
         </deployer>
+        <deployer>
+            <directory>partitions</directory>
+            <extension>xml</extension>
+            <class>org.apache.stratos.autoscaler.partition.deployers.PartitionDeployer</class>
+        </deployer>
     </deployers>
 </component>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
index a3fd9e8..209d1a4 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
@@ -42,9 +42,12 @@ public class Cluster implements Serializable {
     private Region region;
     private Zone zone;
     
-    // Key: Member.memberId
+    // Key- Member.memberId, Value- Member
     private Map<String, Member> memberMap;
+    
     private Properties properties;
+    
+    // Key- IAAS node id, Value- Member
     private Map<String, Member> membertoNodeIdMap;
 
     public Cluster(String serviceName, String clusterId, String autoscalePolicyName) {
@@ -141,20 +144,20 @@ public class Cluster implements Serializable {
     }
 
     public void addMemberToIaasNodeId(Member member) {
-           membertoNodeIdMap.put(member.getIaasNodeId(), member);
-       }
+    	membertoNodeIdMap.put(member.getIaasNodeId(), member);
+    }
 
-       public void removeMemberFromIaasNodeId(Member member) {
-           membertoNodeIdMap.remove(member.getIaasNodeId());
-       }
+    public void removeMemberFromIaasNodeId(Member member) {
+    	membertoNodeIdMap.remove(member.getIaasNodeId());
+    }
 
-       public Member getMemberFromIaasNodeId(String iaasNodeId) {
-           return membertoNodeIdMap.get(iaasNodeId);
-       }
+    public Member getMemberFromIaasNodeId(String iaasNodeId) {
+    	return membertoNodeIdMap.get(iaasNodeId);
+    }
 
-       public boolean memberExistsFromIaasNodeId(String iaasNodeId) {
-           return this.membertoNodeIdMap.containsKey(iaasNodeId);
-       }
+    public boolean memberExistsFromIaasNodeId(String iaasNodeId) {
+    	return this.membertoNodeIdMap.containsKey(iaasNodeId);
+    }
 
 	public String getDeploymentPolicyName() {
 		return deploymentPolicyName;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java
index 2b93188..5f5da7b 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java
@@ -78,6 +78,10 @@ public class Topology implements Serializable {
     public Partition getPartition(String id) {
         return  this.partitionMap.get(id);
     }
+    
+    public boolean partitionExist(String id) {
+        return  null != this.partitionMap.get(id);
+    }
 
     public void setPartitionMap(Map<String, Partition> partitionMap) {
         this.partitionMap = partitionMap;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/features/autoscaler/org.apache.stratos.autoscaler.feature/pom.xml
----------------------------------------------------------------------
diff --git a/features/autoscaler/org.apache.stratos.autoscaler.feature/pom.xml b/features/autoscaler/org.apache.stratos.autoscaler.feature/pom.xml
index 7ed781f..270b3e2 100644
--- a/features/autoscaler/org.apache.stratos.autoscaler.feature/pom.xml
+++ b/features/autoscaler/org.apache.stratos.autoscaler.feature/pom.xml
@@ -40,6 +40,12 @@
             <artifactId>org.apache.stratos.autoscaler</artifactId>
             <version>${project.version}</version>
          </dependency>
+	<dependency>
+		<groupId>org.drools</groupId>
+		<artifactId>knowledge-api</artifactId>
+		<version>${drools.version}</version>
+	</dependency>
+
     </dependencies>
     <build>
         <plugins>
@@ -65,7 +71,8 @@
                             </adviceFile>
                             <bundles>
                                 <bundleDef>org.apache.stratos:org.apache.stratos.autoscaler:${project.version}</bundleDef>
-                                <bundleDef>org.apache.stratos:org.apache.stratos.cloud.controller.service.stub:${project.version}</bundleDef>
+				<bundleDef>org.apache.stratos:org.apache.stratos.cloud.controller.service.stub:${project.version}</bundleDef>
+                                <bundleDef>org.drools:knowledge-api:${drools.version}</bundleDef>
                             </bundles>
                             <importFeatures>
                                 <importFeatureDef>org.wso2.carbon.core.server:${wso2carbon.version}</importFeatureDef>
@@ -76,6 +83,8 @@
             </plugin>
         </plugins>
     </build>
-
+    <properties>
+	<drools.version>5.5.0.Final</drools.version>
+    </properties>
 </project>
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/dca46e39/products/pom.xml
----------------------------------------------------------------------
diff --git a/products/pom.xml b/products/pom.xml
index 5deef6d..b4700ec 100644
--- a/products/pom.xml
+++ b/products/pom.xml
@@ -36,11 +36,11 @@
 
     <modules>
         <module>autoscaler</module>
-        <module>cloud-controller</module>
+        <!--<module>cloud-controller</module>
         <module>load-balancer</module>
         <module>stratos-cli</module>
         <module>stratos-controller</module>
-        <module>cartridge-agent</module>
+        <module>cartridge-agent</module>-->
     </modules>
 </project>
 


[9/9] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos

Posted by ud...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos


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

Branch: refs/heads/master
Commit: 560b1c5fc84f55e484d2d60e1a2ba81015269224
Parents: 1d6f1d2 faca016
Author: Udara Liyanage <ud...@wso2.com>
Authored: Sat Nov 30 14:43:50 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Sat Nov 30 14:43:50 2013 -0500

----------------------------------------------------------------------
 .../stratos/autoscaler/ClusterContext.java      |  10 +-
 .../stratos/autoscaler/ClusterMonitor.java      |  10 +-
 .../stratos/autoscaler/MemberContext.java       |  58 ------
 .../stratos/autoscaler/MemberStatsContext.java  |  58 ++++++
 .../stratos/autoscaler/PartitionContext.java    | 131 ++++++++++++-
 .../autoscaler/algorithm/OneAfterAnother.java   |   4 +-
 .../autoscaler/algorithm/RoundRobin.java        |   4 +-
 .../cloud/controller/CloudControllerClient.java |  10 +-
 .../rule/AutoscalerRuleEvaluator.java           |  27 +--
 .../stratos/autoscaler/TestKnowledgeBase.java   |   4 +
 .../resources/test-minimum-autoscaler-rule.drl  |  21 ++-
 .../deployment/partition/Partition.java         |   4 +-
 .../impl/CloudControllerServiceImpl.java        | 186 ++++---------------
 .../interfaces/CloudControllerService.java      |   3 +-
 .../cloud/controller/pojo/MemberContext.java    |  66 +++++--
 .../controller/topology/TopologyManager.java    |  60 +++---
 .../main/resources/CloudControllerService.wsdl  |  41 ++--
 17 files changed, 372 insertions(+), 325 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/560b1c5f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
index 386ac94,8564143..2b2e861
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
@@@ -102,25 -102,14 +103,29 @@@ public class CloudControllerClient 
              throw new PolicyValidationException(e);
          }
      }
 +    
 +    /*
 +     * Calls the CC to validate the partition.
 +     */
 +    public boolean validatePartition(Partition partition) throws PartitionValidationException{
 +        
 +        try {
 +            return stub.validatePartition(partition);
 +        } catch (RemoteException e) {
 +            log.error(e.getMessage());
 +            throw new PartitionValidationException(e);
 +        } catch (CloudControllerServiceInvalidPartitionExceptionException e) {
 +        	throw new PartitionValidationException(e);
 +		}
 +    }
  
-     public void spawnAnInstance(Partition partition, String clusterId) throws SpawningException {
+     public org.apache.stratos.cloud.controller.pojo.MemberContext spawnAnInstance(Partition partition, String clusterId) throws SpawningException {
          try {
-             stub.startInstance(clusterId, partition);
+             org.apache.stratos.cloud.controller.pojo.MemberContext member = new org.apache.stratos.cloud.controller.pojo.MemberContext();
+             member.setClusterId(clusterId);
+             member.setPartition(partition);
+             member.setInitTime(System.currentTimeMillis());
+             return stub.startInstance(member);
          } catch (CloudControllerServiceIllegalArgumentExceptionException e) {
              log.error(e.getMessage());
              throw new SpawningException(e);


[8/9] git commit: Add patition manager

Posted by ud...@apache.org.
Add patition manager


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

Branch: refs/heads/master
Commit: 1d6f1d21aaff43350fcb1d2ddb2241c0c5594e7b
Parents: 8e58ecc
Author: Udara Liyanage <ud...@wso2.com>
Authored: Sat Nov 30 14:43:07 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Sat Nov 30 14:43:07 2013 -0500

----------------------------------------------------------------------
 .../cloud/controller/CloudControllerClient.java |  8 +--
 .../exception/InvalidPartitionException.java    | 40 -----------
 .../exception/PartitionValidationException.java | 19 +++++
 .../exception/TerminationException.java         |  8 +--
 .../autoscaler/partition/PartitionManager.java  | 76 ++++++++++++++++++++
 .../partition/deployers/PartitionDeployer.java  | 18 +++--
 .../partition/deployers/PartitionReader.java    | 16 ++---
 .../deployers/DeploymentPolicyReader.java       | 30 +++-----
 8 files changed, 131 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1d6f1d21/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
index 3da8269..386ac94 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
@@ -23,7 +23,7 @@ import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.Constants;
-import org.apache.stratos.autoscaler.exception.InvalidPartitionException;
+import org.apache.stratos.autoscaler.exception.PartitionValidationException;
 import org.apache.stratos.autoscaler.exception.PolicyValidationException;
 import org.apache.stratos.autoscaler.exception.SpawningException;
 import org.apache.stratos.autoscaler.exception.TerminationException;
@@ -106,15 +106,15 @@ public class CloudControllerClient {
     /*
      * Calls the CC to validate the partition.
      */
-    public boolean validatePartition(Partition partition) throws InvalidPartitionException{
+    public boolean validatePartition(Partition partition) throws PartitionValidationException{
         
         try {
             return stub.validatePartition(partition);
         } catch (RemoteException e) {
             log.error(e.getMessage());
-            throw new InvalidPartitionException(e);
+            throw new PartitionValidationException(e);
         } catch (CloudControllerServiceInvalidPartitionExceptionException e) {
-        	throw new InvalidPartitionException(e);
+        	throw new PartitionValidationException(e);
 		}
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1d6f1d21/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/InvalidPartitionException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/InvalidPartitionException.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/InvalidPartitionException.java
deleted file mode 100644
index c02824d..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/InvalidPartitionException.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.autoscaler.exception;
-
-public class InvalidPartitionException extends Exception {
-
-	private static final long serialVersionUID = -4914522749282514366L;
-	
-	public InvalidPartitionException(String message) {
-		super(message);
-	}
-	
-	public InvalidPartitionException(String message,Throwable e) {
-		super(message,e);
-	}
-	
-	public InvalidPartitionException(Throwable e) {
-		super(e);
-	}
-	
-	
-	
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1d6f1d21/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/PartitionValidationException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/PartitionValidationException.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/PartitionValidationException.java
new file mode 100644
index 0000000..4245dd7
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/PartitionValidationException.java
@@ -0,0 +1,19 @@
+package org.apache.stratos.autoscaler.exception;
+
+/**
+ *
+ */
+public class PartitionValidationException extends Exception {
+
+	private static final long serialVersionUID = -3904452358279522141L;
+
+
+	public PartitionValidationException(String message, Exception exception){
+        super(message, exception);
+    }
+
+
+    public PartitionValidationException(Exception exception){
+        super(exception);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1d6f1d21/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/TerminationException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/TerminationException.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/TerminationException.java
index 8c7ede7..e368379 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/TerminationException.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/TerminationException.java
@@ -1,10 +1,10 @@
 package org.apache.stratos.autoscaler.exception;
 
-/**
- *
- */
 public class TerminationException extends Throwable {
-    public TerminationException(String s, Exception e) {
+
+	private static final long serialVersionUID = -6038793010380236971L;
+
+	public TerminationException(String s, Exception e) {
         super(s, e);
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1d6f1d21/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java
new file mode 100644
index 0000000..e611ae7
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java
@@ -0,0 +1,76 @@
+/*
+ * 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.autoscaler.partition;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.deployment.partition.Partition;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
+
+/**
+ * The model class for managing Partitions.
+ */
+public class PartitionManager {
+
+private static final Log log = LogFactory.getLog(PartitionManager.class);
+	
+	// Partitions against partitionID
+	private static Map<String,Partition> partitionListMap = new HashMap<String, Partition>();
+	
+	private static PartitionManager instance;
+	
+	private PartitionManager(){}
+	
+	public static PartitionManager getInstance(){
+		if(null == instance)
+			return new PartitionManager();
+		else
+			return instance;
+	}
+	
+	public boolean partitionExist(String partitionId){
+		return partitionListMap.containsKey(partitionId);
+	}
+	
+	public void addPartition(String partitionId, Partition partition){
+		if(partitionExist(partitionId))
+			log.error("A partition with the ID " + partitionId +" already exist.");
+		else
+			partitionListMap.put(partitionId, partition);		 
+	}
+	
+	public void removePartition(String partitionId){
+		if(partitionExist(partitionId))
+			partitionListMap.remove(partitionId);
+		else
+			log.error("A partition with the ID " + partitionId +" already does not exist."); 
+	}
+	
+	public Partition getPartitionById(String partitionId){
+		if(partitionExist(partitionId))
+			return partitionListMap.get(partitionId);
+		else
+			return null;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1d6f1d21/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
index df8ae29..9149a45 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
@@ -30,6 +30,7 @@ import org.apache.axis2.deployment.repository.util.DeploymentFileData;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClient;
+import org.apache.stratos.autoscaler.partition.PartitionManager;
 import org.apache.stratos.cloud.controller.deployment.partition.Partition;
 
 /**
@@ -82,12 +83,21 @@ public class PartitionDeployer extends AbstractDeployer {
 			Iterator<Partition> it = partitionList.iterator();
 			
 			while(it.hasNext()){
-				// validate the partition with CC
-				CloudControllerClient.getInstance().validatePartition(it.next());
+				Partition partition = it.next();
+				if(PartitionManager.getInstance().partitionExist(partition.getId())){
+					log.warn("Partition already exists in the system " + partition.getId());
+					continue;
+				}
+				
+				boolean isValid = CloudControllerClient.getInstance().validatePartition(partition);
+				if(!isValid){
+					log.error("Partition is not valid " + partition.getId());
+					continue;					
+				}
+				PartitionManager.getInstance().addPartition(partition.getId(), partition);
 			}			
 
-			log.info("Successfully deployed the partition specified at "
-					+ deploymentFileData.getAbsolutePath());
+			log.info("Successfully deployed the partition specified at "+ deploymentFileData.getAbsolutePath());
 			 
 		} catch (Exception e) {
 			String msg = "Invalid partition artifact at " + deploymentFileData.getAbsolutePath();

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1d6f1d21/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
index 2246e56..ec6e3fd 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
@@ -31,7 +31,6 @@ import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.xpath.AXIOMXPath;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.exception.InvalidPartitionException;
 import org.apache.stratos.cloud.controller.deployment.partition.Partition;
 import org.apache.stratos.cloud.controller.pojo.Properties;
 import org.apache.stratos.cloud.controller.pojo.Property;
@@ -90,15 +89,12 @@ public class PartitionReader{
                 String msg ="Essential " + AutoScalerConstants.ID_ELEMENT + "element " +
                                 "has not specified in ";
                 // handleException(msg);
-            }
-            // boolean partitionExist = TopologyManager.getInstance().getTopology().partitionExist(id);
-            boolean partitionExist =false;
-            if(!partitionExist){
-            	partition = new Partition();
-                partition.setId(id);
-                partition.setProperties(getProperties(iaasElt)); 
-                
-            }            
+            }         
+            	
+            partition = new Partition();               
+            partition.setId(id);
+            partition.setProperties(getProperties(iaasElt)); 
+                                    
         }
         return partition;
     }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1d6f1d21/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyReader.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyReader.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyReader.java
index 60a31fd..7dc235a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyReader.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyReader.java
@@ -30,6 +30,7 @@ import org.apache.axiom.om.OMElement;
 import org.apache.axis2.deployment.DeploymentException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.partition.PartitionManager;
 import org.apache.stratos.autoscaler.policy.InvalidPolicyException;
 import org.apache.stratos.cloud.controller.deployment.partition.Partition;
 import org.apache.stratos.cloud.controller.deployment.partition.PartitionGroup;
@@ -75,31 +76,16 @@ public class DeploymentPolicyReader  extends AbstractPolicyReader<DeploymentPoli
 							Object next = partitionItr.next();
 							if(next instanceof OMElement){
 								OMElement partitionEle = (OMElement) next;
-								Partition partition = new Partition();
-								Properties props = new Properties();
-								List<Property> propertyList = new ArrayList<Property>();
 								
-								Iterator<?> partitionPropItr = partitionEle.getChildrenWithLocalName("property");
-								while(partitionPropItr.hasNext())
-								{
-									Object nextProperty = partitionPropItr.next();
-									if(nextProperty instanceof OMElement){
-										OMElement property = (OMElement)nextProperty;
-										Property prop = new Property();
-										prop.setName(property.getAttributeValue(new QName("name")));
-										prop.setValue(property.getText());
-										propertyList.add(prop);
-									}
-								}
-								if(props.getProperties() == null) {
-								    props.setProperties(new Property[0]);
-								}
-								props.setProperties(propertyList.toArray(props.getProperties()));
-								partition.setProperties(props);
-								partition.setId(partitionEle.getAttributeValue(new QName("id")));
+								String partitionId = partitionEle.getAttributeValue(new QName("id"));
+								Partition partition = PartitionManager.getInstance().getPartitionById(partitionId);
+								// If a partition with this name does not exist in the partition list.
+								if(partition == null)
+									throw new InvalidPolicyException("No Partition found matching ID " + partitionId);
+								
 								partition.setPartitionMax(Integer.valueOf(readValue(partitionEle, "max")));
 								partition.setPartitionMin(Integer.valueOf(readValue(partitionEle, "min")));
-								partition.setProvider(readValue(partitionEle, "provider"));
+//								partition.setProvider(readValue(partitionEle, "provider"));
 								//TODO partition validation before policy deployment
 //								validatePartition();
 								partitions.add(partition);