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 2013/12/27 20:37:37 UTC

git commit: Adding null checks for requests in flight event handling

Updated Branches:
  refs/heads/master 2fd5d40bd -> 3fca23c8f


Adding null checks for requests in flight event handling


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

Branch: refs/heads/master
Commit: 3fca23c8f0b6a88c4737b32a73010679ae9a56be
Parents: 2fd5d40
Author: Lahiru Sandaruwan <la...@apache.org>
Authored: Sat Dec 28 01:11:53 2013 +0530
Committer: Lahiru Sandaruwan <la...@apache.org>
Committed: Sat Dec 28 01:11:53 2013 +0530

----------------------------------------------------------------------
 .../health/HealthEventMessageDelegator.java     | 65 +++++++++++++++++---
 1 file changed, 55 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/3fca23c8/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/health/HealthEventMessageDelegator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/health/HealthEventMessageDelegator.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/health/HealthEventMessageDelegator.java
index 6fbc4e4..e02f6a5 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/health/HealthEventMessageDelegator.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/health/HealthEventMessageDelegator.java
@@ -79,11 +79,27 @@ public class HealthEventMessageDelegator implements Runnable {
                     Float floatValue = Float.parseFloat(value);
 
                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("%s event: [cluster] %s [network-partition] %s [value] %s", eventName, clusterId, networkPartitionId, value));
+                        log.debug(String.format("%s event: [cluster] %s [network-partition] %s [value] %s", eventName,
+                                clusterId, networkPartitionId, value));
                     }
 
-                    AutoscalerContext.getInstance().getMonitor(clusterId).getNetworkPartitionCtxt(networkPartitionId)
-                            .setAverageRequestsInFlight(floatValue);
+                    AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId);
+                    if(null != monitor){
+                        NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId);
+                        if(null != networkPartitionContext){
+                            networkPartitionContext.setAverageRequestsInFlight(floatValue);
+                        } else {
+                            if(log.isErrorEnabled()) {
+                               log.error(String.format("Network partition context is not available for :" +
+                                       " [network partition] %s", networkPartitionId));
+                            }
+                        }
+                    } else {
+
+                        if(log.isErrorEnabled()) {
+                           log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId));
+                        }
+                    }
 
                 } else if (Constants.GRADIENT_OF_REQUESTS_IN_FLIGHT.equals(eventName)) {
                     String clusterId = event.getProperties().get("cluster_id");
@@ -92,11 +108,26 @@ public class HealthEventMessageDelegator implements Runnable {
                     Float floatValue = Float.parseFloat(value);
 
                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("%s event: [cluster] %s [network-partition] %s [value] %s", eventName, clusterId, networkPartitionId, value));
+                        log.debug(String.format("%s event: [cluster] %s [network-partition] %s [value] %s", eventName,
+                                clusterId, networkPartitionId, value));
                     }
+                    AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId);
+                    if(null != monitor){
+                        NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId);
+                        if(null != networkPartitionContext){
+                            networkPartitionContext.setRequestsInFlightGradient(floatValue);
+                        } else {
+                            if(log.isErrorEnabled()) {
+                               log.error(String.format("Network partition context is not available for :" +
+                                       " [network partition] %s", networkPartitionId));
+                            }
+                        }
+                    } else {
 
-                    AutoscalerContext.getInstance().getMonitor(clusterId).getNetworkPartitionCtxt(networkPartitionId)
-                            .setRequestsInFlightGradient(floatValue);
+                        if(log.isErrorEnabled()) {
+                           log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId));
+                        }
+                    }
 
                 } else if (Constants.SECOND_DERIVATIVE_OF_REQUESTS_IN_FLIGHT.equals(eventName)) {
                     String clusterId = event.getProperties().get("cluster_id");
@@ -105,12 +136,26 @@ public class HealthEventMessageDelegator implements Runnable {
                     Float floatValue = Float.parseFloat(value);
 
                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("%s event: [cluster] %s [network-partition] %s [value] %s", eventName, clusterId, networkPartitionId, value));
+                        log.debug(String.format("%s event: [cluster] %s [network-partition] %s [value] %s", eventName,
+                                clusterId, networkPartitionId, value));
                     }
+                    AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId);
+                    if(null != monitor){
+                        NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId);
+                        if(null != networkPartitionContext){
+                            networkPartitionContext.setRequestsInFlightSecondDerivative(floatValue);
+                        } else {
+                            if(log.isErrorEnabled()) {
+                               log.error(String.format("Network partition context is not available for :" +
+                                       " [network partition] %s", networkPartitionId));
+                            }
+                        }
+                    } else {
 
-                    AutoscalerContext.getInstance().getMonitor(clusterId).getNetworkPartitionCtxt(networkPartitionId)
-                            .setRequestsInFlightSecondDerivative(floatValue);
-
+                        if(log.isErrorEnabled()) {
+                           log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId));
+                        }
+                    }
                 } else if (Constants.MEMBER_FAULT_EVENT_NAME.equals(eventName)) {
                     String clusterId = event.getProperties().get("cluster_id");
                     String memberId = event.getProperties().get("member_id");