Adding package structure for context classes

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

Branch: refs/heads/master
Commit: c20d28c2493115db5fe8e834e2501895aff3ad1a
Parents: e171d58
Author: Lahiru Sandaruwan <[email protected]>
Authored: Fri Nov 28 14:20:11 2014 +0530
Committer: Lahiru Sandaruwan <[email protected]>
Committed: Fri Nov 28 14:20:11 2014 +0530

----------------------------------------------------------------------
 .../autoscaler/AbstractClusterContext.java      |  57 --
 ...ApplicationLevelNetworkPartitionContext.java |  97 ---
 .../stratos/autoscaler/AutoscalerContext.java   |  89 ---
 .../autoscaler/ClusterContextFactory.java       | 386 ----------
 .../autoscaler/ClusterInstanceContext.java      |  81 --
 .../ClusterLevelNetworkPartitionContext.java    | 443 -----------
 .../ClusterLevelPartitionContext.java           | 719 ------------------
 .../GroupLevelNetworkPartitionContext.java      | 201 -----
 .../autoscaler/GroupLevelPartitionContext.java  | 738 ------------------
 .../autoscaler/KubernetesClusterContext.java    | 761 -------------------
 .../stratos/autoscaler/MemberStatsContext.java  | 112 ---
 .../autoscaler/NetworkPartitionContext.java     |  29 -
 .../stratos/autoscaler/PartitionContext.java    |  73 --
 .../stratos/autoscaler/VMClusterContext.java    | 102 ---
 .../autoscaler/VMServiceClusterContext.java     |  54 --
 .../algorithm/AutoscaleAlgorithm.java           |   7 +-
 .../autoscaler/algorithm/OneAfterAnother.java   |   5 +-
 .../autoscaler/algorithm/RoundRobin.java        |   5 +-
 .../autoscaler/api/AutoScalerServiceImpl.java   |   2 +-
 .../applications/topic/ApplicationBuilder.java  |   2 +-
 .../autoscaler/context/AutoscalerContext.java   |  89 +++
 .../context/cluster/AbstractClusterContext.java |  49 ++
 .../context/cluster/ClusterContextFactory.java  | 390 ++++++++++
 .../context/cluster/ClusterInstanceContext.java |  80 ++
 .../cluster/KubernetesClusterContext.java       | 761 +++++++++++++++++++
 .../context/cluster/VMClusterContext.java       | 103 +++
 .../cluster/VMServiceClusterContext.java        |  55 ++
 .../context/member/MemberStatsContext.java      | 112 +++
 .../partition/ClusterLevelPartitionContext.java | 720 ++++++++++++++++++
 .../partition/GroupLevelPartitionContext.java   | 739 ++++++++++++++++++
 .../context/partition/PartitionContext.java     |  73 ++
 ...ApplicationLevelNetworkPartitionContext.java |  97 +++
 .../ClusterLevelNetworkPartitionContext.java    | 444 +++++++++++
 .../GroupLevelNetworkPartitionContext.java      | 202 +++++
 .../network/NetworkPartitionContext.java        |  29 +
 .../AutoscalerHealthStatEventReceiver.java      |   2 +-
 .../AutoscalerTopologyEventReceiver.java        |   5 +-
 .../monitor/application/ApplicationMonitor.java |   4 +-
 .../application/ApplicationMonitorFactory.java  |   2 +-
 .../monitor/cluster/AbstractClusterMonitor.java |   2 +-
 .../cluster/KubernetesClusterMonitor.java       |   6 +-
 .../KubernetesServiceClusterMonitor.java        |   4 +-
 .../monitor/cluster/VMClusterMonitor.java       |   6 +-
 .../monitor/cluster/VMLbClusterMonitor.java     |   3 +
 .../cluster/VMServiceClusterMonitor.java        |   5 +-
 .../autoscaler/monitor/group/GroupMonitor.java  |   4 +-
 .../rule/AutoscalerRuleEvaluator.java           |   2 +-
 .../autoscaler/rule/RuleTasksDelegator.java     |   6 +-
 .../status/processor/StatusChecker.java         |   6 +-
 .../cluster/ClusterStatusActiveProcessor.java   |   6 +-
 .../cluster/ClusterStatusInActiveProcessor.java |   6 +-
 .../ClusterStatusTerminatedProcessor.java       |   6 +-
 .../stratos/autoscaler/TestMinimumRule.java     |   1 +
 .../autoscaler/TestObsoletedMemberRule.java     |   1 +
 .../src/test/resources/autoscaler-old.drl       |   4 +-
 .../src/test/resources/autoscaler.drl           |   6 +-
 .../test/resources/minimum-autoscaler-rule.drl  |   4 +-
 .../resources/test-minimum-autoscaler-rule.drl  |   6 +-
 .../test-terminating-obsoleted-members-rule.drl |   6 +-
 .../src/main/conf/drools/container-mincheck.drl |   2 +-
 .../conf/drools/container-obsoletecheck.drl     |   2 +-
 .../src/main/conf/drools/container-scaling.drl  |   2 +-
 .../src/main/conf/drools/dependent-scaling.drl  |   8 +-
 .../src/main/conf/drools/mincheck.drl           |   6 +-
 .../src/main/conf/drools/obsoletecheck.drl      |   6 +-
 .../src/main/conf/drools/scaling.drl            |   8 +-
 .../src/main/conf/drools/terminateall.drl       |   2 +-
 .../main/conf/drools/terminatedependency.drl    |   2 +-
 68 files changed, 4028 insertions(+), 4019 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/c20d28c2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AbstractClusterContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AbstractClusterContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AbstractClusterContext.java
