Updated Branches: refs/heads/master 4e159ce1c -> bb5b4bf2b
Fixing LB cluster monitor handling at health stat events Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/9f312981 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/9f312981 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/9f312981 Branch: refs/heads/master Commit: 9f31298145c9c0c658540dcdc1e7c6e29c008391 Parents: 9a6dd17 Author: Lahiru Sandaruwan <[email protected]> Authored: Fri Jan 10 14:41:00 2014 +0530 Committer: Lahiru Sandaruwan <[email protected]> Committed: Fri Jan 10 14:41:00 2014 +0530 ---------------------------------------------------------------------- .../health/AutoscalerHealthStatReceiver.java | 217 +++++++++++++------ 1 file changed, 149 insertions(+), 68 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9f312981/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/health/AutoscalerHealthStatReceiver.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/health/AutoscalerHealthStatReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/health/AutoscalerHealthStatReceiver.java index 35a5e1d..53c2541 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/health/AutoscalerHealthStatReceiver.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/health/AutoscalerHealthStatReceiver.java @@ -462,7 +462,20 @@ public class AutoscalerHealthStatReceiver implements Runnable { log.debug(String.format("Avg load avg event: [cluster] %s [network-partition] %s [value] %s", clusterId, networkPartitionId, floatValue)); } - AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + AbstractMonitor monitor; + + if(asCtx.moniterExist(clusterId)){ + monitor = asCtx.getMonitor(clusterId); + }else if(asCtx.lbMoniterExist(clusterId)){ + monitor = asCtx.getLBMonitor(clusterId); + }else{ + String errMsg = "A monitor is not found for this cluster"; + if(log.isErrorEnabled()){ + log.error(String.format("A cluster monitor is not found in autoscaler context [cluster] %s", clusterId)); + } + throw new RuntimeException(errMsg); + } if(null != monitor){ NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId); if(null != networkPartitionContext){ @@ -473,11 +486,6 @@ public class AutoscalerHealthStatReceiver implements Runnable { " [network partition] %s", networkPartitionId)); } } - } else { - - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId)); - } } } @@ -497,7 +505,21 @@ public class AutoscalerHealthStatReceiver implements Runnable { log.debug(String.format("Avg Memory Consumption event: [cluster] %s [network-partition] %s [value] %s", clusterId, networkPartitionId, floatValue)); } - AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + AbstractMonitor monitor; + + if(asCtx.moniterExist(clusterId)){ + monitor = asCtx.getMonitor(clusterId); + }else if(asCtx.lbMoniterExist(clusterId)){ + monitor = asCtx.getLBMonitor(clusterId); + }else{ + String errMsg = "A monitor is not found for this cluster"; + if(log.isErrorEnabled()){ + log.error(String.format("A cluster monitor is not found in autoscaler context [cluster] %s", clusterId)); + } + throw new RuntimeException(errMsg); + } + if(null != monitor){ NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId); if(null != networkPartitionContext){ @@ -508,11 +530,6 @@ public class AutoscalerHealthStatReceiver implements Runnable { " [network partition] %s", networkPartitionId)); } } - } else { - - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId)); - } } } @@ -531,8 +548,20 @@ public class AutoscalerHealthStatReceiver implements Runnable { log.debug(String.format("Average Rif event: [cluster] %s [network-partition] %s [value] %s", clusterId, networkPartitionId, floatValue)); } - - AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + AbstractMonitor monitor; + + if(asCtx.moniterExist(clusterId)){ + monitor = asCtx.getMonitor(clusterId); + }else if(asCtx.lbMoniterExist(clusterId)){ + monitor = asCtx.getLBMonitor(clusterId); + }else{ + String errMsg = "A monitor is not found for this cluster"; + if(log.isErrorEnabled()){ + log.error(String.format("A cluster monitor is not found in autoscaler context [cluster] %s", clusterId)); + } + throw new RuntimeException(errMsg); + } if(null != monitor){ NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId); if(null != networkPartitionContext){ @@ -543,11 +572,6 @@ public class AutoscalerHealthStatReceiver implements Runnable { " [network partition] %s", networkPartitionId)); } } - } else { - - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId)); - } } } @@ -565,7 +589,20 @@ public class AutoscalerHealthStatReceiver implements Runnable { log.debug(String.format("Grad of load avg event: [cluster] %s [network-partition] %s [value] %s", clusterId, networkPartitionId, floatValue)); } - AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + AbstractMonitor monitor; + + if(asCtx.moniterExist(clusterId)){ + monitor = asCtx.getMonitor(clusterId); + }else if(asCtx.lbMoniterExist(clusterId)){ + monitor = asCtx.getLBMonitor(clusterId); + }else{ + String errMsg = "A monitor is not found for this cluster"; + if(log.isErrorEnabled()){ + log.error(String.format("A cluster monitor is not found in autoscaler context [cluster] %s", clusterId)); + } + throw new RuntimeException(errMsg); + } if(null != monitor){ NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId); if(null != networkPartitionContext){ @@ -576,11 +613,6 @@ public class AutoscalerHealthStatReceiver implements Runnable { " [network partition] %s", networkPartitionId)); } } - } else { - - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId)); - } } } @@ -599,7 +631,20 @@ public class AutoscalerHealthStatReceiver implements Runnable { log.debug(String.format("Grad of Memory Consumption event: [cluster] %s [network-partition] %s [value] %s", clusterId, networkPartitionId, floatValue)); } - AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + AbstractMonitor monitor; + + if(asCtx.moniterExist(clusterId)){ + monitor = asCtx.getMonitor(clusterId); + }else if(asCtx.lbMoniterExist(clusterId)){ + monitor = asCtx.getLBMonitor(clusterId); + }else{ + String errMsg = "A monitor is not found for this cluster"; + if(log.isErrorEnabled()){ + log.error(String.format("A cluster monitor is not found in autoscaler context [cluster] %s", clusterId)); + } + throw new RuntimeException(errMsg); + }; if(null != monitor){ NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId); if(null != networkPartitionContext){ @@ -610,11 +655,6 @@ public class AutoscalerHealthStatReceiver implements Runnable { " [network partition] %s", networkPartitionId)); } } - } else { - - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId)); - } } } @@ -632,7 +672,20 @@ public class AutoscalerHealthStatReceiver implements Runnable { log.debug(String.format("Gradient of Rif event: [cluster] %s [network-partition] %s [value] %s", clusterId, networkPartitionId, floatValue)); } - AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + AbstractMonitor monitor; + + if(asCtx.moniterExist(clusterId)){ + monitor = asCtx.getMonitor(clusterId); + }else if(asCtx.lbMoniterExist(clusterId)){ + monitor = asCtx.getLBMonitor(clusterId); + }else{ + String errMsg = "A monitor is not found for this cluster"; + if(log.isErrorEnabled()){ + log.error(String.format("A cluster monitor is not found in autoscaler context [cluster] %s", clusterId)); + } + throw new RuntimeException(errMsg); + } if(null != monitor){ NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId); if(null != networkPartitionContext){ @@ -643,11 +696,6 @@ public class AutoscalerHealthStatReceiver implements Runnable { " [network partition] %s", networkPartitionId)); } } - } else { - - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId)); - } } } @@ -737,7 +785,7 @@ public class AutoscalerHealthStatReceiver implements Runnable { memoryConsumption.setGradient(floatValue); if (log.isDebugEnabled()) { - log.debug(String.format("Meber grad of Memory Consumption event: [member] %s [value] %s", e.getMemberId(), + log.debug(String.format("Member grad of Memory Consumption event: [member] %s [value] %s", e.getMemberId(), floatValue)); } } @@ -783,7 +831,20 @@ public class AutoscalerHealthStatReceiver implements Runnable { log.debug(String.format("Second Derivation of load avg event: [cluster] %s [network-partition] %s [value] %s", clusterId, networkPartitionId, floatValue)); } - AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + AbstractMonitor monitor; + + if(asCtx.moniterExist(clusterId)){ + monitor = asCtx.getMonitor(clusterId); + }else if(asCtx.lbMoniterExist(clusterId)){ + monitor = asCtx.getLBMonitor(clusterId); + }else{ + String errMsg = "A monitor is not found for this cluster"; + if(log.isErrorEnabled()){ + log.error(String.format("A cluster monitor is not found in autoscaler context [cluster] %s", clusterId)); + } + throw new RuntimeException(errMsg); + } if(null != monitor){ NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId); if(null != networkPartitionContext){ @@ -794,11 +855,6 @@ public class AutoscalerHealthStatReceiver implements Runnable { " [network partition] %s", networkPartitionId)); } } - } else { - - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId)); - } } } @@ -817,7 +873,20 @@ public class AutoscalerHealthStatReceiver implements Runnable { log.debug(String.format("Second Derivation of Memory Consumption event: [cluster] %s [network-partition] %s [value] %s", clusterId, networkPartitionId, floatValue)); } - AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + AbstractMonitor monitor; + + if(asCtx.moniterExist(clusterId)){ + monitor = asCtx.getMonitor(clusterId); + }else if(asCtx.lbMoniterExist(clusterId)){ + monitor = asCtx.getLBMonitor(clusterId); + }else{ + String errMsg = "A monitor is not found for this cluster"; + if(log.isErrorEnabled()){ + log.error(String.format("A cluster monitor is not found in autoscaler context [cluster] %s", clusterId)); + } + throw new RuntimeException(errMsg); + } if(null != monitor){ NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId); if(null != networkPartitionContext){ @@ -828,11 +897,6 @@ public class AutoscalerHealthStatReceiver implements Runnable { " [network partition] %s", networkPartitionId)); } } - } else { - - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId)); - } } } @@ -847,10 +911,23 @@ public class AutoscalerHealthStatReceiver implements Runnable { Float floatValue = e.getValue(); if (log.isDebugEnabled()) { - log.debug(String.format("Second dericvative of Rif event: [cluster] %s [network-partition] %s [value] %s", + log.debug(String.format("Second derivative of Rif event: [cluster] %s [network-partition] %s [value] %s", clusterId, networkPartitionId, floatValue)); } - AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + AbstractMonitor monitor; + + if(asCtx.moniterExist(clusterId)){ + monitor = asCtx.getMonitor(clusterId); + }else if(asCtx.lbMoniterExist(clusterId)){ + monitor = asCtx.getLBMonitor(clusterId); + }else{ + String errMsg = "A monitor is not found for this cluster"; + if(log.isErrorEnabled()){ + log.error(String.format("A cluster monitor is not found in autoscaler context [cluster] %s", clusterId)); + } + throw new RuntimeException(errMsg); + } if(null != monitor){ NetworkPartitionContext networkPartitionContext = monitor.getNetworkPartitionCtxt(networkPartitionId); if(null != networkPartitionContext){ @@ -861,11 +938,6 @@ public class AutoscalerHealthStatReceiver implements Runnable { " [network partition] %s", networkPartitionId)); } } - } else { - - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [cluster] %s", clusterId)); - } } } @@ -881,16 +953,20 @@ public class AutoscalerHealthStatReceiver implements Runnable { if(null == member){ if(log.isErrorEnabled()) { - log.error(String.format("Member not found: [member] %s", memberId)); + log.error(String.format("Member not found in the Topology: [member] %s", memberId)); } return null; } AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(member.getClusterId()); if(null == monitor){ - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [member] %s", memberId)); + monitor = AutoscalerContext.getInstance().getLBMonitor(member.getClusterId()); + if(null == monitor){ + + if(log.isErrorEnabled()) { + log.error(String.format("Cluster monitor is not available for : [member] %s", memberId)); + } + return null; } - return null; } String networkPartitionId = findNetworkPartitionId(memberId); MemberStatsContext memberStatsContext = monitor.getNetworkPartitionCtxt(networkPartitionId) @@ -920,20 +996,23 @@ public class AutoscalerHealthStatReceiver implements Runnable { if(null == member){ if(log.isErrorEnabled()) { - log.error(String.format("Member not found: [member] %s", memberId)); + log.error(String.format("Member not found in the Topology : [member] %s", memberId)); } return null; } AbstractMonitor monitor = AutoscalerContext.getInstance().getMonitor(member.getClusterId()); if(null == monitor){ - if(log.isErrorEnabled()) { - log.error(String.format("Cluster monitor is not available for : [member] %s", memberId)); + + monitor = AutoscalerContext.getInstance().getLBMonitor(member.getClusterId()); + if(null == monitor){ + if(log.isErrorEnabled()) { + log.error(String.format("Cluster monitor is not available for : [member] %s", memberId)); + } } return null; } - - + String networkPartitionId = findNetworkPartitionId(memberId); MemberStatsContext memberStatsContext = monitor.getNetworkPartitionCtxt(networkPartitionId) .getPartitionCtxt(member.getPartitionId()) @@ -993,8 +1072,10 @@ public class AutoscalerHealthStatReceiver implements Runnable { }else if(asCtx.lbMoniterExist(clusterId)){ monitor = asCtx.getLBMonitor(clusterId); }else{ - String errMsg = "A monitor is not found for this custer"; - log.error(errMsg); + String errMsg = "A monitor is not found for this cluster"; + if(log.isErrorEnabled()){ + log.error(String.format("A cluster monitor is not found in autoscaler context [cluster] %s", clusterId)); + } throw new RuntimeException(errMsg); }
