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 <[email protected]>
Authored: Fri Nov 29 09:02:31 2013 -0500
Committer: Udara Liyanage <[email protected]>
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>
 

Reply via email to