deleted file mode 100644
index 6faa4f9..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AbstractClusterContext.java
+++ /dev/null
@@ -1,57 +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;
-
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
-import org.apache.stratos.autoscaler.policy.model.LoadAverage;
-import org.apache.stratos.autoscaler.policy.model.MemoryConsumption;
-import org.apache.stratos.autoscaler.policy.model.RequestsInFlight;
-import org.apache.stratos.autoscaler.util.ConfUtil;
-import org.apache.stratos.cloud.controller.stub.pojo.MemberContext;
-import org.apache.stratos.common.constants.StratosConstants;
-
-import java.io.Serializable;
-import java.util.*;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-
-/*
- * It holds the runtime data of a service cluster
- */
-public class AbstractClusterContext implements Serializable {
-
-    private static final Log log = 
LogFactory.getLog(AbstractClusterContext.class);
-
-
-    // cluster id
-    protected String clusterId;
-    private String serviceId;
-
-    public AbstractClusterContext(String clusterId, String serviceId){
-        this.clusterId = clusterId;
-        this.serviceId = serviceId;
-    }
-
-    public String getServiceId() {
-        return serviceId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/c20d28c2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ApplicationLevelNetworkPartitionContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ApplicationLevelNetworkPartitionContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ApplicationLevelNetworkPartitionContext.java
deleted file mode 100644
index 282e304..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ApplicationLevelNetworkPartitionContext.java
+++ /dev/null
@@ -1,97 +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;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.instance.ApplicationInstance;
-
-import java.io.Serializable;
-import java.util.Map;
-
-/**
- * Holds runtime data of a network partition.
- *
- */
-public class ApplicationLevelNetworkPartitionContext extends 
NetworkPartitionContext implements Serializable {
-    private static final Log log = 
LogFactory.getLog(ApplicationLevelNetworkPartitionContext.class);
-    private final String id;
-
-    //group instances kept inside a partition
-    private Map<String, ApplicationInstance> instanceIdToInstanceContextMap;
-
-    public ApplicationLevelNetworkPartitionContext(String id) {
-        this.id = id;
-    }
-
-    public Map<String, ApplicationInstance> 
getInstanceIdToInstanceContextMap() {
-        return instanceIdToInstanceContextMap;
-    }
-
-    public void setInstanceIdToInstanceContextMap(Map<String, 
ApplicationInstance> instanceIdToInstanceContextMap) {
-        this.instanceIdToInstanceContextMap = instanceIdToInstanceContextMap;
-    }
-
-    public void addInstanceContext(ApplicationInstance context) {
-        this.instanceIdToInstanceContextMap.put(context.getInstanceId(), 
context);
-
-    }
-
-
-    public int hashCode() {
-
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
-        return result;
-
-    }
-
-    public boolean equals(final Object obj) {
-
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (!(obj instanceof ApplicationLevelNetworkPartitionContext)) {
-            return false;
-        }
-        final ApplicationLevelNetworkPartitionContext other = 
(ApplicationLevelNetworkPartitionContext) obj;
-        if (this.id == null) {
-            if (other.id != null) {
-                return false;
-            }
-        } else if (!this.id.equals(other.id)) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public String toString() {
-        return "ApplicationNetworkPartitionContext [id=" + id  + "]";
-    }
-
-    public String getId() {
-        return id;
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/c20d28c2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
deleted file mode 100644
index dc710fb..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
+++ /dev/null
@@ -1,89 +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;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.stratos.autoscaler.monitor.application.ApplicationMonitor;
-import org.apache.stratos.autoscaler.monitor.cluster.AbstractClusterMonitor;
-
-/**
- * It holds all cluster monitors which are active in stratos.
- */
-public class AutoscalerContext {
-
-    private static final AutoscalerContext INSTANCE = new AutoscalerContext();
-
-    // Map<ClusterId, AbstractClusterMonitor>
-    private Map<String, AbstractClusterMonitor> clusterMonitors;
-    // Map<ApplicationId, ApplicationMonitor>
-    private Map<String, ApplicationMonitor> applicationMonitors;
-
-    private AutoscalerContext() {
-        setClusterMonitors(new HashMap<String, AbstractClusterMonitor>());
-        setApplicationMonitors(new HashMap<String, ApplicationMonitor>());
-    }
-
-    public static AutoscalerContext getInstance() {
-        return INSTANCE;
-    }
-
-    public void addClusterMonitor(AbstractClusterMonitor clusterMonitor) {
-        getClusterMonitors().put(clusterMonitor.getClusterId(), 
clusterMonitor);
-    }
-
-    public AbstractClusterMonitor getClusterMonitor(String clusterId) {
-        return getClusterMonitors().get(clusterId);
-    }
-
-    public AbstractClusterMonitor removeClusterMonitor(String clusterId) {
-        return getClusterMonitors().remove(clusterId);
-    }
-
-    public void addAppMonitor(ApplicationMonitor applicationMonitor) {
-        getApplicationMonitors().put(applicationMonitor.getId(), 
applicationMonitor);
-    }
-
-    public ApplicationMonitor getAppMonitor(String applicationId) {
-        return getApplicationMonitors().get(applicationId);
-    }
-
-    public void removeAppMonitor(String applicationId) {
-        getApplicationMonitors().remove(applicationId);
-    }
-
-    public Map<String, AbstractClusterMonitor> getClusterMonitors() {
-        return clusterMonitors;
-    }
-
-    public void setClusterMonitors(Map<String, AbstractClusterMonitor> 
clusterMonitors) {
-        this.clusterMonitors = clusterMonitors;
-    }
-
-    public Map<String, ApplicationMonitor> getApplicationMonitors() {
-        return applicationMonitors;
-    }
-
-    public void setApplicationMonitors(Map<String, ApplicationMonitor> 
applicationMonitors) {
-        this.applicationMonitors = applicationMonitors;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/c20d28c2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContextFactory.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContextFactory.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContextFactory.java
deleted file mode 100644
index 0c1dcbe..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContextFactory.java
+++ /dev/null
@@ -1,386 +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;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.client.CloudControllerClient;
-import org.apache.stratos.autoscaler.exception.PartitionValidationException;
-import org.apache.stratos.autoscaler.exception.PolicyValidationException;
-import org.apache.stratos.autoscaler.partition.PartitionGroup;
-import org.apache.stratos.autoscaler.partition.PartitionManager;
-import org.apache.stratos.autoscaler.policy.PolicyManager;
-import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
-import org.apache.stratos.autoscaler.policy.model.DeploymentPolicy;
-import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition;
-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.constants.StratosConstants;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.Member;
-import org.apache.stratos.messaging.domain.topology.MemberStatus;
-import org.apache.stratos.messaging.util.Constants;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Random;
-
-public class ClusterContextFactory {
-
-    private static final Log log = 
LogFactory.getLog(ClusterContextFactory.class);
-
-    public static VMServiceClusterContext getVMServiceClusterContext (Cluster 
cluster) throws PolicyValidationException, PartitionValidationException {
-
-        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 autoscalePolicy =
-                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 =
-                    "Partitions are null in deployment policy: [policy-name]: 
" +
-                            deploymentPolicyName;
-            log.error(msg);
-            throw new PolicyValidationException(msg);
-        }
-
-        
CloudControllerClient.getInstance().validateDeploymentPolicy(cluster.getServiceName(),
 deploymentPolicy);
-
-        Map<String, ClusterLevelNetworkPartitionContext> 
networkPartitionContextMap = new HashMap<String, 
ClusterLevelNetworkPartitionContext>();
-
-        for (PartitionGroup partitionGroup : 
deploymentPolicy.getPartitionGroups()) {
-
-            String networkPartitionId = partitionGroup.getId();
-            ClusterLevelNetworkPartitionContext 
clusterLevelNetworkPartitionContext = new 
ClusterLevelNetworkPartitionContext(networkPartitionId,
-                    partitionGroup.getPartitionAlgo(),
-                    partitionGroup.getPartitions());
-
-            for (Partition partition : partitionGroup.getPartitions()) {
-                ClusterLevelPartitionContext clusterMonitorPartitionContext = 
new ClusterLevelPartitionContext(partition);
-                
clusterMonitorPartitionContext.setServiceName(cluster.getServiceName());
-                
clusterMonitorPartitionContext.setProperties(cluster.getProperties());
-                
clusterMonitorPartitionContext.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.setInitTime(member.getInitTime());
-                        memberContext.setPartition(partition);
-                        
memberContext.setProperties(convertMemberPropsToMemberContextProps(member.getProperties()));
-
-                        if (MemberStatus.Activated.equals(member.getStatus())) 
{
-                            if (log.isDebugEnabled()) {
-                                String msg = String.format("Active member 
loaded from topology and added to active member list, %s", member.toString());
-                                log.debug(msg);
-                            }
-                            
clusterMonitorPartitionContext.addActiveMember(memberContext);
-//                            
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
-//                            
partitionContext.incrementCurrentActiveMemberCount(1);
-
-                        } else if 
(MemberStatus.Created.equals(member.getStatus()) || 
MemberStatus.Starting.equals(member.getStatus())) {
-                            if (log.isDebugEnabled()) {
-                                String msg = String.format("Pending member 
loaded from topology and added to pending member list, %s", member.toString());
-                                log.debug(msg);
-                            }
-                            
clusterMonitorPartitionContext.addPendingMember(memberContext);
-
-//                            
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
-                        } else if 
(MemberStatus.Suspended.equals(member.getStatus())) {
-//                            partitionContext.addFaultyMember(memberId);
-                        }
-                        
clusterMonitorPartitionContext.addMemberStatsContext(new 
MemberStatsContext(memberId));
-                        if (log.isInfoEnabled()) {
-                            log.info(String.format("Member stat context has 
been added: [member] %s", memberId));
-                        }
-                    }
-
-                }
-                
clusterLevelNetworkPartitionContext.addPartitionContext(clusterMonitorPartitionContext);
-                if (log.isInfoEnabled()) {
-                    log.info(String.format("Partition context has been added: 
[partition] %s",
-                            clusterMonitorPartitionContext.getPartitionId()));
-                }
-            }
-
-            networkPartitionContextMap.put(networkPartitionId, 
clusterLevelNetworkPartitionContext);
-            if (log.isInfoEnabled()) {
-                log.info(String.format("Network partition context has been 
added: [network partition] %s",
-                        clusterLevelNetworkPartitionContext.getId()));
-            }
-        }
-
-        return new VMServiceClusterContext(cluster.getClusterId(), 
cluster.getServiceName(), autoscalePolicy,
-                        deploymentPolicy, networkPartitionContextMap);
-    }
-
-    public static VMClusterContext getVMLBClusterContext (Cluster cluster) 
throws PolicyValidationException {
-
-        // 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 autoscalePolicy =
-                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();
-
-        Map<String, ClusterLevelNetworkPartitionContext> 
networkPartitionContextMap = new HashMap<String, 
ClusterLevelNetworkPartitionContext>();
-
-        // partition group = network partition context
-        for (PartitionGroup partitionGroup : 
deploymentPolicy.getPartitionGroups()) {
-
-            String networkPartitionId = partitionGroup.getId();
-            NetworkPartitionLbHolder networkPartitionLbHolder =
-                    PartitionManager.getInstance()
-                            .getNetworkPartitionLbHolder(networkPartitionId);
-//                                                              
PartitionManager.getInstance()
-//                                                                             
 .getNetworkPartitionLbHolder(partitionGroup.getPartitionId());
-            // FIXME pick a random partition
-            Partition partition =
-                    partitionGroup.getPartitions()[new 
Random().nextInt(partitionGroup.getPartitions().length)];
-            ClusterLevelPartitionContext clusterMonitorPartitionContext = new 
ClusterLevelPartitionContext(partition);
-            
clusterMonitorPartitionContext.setServiceName(cluster.getServiceName());
-            
clusterMonitorPartitionContext.setProperties(cluster.getProperties());
-            
clusterMonitorPartitionContext.setNetworkPartitionId(networkPartitionId);
-            clusterMonitorPartitionContext.setMinimumMemberCount(1);//Here it 
hard codes the minimum value as one for LB cartridge partitions
-
-            ClusterLevelNetworkPartitionContext 
clusterLevelNetworkPartitionContext = new 
ClusterLevelNetworkPartitionContext(networkPartitionId,
-                    partitionGroup.getPartitionAlgo(),
-                    partitionGroup.getPartitions());
-            for (Member member : cluster.getMembers()) {
-                String memberId = member.getMemberId();
-                if 
(member.getNetworkPartitionId().equalsIgnoreCase(clusterLevelNetworkPartitionContext.getId()))
 {
-                    MemberContext memberContext = new MemberContext();
-                    memberContext.setClusterId(member.getClusterId());
-                    memberContext.setMemberId(memberId);
-                    memberContext.setPartition(partition);
-                    memberContext.setInitTime(member.getInitTime());
-
-                    if (MemberStatus.Activated.equals(member.getStatus())) {
-                        if (log.isDebugEnabled()) {
-                            String msg = String.format("Active member loaded 
from topology and added to active member list, %s", member.toString());
-                            log.debug(msg);
-                        }
-                        
clusterMonitorPartitionContext.addActiveMember(memberContext);
-//                        
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
-//                        
partitionContext.incrementCurrentActiveMemberCount(1);
-                    } else if (MemberStatus.Created.equals(member.getStatus()) 
||
-                            MemberStatus.Starting.equals(member.getStatus())) {
-                        if (log.isDebugEnabled()) {
-                            String msg = String.format("Pending member loaded 
from topology and added to pending member list, %s", member.toString());
-                            log.debug(msg);
-                        }
-                        
clusterMonitorPartitionContext.addPendingMember(memberContext);
-//                        
networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(),
 1);
-                    } else if 
(MemberStatus.Suspended.equals(member.getStatus())) {
-//                        partitionContext.addFaultyMember(memberId);
-                    }
-
-                    clusterMonitorPartitionContext.addMemberStatsContext(new 
MemberStatsContext(memberId));
-                    if (log.isInfoEnabled()) {
-                        log.info(String.format("Member stat context has been 
added: [member] %s", memberId));
-                    }
-                }
-
-            }
-            
clusterLevelNetworkPartitionContext.addPartitionContext(clusterMonitorPartitionContext);
-
-            // 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(org.apache.stratos.messaging.util.Constants.LOAD_BALANCED_SERVICE_TYPE);
-
-            if 
(props.containsKey(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF))
 {
-                String value = 
props.getProperty(org.apache.stratos.messaging.util.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);
-                        }
-                    }
-                }
-            }
-
-            networkPartitionContextMap.put(networkPartitionId, 
clusterLevelNetworkPartitionContext);
-        }
-
-        return new VMClusterContext(clusterId, cluster.getServiceName(), 
autoscalePolicy,
-                deploymentPolicy, networkPartitionContextMap);
-    }
-
-    public static KubernetesClusterContext getKubernetesClusterContext 
(Cluster cluster) throws PolicyValidationException {
-
-        if (null == cluster) {
-            return null;
-        }
-
-        String autoscalePolicyName = cluster.getAutoscalePolicyName();
-
-        AutoscalePolicy autoscalePolicy =
-                PolicyManager.getInstance()
-                        .getAutoscalePolicy(autoscalePolicyName);
-        if (log.isDebugEnabled()) {
-            log.debug("Autoscaling policy name: " + autoscalePolicyName);
-        }
-
-        AutoscalePolicy policy = 
PolicyManager.getInstance().getAutoscalePolicy(autoscalePolicyName);
-
-        if (policy == null) {
-            String msg = String.format("Autoscaling policy is null: 
[policy-name] %s", autoscalePolicyName);
-            log.error(msg);
-            throw new PolicyValidationException(msg);
-        }
-
-        java.util.Properties properties = cluster.getProperties();
-        if(properties == null) {
-            String message = String.format("Properties not found in kubernetes 
cluster: [cluster-id] %s",
-                    cluster.getClusterId());
-            log.error(message);
-            throw new RuntimeException(message);
-        }
-        String minReplicasProperty = 
properties.getProperty(StratosConstants.KUBERNETES_MIN_REPLICAS);
-        int minReplicas = 0;
-        if (minReplicasProperty != null && !minReplicasProperty.isEmpty()) {
-            minReplicas = Integer.parseInt(minReplicasProperty);
-        }
-
-        int maxReplicas = 0;
-        String maxReplicasProperty = 
properties.getProperty(StratosConstants.KUBERNETES_MAX_REPLICAS);
-        if (maxReplicasProperty != null && !maxReplicasProperty.isEmpty()) {
-            maxReplicas = Integer.parseInt(maxReplicasProperty);
-        }
-
-        String kubernetesHostClusterID = 
properties.getProperty(StratosConstants.KUBERNETES_CLUSTER_ID);
-        KubernetesClusterContext kubernetesClusterCtxt = new 
KubernetesClusterContext(kubernetesHostClusterID,
-                cluster.getClusterId(), cluster.getServiceName(),  
autoscalePolicy, minReplicas, maxReplicas);
-
-        //populate the members after restarting
-        for (Member member : cluster.getMembers()) {
-            String memberId = member.getMemberId();
-            String clusterId = member.getClusterId();
-            MemberContext memberContext = new MemberContext();
-            memberContext.setMemberId(memberId);
-            memberContext.setClusterId(clusterId);
-            memberContext.setInitTime(member.getInitTime());
-
-            // if there is at least one member in the topology, that means 
service has been created already
-            // this is to avoid calling startContainer() method again
-            kubernetesClusterCtxt.setServiceClusterCreated(true);
-
-            if (MemberStatus.Activated.equals(member.getStatus())) {
-                if (log.isDebugEnabled()) {
-                    String msg = String.format("Active member loaded from 
topology and added to active member list, %s", member.toString());
-                    log.debug(msg);
-                }
-                
//dockerClusterMonitor.getKubernetesClusterCtxt().addActiveMember(memberContext);
-            } else if (MemberStatus.Created.equals(member.getStatus())
-                    || MemberStatus.Starting.equals(member.getStatus())) {
-                if (log.isDebugEnabled()) {
-                    String msg = String.format("Pending member loaded from 
topology and added to pending member list, %s", member.toString());
-                    log.debug(msg);
-                }
-                
//dockerClusterMonitor.getKubernetesClusterCtxt().addPendingMember(memberContext);
-            }
-
-            kubernetesClusterCtxt.addMemberStatsContext(new 
MemberStatsContext(memberId));
-            if (log.isInfoEnabled()) {
-                log.info(String.format("Member stat context has been added: 
[member] %s", memberId));
-            }
-        }
-
-        // find lb reference type
-        if 
(properties.containsKey(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF))
 {
-            String value = properties.getProperty(Constants.LOAD_BALANCER_REF);
-            //dockerClusterMonitor.setLbReferenceType(value);
-            if (log.isDebugEnabled()) {
-                log.debug("Set the lb reference type: " + value);
-            }
-        }
-
-        return kubernetesClusterCtxt;
-    }
-
-    private static Properties convertMemberPropsToMemberContextProps(
-            java.util.Properties properties) {
-        Properties props = new Properties();
-        for (Map.Entry<Object, Object> e : properties.entrySet()) {
-            Property property = new Property();
-            property.setName((String) e.getKey());
-            property.setValue((String) e.getValue());
-            props.addProperties(property);
-        }
-        return props;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/c20d28c2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterInstanceContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterInstanceContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterInstanceContext.java
deleted file mode 100644
index fed65fa..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterInstanceContext.java
+++ /dev/null
@@ -1,81 +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;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
-import org.apache.stratos.autoscaler.policy.model.DeploymentPolicy;
-import org.apache.stratos.messaging.domain.topology.Member;
-
-import java.util.Map;
-
-/*
- * It holds the runtime data of a VM cluster
- */
-public class ClusterInstanceContext {
-
-    private static final Log log = 
LogFactory.getLog(ClusterInstanceContext.class);
-    private final String clusterInstanceId;
-
-    // Map<PartitionId, Partition Context>
-    protected Map<String, ClusterLevelPartitionContext> partitionCtxts;
-    public ClusterInstanceContext(String clusterInstanceId, String serviceId,
-                                  Map<String, ClusterLevelPartitionContext> 
partitionCtxts) {
-
-        this.clusterInstanceId = clusterInstanceId;
-
-    }
-
-    public Map<String, ClusterLevelPartitionContext> getPartitionCtxts(){
-        return partitionCtxts;
-    }
-
-    public ClusterLevelPartitionContext getNetworkPartitionCtxt(String 
PartitionId) {
-        return partitionCtxts.get(PartitionId);
-    }
-
-    public void setPartitionCtxt(Map<String, ClusterLevelPartitionContext> 
partitionCtxt) {
-        this.partitionCtxts = partitionCtxt;
-    }
-
-    public boolean partitionCtxtAvailable(String partitionId) {
-        return partitionCtxts.containsKey(partitionId);
-    }
-
-    public void addPartitionCtxt(ClusterLevelPartitionContext ctxt) {
-        this.partitionCtxts.put(ctxt.getPartitionId(), ctxt);
-    }
-
-    public ClusterLevelPartitionContext getPartitionCtxt(String id) {
-        return this.partitionCtxts.get(id);
-    }
-
-    public ClusterLevelPartitionContext getPartitionCtxt(Member member) {
-        log.info("Getting [Partition] " + member.getPartitionId());
-        String partitionId = member.getPartitionId();
-        if (partitionCtxts.containsKey(partitionId)) {
-            log.info("Returning partition context, of [partition] " + 
partitionCtxts.get(partitionId));
-            return partitionCtxts.get(partitionId);
-        }
-
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/c20d28c2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterLevelNetworkPartitionContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterLevelNetworkPartitionContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterLevelNetworkPartitionContext.java
deleted file mode 100644
index aa835ab..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterLevelNetworkPartitionContext.java
+++ /dev/null
@@ -1,443 +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;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.policy.model.LoadAverage;
-import org.apache.stratos.autoscaler.policy.model.MemoryConsumption;
-import org.apache.stratos.autoscaler.policy.model.RequestsInFlight;
-import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition;
-import org.apache.stratos.messaging.domain.instance.Instance;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Holds runtime data of a network partition.
- *
- */
-public class ClusterLevelNetworkPartitionContext extends 
NetworkPartitionContext implements Serializable {
-
-    private static final Log log = 
LogFactory.getLog(ClusterLevelNetworkPartitionContext.class);
-    private static final long serialVersionUID = 572769304374110159L;
-    private final String id;
-    private int scaleDownRequestsCount = 0;
-    private float averageRequestsServedPerInstance;
-    private float requestsServedPerInstance;
-
-    private int minInstanceCount = 0, maxInstanceCount = 0;
-    private int requiredInstanceCountBasedOnStats;
-    private int requiredInstanceCountBasedOnDependencies;
-
-    private Map<String, Instance> instanceIdToInstanceContextMap;
-
-
-    private final String partitionAlgorithm;
-
-    //boolean values to keep whether the requests in flight parameters are 
reset or not
-    private boolean rifReset = false, averageRifReset = false, 
gradientRifReset = false, secondDerivativeRifRest = false;
-    //boolean values to keep whether the memory consumption parameters are 
reset or not
-    private boolean memoryConsumptionReset = false, 
averageMemoryConsumptionReset = false,
-            gradientMemoryConsumptionReset = false, 
secondDerivativeMemoryConsumptionRest = false;
-    //boolean values to keep whether the load average parameters are reset or 
not
-    private boolean loadAverageReset = false, averageLoadAverageReset = false, 
gradientLoadAverageReset = false,
-            secondDerivativeLoadAverageRest = false;
-    //boolean values to keep whether average requests served per instance 
parameters are reset or not
-    private boolean averageRequestServedPerInstanceReset = false;
-
-    private final Partition[] partitions;
-
-    //Following information will keep events details
-    private RequestsInFlight requestsInFlight;
-    private MemoryConsumption memoryConsumption;
-    private LoadAverage loadAverage;
-
-    //details required for partition selection algorithms
-    private int currentPartitionIndex;
-
-    //partitions of this network partition
-    private final Map<String, ClusterLevelPartitionContext> partitionCtxts;
-
-    public ClusterLevelNetworkPartitionContext(String id, String 
partitionAlgo, Partition[] partitions) {
-
-        //super(id, partitionAlgo, partitions);
-        this.id = id;
-        this.partitionAlgorithm = partitionAlgo;
-        if (partitions == null) {
-            this.partitions = new Partition[0];
-        } else {
-            this.partitions = Arrays.copyOf(partitions, partitions.length);
-        }
-        partitionCtxts = new HashMap<String, ClusterLevelPartitionContext>();
-        requestsInFlight = new RequestsInFlight();
-        loadAverage = new LoadAverage();
-        memoryConsumption = new MemoryConsumption();
-        for (Partition partition : partitions) {
-            minInstanceCount += partition.getPartitionMin();
-            maxInstanceCount += partition.getPartitionMax();
-        }
-        requiredInstanceCountBasedOnStats = minInstanceCount;
-        requiredInstanceCountBasedOnDependencies = minInstanceCount;
-        instanceIdToInstanceContextMap = new HashMap<String, Instance>();
-
-    }
-
-    public int getMinInstanceCount() {
-        return minInstanceCount;
-    }
-
-    public void setMinInstanceCount(int minInstanceCount) {
-        this.minInstanceCount = minInstanceCount;
-    }
-
-    public int getMaxInstanceCount() {
-        return maxInstanceCount;
-    }
-
-    public void setMaxInstanceCount(int maxInstanceCount) {
-        this.maxInstanceCount = maxInstanceCount;
-    }
-
-    public int hashCode() {
-
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
-        return result;
-
-    }
-
-    public boolean equals(final Object obj) {
-
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (!(obj instanceof ClusterLevelNetworkPartitionContext)) {
-            return false;
-        }
-        final ClusterLevelNetworkPartitionContext other = 
(ClusterLevelNetworkPartitionContext) obj;
-        if (this.id == null) {
-            if (other.id != null) {
-                return false;
-            }
-        } else if (!this.id.equals(other.id)) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public String toString() {
-        return "NetworkPartitionContext [id=" + id + "partitionAlgorithm=" + 
partitionAlgorithm + ", minInstanceCount=" +
-                minInstanceCount + ", maxInstanceCount=" + maxInstanceCount + 
"]";
-    }
-
-    public int getCurrentPartitionIndex() {
-        return currentPartitionIndex;
-    }
-
-    public void setCurrentPartitionIndex(int currentPartitionIndex) {
-        this.currentPartitionIndex = currentPartitionIndex;
-    }
-
-    public float getAverageRequestsServedPerInstance() {
-        return averageRequestsServedPerInstance;
-    }
-
-    public void setAverageRequestsServedPerInstance(float 
averageRequestServedPerInstance) {
-        this.averageRequestsServedPerInstance = 
averageRequestServedPerInstance;
-        averageRequestServedPerInstanceReset = true;
-
-        if (log.isDebugEnabled()) {
-            log.debug(String.format("Average Requesets Served Per Instance 
stats are reset, ready to do scale check [network partition] %s"
-                    , this.id));
-
-        }
-    }
-
-    public float getRequestsServedPerInstance() {
-        return requestsServedPerInstance;
-    }
-
-    public float getAverageRequestsInFlight() {
-        return requestsInFlight.getAverage();
-    }
-
-    public void setAverageRequestsInFlight(float averageRequestsInFlight) {
-        requestsInFlight.setAverage(averageRequestsInFlight);
-        averageRifReset = true;
-        if (secondDerivativeRifRest && gradientRifReset) {
-            rifReset = true;
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Requests in flights stats are reset, 
ready to do scale check [network partition] %s"
-                        , this.id));
-            }
-        }
-    }
-
-    public float getRequestsInFlightSecondDerivative() {
-        return requestsInFlight.getSecondDerivative();
-    }
-
-    public void setRequestsInFlightSecondDerivative(float 
requestsInFlightSecondDerivative) {
-        requestsInFlight.setSecondDerivative(requestsInFlightSecondDerivative);
-        secondDerivativeRifRest = true;
-        if (averageRifReset && gradientRifReset) {
-            rifReset = true;
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Requests in flights stats are reset, 
ready to do scale check [network partition] %s"
-                        , this.id));
-            }
-        }
-    }
-
-    public float getRequestsInFlightGradient() {
-        return requestsInFlight.getGradient();
-    }
-
-    public void setRequestsInFlightGradient(float requestsInFlightGradient) {
-        requestsInFlight.setGradient(requestsInFlightGradient);
-        gradientRifReset = true;
-        if (secondDerivativeRifRest && averageRifReset) {
-            rifReset = true;
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Requests in flights stats are reset, 
ready to do scale check [network partition] %s"
-                        , this.id));
-            }
-        }
-    }
-
-    public boolean isRifReset() {
-        return rifReset;
-    }
-
-    public void setRifReset(boolean rifReset) {
-        this.rifReset = rifReset;
-        this.averageRifReset = rifReset;
-        this.gradientRifReset = rifReset;
-        this.secondDerivativeRifRest = rifReset;
-    }
-
-
-    public float getAverageMemoryConsumption() {
-        return memoryConsumption.getAverage();
-    }
-
-    public void setAverageMemoryConsumption(float averageMemoryConsumption) {
-        memoryConsumption.setAverage(averageMemoryConsumption);
-        averageMemoryConsumptionReset = true;
-        if (secondDerivativeMemoryConsumptionRest && 
gradientMemoryConsumptionReset) {
-            memoryConsumptionReset = true;
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Memory consumption stats are reset, 
ready to do scale check [network partition] %s"
-                        , this.id));
-            }
-        }
-    }
-
-    public float getMemoryConsumptionSecondDerivative() {
-        return memoryConsumption.getSecondDerivative();
-    }
-
-    public void setMemoryConsumptionSecondDerivative(float 
memoryConsumptionSecondDerivative) {
-        
memoryConsumption.setSecondDerivative(memoryConsumptionSecondDerivative);
-        secondDerivativeMemoryConsumptionRest = true;
-        if (averageMemoryConsumptionReset && gradientMemoryConsumptionReset) {
-            memoryConsumptionReset = true;
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Memory consumption stats are reset, 
ready to do scale check [network partition] %s"
-                        , this.id));
-            }
-        }
-    }
-
-    public float getMemoryConsumptionGradient() {
-        return memoryConsumption.getGradient();
-    }
-
-    public void setMemoryConsumptionGradient(float memoryConsumptionGradient) {
-        memoryConsumption.setGradient(memoryConsumptionGradient);
-        gradientMemoryConsumptionReset = true;
-        if (secondDerivativeMemoryConsumptionRest && 
averageMemoryConsumptionReset) {
-            memoryConsumptionReset = true;
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Memory consumption stats are reset, 
ready to do scale check [network partition] %s"
-                        , this.id));
-            }
-        }
-    }
-
-    public boolean isMemoryConsumptionReset() {
-        return memoryConsumptionReset;
-    }
-
-    public void setMemoryConsumptionReset(boolean memoryConsumptionReset) {
-        this.memoryConsumptionReset = memoryConsumptionReset;
-        this.averageMemoryConsumptionReset = memoryConsumptionReset;
-        this.gradientMemoryConsumptionReset = memoryConsumptionReset;
-        this.secondDerivativeMemoryConsumptionRest = memoryConsumptionReset;
-    }
-
-
-    public float getAverageLoadAverage() {
-        return loadAverage.getAverage();
-    }
-
-    public void setAverageLoadAverage(float averageLoadAverage) {
-        loadAverage.setAverage(averageLoadAverage);
-        averageLoadAverageReset = true;
-        if (secondDerivativeLoadAverageRest && gradientLoadAverageReset) {
-            loadAverageReset = true;
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Load average stats are reset, ready 
to do scale check [network partition] %s"
-                        , this.id));
-            }
-        }
-    }
-
-    public float getLoadAverageSecondDerivative() {
-        return loadAverage.getSecondDerivative();
-    }
-
-    public void setLoadAverageSecondDerivative(float 
loadAverageSecondDerivative) {
-        loadAverage.setSecondDerivative(loadAverageSecondDerivative);
-        secondDerivativeLoadAverageRest = true;
-        if (averageLoadAverageReset && gradientLoadAverageReset) {
-            loadAverageReset = true;
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Load average stats are reset, ready 
to do scale check [network partition] %s"
-                        , this.id));
-            }
-        }
-    }
-
-    public float getLoadAverageGradient() {
-        return loadAverage.getGradient();
-    }
-
-    public void setLoadAverageGradient(float loadAverageGradient) {
-        loadAverage.setGradient(loadAverageGradient);
-        gradientLoadAverageReset = true;
-        if (secondDerivativeLoadAverageRest && averageLoadAverageReset) {
-            loadAverageReset = true;
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Load average stats are reset, ready 
to do scale check [network partition] %s"
-                        , this.id));
-            }
-        }
-    }
-
-    public boolean isLoadAverageReset() {
-        return loadAverageReset;
-    }
-
-    public void setLoadAverageReset(boolean loadAverageReset) {
-        this.loadAverageReset = loadAverageReset;
-        this.averageLoadAverageReset = loadAverageReset;
-        this.gradientLoadAverageReset = loadAverageReset;
-        this.secondDerivativeLoadAverageRest = loadAverageReset;
-    }
-
-
-    public String getId() {
-        return id;
-    }
-
-    public Map<String, ClusterLevelPartitionContext> getPartitionCtxts() {
-        return partitionCtxts;
-    }
-
-    public ClusterLevelPartitionContext getPartitionCtxt(String partitionId) {
-        return partitionCtxts.get(partitionId);
-    }
-
-    public void addPartitionContext(ClusterLevelPartitionContext 
partitionContext) {
-        partitionCtxts.put(partitionContext.getPartitionId(), 
partitionContext);
-    }
-
-    public String getPartitionAlgorithm() {
-        return partitionAlgorithm;
-    }
-
-    public Partition[] getPartitions() {
-        return partitions;
-    }
-
-    public int getNonTerminatedMemberCountOfPartition(String partitionId) {
-        if (partitionCtxts.containsKey(partitionId)) {
-            return getPartitionCtxt(partitionId).getNonTerminatedMemberCount();
-        }
-        return 0;
-    }
-
-    public int getActiveMemberCount(String currentPartitionId) {
-        if (partitionCtxts.containsKey(currentPartitionId)) {
-            return getPartitionCtxt(currentPartitionId).getActiveMemberCount();
-        }
-        return 0;
-    }
-
-    public int getScaleDownRequestsCount() {
-        return scaleDownRequestsCount;
-    }
-
-    public void resetScaleDownRequestsCount() {
-        this.scaleDownRequestsCount = 0;
-    }
-
-    public void increaseScaleDownRequestsCount() {
-        this.scaleDownRequestsCount += 1;
-    }
-
-    public float getRequiredInstanceCountBasedOnStats() {
-        return requiredInstanceCountBasedOnStats;
-    }
-
-    public void setRequiredInstanceCountBasedOnStats(int 
requiredInstanceCountBasedOnStats) {
-        this.requiredInstanceCountBasedOnStats = 
requiredInstanceCountBasedOnStats;
-    }
-
-    public int getRequiredInstanceCountBasedOnDependencies() {
-        return requiredInstanceCountBasedOnDependencies;
-    }
-
-    public void setRequiredInstanceCountBasedOnDependencies(int 
requiredInstanceCountBasedOnDependencies) {
-        this.requiredInstanceCountBasedOnDependencies = 
requiredInstanceCountBasedOnDependencies;
-    }
-
-    public Map<String, Instance> getInstanceIdToInstanceContextMap() {
-        return instanceIdToInstanceContextMap;
-    }
-
-    public void setInstanceIdToInstanceContextMap(Map<String, Instance> 
instanceIdToInstanceContextMap) {
-        this.instanceIdToInstanceContextMap = instanceIdToInstanceContextMap;
-    }
-
-    public void addInstanceContext(Instance context) {
-        this.instanceIdToInstanceContextMap.put(context.getInstanceId(), 
context);
-
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/c20d28c2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterLevelPartitionContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterLevelPartitionContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterLevelPartitionContext.java
deleted file mode 100644
index ddf8fd7..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterLevelPartitionContext.java
+++ /dev/null
@@ -1,719 +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;
-
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.util.ConfUtil;
-import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition;
-import org.apache.stratos.cloud.controller.stub.pojo.MemberContext;
-
-import java.io.Serializable;
-import java.util.*;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-import org.apache.stratos.common.constants.StratosConstants;
-
-/**
- * This is an object that inserted to the rules engine.
- * Holds information about a partition.
- *
- *
- */
-
-public class ClusterLevelPartitionContext extends PartitionContext implements 
Serializable{
-
-       private static final long serialVersionUID = -2920388667345980487L;
-       private static final Log log = 
LogFactory.getLog(ClusterLevelPartitionContext.class);
-    private String serviceName;
-    private String networkPartitionId;
-    private Partition partition;
-    private int minimumMemberCount = 0;
-    private int pendingMembersFailureCount = 0;
-    private final int PENDING_MEMBER_FAILURE_THRESHOLD = 5;
-
-    // properties
-    private Properties properties;
-    
-    // 15 mints as the default
-    private long pendingMemberExpiryTime = 900000;
-    // pending members
-    private List<MemberContext> pendingMembers;
-    
-    // 1 day as default
-    private long obsoltedMemberExpiryTime = 1*24*60*60*1000;
-
-    // 30 mints as default
-    private long terminationPendingMemberExpiryTime = 1800000;
-
-    // members to be terminated
-    private Map<String, MemberContext> obsoletedMembers;
-    
-    // active members
-    private List<MemberContext> activeMembers;
-
-    // termination pending members, member is added to this when Autoscaler 
send grace fully shut down event
-    private List<MemberContext> terminationPendingMembers;
-
-    //member id: time that member is moved to termination pending status
-    private Map<String, Long> terminationPendingStartedTime;
-
-    //Keep statistics come from CEP
-    private Map<String, MemberStatsContext> memberStatsContexts;
-
-    // for the use of tests
-    public ClusterLevelPartitionContext(long memberExpiryTime) {
-        super(memberExpiryTime);
-        this.activeMembers = new ArrayList<MemberContext>();
-        this.terminationPendingMembers = new ArrayList<MemberContext>();
-    }
-    
-    public ClusterLevelPartitionContext(Partition partition) {
-
-        super(partition);
-        this.minimumMemberCount = partition.getPartitionMin();
-        this.pendingMembers = new ArrayList<MemberContext>();
-        this.activeMembers = new ArrayList<MemberContext>();
-        this.terminationPendingMembers = new ArrayList<MemberContext>();
-        this.obsoletedMembers = new ConcurrentHashMap<String, MemberContext>();
-        memberStatsContexts = new ConcurrentHashMap<String, 
MemberStatsContext>();
-
-        terminationPendingStartedTime = new HashMap<String, Long>();
-        // check if a different value has been set for expiryTime
-        XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
-        pendingMemberExpiryTime = 
conf.getLong(StratosConstants.PENDING_VM_MEMBER_EXPIRY_TIMEOUT, 900000);
-        obsoltedMemberExpiryTime = 
conf.getLong(StratosConstants.OBSOLETED_VM_MEMBER_EXPIRY_TIMEOUT, 86400000);
-        if (log.isDebugEnabled()) {
-               log.debug("Member expiry time is set to: " + 
pendingMemberExpiryTime);
-               log.debug("Member obsoleted expiry time is set to: " + 
obsoltedMemberExpiryTime);
-        }
-
-        Thread th = new Thread(new PendingMemberWatcher(this));
-        th.start();
-        Thread th2 = new Thread(new ObsoletedMemberWatcher(this));
-        th2.start();
-        Thread th3 = new Thread(new TerminationPendingMemberWatcher(this));
-        th3.start();
-    }
-
-    public long getTerminationPendingStartedTimeOfMember(String memberId) {
-        return terminationPendingStartedTime.get(memberId);
-    }
-    
-    public List<MemberContext> getPendingMembers() {
-        return pendingMembers;
-    }
-    
-    public void setPendingMembers(List<MemberContext> pendingMembers) {
-        this.pendingMembers = pendingMembers;
-    }
-    
-    public int getActiveMemberCount() {
-        return activeMembers.size();
-    }
-    
-    public void setActiveMembers(List<MemberContext> activeMembers) {
-        this.activeMembers = activeMembers;
-    }
-
-    public int getMinimumMemberCount() {
-        return minimumMemberCount;
-    }
-
-    public void setMinimumMemberCount(int minimumMemberCount) {
-        this.minimumMemberCount = minimumMemberCount;
-    }
-
-    public Partition getPartition() {
-        return partition;
-    }
-
-    public void setPartition(Partition partition) {
-        this.partition = partition;
-    }
-    
-    public void addPendingMember(MemberContext ctxt) {
-        this.pendingMembers.add(ctxt);
-    }
-    
-    public boolean removePendingMember(String id) {
-       if (id == null) {
-            return false;
-        }
-        synchronized (pendingMembers) {
-            for (Iterator<MemberContext> iterator = pendingMembers.iterator(); 
iterator.hasNext(); ) {
-                MemberContext pendingMember = (MemberContext) iterator.next();
-                if (id.equals(pendingMember.getMemberId())) {
-                    iterator.remove();
-                    return true;
-                }
-
-            }
-        }
-       
-       return false;
-    }
-    
-    public void movePendingMemberToActiveMembers(String memberId) {
-        if (memberId == null) {
-            return;
-        }
-        synchronized (pendingMembers) {
-            Iterator<MemberContext> iterator = pendingMembers.listIterator();
-            while (iterator.hasNext()) {
-                MemberContext pendingMember = iterator.next();
-                if (pendingMember == null) {
-                    iterator.remove();
-                    continue;
-                }
-                if (memberId.equals(pendingMember.getMemberId())) {
-                    // member is activated
-                    // remove from pending list
-                    iterator.remove();
-                    // add to the activated list
-                    this.activeMembers.add(pendingMember);
-                    pendingMembersFailureCount = 0;
-                    if (log.isDebugEnabled()) {
-                        log.debug(String.format("Pending member is removed and 
added to the " +
-                                "activated member list. [Member Id] %s", 
memberId));
-                    }
-                    break;
-                }
-            }
-        }
-    }
-
-    public boolean activeMemberAvailable(String memberId) {
-        for (MemberContext activeMember : activeMembers) {
-            if (memberId.equals(activeMember.getMemberId())) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    public boolean pendingMemberAvailable(String memberId) {
-
-        for (MemberContext pendingMember : pendingMembers) {
-            if (memberId.equals(pendingMember.getMemberId())) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    public void moveActiveMemberToTerminationPendingMembers(String memberId) {
-        if (memberId == null) {
-            return;
-        }
-        synchronized (activeMembers) {
-            Iterator<MemberContext> iterator = activeMembers.listIterator();
-            while (iterator.hasNext()) {
-                MemberContext activeMember = iterator.next();
-                if (activeMember == null) {
-                    iterator.remove();
-                    continue;
-                }
-                if (memberId.equals(activeMember.getMemberId())) {
-                    // member is activated
-                    // remove from pending list
-                    iterator.remove();
-                    // add to the activated list
-                    this.terminationPendingMembers.add(activeMember);
-                    if (log.isDebugEnabled()) {
-                        log.debug(String.format("Active member is removed and 
added to the " +
-                                "termination pending member list. [Member Id] 
%s", memberId));
-                    }
-                    break;
-                }
-            }
-        }
-    }
-
-    /**
-     * Check the member lists for the provided member ID and move the member 
to the obsolete list
-     *
-     * @param memberId The member ID of the member to search
-     */
-    public void moveMemberToObsoleteList(String memberId) {
-        if (memberId == null) {
-            return;
-        }
-
-        // check active member list
-        Iterator<MemberContext> activeMemberIterator = 
activeMembers.listIterator();
-        MemberContext removedMember = 
this.removeMemberFrom(activeMemberIterator, memberId);
-        if (removedMember != null) {
-            this.addObsoleteMember(removedMember);
-            removedMember.setObsoleteInitTime(System.currentTimeMillis());
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Active member is removed and added to 
the " +
-                        "obsolete member list. [Member Id] %s", memberId));
-            }
-
-            return;
-        }
-
-        // check pending member list
-        Iterator<MemberContext> pendingMemberIterator = 
pendingMembers.listIterator();
-        removedMember = this.removeMemberFrom(pendingMemberIterator, memberId);
-        if (removedMember != null) {
-            this.addObsoleteMember(removedMember);
-            removedMember.setObsoleteInitTime(System.currentTimeMillis());
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Pending member is removed and added 
to the " +
-                        "obsolete member list. [Member Id] %s", memberId));
-            }
-
-            return;
-        }
-
-        // check termination pending member list
-        Iterator<MemberContext> terminationPendingMembersIterator = 
terminationPendingMembers.listIterator();
-        removedMember = 
this.removeMemberFrom(terminationPendingMembersIterator, memberId);
-        if (removedMember != null) {
-            this.addObsoleteMember(removedMember);
-            removedMember.setObsoleteInitTime(System.currentTimeMillis());
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Termination Pending member is removed 
and added to the " +
-                        "obsolete member list. [Member Id] %s", memberId));
-            }
-        }
-    }
-
-    /**
-     * Removes the {@link 
org.apache.stratos.cloud.controller.stub.pojo.MemberContext} object mapping
-     * to the specified member id from the specified MemberContext collection
-     *
-     * @param iterator The {@link java.util.Iterator} for the collection 
containing {@link org.apache.stratos.cloud.controller.stub.pojo.MemberContext}
-     *                 objects
-     * @param memberId Member Id {@link String} for the {@link 
org.apache.stratos.cloud.controller.stub.pojo.MemberContext}
-     *                 to be removed
-     * @return {@link 
org.apache.stratos.cloud.controller.stub.pojo.MemberContext} object if
-     * object found and removed, null if otherwise.
-     */
-    private MemberContext removeMemberFrom(Iterator<MemberContext> iterator, 
String memberId) {
-        while (iterator.hasNext()) {
-            MemberContext activeMember = iterator.next();
-            if (activeMember == null) {
-                iterator.remove();
-                continue;
-            }
-            if (memberId.equals(activeMember.getMemberId())) {
-                iterator.remove();
-                return activeMember;
-            }
-        }
-
-        return null;
-    }
-    
-    public void addActiveMember(MemberContext ctxt) {
-        this.activeMembers.add(ctxt);
-    }
-    
-    public void removeActiveMember(MemberContext ctxt) {
-        this.activeMembers.remove(ctxt);
-    }
-
-    public boolean removeTerminationPendingMember(String memberId) {
-        boolean terminationPendingMemberAvailable = false;
-        synchronized (terminationPendingMembers) {
-            for (MemberContext memberContext : terminationPendingMembers) {
-                if (memberContext.getMemberId().equals(memberId)) {
-                    terminationPendingMemberAvailable = true;
-                    terminationPendingMembers.remove(memberContext);
-                    break;
-                }
-            }
-        }
-        return terminationPendingMemberAvailable;
-    }
-    
-    public long getObsoltedMemberExpiryTime() {
-       return obsoltedMemberExpiryTime;
-    }
-    
-    public void setObsoltedMemberExpiryTime(long obsoltedMemberExpiryTime) {
-       this.obsoltedMemberExpiryTime = obsoltedMemberExpiryTime;
-    }
-    
-    public void addObsoleteMember(MemberContext ctxt) {
-        this.obsoletedMembers.put(ctxt.getMemberId(), ctxt);
-    }
-    
-    public boolean removeObsoleteMember(String memberId) {
-       if(this.obsoletedMembers.remove(memberId) == null) {
-               return false;
-       }
-       return true;
-    }
-
-    public long getPendingMemberExpiryTime() {
-        return pendingMemberExpiryTime;
-    }
-
-    public void setPendingMemberExpiryTime(long pendingMemberExpiryTime) {
-        this.pendingMemberExpiryTime = pendingMemberExpiryTime;
-    }
-    
-    public Map<String, MemberContext> getObsoletedMembers() {
-        return obsoletedMembers;
-    }
-        
-    public void setObsoletedMembers(Map<String, MemberContext> 
obsoletedMembers) {
-        this.obsoletedMembers = obsoletedMembers;
-    }
-
-    public String getNetworkPartitionId() {
-        return networkPartitionId;
-    }
-
-    public void setNetworkPartitionId(String networkPartitionId) {
-        this.networkPartitionId = networkPartitionId;
-    }
-
-    
-    public Map<String, MemberStatsContext> getMemberStatsContexts() {
-        return memberStatsContexts;
-    }
-
-    public MemberStatsContext getMemberStatsContext(String memberId) {
-        return memberStatsContexts.get(memberId);
-    }
-
-    public void addMemberStatsContext(MemberStatsContext ctxt) {
-        this.memberStatsContexts.put(ctxt.getMemberId(), ctxt);
-    }
-
-    public void removeMemberStatsContext(String memberId) {
-        this.memberStatsContexts.remove(memberId);
-    }
-
-    public MemberStatsContext getPartitionCtxt(String id) {
-        return this.memberStatsContexts.get(id);
-    }
-
-//    public boolean memberExist(String memberId) {
-//        return memberStatsContexts.containsKey(memberId);
-//    }
-
-
-    public Properties getProperties() {
-        return properties;
-    }
-
-    public void setProperties(Properties properties) {
-        this.properties = properties;
-    }
-
-    public String getServiceName() {
-        return serviceName;
-    }
-
-    public void setServiceName(String serviceName) {
-        this.serviceName = serviceName;
-    }
-
-    public List<MemberContext> getTerminationPendingMembers() {
-        return terminationPendingMembers;
-    }
-
-    public void setTerminationPendingMembers(List<MemberContext> 
terminationPendingMembers) {
-        this.terminationPendingMembers = terminationPendingMembers;
-    }
-
-    public int getTotalMemberCount() {
-
-        return activeMembers.size() + pendingMembers.size() + 
terminationPendingMembers.size();
-    }
-
-    public int getNonTerminatedMemberCount() {
-        return activeMembers.size() + pendingMembers.size();
-    }
-    
-    public List<MemberContext> getActiveMembers() {
-               return activeMembers;
-       }
-
-       public boolean removeActiveMemberById(String memberId) {
-        boolean removeActiveMember = false;
-        synchronized (activeMembers) {
-            Iterator<MemberContext> iterator = activeMembers.listIterator();
-            while (iterator.hasNext()) {
-                MemberContext memberContext = iterator.next();
-                if(memberId.equals(memberContext.getMemberId())){
-                    iterator.remove();
-                    removeActiveMember = true;
-
-                    break;
-                }
-            }
-        }
-        return removeActiveMember;
-    }
-
-    public boolean activeMemberExist(String memberId) {
-
-        for (MemberContext memberContext: activeMembers) {
-            if(memberId.equals(memberContext.getMemberId())){
-                return true;
-            }
-        }
-        return false;
-    }
-    
-    public  int getAllMemberForTerminationCount () {
-       int count = activeMembers.size() + pendingMembers.size() + 
terminationPendingMembers.size();
-               if (log.isDebugEnabled()) {
-               
log.debug("PartitionContext:getAllMemberForTerminationCount:size:" + count);
-       }
-       return count;
-    }
-    
-    // Map<String, MemberStatsContext> getMemberStatsContexts().keySet()
-    public  Set<String> getAllMemberForTermination () {
-
-       List<MemberContext> merged =  new ArrayList<MemberContext>();
-       
-       
-       merged.addAll(activeMembers);
-       merged.addAll(pendingMembers);
-       merged.addAll(terminationPendingMembers);
-       
-       Set<String> results = new HashSet<String>(merged.size());
-       
-       for (MemberContext ctx: merged) {
-               results.add(ctx.getMemberId());
-       }
-       
-
-       if (log.isDebugEnabled()) {
-               log.debug("PartitionContext:getAllMemberForTermination:size:" + 
results.size());
-       }
-       
-       //MemberContext x = new MemberContext();
-       //x.getMemberId()
-       
-       return results;
-    }
-
-    public void movePendingTerminationMemberToObsoleteMembers(String memberId) 
{
-
-        log.info("Starting the moving of termination pending to obsolete for 
[member] " + memberId);
-        if (memberId == null) {
-            return;
-        }
-        Iterator<MemberContext> iterator = 
terminationPendingMembers.listIterator();
-        while (iterator.hasNext()) {
-            MemberContext terminationPendingMember = iterator.next();
-            if (terminationPendingMember == null) {
-                iterator.remove();
-                continue;
-            }
-            if (memberId.equals(terminationPendingMember.getMemberId())) {
-
-                log.info("Found termination pending member and trying to move 
[member] " + memberId + " to obsolete list");
-                // member is pending termination
-                // remove from pending termination list
-                iterator.remove();
-                // add to the obsolete list
-                this.obsoletedMembers.put(memberId, terminationPendingMember);
-
-                terminationPendingStartedTime.put(memberId, 
System.currentTimeMillis());
-
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Termination pending member is 
removed and added to the " +
-                            "obsolete member list. [Member Id] %s", memberId));
-                }
-                break;
-            }
-        }
-    }
-
-    public MemberContext getPendingTerminationMember(String memberId) {
-        for (MemberContext memberContext : terminationPendingMembers) {
-            if (memberId.equals(memberContext.getMemberId())) {
-                return memberContext;
-            }
-        }
-        return null;
-    }
-
-    public long getTerminationPendingMemberExpiryTime() {
-        return terminationPendingMemberExpiryTime;
-    }
-
-    public void movePendingMemberToObsoleteMembers(String memberId) {
-        if (memberId == null) {
-            return;
-        }
-        Iterator<MemberContext> iterator = pendingMembers.listIterator();
-        while (iterator.hasNext()) {
-            MemberContext pendingMember = iterator.next();
-            if (pendingMember == null) {
-                iterator.remove();
-                continue;
-            }
-            if (memberId.equals(pendingMember.getMemberId())) {
-
-                // remove from pending list
-                iterator.remove();
-                // add to the obsolete list
-                this.obsoletedMembers.put(memberId, pendingMember);
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Pending member is removed and 
added to the " +
-                            "obsolete member list. [Member Id] %s", memberId));
-                }
-                break;
-            }
-        }
-
-    }
-
-    @Override
-    public int getCurrentElementCount() {
-        //TODO find and return correct member instance count
-        return 0;
-    }
-
-    private class PendingMemberWatcher implements Runnable {
-        private ClusterLevelPartitionContext ctxt;
-
-        public PendingMemberWatcher(ClusterLevelPartitionContext ctxt) {
-            this.ctxt = ctxt;
-        }
-
-        @Override
-        public void run() {
-
-            while (true) {
-                long expiryTime = ctxt.getPendingMemberExpiryTime();
-                List<MemberContext> pendingMembers = ctxt.getPendingMembers();
-                
-                synchronized (pendingMembers) {
-                    Iterator<MemberContext> iterator = 
pendingMembers.listIterator();
-                    while ( iterator.hasNext()) {
-                        MemberContext pendingMember = iterator.next();
-
-                        if (pendingMember == null) {
-                            continue;
-                        }
-                        long pendingTime = System.currentTimeMillis() - 
pendingMember.getInitTime();
-                        if (pendingTime >= expiryTime) {
-
-
-                            iterator.remove();
-                            log.info("Pending state of member: " + 
pendingMember.getMemberId() +
-                                     " is expired. " + "Adding as an obsoleted 
member.");
-                            // member should be terminated
-                            ctxt.addObsoleteMember(pendingMember);
-                            pendingMembersFailureCount++;
-                            if( pendingMembersFailureCount > 
PENDING_MEMBER_FAILURE_THRESHOLD){
-                                setPendingMemberExpiryTime(expiryTime * 
2);//Doubles the expiry time after the threshold of failure exceeded
-                                //TODO Implement an alerting system: 
STRATOS-369
-                            }
-                        }
-                    }
-                }
-
-                try {
-                    // TODO find a constant
-                    Thread.sleep(15000);
-                } catch (InterruptedException ignore) {
-                }
-            }
-        }
-
-    } 
-    
-    private class ObsoletedMemberWatcher implements Runnable {
-        private ClusterLevelPartitionContext ctxt;
-
-        public ObsoletedMemberWatcher(ClusterLevelPartitionContext ctxt) {
-            this.ctxt = ctxt;
-        }
-
-        @Override
-        public void run() {
-            while (true) {
-                long obsoltedMemberExpiryTime = 
ctxt.getObsoltedMemberExpiryTime();
-                Map<String, MemberContext> obsoletedMembers = 
ctxt.getObsoletedMembers();
-
-                Iterator<Entry<String, MemberContext>> iterator = 
obsoletedMembers.entrySet().iterator();
-                while (iterator.hasNext()) {
-                    Map.Entry<String, MemberContext> pairs = iterator.next();
-                    MemberContext obsoleteMember = (MemberContext) 
pairs.getValue();
-                    if (obsoleteMember == null) {
-                        continue;
-                    }
-                    long obsoleteTime = System.currentTimeMillis() - 
obsoleteMember.getInitTime();
-                    if (obsoleteTime >= obsoltedMemberExpiryTime) {
-                        iterator.remove();
-                    }
-                }
-                try {
-                    // TODO find a constant
-                    Thread.sleep(15000);
-                } catch (InterruptedException ignore) {
-                }
-            }
-        }
-    }
-
-    /**
-     * This thread is responsible for moving member to obsolete list if 
pending termination timeout happens
-     */
-    private class TerminationPendingMemberWatcher implements Runnable {
-        private ClusterLevelPartitionContext ctxt;
-
-        public TerminationPendingMemberWatcher(ClusterLevelPartitionContext 
ctxt) {
-            this.ctxt = ctxt;
-        }
-
-        @Override
-        public void run() {
-
-            while (true) {
-                long terminationPendingMemberExpiryTime = 
ctxt.getTerminationPendingMemberExpiryTime();
-
-                Iterator<MemberContext> iterator = 
ctxt.getTerminationPendingMembers().listIterator();
-                while (iterator.hasNext()) {
-
-                    MemberContext terminationPendingMember = iterator.next();
-                    if (terminationPendingMember == null){
-                        continue;
-                    }
-                    long terminationPendingTime = System.currentTimeMillis()
-                            - 
ctxt.getTerminationPendingStartedTimeOfMember(terminationPendingMember.getMemberId());
-                    if (terminationPendingTime >= 
terminationPendingMemberExpiryTime) {
-                        log.info("Moving [member] " + 
terminationPendingMember.getMemberId() + partitionId);
-                        iterator.remove();
-                        
obsoletedMembers.put(terminationPendingMember.getMemberId(), 
terminationPendingMember);
-                    }
-                }
-                try {
-                    // TODO find a constant
-                    Thread.sleep(15000);
-                } catch (InterruptedException ignore) {}
-            }
-        }
-    }
-}

Reply via email to