Repository: stratos
Updated Branches:
  refs/heads/docker-integration 9f374fe07 -> a93781038


http://git-wip-us.apache.org/repos/asf/stratos/blob/d6f49d37/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesClusterMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesClusterMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesClusterMonitor.java
deleted file mode 100644
index ac5be7b..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesClusterMonitor.java
+++ /dev/null
@@ -1,186 +0,0 @@
-package org.apache.stratos.autoscaler.monitor;
-
-import java.util.Properties;
-
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.KubernetesClusterContext;
-import 
org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClient;
-import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
-import org.apache.stratos.autoscaler.util.AutoScalerConstants;
-import org.apache.stratos.autoscaler.util.ConfUtil;
-import org.apache.stratos.common.constants.StratosConstants;
-import org.apache.stratos.messaging.domain.topology.ClusterStatus;
-import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-
-public class KubernetesClusterMonitor implements Runnable{
-       
-       private static final Log log = 
LogFactory.getLog(KubernetesClusterMonitor.class);
-
-       protected KubernetesClusterContext kubernetesClusterCtxt;
-       protected String clusterId;
-       protected String serviceId;
-       protected AutoscalePolicy autoscalePolicy;
-       protected int monitorInterval;
-       protected boolean isDestroyed;
-    private ClusterStatus status;
-    private String lbReferenceType;
-    private boolean hasPrimary;
-    private int numberOfReplicasInServiceCluster = 0;
-    // is container created successfully?
-       boolean success = false;
-       int retryInterval = 60000;
-       
-    public KubernetesClusterMonitor(KubernetesClusterContext 
kubernetesClusterCtxt, String serviceClusterID, String serviceId, 
-               AutoscalePolicy autoscalePolicy) {
-       this.clusterId = serviceClusterID;
-       this.serviceId = serviceId;
-       this.kubernetesClusterCtxt = kubernetesClusterCtxt;
-       this.autoscalePolicy = autoscalePolicy;
-        readConfigurations();
-    }
-
-    private void readConfigurations () {
-       // same as VM cluster monitor interval
-        XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
-        monitorInterval = 
conf.getInt(AutoScalerConstants.AUTOSCALER_MONITOR_INTERVAL, 90000);
-        if (log.isDebugEnabled()) {
-            log.debug("Kubernetes Cluster Monitor task interval: " + 
getMonitorInterval());
-        }
-    }
-       
-       @Override
-       public void run() {
-               try {
-                       // TODO make this configurable,
-                       // this is the delay the min check of normal cluster 
monitor to wait
-                       // until LB monitor is added
-                       Thread.sleep(60000);
-               } catch (InterruptedException ignore) {
-               }
-
-               while (!isDestroyed()) {
-                       if (log.isDebugEnabled()) {
-                               log.debug("Kubernetes cluster monitor is 
running.. " + this.toString());
-                       }
-                       try {
-                               if 
(!ClusterStatus.In_Maintenance.equals(status)) {
-                                       monitor();
-                               } else {
-                                       if (log.isDebugEnabled()) {
-                                               log.debug("Kubernetes cluster 
monitor is suspended as the cluster is in "
-                                                               + 
ClusterStatus.In_Maintenance + " mode......");
-                                       }
-                               }
-                       } catch (Exception e) {
-                               log.error("Kubernetes cluster monitor: Monitor 
failed." + this.toString(),
-                                               e);
-                       }
-                       try {
-                               Thread.sleep(monitorInterval);
-                       } catch (InterruptedException ignore) {
-                       }
-               }
-       }
-       
-       private void monitor() {
-               
-               String kubernetesClusterId = 
this.kubernetesClusterCtxt.getKubernetesClusterID();
-               
-               try {
-                       TopologyManager.acquireReadLock();
-                       Properties props = 
TopologyManager.getTopology().getService(serviceId).getCluster(clusterId).getProperties();
-                       int minReplicas = 
Integer.parseInt(props.getProperty(StratosConstants.KUBERNETES_MIN_REPLICAS));
-
-                       if (this.numberOfReplicasInServiceCluster < 
minReplicas) {
-                               
-                               while (!success) {
-                                       try {
-                                               
CloudControllerClient.getInstance().createContainer(kubernetesClusterId, 
clusterId);
-                                               success = true;
-                                               
numberOfReplicasInServiceCluster = minReplicas;
-                                       } catch (Throwable e) {
-                                               String message = "Cannot create 
a container, will retry in "+(retryInterval/1000)+"s";
-                                               log.debug(message, e);
-                                       }
-                                       
-                       try {
-                           Thread.sleep(retryInterval);
-                       } catch (InterruptedException e1) {
-                       }
-                               }
-                       }
-               } finally {
-                       TopologyManager.releaseReadLock();
-               }
-       }
-
-    @Override
-    public String toString() {
-        return "KubernetesClusterMonitor "
-                       + "[ kubernetesHostClusterId=" + 
this.kubernetesClusterCtxt.getKubernetesClusterID() 
-                       + ", clusterId=" + clusterId 
-                       + ", serviceId=" + serviceId + "]";
-    }
-    
-       public String getServiceId() {
-        return serviceId;
-    }
-
-    public void setServiceId(String serviceId) {
-        this.serviceId = serviceId;
-    }
-    
-    public String getClusterId() {
-        return clusterId;
-    }
-
-    public void setClusterId(String clusterId) {
-        this.clusterId = clusterId;
-    }
-    
-       public AutoscalePolicy getAutoscalePolicy() {
-               return autoscalePolicy;
-       }
-
-       public void setAutoscalePolicy(AutoscalePolicy autoscalePolicy) {
-               this.autoscalePolicy = autoscalePolicy;
-       }
-
-       public int getMonitorInterval() {
-               return monitorInterval;
-       }
-       
-    public ClusterStatus getStatus() {
-        return status;
-    }
-
-    public void setStatus(ClusterStatus status) {
-        this.status = status;
-    }
-    
-    public boolean isDestroyed() {
-        return isDestroyed;
-    }
-
-    public void setDestroyed(boolean isDestroyed) {
-        this.isDestroyed = isDestroyed;
-    }
-
-       public String getLbReferenceType() {
-               return lbReferenceType;
-       }
-
-       public void setLbReferenceType(String lbReferenceType) {
-               this.lbReferenceType = lbReferenceType;
-       }
-
-       public boolean isHasPrimary() {
-               return hasPrimary;
-       }
-
-       public void setHasPrimary(boolean hasPrimary) {
-               this.hasPrimary = hasPrimary;
-       }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/d6f49d37/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/LbClusterMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/LbClusterMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/LbClusterMonitor.java
deleted file mode 100644
index 8d6c40b..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/LbClusterMonitor.java
+++ /dev/null
@@ -1,126 +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.monitor;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.NetworkPartitionContext;
-import org.apache.stratos.autoscaler.PartitionContext;
-import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
-import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
-import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator;
-import org.apache.stratos.messaging.domain.topology.ClusterStatus;
-
-/**
- * Is responsible for monitoring a service cluster. This runs periodically
- * and perform minimum instance check and scaling check using the underlying
- * rules engine.
- *
- */
-public class LbClusterMonitor extends AbstractMonitor{
-
-    private static final Log log = LogFactory.getLog(LbClusterMonitor.class);
-    private ClusterStatus status;
-
-    public LbClusterMonitor(String clusterId, String serviceId, 
DeploymentPolicy deploymentPolicy,
-                            AutoscalePolicy autoscalePolicy) {
-        this.clusterId = clusterId;
-        this.serviceId = serviceId;
-
-        this.autoscalerRuleEvaluator = new AutoscalerRuleEvaluator();
-        this.scaleCheckKnowledgeSession = 
autoscalerRuleEvaluator.getScaleCheckStatefulSession();
-        this.minCheckKnowledgeSession = 
autoscalerRuleEvaluator.getMinCheckStatefulSession();
-
-        this.deploymentPolicy = deploymentPolicy;
-        this.deploymentPolicy = deploymentPolicy;
-        networkPartitionCtxts = new ConcurrentHashMap<String, 
NetworkPartitionContext>();
-    }
-
-    @Override
-    public void run() {
-
-        while (!isDestroyed()) {
-            if (log.isDebugEnabled()) {
-                log.debug("Cluster monitor is running.. "+this.toString());
-            }
-            try {
-                if( !ClusterStatus.In_Maintenance.equals(status)) {
-                    monitor();
-                } else {
-                    if (log.isDebugEnabled()) {
-                        log.debug("LB Cluster monitor is suspended as the 
cluster is in " +
-                                    ClusterStatus.In_Maintenance + " 
mode......");
-                    }
-                }
-            } catch (Exception e) {
-                log.error("Cluster monitor: Monitor failed. "+this.toString(), 
e);
-            }
-            try {
-                Thread.sleep(monitorInterval);
-            } catch (InterruptedException ignore) {
-            }
-        }
-    }
-    
-    private void monitor() {
-        // TODO make this concurrent
-        for (NetworkPartitionContext networkPartitionContext : 
networkPartitionCtxts.values()) {
-
-            // minimum check per partition
-            for (PartitionContext partitionContext : 
networkPartitionContext.getPartitionCtxts()
-                                                                            
.values()) {
-
-                if (partitionContext != null) {
-                    minCheckKnowledgeSession.setGlobal("clusterId", clusterId);
-                    minCheckKnowledgeSession.setGlobal("isPrimary", false);
-                    
-                    if (log.isDebugEnabled()) {
-                        log.debug(String.format("Running minimum check for 
partition %s ",
-                                                
partitionContext.getPartitionId()));
-                    }
-
-                    minCheckFactHandle =
-                                         
AutoscalerRuleEvaluator.evaluateMinCheck(minCheckKnowledgeSession,
-                                                                               
   minCheckFactHandle,
-                                                                               
   partitionContext);
-                    // start only in the first partition context
-                    break;
-                }
-
-            }
-
-        }
-    }       
-
-    @Override
-    public String toString() {
-        return "LbClusterMonitor [clusterId=" + clusterId + ", serviceId=" + 
serviceId + "]";
-    }
-
-
-    public ClusterStatus getStatus() {
-        return status;
-    }
-
-    public void setStatus(ClusterStatus status) {
-        this.status = status;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/d6f49d37/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMClusterMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMClusterMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMClusterMonitor.java
new file mode 100644
index 0000000..ffd6713
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMClusterMonitor.java
@@ -0,0 +1,120 @@
+/*
+ * 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.monitor;
+
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.NetworkPartitionContext;
+import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
+import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
+import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator;
+import org.apache.stratos.common.enums.ClusterType;
+import org.apache.stratos.messaging.domain.topology.Cluster;
+import org.apache.stratos.messaging.domain.topology.Member;
+import org.apache.stratos.messaging.domain.topology.Service;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
+
+/**
+ * Is responsible for monitoring a service cluster. This runs periodically
+ * and perform minimum instance check and scaling check using the underlying
+ * rules engine.
+ *
+ */
+   abstract public class VMClusterMonitor extends AbstractClusterMonitor{
+
+       private static final Log log = 
LogFactory.getLog(VMClusterMonitor.class);
+       // Map<NetworkpartitionId, Network Partition Context>
+       protected Map<String, NetworkPartitionContext> networkPartitionCtxts;
+       protected DeploymentPolicy deploymentPolicy;
+       protected AutoscalePolicy autoscalePolicy;
+       
+    protected VMClusterMonitor(String clusterId, String serviceId, ClusterType 
clusterType, 
+               AutoscalerRuleEvaluator autoscalerRuleEvaluator, 
+               DeploymentPolicy deploymentPolicy, AutoscalePolicy 
autoscalePolicy, 
+               Map<String, NetworkPartitionContext> networkPartitionCtxts) {
+       super(clusterId, serviceId, clusterType, autoscalerRuleEvaluator);
+       this.deploymentPolicy = deploymentPolicy;
+       this.autoscalePolicy = autoscalePolicy;
+       this.networkPartitionCtxts = networkPartitionCtxts;
+    }
+
+       public NetworkPartitionContext getNetworkPartitionCtxt(Member member) {
+               log.info("***** getNetworkPartitionCtxt " + 
member.getNetworkPartitionId());
+               String networkPartitionId = member.getNetworkPartitionId();
+       if(networkPartitionCtxts.containsKey(networkPartitionId)) {
+               log.info("returnnig network partition context " + 
networkPartitionCtxts.get(networkPartitionId));
+               return networkPartitionCtxts.get(networkPartitionId);
+       }
+       log.info("returning null getNetworkPartitionCtxt");
+           return null;
+       }
+       
+    public String getPartitionOfMember(String memberId){
+        for(Service service: TopologyManager.getTopology().getServices()){
+            for(Cluster cluster: service.getClusters()){
+                if(cluster.memberExists(memberId)){
+                    return cluster.getMember(memberId).getPartitionId();
+                }
+            }
+        }
+        return null;
+       }
+    
+    public DeploymentPolicy getDeploymentPolicy() {
+        return deploymentPolicy;
+    }
+
+    public void setDeploymentPolicy(DeploymentPolicy deploymentPolicy) {
+        this.deploymentPolicy = deploymentPolicy;
+    }
+
+    public AutoscalePolicy getAutoscalePolicy() {
+        return autoscalePolicy;
+    }
+
+    public void setAutoscalePolicy(AutoscalePolicy autoscalePolicy) {
+        this.autoscalePolicy = autoscalePolicy;
+    }    
+
+    public Map<String, NetworkPartitionContext> getNetworkPartitionCtxts() {
+        return networkPartitionCtxts;
+    }
+
+    public NetworkPartitionContext getNetworkPartitionCtxt(String 
networkPartitionId) {
+        return networkPartitionCtxts.get(networkPartitionId);
+    }
+
+    public void setPartitionCtxt(Map<String, NetworkPartitionContext> 
partitionCtxt) {
+        this.networkPartitionCtxts = partitionCtxt;
+    }
+
+    public boolean partitionCtxtAvailable(String partitionId) {
+        return networkPartitionCtxts.containsKey(partitionId);
+    }
+
+    public void addNetworkPartitionCtxt(NetworkPartitionContext ctxt) {
+        this.networkPartitionCtxts.put(ctxt.getId(), ctxt);
+    }
+    
+    public NetworkPartitionContext getPartitionCtxt(String id) {
+        return this.networkPartitionCtxts.get(id);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/d6f49d37/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMLbClusterMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMLbClusterMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMLbClusterMonitor.java
new file mode 100644
index 0000000..666fa75
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMLbClusterMonitor.java
@@ -0,0 +1,135 @@
+/*
+ * 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.monitor;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.NetworkPartitionContext;
+import org.apache.stratos.autoscaler.PartitionContext;
+import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
+import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
+import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator;
+import org.apache.stratos.autoscaler.util.AutoScalerConstants;
+import org.apache.stratos.autoscaler.util.ConfUtil;
+import org.apache.stratos.common.enums.ClusterType;
+import org.apache.stratos.messaging.domain.topology.ClusterStatus;
+
+/**
+ * Is responsible for monitoring a service cluster. This runs periodically
+ * and perform minimum instance check and scaling check using the underlying
+ * rules engine.
+ *
+ */
+public class VMLbClusterMonitor extends VMClusterMonitor{
+
+    private static final Log log = LogFactory.getLog(VMLbClusterMonitor.class);
+
+    public VMLbClusterMonitor(String clusterId, String serviceId, 
DeploymentPolicy deploymentPolicy,
+                            AutoscalePolicy autoscalePolicy) {
+       super(clusterId, serviceId, ClusterType.VMLbCluster, new 
AutoscalerRuleEvaluator(), 
+                       deploymentPolicy, autoscalePolicy, 
+                       new ConcurrentHashMap<String, 
NetworkPartitionContext>());
+        readConfigurations();
+    }
+
+    @Override
+    public void run() {
+
+        while (!isDestroyed()) {
+            if (log.isDebugEnabled()) {
+                log.debug("Cluster monitor is running.. "+this.toString());
+            }
+            try {
+                if( !ClusterStatus.In_Maintenance.equals(getStatus())) {
+                    monitor();
+                } else {
+                    if (log.isDebugEnabled()) {
+                        log.debug("LB Cluster monitor is suspended as the 
cluster is in " +
+                                    ClusterStatus.In_Maintenance + " 
mode......");
+                    }
+                }
+            } catch (Exception e) {
+                log.error("Cluster monitor: Monitor failed. "+this.toString(), 
e);
+            }
+            try {
+                Thread.sleep(getMonitorInterval());
+            } catch (InterruptedException ignore) {
+            }
+        }
+    }
+    
+    @Override
+    protected void monitor() {
+        // TODO make this concurrent
+        for (NetworkPartitionContext networkPartitionContext : 
networkPartitionCtxts.values()) {
+
+            // minimum check per partition
+            for (PartitionContext partitionContext : 
networkPartitionContext.getPartitionCtxts()
+                                                                            
.values()) {
+
+                if (partitionContext != null) {
+                    getMinCheckKnowledgeSession().setGlobal("clusterId", 
getClusterId());
+                    getMinCheckKnowledgeSession().setGlobal("isPrimary", 
false);
+                    
+                    if (log.isDebugEnabled()) {
+                        log.debug(String.format("Running minimum check for 
partition %s ",
+                                                
partitionContext.getPartitionId()));
+                    }
+
+                    minCheckFactHandle =
+                                         
AutoscalerRuleEvaluator.evaluateMinCheck(getMinCheckKnowledgeSession(),
+                                                                               
   minCheckFactHandle,
+                                                                               
   partitionContext);
+                    // start only in the first partition context
+                    break;
+                }
+
+            }
+
+        }
+    }     
+    
+       @Override
+    public void destroy() {
+        getMinCheckKnowledgeSession().dispose();
+        getMinCheckKnowledgeSession().dispose();
+        setDestroyed(true);
+        if(log.isDebugEnabled()) {
+            log.debug("LbClusterMonitor Drools session has been disposed. 
"+this.toString());
+        }
+    }
+    
+    @Override
+    protected void readConfigurations () {
+        XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+        int monitorInterval = 
conf.getInt(AutoScalerConstants.AUTOSCALER_MONITOR_INTERVAL, 90000);
+        setMonitorInterval(monitorInterval);
+        if (log.isDebugEnabled()) {
+            log.debug("LbClusterMonitor task interval: " + 
getMonitorInterval());
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "LbClusterMonitor [clusterId=" + getClusterId() + ", 
serviceId=" + getServiceId() + "]";
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/d6f49d37/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMServiceClusterMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMServiceClusterMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMServiceClusterMonitor.java
new file mode 100644
index 0000000..ed98859
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMServiceClusterMonitor.java
@@ -0,0 +1,231 @@
+/*
+ * 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.monitor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.NetworkPartitionContext;
+import org.apache.stratos.autoscaler.PartitionContext;
+import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
+import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
+import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator;
+import org.apache.stratos.autoscaler.util.AutoScalerConstants;
+import org.apache.stratos.autoscaler.util.ConfUtil;
+import org.apache.stratos.cloud.controller.stub.pojo.MemberContext;
+import org.apache.stratos.cloud.controller.stub.pojo.Properties;
+import org.apache.stratos.cloud.controller.stub.pojo.Property;
+import org.apache.stratos.common.enums.ClusterType;
+import org.apache.stratos.messaging.domain.topology.ClusterStatus;
+
+/**
+ * Is responsible for monitoring a service cluster. This runs periodically
+ * and perform minimum instance check and scaling check using the underlying
+ * rules engine.
+ *
+ */
+public class VMServiceClusterMonitor extends VMClusterMonitor {
+
+    private static final Log log = 
LogFactory.getLog(VMServiceClusterMonitor.class);
+    private String lbReferenceType;
+    private boolean hasPrimary;
+
+    public VMServiceClusterMonitor(String clusterId, String serviceId, 
DeploymentPolicy deploymentPolicy,
+                          AutoscalePolicy autoscalePolicy) {
+       super(clusterId, serviceId, ClusterType.VMServiceCluster, new 
AutoscalerRuleEvaluator(), 
+                       deploymentPolicy, autoscalePolicy, 
+                       new ConcurrentHashMap<String, 
NetworkPartitionContext>());
+        readConfigurations();
+    }
+
+    @Override
+    public void run() {
+
+        try {
+            // TODO make this configurable,
+            // this is the delay the min check of normal cluster monitor to 
wait until LB monitor is added
+            Thread.sleep(60000);
+        } catch (InterruptedException ignore) {
+        }
+
+        while (!isDestroyed()) {
+            if (log.isDebugEnabled()) {
+                log.debug("Cluster monitor is running.. " + this.toString());
+            }
+            try {
+                if(!ClusterStatus.In_Maintenance.equals(getStatus())) {
+                    monitor();
+                } else {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Cluster monitor is suspended as the cluster 
is in " +
+                                    ClusterStatus.In_Maintenance + " 
mode......");
+                    }
+                }
+            } catch (Exception e) {
+                log.error("Cluster monitor: Monitor failed." + 
this.toString(), e);
+            }
+            try {
+                Thread.sleep(getMonitorInterval());
+            } catch (InterruptedException ignore) {
+            }
+        }
+    }
+
+    @Override
+    protected void monitor() {
+
+        //TODO make this concurrent
+        for (NetworkPartitionContext networkPartitionContext : 
networkPartitionCtxts.values()) {
+            // store primary members in the network partition context
+            List<String> primaryMemberListInNetworkPartition = new 
ArrayList<String>();
+
+            //minimum check per partition
+            for (PartitionContext partitionContext : 
networkPartitionContext.getPartitionCtxts().values()) {
+                // store primary members in the partition context
+                List<String> primaryMemberListInPartition = new 
ArrayList<String>();
+                // get active primary members in this partition context
+                for (MemberContext memberContext : 
partitionContext.getActiveMembers()) {
+                    if (isPrimaryMember(memberContext)){
+                        
primaryMemberListInPartition.add(memberContext.getMemberId());
+                    }
+                }
+                // get pending primary members in this partition context
+                for (MemberContext memberContext : 
partitionContext.getPendingMembers()) {
+                    if (isPrimaryMember(memberContext)){
+                        
primaryMemberListInPartition.add(memberContext.getMemberId());
+                    }
+                }
+                
primaryMemberListInNetworkPartition.addAll(primaryMemberListInPartition);
+                getMinCheckKnowledgeSession().setGlobal("clusterId", 
getClusterId());
+                getMinCheckKnowledgeSession().setGlobal("lbRef", 
lbReferenceType);
+                getMinCheckKnowledgeSession().setGlobal("isPrimary", 
hasPrimary);
+                getMinCheckKnowledgeSession().setGlobal("primaryMemberCount", 
primaryMemberListInPartition.size());
+
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Running minimum check for 
partition %s ", partitionContext.getPartitionId()));
+                }
+
+                minCheckFactHandle = 
AutoscalerRuleEvaluator.evaluateMinCheck(getMinCheckKnowledgeSession()
+                        , minCheckFactHandle, partitionContext);
+
+            }
+
+            boolean rifReset = networkPartitionContext.isRifReset();
+            boolean memoryConsumptionReset = 
networkPartitionContext.isMemoryConsumptionReset();
+            boolean loadAverageReset = 
networkPartitionContext.isLoadAverageReset();
+            if (log.isDebugEnabled()) {
+                log.debug("flag of rifReset: "  + rifReset + " flag of 
memoryConsumptionReset" + memoryConsumptionReset
+                        + " flag of loadAverageReset" + loadAverageReset);
+            }
+            if (rifReset || memoryConsumptionReset || loadAverageReset) {
+               getScaleCheckKnowledgeSession().setGlobal("clusterId", 
getClusterId());
+                //scaleCheckKnowledgeSession.setGlobal("deploymentPolicy", 
deploymentPolicy);
+               getScaleCheckKnowledgeSession().setGlobal("autoscalePolicy", 
autoscalePolicy);
+               getScaleCheckKnowledgeSession().setGlobal("rifReset", rifReset);
+               getScaleCheckKnowledgeSession().setGlobal("mcReset", 
memoryConsumptionReset);
+               getScaleCheckKnowledgeSession().setGlobal("laReset", 
loadAverageReset);
+               getScaleCheckKnowledgeSession().setGlobal("lbRef", 
lbReferenceType);
+               getScaleCheckKnowledgeSession().setGlobal("isPrimary", false);
+               getScaleCheckKnowledgeSession().setGlobal("primaryMembers", 
primaryMemberListInNetworkPartition);
+
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Running scale check for network 
partition %s ", networkPartitionContext.getId()));
+                    log.debug(" Primary members : " + 
primaryMemberListInNetworkPartition);
+                }
+
+                scaleCheckFactHandle = 
AutoscalerRuleEvaluator.evaluateScaleCheck(getScaleCheckKnowledgeSession()
+                        , scaleCheckFactHandle, networkPartitionContext);
+
+                networkPartitionContext.setRifReset(false);
+                networkPartitionContext.setMemoryConsumptionReset(false);
+                networkPartitionContext.setLoadAverageReset(false);
+            } else if (log.isDebugEnabled()) {
+                log.debug(String.format("Scale rule will not run since the LB 
statistics have not received before this " +
+                        "cycle for network partition %s", 
networkPartitionContext.getId()));
+            }
+        }
+    }
+    
+    private boolean isPrimaryMember(MemberContext memberContext){
+        Properties props = memberContext.getProperties();
+        if (log.isDebugEnabled()) {
+            log.debug(" Properties [" + props + "] ");
+        }
+        if (props != null && props.getProperties() != null) {
+            for (Property prop : props.getProperties()) {
+                if (prop.getName().equals("PRIMARY")) {
+                    if (Boolean.parseBoolean(prop.getValue())) {
+                        log.debug("Adding member id [" + 
memberContext.getMemberId() + "] " +
+                                "member instance id [" + 
memberContext.getInstanceId() + "] as a primary member");
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+    
+    @Override
+    protected void readConfigurations () {
+        XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+        int monitorInterval = 
conf.getInt(AutoScalerConstants.AUTOSCALER_MONITOR_INTERVAL, 90000);
+        setMonitorInterval(monitorInterval);
+        if (log.isDebugEnabled()) {
+            log.debug("Cluster Monitor task interval: " + 
getMonitorInterval());
+        }
+    }
+    
+       @Override
+    public void destroy() {
+        getMinCheckKnowledgeSession().dispose();
+        getScaleCheckKnowledgeSession().dispose();
+        setDestroyed(true);
+        if(log.isDebugEnabled()) {
+            log.debug("Cluster Monitor Drools session has been disposed. 
"+this.toString());
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "ClusterMonitor [clusterId=" + getClusterId() + ", serviceId=" 
+ getServiceId() +
+                ", deploymentPolicy=" + deploymentPolicy + ", 
autoscalePolicy=" + autoscalePolicy +
+                ", lbReferenceType=" + lbReferenceType +
+                ", hasPrimary=" + hasPrimary + " ]";
+    }
+
+    public String getLbReferenceType() {
+        return lbReferenceType;
+    }
+
+    public void setLbReferenceType(String lbReferenceType) {
+        this.lbReferenceType = lbReferenceType;
+    }
+
+    public boolean isHasPrimary() {
+        return hasPrimary;
+    }
+
+    public void setHasPrimary(boolean hasPrimary) {
+        this.hasPrimary = hasPrimary;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/d6f49d37/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 1bc9ce7..4f58e8d 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
@@ -31,9 +31,9 @@ import 
org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClie
 import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
 import org.apache.stratos.autoscaler.exception.PartitionValidationException;
 import org.apache.stratos.autoscaler.exception.PolicyValidationException;
-import org.apache.stratos.autoscaler.monitor.ClusterMonitor;
-import org.apache.stratos.autoscaler.monitor.KubernetesClusterMonitor;
-import org.apache.stratos.autoscaler.monitor.LbClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.VMServiceClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.DockerServiceClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.VMLbClusterMonitor;
 import org.apache.stratos.autoscaler.partition.PartitionGroup;
 import org.apache.stratos.autoscaler.partition.PartitionManager;
 import org.apache.stratos.autoscaler.policy.PolicyManager;
@@ -73,292 +73,292 @@ public class AutoscalerUtil {
      * @throws PolicyValidationException
      * @throws PartitionValidationException
      */
-    public static ClusterMonitor getClusterMonitor(Cluster cluster) throws 
PolicyValidationException, PartitionValidationException {
-        // FIXME fix the following code to correctly update
-        // AutoscalerContext context = AutoscalerContext.getInstance();
-        if (null == cluster) {
-            return null;
-        }
-
-        String autoscalePolicyName = cluster.getAutoscalePolicyName();
-        String deploymentPolicyName = cluster.getDeploymentPolicyName();
-
-        if (log.isDebugEnabled()) {
-            log.debug("Deployment policy name: " + deploymentPolicyName);
-            log.debug("Autoscaler policy name: " + autoscalePolicyName);
-        }
-
-        AutoscalePolicy policy =
-                                 PolicyManager.getInstance()
-                                              
.getAutoscalePolicy(autoscalePolicyName);
-        DeploymentPolicy deploymentPolicy =
-                                            PolicyManager.getInstance()
-                                                         
.getDeploymentPolicy(deploymentPolicyName);
-
-        if (deploymentPolicy == null) {
-            String msg = "Deployment Policy is null. Policy name: " + 
deploymentPolicyName;
-            log.error(msg);
-            throw new PolicyValidationException(msg);
-        }
-
-        Partition[] allPartitions = deploymentPolicy.getAllPartitions();
-        if (allPartitions == null) {
-            String msg =
-                         "Deployment Policy's Partitions are null. Policy 
name: " +
-                                 deploymentPolicyName;
-            log.error(msg);
-            throw new PolicyValidationException(msg);
-        }
-
-        
CloudControllerClient.getInstance().validateDeploymentPolicy(cluster.getServiceName(),
 deploymentPolicy);
-
-        ClusterMonitor clusterMonitor =
-                                        new 
ClusterMonitor(cluster.getClusterId(),
-                                                           
cluster.getServiceName(),
-                                                           deploymentPolicy, 
policy);
-        clusterMonitor.setStatus(ClusterStatus.Created);
-        
-        for (PartitionGroup partitionGroup: 
deploymentPolicy.getPartitionGroups()){
-
-            NetworkPartitionContext networkPartitionContext = new 
NetworkPartitionContext(partitionGroup.getId(),
-                    partitionGroup.getPartitionAlgo(), 
partitionGroup.getPartitions());
-
-            for(Partition partition: partitionGroup.getPartitions()){
-                PartitionContext partitionContext = new 
PartitionContext(partition);
-                partitionContext.setServiceName(cluster.getServiceName());
-                partitionContext.setProperties(cluster.getProperties());
-                partitionContext.setNetworkPartitionId(partitionGroup.getId());
-                
-                for (Member member: cluster.getMembers()){
-                    String memberId = member.getMemberId();
-                    
if(member.getPartitionId().equalsIgnoreCase(partition.getId())){
-                        MemberContext memberContext = new MemberContext();
-                        memberContext.setClusterId(member.getClusterId());
-                        memberContext.setMemberId(memberId);
-                        memberContext.setPartition(partition);
-                        
memberContext.setProperties(convertMemberPropsToMemberContextProps(member.getProperties()));
-                        
-                        if(MemberStatus.Activated.equals(member.getStatus())){
-                            partitionContext.addActiveMember(memberContext);
-//                            
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
-//                            
partitionContext.incrementCurrentActiveMemberCount(1);
-
-                        } else 
if(MemberStatus.Created.equals(member.getStatus()) || 
MemberStatus.Starting.equals(member.getStatus())){
-                            partitionContext.addPendingMember(memberContext);
-
-//                            
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
-                        } else 
if(MemberStatus.Suspended.equals(member.getStatus())){
-//                            partitionContext.addFaultyMember(memberId);
-                        }
-                        partitionContext.addMemberStatsContext(new 
MemberStatsContext(memberId));
-                        if(log.isInfoEnabled()){
-                            log.info(String.format("Member stat context has 
been added: [member] %s", memberId));
-                        }
-                    }
-
-                }
-                networkPartitionContext.addPartitionContext(partitionContext);
-                if(log.isInfoEnabled()){
-                    log.info(String.format("Partition context has been added: 
[partition] %s",
-                            partitionContext.getPartitionId()));
-                }
-            }
-
-            clusterMonitor.addNetworkPartitionCtxt(networkPartitionContext);
-            if(log.isInfoEnabled()){
-                log.info(String.format("Network partition context has been 
added: [network partition] %s",
-                            networkPartitionContext.getId()));
-            }
-        }
-        
-        
-        // find lb reference type
-        java.util.Properties props = cluster.getProperties();
-        
-        if(props.containsKey(Constants.LOAD_BALANCER_REF)) {
-            String value = props.getProperty(Constants.LOAD_BALANCER_REF);
-            clusterMonitor.setLbReferenceType(value);
-            if(log.isDebugEnabled()) {
-                log.debug("Set the lb reference type: "+value);
-            }
-        }
-        
-        // set hasPrimary property
-        // hasPrimary is true if there are primary members available in that 
cluster
-        
clusterMonitor.setHasPrimary(Boolean.parseBoolean(cluster.getProperties().getProperty(Constants.IS_PRIMARY)));
-
-        log.info("Cluster monitor created: "+clusterMonitor.toString());
-        return clusterMonitor;
-    }
-    
-    private static Properties convertMemberPropsToMemberContextProps(
-                       java.util.Properties properties) {
-       Properties props = new Properties();
-       for (Map.Entry<Object, Object> e : properties.entrySet()        ) {
-                       Property prop = new Property();
-                       prop.setName((String)e.getKey());
-                       prop.setValue((String)e.getValue());
-                       props.addProperties(prop);
-               }       
-               return props;
-       }
-
-
-       public static LbClusterMonitor getLBClusterMonitor(Cluster cluster) 
throws PolicyValidationException, PartitionValidationException {
-        // FIXME fix the following code to correctly update
-        // AutoscalerContext context = AutoscalerContext.getInstance();
-        if (null == cluster) {
-            return null;
-        }
-
-        String autoscalePolicyName = cluster.getAutoscalePolicyName();
-        String deploymentPolicyName = cluster.getDeploymentPolicyName();
-
-        if (log.isDebugEnabled()) {
-            log.debug("Deployment policy name: " + deploymentPolicyName);
-            log.debug("Autoscaler policy name: " + autoscalePolicyName);
-        }
-
-        AutoscalePolicy policy =
-                                 PolicyManager.getInstance()
-                                              
.getAutoscalePolicy(autoscalePolicyName);
-        DeploymentPolicy deploymentPolicy =
-                                            PolicyManager.getInstance()
-                                                         
.getDeploymentPolicy(deploymentPolicyName);
-
-        if (deploymentPolicy == null) {
-            String msg = "Deployment Policy is null. Policy name: " + 
deploymentPolicyName;
-            log.error(msg);
-            throw new PolicyValidationException(msg);
-        }
-
-        String clusterId = cluster.getClusterId();
-        LbClusterMonitor clusterMonitor =
-                                        new LbClusterMonitor(clusterId,
-                                                           
cluster.getServiceName(),
-                                                           deploymentPolicy, 
policy);
-        clusterMonitor.setStatus(ClusterStatus.Created);
-        // partition group = network partition context
-        for (PartitionGroup partitionGroup : 
deploymentPolicy.getPartitionGroups()) {
-
-            NetworkPartitionLbHolder networkPartitionLbHolder =
-                                                              
PartitionManager.getInstance()
-                                                                              
.getNetworkPartitionLbHolder(partitionGroup.getId());
+//    public static ClusterMonitor getClusterMonitor(Cluster cluster) throws 
PolicyValidationException, PartitionValidationException {
+//        // FIXME fix the following code to correctly update
+//        // AutoscalerContext context = AutoscalerContext.getInstance();
+//        if (null == cluster) {
+//            return null;
+//        }
+//
+//        String autoscalePolicyName = cluster.getAutoscalePolicyName();
+//        String deploymentPolicyName = cluster.getDeploymentPolicyName();
+//
+//        if (log.isDebugEnabled()) {
+//            log.debug("Deployment policy name: " + deploymentPolicyName);
+//            log.debug("Autoscaler policy name: " + autoscalePolicyName);
+//        }
+//
+//        AutoscalePolicy policy =
+//                                 PolicyManager.getInstance()
+//                                              
.getAutoscalePolicy(autoscalePolicyName);
+//        DeploymentPolicy deploymentPolicy =
+//                                            PolicyManager.getInstance()
+//                                                         
.getDeploymentPolicy(deploymentPolicyName);
+//
+//        if (deploymentPolicy == null) {
+//            String msg = "Deployment Policy is null. Policy name: " + 
deploymentPolicyName;
+//            log.error(msg);
+//            throw new PolicyValidationException(msg);
+//        }
+//
+//        Partition[] allPartitions = deploymentPolicy.getAllPartitions();
+//        if (allPartitions == null) {
+//            String msg =
+//                         "Deployment Policy's Partitions are null. Policy 
name: " +
+//                                 deploymentPolicyName;
+//            log.error(msg);
+//            throw new PolicyValidationException(msg);
+//        }
+//
+//        
CloudControllerClient.getInstance().validateDeploymentPolicy(cluster.getServiceName(),
 deploymentPolicy);
+//
+//        ClusterMonitor clusterMonitor =
+//                                        new 
ClusterMonitor(cluster.getClusterId(),
+//                                                           
cluster.getServiceName(),
+//                                                           deploymentPolicy, 
policy);
+//        clusterMonitor.setStatus(ClusterStatus.Created);
+//        
+//        for (PartitionGroup partitionGroup: 
deploymentPolicy.getPartitionGroups()){
+//
+//            NetworkPartitionContext networkPartitionContext = new 
NetworkPartitionContext(partitionGroup.getId(),
+//                    partitionGroup.getPartitionAlgo(), 
partitionGroup.getPartitions());
+//
+//            for(Partition partition: partitionGroup.getPartitions()){
+//                PartitionContext partitionContext = new 
PartitionContext(partition);
+//                partitionContext.setServiceName(cluster.getServiceName());
+//                partitionContext.setProperties(cluster.getProperties());
+//                
partitionContext.setNetworkPartitionId(partitionGroup.getId());
+//                
+//                for (Member member: cluster.getMembers()){
+//                    String memberId = member.getMemberId();
+//                    
if(member.getPartitionId().equalsIgnoreCase(partition.getId())){
+//                        MemberContext memberContext = new MemberContext();
+//                        memberContext.setClusterId(member.getClusterId());
+//                        memberContext.setMemberId(memberId);
+//                        memberContext.setPartition(partition);
+//                        
memberContext.setProperties(convertMemberPropsToMemberContextProps(member.getProperties()));
+//                        
+//                        
if(MemberStatus.Activated.equals(member.getStatus())){
+//                            partitionContext.addActiveMember(memberContext);
+////                            
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
+////                            
partitionContext.incrementCurrentActiveMemberCount(1);
+//
+//                        } else 
if(MemberStatus.Created.equals(member.getStatus()) || 
MemberStatus.Starting.equals(member.getStatus())){
+//                            partitionContext.addPendingMember(memberContext);
+//
+////                            
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
+//                        } else 
if(MemberStatus.Suspended.equals(member.getStatus())){
+////                            partitionContext.addFaultyMember(memberId);
+//                        }
+//                        partitionContext.addMemberStatsContext(new 
MemberStatsContext(memberId));
+//                        if(log.isInfoEnabled()){
+//                            log.info(String.format("Member stat context has 
been added: [member] %s", memberId));
+//                        }
+//                    }
+//
+//                }
+//                
networkPartitionContext.addPartitionContext(partitionContext);
+//                if(log.isInfoEnabled()){
+//                    log.info(String.format("Partition context has been 
added: [partition] %s",
+//                            partitionContext.getPartitionId()));
+//                }
+//            }
+//
+//            clusterMonitor.addNetworkPartitionCtxt(networkPartitionContext);
+//            if(log.isInfoEnabled()){
+//                log.info(String.format("Network partition context has been 
added: [network partition] %s",
+//                            networkPartitionContext.getId()));
+//            }
+//        }
+//        
+//        
+//        // find lb reference type
+//        java.util.Properties props = cluster.getProperties();
+//        
+//        if(props.containsKey(Constants.LOAD_BALANCER_REF)) {
+//            String value = props.getProperty(Constants.LOAD_BALANCER_REF);
+//            clusterMonitor.setLbReferenceType(value);
+//            if(log.isDebugEnabled()) {
+//                log.debug("Set the lb reference type: "+value);
+//            }
+//        }
+//        
+//        // set hasPrimary property
+//        // hasPrimary is true if there are primary members available in that 
cluster
+//        
clusterMonitor.setHasPrimary(Boolean.parseBoolean(cluster.getProperties().getProperty(Constants.IS_PRIMARY)));
+//
+//        log.info("Cluster monitor created: "+clusterMonitor.toString());
+//        return clusterMonitor;
+//    }
+//    
+//    private static Properties convertMemberPropsToMemberContextProps(
+//                     java.util.Properties properties) {
+//     Properties props = new Properties();
+//     for (Map.Entry<Object, Object> e : properties.entrySet()        ) {
+//                     Property prop = new Property();
+//                     prop.setName((String)e.getKey());
+//                     prop.setValue((String)e.getValue());
+//                     props.addProperties(prop);
+//             }       
+//             return props;
+//     }
+//
+//
+//     public static LbClusterMonitor getLBClusterMonitor(Cluster cluster) 
throws PolicyValidationException, PartitionValidationException {
+//        // FIXME fix the following code to correctly update
+//        // AutoscalerContext context = AutoscalerContext.getInstance();
+//        if (null == cluster) {
+//            return null;
+//        }
+//
+//        String autoscalePolicyName = cluster.getAutoscalePolicyName();
+//        String deploymentPolicyName = cluster.getDeploymentPolicyName();
+//
+//        if (log.isDebugEnabled()) {
+//            log.debug("Deployment policy name: " + deploymentPolicyName);
+//            log.debug("Autoscaler policy name: " + autoscalePolicyName);
+//        }
+//
+//        AutoscalePolicy policy =
+//                                 PolicyManager.getInstance()
+//                                              
.getAutoscalePolicy(autoscalePolicyName);
+//        DeploymentPolicy deploymentPolicy =
+//                                            PolicyManager.getInstance()
+//                                                         
.getDeploymentPolicy(deploymentPolicyName);
+//
+//        if (deploymentPolicy == null) {
+//            String msg = "Deployment Policy is null. Policy name: " + 
deploymentPolicyName;
+//            log.error(msg);
+//            throw new PolicyValidationException(msg);
+//        }
+//
+//        String clusterId = cluster.getClusterId();
+//        LbClusterMonitor clusterMonitor =
+//                                        new LbClusterMonitor(clusterId,
+//                                                           
cluster.getServiceName(),
+//                                                           deploymentPolicy, 
policy);
+//        clusterMonitor.setStatus(ClusterStatus.Created);
+//        // partition group = network partition context
+//        for (PartitionGroup partitionGroup : 
deploymentPolicy.getPartitionGroups()) {
+//
+//            NetworkPartitionLbHolder networkPartitionLbHolder =
 //                                                              
PartitionManager.getInstance()
 //                                                                             
 .getNetworkPartitionLbHolder(partitionGroup.getId());
-            // FIXME pick a random partition
-            Partition partition =
-                                  partitionGroup.getPartitions()[new 
Random().nextInt(partitionGroup.getPartitions().length)];
-            PartitionContext partitionContext = new 
PartitionContext(partition);
-            partitionContext.setServiceName(cluster.getServiceName());
-            partitionContext.setProperties(cluster.getProperties());
-            partitionContext.setNetworkPartitionId(partitionGroup.getId());
-            partitionContext.setMinimumMemberCount(1);//Here it hard codes the 
minimum value as one for LB cartridge partitions
-
-            NetworkPartitionContext networkPartitionContext = new 
NetworkPartitionContext(partitionGroup.getId(),
-                    partitionGroup.getPartitionAlgo(), 
partitionGroup.getPartitions()) ;
-            for (Member member : cluster.getMembers()) {
-                String memberId = member.getMemberId();
-                if 
(member.getNetworkPartitionId().equalsIgnoreCase(networkPartitionContext.getId()))
 {
-                    MemberContext memberContext = new MemberContext();
-                    memberContext.setClusterId(member.getClusterId());
-                    memberContext.setMemberId(memberId);
-                    memberContext.setPartition(partition);
-
-                    if (MemberStatus.Activated.equals(member.getStatus())) {
-                        partitionContext.addActiveMember(memberContext);
-//                        
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
-//                        
partitionContext.incrementCurrentActiveMemberCount(1);
-                    } else if (MemberStatus.Created.equals(member.getStatus()) 
||
-                               
MemberStatus.Starting.equals(member.getStatus())) {
-                        partitionContext.addPendingMember(memberContext);
-//                        
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
-                    } else if 
(MemberStatus.Suspended.equals(member.getStatus())) {
-//                        partitionContext.addFaultyMember(memberId);
-                    }
-
-                    partitionContext.addMemberStatsContext(new 
MemberStatsContext(memberId));
-                    if(log.isInfoEnabled()){
-                        log.info(String.format("Member stat context has been 
added: [member] %s", memberId));
-                    }
-                }
-
-            }
-            networkPartitionContext.addPartitionContext(partitionContext);
-            
-            // populate lb cluster id in network partition context.
-            java.util.Properties props = cluster.getProperties();
-
-            // get service type of load balanced cluster
-            String loadBalancedServiceType = 
props.getProperty(Constants.LOAD_BALANCED_SERVICE_TYPE);
-            
-            if(props.containsKey(Constants.LOAD_BALANCER_REF)) {
-                String value = props.getProperty(Constants.LOAD_BALANCER_REF);
-                
-                if 
(value.equals(org.apache.stratos.messaging.util.Constants.DEFAULT_LOAD_BALANCER))
 {
-                    networkPartitionLbHolder.setDefaultLbClusterId(clusterId);
-
-                } else if 
(value.equals(org.apache.stratos.messaging.util.Constants.SERVICE_AWARE_LOAD_BALANCER))
 {
-                    String serviceName = cluster.getServiceName();
-                    // TODO: check if this is correct
-                    networkPartitionLbHolder.addServiceLB(serviceName, 
clusterId);
-
-                    if (loadBalancedServiceType != null && 
!loadBalancedServiceType.isEmpty()) {
-                        
networkPartitionLbHolder.addServiceLB(loadBalancedServiceType, clusterId);
-                        if (log.isDebugEnabled()) {
-                            log.debug("Added cluster id " + clusterId + " as 
the LB cluster id for service type " + loadBalancedServiceType);
-                        }
-                    }
-                }
-            }
-
-            clusterMonitor.addNetworkPartitionCtxt(networkPartitionContext);
-        }
-
-        log.info("LB Cluster monitor created: "+clusterMonitor.toString());
-        return clusterMonitor;
-    }
-       
-    public static KubernetesClusterMonitor getKubernetesClusterMonitor(Cluster 
cluster) {
-
-       if (null == cluster) {
-            return null;
-        }
-
-        String autoscalePolicyName = cluster.getAutoscalePolicyName();
-        if (log.isDebugEnabled()) {
-            log.debug("Autoscaler policy name: " + autoscalePolicyName);
-        }
-
-        AutoscalePolicy policy = 
PolicyManager.getInstance().getAutoscalePolicy(autoscalePolicyName);
-        java.util.Properties props = cluster.getProperties();
-        String kubernetesHostClusterID = 
props.getProperty(StratosConstants.KUBERNETES_CLUSTER_ID);
-               KubernetesClusterContext kubernetesClusterCtxt = new 
KubernetesClusterContext(kubernetesHostClusterID);
-
-        KubernetesClusterMonitor kubernetesClusterMonitor = new 
KubernetesClusterMonitor(
-                       kubernetesClusterCtxt, 
-                       cluster.getClusterId(), 
-                       cluster.getServiceName(), 
-                       policy);
-                                        
-        kubernetesClusterMonitor.setStatus(ClusterStatus.Created);
-        
-        // find lb reference type
-        if(props.containsKey(Constants.LOAD_BALANCER_REF)) {
-            String value = props.getProperty(Constants.LOAD_BALANCER_REF);
-            kubernetesClusterMonitor.setLbReferenceType(value);
-            if(log.isDebugEnabled()) {
-                log.debug("Set the lb reference type: "+value);
-            }
-        }
-        
-        // set hasPrimary property
-        // hasPrimary is true if there are primary members available in that 
cluster
-        
kubernetesClusterMonitor.setHasPrimary(Boolean.parseBoolean(props.getProperty(Constants.IS_PRIMARY)));
-
-        log.info("Kubernetes cluster monitor created: "+ 
kubernetesClusterMonitor.toString());
-        return kubernetesClusterMonitor;
-    }
+////                                                              
PartitionManager.getInstance()
+////                                                                           
   .getNetworkPartitionLbHolder(partitionGroup.getId());
+//            // FIXME pick a random partition
+//            Partition partition =
+//                                  partitionGroup.getPartitions()[new 
Random().nextInt(partitionGroup.getPartitions().length)];
+//            PartitionContext partitionContext = new 
PartitionContext(partition);
+//            partitionContext.setServiceName(cluster.getServiceName());
+//            partitionContext.setProperties(cluster.getProperties());
+//            partitionContext.setNetworkPartitionId(partitionGroup.getId());
+//            partitionContext.setMinimumMemberCount(1);//Here it hard codes 
the minimum value as one for LB cartridge partitions
+//
+//            NetworkPartitionContext networkPartitionContext = new 
NetworkPartitionContext(partitionGroup.getId(),
+//                    partitionGroup.getPartitionAlgo(), 
partitionGroup.getPartitions()) ;
+//            for (Member member : cluster.getMembers()) {
+//                String memberId = member.getMemberId();
+//                if 
(member.getNetworkPartitionId().equalsIgnoreCase(networkPartitionContext.getId()))
 {
+//                    MemberContext memberContext = new MemberContext();
+//                    memberContext.setClusterId(member.getClusterId());
+//                    memberContext.setMemberId(memberId);
+//                    memberContext.setPartition(partition);
+//
+//                    if (MemberStatus.Activated.equals(member.getStatus())) {
+//                        partitionContext.addActiveMember(memberContext);
+////                        
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
+////                        
partitionContext.incrementCurrentActiveMemberCount(1);
+//                    } else if 
(MemberStatus.Created.equals(member.getStatus()) ||
+//                               
MemberStatus.Starting.equals(member.getStatus())) {
+//                        partitionContext.addPendingMember(memberContext);
+////                        
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
+//                    } else if 
(MemberStatus.Suspended.equals(member.getStatus())) {
+////                        partitionContext.addFaultyMember(memberId);
+//                    }
+//
+//                    partitionContext.addMemberStatsContext(new 
MemberStatsContext(memberId));
+//                    if(log.isInfoEnabled()){
+//                        log.info(String.format("Member stat context has been 
added: [member] %s", memberId));
+//                    }
+//                }
+//
+//            }
+//            networkPartitionContext.addPartitionContext(partitionContext);
+//            
+//            // populate lb cluster id in network partition context.
+//            java.util.Properties props = cluster.getProperties();
+//
+//            // get service type of load balanced cluster
+//            String loadBalancedServiceType = 
props.getProperty(Constants.LOAD_BALANCED_SERVICE_TYPE);
+//            
+//            if(props.containsKey(Constants.LOAD_BALANCER_REF)) {
+//                String value = 
props.getProperty(Constants.LOAD_BALANCER_REF);
+//                
+//                if 
(value.equals(org.apache.stratos.messaging.util.Constants.DEFAULT_LOAD_BALANCER))
 {
+//                    
networkPartitionLbHolder.setDefaultLbClusterId(clusterId);
+//
+//                } else if 
(value.equals(org.apache.stratos.messaging.util.Constants.SERVICE_AWARE_LOAD_BALANCER))
 {
+//                    String serviceName = cluster.getServiceName();
+//                    // TODO: check if this is correct
+//                    networkPartitionLbHolder.addServiceLB(serviceName, 
clusterId);
+//
+//                    if (loadBalancedServiceType != null && 
!loadBalancedServiceType.isEmpty()) {
+//                        
networkPartitionLbHolder.addServiceLB(loadBalancedServiceType, clusterId);
+//                        if (log.isDebugEnabled()) {
+//                            log.debug("Added cluster id " + clusterId + " as 
the LB cluster id for service type " + loadBalancedServiceType);
+//                        }
+//                    }
+//                }
+//            }
+//
+//            clusterMonitor.addNetworkPartitionCtxt(networkPartitionContext);
+//        }
+//
+//        log.info("LB Cluster monitor created: "+clusterMonitor.toString());
+//        return clusterMonitor;
+//    }
+//     
+//    public static DockerClusterMonitor getDockerClusterMonitor(Cluster 
cluster) {
+//
+//     if (null == cluster) {
+//            return null;
+//        }
+//
+//        String autoscalePolicyName = cluster.getAutoscalePolicyName();
+//        if (log.isDebugEnabled()) {
+//            log.debug("Autoscaler policy name: " + autoscalePolicyName);
+//        }
+//
+//        AutoscalePolicy policy = 
PolicyManager.getInstance().getAutoscalePolicy(autoscalePolicyName);
+//        java.util.Properties props = cluster.getProperties();
+//        String kubernetesHostClusterID = 
props.getProperty(StratosConstants.KUBERNETES_CLUSTER_ID);
+//             KubernetesClusterContext kubernetesClusterCtxt = new 
KubernetesClusterContext(kubernetesHostClusterID);
+//
+//        DockerClusterMonitor dockerClusterMonitor = new DockerClusterMonitor(
+//                     kubernetesClusterCtxt, 
+//                     cluster.getClusterId(), 
+//                     cluster.getServiceName(), 
+//                     policy);
+//                                        
+//        dockerClusterMonitor.setStatus(ClusterStatus.Created);
+//        
+//        // find lb reference type
+//        if(props.containsKey(Constants.LOAD_BALANCER_REF)) {
+//            String value = props.getProperty(Constants.LOAD_BALANCER_REF);
+//            dockerClusterMonitor.setLbReferenceType(value);
+//            if(log.isDebugEnabled()) {
+//                log.debug("Set the lb reference type: "+value);
+//            }
+//        }
+//        
+////        // set hasPrimary property
+////        // hasPrimary is true if there are primary members available in 
that cluster
+////        
dockerClusterMonitor.setHasPrimary(Boolean.parseBoolean(props.getProperty(Constants.IS_PRIMARY)));
+//
+//        log.info("Docker cluster monitor created: "+ 
dockerClusterMonitor.toString());
+//        return dockerClusterMonitor;
+//    }
     
     public static Properties getProperties(final OMElement elt) {
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/d6f49d37/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/enums/ClusterType.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/enums/ClusterType.java
 
b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/enums/ClusterType.java
new file mode 100644
index 0000000..8842fb6
--- /dev/null
+++ 
b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/enums/ClusterType.java
@@ -0,0 +1,5 @@
+package org.apache.stratos.common.enums;
+
+public enum ClusterType {
+       VMServiceCluster, VMLbCluster, DockerServiceCluster, DockerLbCluster;
+}

Reply via email to