stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lahi...@apache.org
Subject stratos git commit: Changing partition context map to a list
Date Mon, 01 Dec 2014 11:12:43 GMT
Repository: stratos
Updated Branches:
  refs/heads/master 664c219f7 -> ec3561606


Changing partition context map to a list


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

Branch: refs/heads/master
Commit: ec35616060c670ff8f28b73cfabca92a14815d93
Parents: 664c219
Author: Lahiru Sandaruwan <lahirus@apache.org>
Authored: Mon Dec 1 16:44:18 2014 +0530
Committer: Lahiru Sandaruwan <lahirus@apache.org>
Committed: Mon Dec 1 16:44:18 2014 +0530

----------------------------------------------------------------------
 .../context/cluster/ClusterInstanceContext.java | 61 ++++++++++++++------
 .../monitor/cluster/VMClusterMonitor.java       |  2 +-
 .../cluster/VMServiceClusterMonitor.java        |  2 +-
 .../autoscaler/rule/RuleTasksDelegator.java     |  4 +-
 .../cluster/ClusterStatusActiveProcessor.java   |  2 +-
 .../cluster/ClusterStatusInActiveProcessor.java |  2 +-
 .../ClusterStatusTerminatedProcessor.java       |  2 +-
 7 files changed, 50 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/ec356160/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterInstanceContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterInstanceContext.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterInstanceContext.java
index ff2aaf3..f2c13b9 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterInstanceContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterInstanceContext.java
@@ -21,15 +21,17 @@ package org.apache.stratos.autoscaler.context.cluster;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.context.partition.ClusterLevelPartitionContext;
+import org.apache.stratos.autoscaler.context.partition.GroupLevelPartitionContext;
 import org.apache.stratos.autoscaler.context.partition.PartitionContext;
 import org.apache.stratos.autoscaler.pojo.policy.autoscale.LoadAverage;
 import org.apache.stratos.autoscaler.pojo.policy.autoscale.MemoryConsumption;
 import org.apache.stratos.autoscaler.pojo.policy.autoscale.RequestsInFlight;
 import org.apache.stratos.autoscaler.pojo.policy.deployment.partition.network.ChildLevelPartition;
