You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2015/05/15 12:40:15 UTC

stratos git commit: Allow LB requests in flight to send not defined instance id

Repository: stratos
Updated Branches:
  refs/heads/master c7434fa0f -> b579e8a13


Allow LB requests in flight to send not defined instance id


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

Branch: refs/heads/master
Commit: b579e8a13698c2a511b3b3b1ec3511b052ed0570
Parents: c7434fa
Author: Lahiru Sandaruwan <la...@apache.org>
Authored: Fri May 15 16:10:00 2015 +0530
Committer: Lahiru Sandaruwan <la...@apache.org>
Committed: Fri May 15 16:10:09 2015 +0530

----------------------------------------------------------------------
 .../monitor/cluster/ClusterMonitor.java         | 61 +++++++++++++++++---
 1 file changed, 53 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/b579e8a1/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
index 64a5ab2..6973db1 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
@@ -85,7 +85,7 @@ public class ClusterMonitor extends Monitor {
 
     private final ScheduledExecutorService scheduler;
     private final ExecutorService executorService;
-
+    private static final String NOT_DEFINED = "not-defined";
 
     protected boolean hasFaultyMember = false;
     protected ClusterContext clusterContext;
@@ -819,14 +819,42 @@ public class ClusterMonitor extends Monitor {
             log.debug(String.format("Average Rif event: [cluster] %s [network-partition] %s [value] %s",
                     clusterId, networkPartitionId, value));
         }
-        ClusterInstanceContext clusterLevelNetworkPartitionContext = getClusterInstanceContext(
-                networkPartitionId, clusterInstanceId);
-        if (null != clusterLevelNetworkPartitionContext) {
-            clusterLevelNetworkPartitionContext.setAverageRequestsInFlight(value);
+        if (clusterInstanceId.equals(NOT_DEFINED)) {
+
+            ClusterLevelNetworkPartitionContext networkPartitionContext = getNetworkPartitionContext(networkPartitionId);
+
+            if (null != networkPartitionContext) {
+
+                int totalActiveMemberCount = 0;
+                for(InstanceContext clusterInstanceContext : networkPartitionContext.getActiveInstances()){
+                    if(clusterInstanceContext instanceof ClusterInstanceContext){
+                        totalActiveMemberCount += ((ClusterInstanceContext) clusterInstanceContext).getActiveMemberCount();
+                    }
+                }
+                for(InstanceContext instanceContext : networkPartitionContext.getActiveInstances()){
+                    if(instanceContext instanceof ClusterInstanceContext){
+                        ClusterInstanceContext clusterInstanceContext = ((ClusterInstanceContext) instanceContext);
+                        clusterInstanceContext.setAverageRequestsInFlight(
+                                value * clusterInstanceContext.getActiveMemberCount() / totalActiveMemberCount);
+                    }
+                }
+            } else {
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Network partition context is not available for :" +
+                            " [network partition] %s", networkPartitionId));
+                }
+            }
         } else {
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Network partition context is not available for :" +
-                        " [network partition] %s", networkPartitionId));
+            ClusterInstanceContext clusterInstanceContext = getClusterInstanceContext(
+                    networkPartitionId, clusterInstanceId);
+
+            if (null != clusterInstanceContext) {
+                clusterInstanceContext.setAverageRequestsInFlight(value);
+            } else {
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Cluster instance context is not available for :" +
+                            " [cluster instance id] %s", clusterInstanceId));
+                }
             }
         }
     }
@@ -1292,6 +1320,23 @@ public class ClusterMonitor extends Monitor {
         return (ClusterInstanceContext) networkPartitionContext.getInstanceContext(instanceId);
     }
 
+    public ClusterLevelNetworkPartitionContext getNetworkPartitionContext(String networkPartitionId) {
+        Map<String,
+                ClusterLevelNetworkPartitionContext> clusterLevelNetworkPartitionContextMap =
+                (this.clusterContext).getNetworkPartitionCtxts();
+        if (StringUtils.isBlank(networkPartitionId)) {
+            throw new RuntimeException("Network partition id is null");
+        }
+        ClusterLevelNetworkPartitionContext networkPartitionContext =
+                clusterLevelNetworkPartitionContextMap.get(networkPartitionId);
+        if (networkPartitionContext == null) {
+            throw new RuntimeException("Network partition context not found: [network-partition-id] " +
+                    networkPartitionId);
+        }
+
+        return networkPartitionContext;
+    }
+
     public Collection<ClusterLevelNetworkPartitionContext> getNetworkPartitionCtxts() {
         return (this.clusterContext).getNetworkPartitionCtxts().values();
     }