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 in GroupLevelNetworkPartitionContext
Date Mon, 01 Dec 2014 11:19:01 GMT
Repository: stratos
Updated Branches:
  refs/heads/master ec3561606 -> 4bfd66583


Changing partition context map to a list in GroupLevelNetworkPartitionContext


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

Branch: refs/heads/master
Commit: 4bfd665833b9f84ef1ed610d7576478f80c3ee83
Parents: ec35616
Author: Lahiru Sandaruwan <lahirus@apache.org>
Authored: Mon Dec 1 16:50:38 2014 +0530
Committer: Lahiru Sandaruwan <lahirus@apache.org>
Committed: Mon Dec 1 16:50:38 2014 +0530

----------------------------------------------------------------------
 .../GroupLevelNetworkPartitionContext.java      | 37 +++++++++++++-------
 1 file changed, 25 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/4bfd6658/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/GroupLevelNetworkPartitionContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/GroupLevelNetworkPartitionContext.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/GroupLevelNetworkPartitionContext.java
index a9f7f56..2248a68 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/GroupLevelNetworkPartitionContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/GroupLevelNetworkPartitionContext.java
@@ -20,13 +20,12 @@ package org.apache.stratos.autoscaler.context.partition.network;
 
 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.cloud.controller.stub.domain.Partition;
 
 import java.io.Serializable;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 /**
  * Holds runtime data of a network partition.
@@ -50,7 +49,7 @@ public class GroupLevelNetworkPartitionContext extends NetworkPartitionContext
i
     private int currentPartitionIndex;
 
     //partitions of this network partition
-    private final Map<String, GroupLevelPartitionContext> partitionCtxts;
+    private final List<GroupLevelPartitionContext> partitionCtxts;
 
     public GroupLevelNetworkPartitionContext(String id, String partitionAlgo, Partition[]
partitions) {
         this.id = id;
@@ -60,7 +59,7 @@ public class GroupLevelNetworkPartitionContext extends NetworkPartitionContext
i
         } else {
             this.partitions = Arrays.copyOf(partitions, partitions.length);
         }
-        partitionCtxts = new HashMap<String, GroupLevelPartitionContext>();
+        partitionCtxts = new ArrayList<GroupLevelPartitionContext>();
         for (Partition partition : partitions) {
             minInstanceCount += partition.getPartitionMin();
             maxInstanceCount += partition.getPartitionMax();
@@ -135,16 +134,24 @@ public class GroupLevelNetworkPartitionContext extends NetworkPartitionContext
i
         return id;
     }
 
-    public Map<String, GroupLevelPartitionContext> getPartitionCtxts() {
+    public List<GroupLevelPartitionContext> getPartitionCtxts() {
+
         return partitionCtxts;
     }
 
     public GroupLevelPartitionContext getPartitionCtxt(String partitionId) {
-        return partitionCtxts.get(partitionId);
+
+
+        for(GroupLevelPartitionContext partitionContext : partitionCtxts){
+            if(partitionContext.getPartitionId().equals(partitionId)){
+                return partitionContext;
+            }
+        }
+        return null;
     }
 
     public void addPartitionContext(GroupLevelPartitionContext partitionContext) {
-        partitionCtxts.put(partitionContext.getPartitionId(), partitionContext);
+        partitionCtxts.add(partitionContext);
     }
 
     public String getPartitionAlgorithm() {
@@ -156,15 +163,21 @@ public class GroupLevelNetworkPartitionContext extends NetworkPartitionContext
i
     }
 
     public int getNonTerminatedMemberCountOfPartition(String partitionId) {
-        if (partitionCtxts.containsKey(partitionId)) {
-            return getPartitionCtxt(partitionId).getNonTerminatedInstanceCount();
+
+        for(GroupLevelPartitionContext partitionContext : partitionCtxts){
+            if(partitionContext.getPartitionId().equals(partitionId)){
+                return partitionContext.getNonTerminatedInstanceCount();
+            }
         }
         return 0;
     }
 
     public int getActiveMemberCount(String currentPartitionId) {
-        if (partitionCtxts.containsKey(currentPartitionId)) {
-            return getPartitionCtxt(currentPartitionId).getActiveInstanceCount();
+
+        for(GroupLevelPartitionContext partitionContext : partitionCtxts){
+            if(partitionContext.getPartitionId().equals(currentPartitionId)){
+                return partitionContext.getActiveInstanceCount();
+            }
         }
         return 0;
     }


Mime
View raw message