+import org.apache.stratos.autoscaler.pojo.policy.deployment.partition.network.ChildLevelNetworkPartition;
+import org.apache.stratos.cloud.controller.stub.domain.Partition;
 import org.apache.stratos.messaging.domain.topology.Member;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 /*
  * It holds the runtime data of a VM cluster
@@ -76,13 +78,21 @@ public class ClusterInstanceContext {
     private int currentPartitionIndex;
 
     // Map<PartitionId, Partition Context>
-    protected Map<String, ClusterLevelPartitionContext> partitionCtxts;
+    protected List<ClusterLevelPartitionContext> partitionCtxts;
+
+    private ChildLevelPartition[] partitions;
+
     public ClusterInstanceContext(String clusterInstanceId, String partitionAlgo, ChildLevelPartition[]
partitions,
                                   int min) {
 
         this.id = clusterInstanceId;
         this.min = min;
-        partitionCtxts = new HashMap<String, ClusterLevelPartitionContext>();
+        if (partitions == null) {
+            this.partitions = new ChildLevelPartition[0];
+        } else {
+            this.partitions = Arrays.copyOf(partitions, partitions.length);
+        }
+        partitionCtxts = new ArrayList<ClusterLevelPartitionContext>();
         this.partitionAlgorithm = partitionAlgo;
         //partitionCtxts = new HashMap<String, ClusterLevelPartitionContext>();
         requestsInFlight = new RequestsInFlight();
@@ -97,42 +107,57 @@ public class ClusterInstanceContext {
 
     }
 
-    public Map<String, ClusterLevelPartitionContext> getPartitionCtxts(){
+    public List<ClusterLevelPartitionContext> getPartitionCtxts(){
         return partitionCtxts;
     }
-    public PartitionContext[] getPartitionCtxtsAsAnArray(){
 
-        return (PartitionContext[])getPartitionCtxts().values().toArray();
-    }
+    public ClusterLevelPartitionContext[] getPartitionCtxtsAsAnArray(){
 
-    public ClusterLevelPartitionContext getNetworkPartitionCtxt(String PartitionId) {
-        return partitionCtxts.get(PartitionId);
+        return partitionCtxts.toArray(new ClusterLevelPartitionContext[0]);
     }
 
-    public void setPartitionCtxt(Map<String, ClusterLevelPartitionContext> partitionCtxt)
{
+//    public ClusterLevelPartitionContext getNetworkPartitionCtxt(String PartitionId) {
+//        return partitionCtxts.get(PartitionId);
+//    }
+
+    public void setPartitionCtxts(List<ClusterLevelPartitionContext> partitionCtxt)
{
         this.partitionCtxts = partitionCtxt;
     }
 
     public boolean partitionCtxtAvailable(String partitionId) {
-        return partitionCtxts.containsKey(partitionId);
+
+        for(ClusterLevelPartitionContext partitionContext : partitionCtxts){
+            if(partitionContext.getPartitionId().equals(partitionId)){
+                return true;
+            }
+        }
+        return false;
     }
 
     public void addPartitionCtxt(ClusterLevelPartitionContext ctxt) {
-        this.partitionCtxts.put(ctxt.getPartitionId(), ctxt);
+        this.partitionCtxts.add(ctxt);
     }
 
     public ClusterLevelPartitionContext getPartitionCtxt(String id) {
-        return this.partitionCtxts.get(id);
+
+        for(ClusterLevelPartitionContext partitionContext : partitionCtxts){
+            if(partitionContext.getPartitionId().equals(id)){
+                return partitionContext;
+            }
+        }
+        return null;
     }
 
     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);
-        }
 
+        for(ClusterLevelPartitionContext partitionContext : partitionCtxts){
+            if(partitionContext.getPartitionId().equals(partitionId)){
+                log.info("Returning partition context, of [partition] " + partitionId);
+                return partitionContext;
+            }
+        }
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/ec356160/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
index 1db7a31..69e7ca0 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
@@ -687,7 +687,7 @@ abstract public class VMClusterMonitor extends AbstractClusterMonitor
{
 
                 for (ClusterLevelNetworkPartitionContext networkPartitionContext : getAllNetworkPartitionCtxts().values())
{
                     for(ClusterInstanceContext instanceContext : networkPartitionContext.getClusterInstanceContextMap().values())
{
-                        for (ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts().values())
{
+                        for (ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts())
{
                             //if (log.isDebugEnabled()) {
                             log.info("Starting to terminate all members in cluster [" + getClusterId()
+ "] Network Partition [ " +
                                     networkPartitionContext.getId() + " ], Partition [ "
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/ec356160/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMServiceClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMServiceClusterMonitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMServiceClusterMonitor.java
index 68ce932..a20e1f2 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMServiceClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMServiceClusterMonitor.java
@@ -127,7 +127,7 @@ public class VMServiceClusterMonitor extends VMClusterMonitor {
                         //FIXME to check the status of the instance
                         if (true) {
                             for (ClusterLevelPartitionContext partitionContext :
-                                    instanceContext.getPartitionCtxts().values()) {
+                                    instanceContext.getPartitionCtxts()) {
                                 // store primary members in the partition context
                                 List<String> primaryMemberListInPartition = new ArrayList<String>();
                                 // get active primary members in this partition context

http://git-wip-us.apache.org/repos/asf/stratos/blob/ec356160/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
index 2582fb8..2dfe967 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
@@ -481,7 +481,7 @@ public class RuleTasksDelegator {
     public double getLoadAveragePredictedValue(ClusterInstanceContext clusterInstanceContext)
{
         double loadAveragePredicted = 0.0d;
         int totalMemberCount = 0;
-        for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts().values())
{
+        for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts())
{
             for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts().values())
{
 
                 float memberAverageLoadAverage = memberStatsContext.getLoadAverage().getAverage();
@@ -508,7 +508,7 @@ public class RuleTasksDelegator {
     public double getMemoryConsumptionPredictedValue(ClusterInstanceContext clusterInstanceContext)
{
         double memoryConsumptionPredicted = 0.0d;
         int totalMemberCount = 0;
-        for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts().values())
{
+        for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts())
{
             for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts().values())
{
 
                 float memberMemoryConsumptionAverage = memberStatsContext.getMemoryConsumption().getAverage();

http://git-wip-us.apache.org/repos/asf/stratos/blob/ec356160/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
index d6dc59e..1967a4b 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
@@ -70,7 +70,7 @@ public class ClusterStatusActiveProcessor extends ClusterStatusProcessor
{
         for (ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext : monitor.getNetworkPartitionCtxts())
{
             //minimum check per partition
             ClusterInstanceContext instanceContext = clusterLevelNetworkPartitionContext.getClusterInstanceContext(instanceId);
-            for (ClusterLevelPartitionContext clusterMonitorPartitionContext : instanceContext.getPartitionCtxts().values())
{
+            for (ClusterLevelPartitionContext clusterMonitorPartitionContext : instanceContext.getPartitionCtxts())
{
                 if (clusterMonitorPartitionContext.getMinimumMemberCount() == clusterMonitorPartitionContext.getActiveMemberCount())
{
                     clusterActive = true;
                 } else if (clusterMonitorPartitionContext.getActiveMemberCount() > clusterMonitorPartitionContext.getMinimumMemberCount())
{

http://git-wip-us.apache.org/repos/asf/stratos/blob/ec356160/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusInActiveProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusInActiveProcessor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusInActiveProcessor.java
index 01daa54..c0773a4 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusInActiveProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusInActiveProcessor.java
@@ -94,7 +94,7 @@ public class ClusterStatusInActiveProcessor extends ClusterStatusProcessor
{
         boolean clusterInActive = false;
         for (ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext : monitor.getAllNetworkPartitionCtxts().values())
{
             ClusterInstanceContext instanceContext = clusterLevelNetworkPartitionContext.getClusterInstanceContext(instanceId);
-            for (ClusterLevelPartitionContext partition : instanceContext.getPartitionCtxts().values())
{
+            for (ClusterLevelPartitionContext partition : instanceContext.getPartitionCtxts())
{
                 if (partition.getActiveMemberCount() <= partition.getMinimumMemberCount())
{
                     clusterInActive = true;
                     return clusterInActive;

http://git-wip-us.apache.org/repos/asf/stratos/blob/ec356160/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusTerminatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusTerminatedProcessor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusTerminatedProcessor.java
index 45a8b5f..00abe34 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusTerminatedProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusTerminatedProcessor.java
@@ -127,7 +127,7 @@ public class ClusterStatusTerminatedProcessor extends ClusterStatusProcessor
{
             for(ClusterInstanceContext clusterInstanceContext :
                     clusterLevelNetworkPartitionContext.getClusterInstanceContextMap().values())
{
                 for (ClusterLevelPartitionContext partitionContext :
-                        clusterInstanceContext.getPartitionCtxts().values()) {
+                        clusterInstanceContext.getPartitionCtxts()) {
                     if (partitionContext.getNonTerminatedMemberCount() > 0) {
                         hasMember = true;
                     } else {


Mime
View raw message