Updated Branches: refs/heads/master a41ee2f77 -> febcde501
Correcting logic faults and dead codes in health event handler Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/f7b10924 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/f7b10924 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/f7b10924 Branch: refs/heads/master Commit: f7b10924596772065cf80d720b4d09ffc35e3dc8 Parents: cc572db Author: Udara Liyanage <[email protected]> Authored: Fri Dec 20 13:51:12 2013 -0500 Committer: Udara Liyanage <[email protected]> Committed: Fri Dec 20 13:51:12 2013 -0500 ---------------------------------------------------------------------- .../health/HealthEventMessageDelegator.java | 97 ++++++++++---------- 1 file changed, 47 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f7b10924/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 cab71e6..b6a8289 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 @@ -210,72 +210,68 @@ public class HealthEventMessageDelegator implements Runnable { private LoadAverage findLoadAverage(Event event) { String memberId = event.getProperties().get("member_id"); Member member = findMember(memberId); - - if(member.isActive()){ + + if(null == member){ + if(log.isErrorEnabled()) { + log.error(String.format("Member not found: [member] %s", memberId)); + } + return null; + } + if(!member.isActive()){ if(log.isDebugEnabled()){ log.debug(String.format("Member activated event has not received for the member %s. Therefore ignoring" + " the load average health stat", memberId)); } return null; } - if(member != null) { - String networkPartitionId = findNetworkPartitionId(memberId); - LoadAverage loadAverage = AutoscalerContext.getInstance().getMonitor(member.getClusterId()) + + String networkPartitionId = findNetworkPartitionId(memberId); + LoadAverage loadAverage = AutoscalerContext.getInstance().getMonitor(member.getClusterId()) + .getNetworkPartitionCtxt(networkPartitionId) + .getPartitionCtxt(member.getPartitionId()) + .getMemberStatsContext(memberId).getLoadAverage(); + + if(loadAverage == null) { + loadAverage = new LoadAverage(); + AutoscalerContext.getInstance().getMonitor(member.getClusterId()) .getNetworkPartitionCtxt(networkPartitionId) .getPartitionCtxt(member.getPartitionId()) - .getMemberStatsContext(memberId).getLoadAverage(); - - if(loadAverage == null) { - loadAverage = new LoadAverage(); - AutoscalerContext.getInstance().getMonitor(member.getClusterId()) - .getNetworkPartitionCtxt(networkPartitionId) - .getPartitionCtxt(member.getPartitionId()) - .getMemberStatsContext(memberId).setLoadAverage(loadAverage); - } - return loadAverage; - } - else { - if(log.isErrorEnabled()) { - log.error(String.format("Member not found: [member] %s", memberId)); - } - return null; + .getMemberStatsContext(memberId).setLoadAverage(loadAverage); } + return loadAverage; } private MemoryConsumption findMemoryConsumption(Event event) { String memberId = event.getProperties().get("member_id"); Member member = findMember(memberId); - - if(member.isActive()){ + + if(null == member){ + if(log.isErrorEnabled()) { + log.error(String.format("Member not found: [member] %s", memberId)); + } + return null; + } + if(!member.isActive()){ if(log.isDebugEnabled()){ log.debug(String.format("Member activated event has not received for the member %s. Therefore ignoring" + " the health stat", memberId)); } return null; - } - - if(member != null) { - String networkPartitionId = findNetworkPartitionId(memberId); - MemoryConsumption memoryConsumption = AutoscalerContext.getInstance().getMonitor(member.getClusterId()) + } + String networkPartitionId = findNetworkPartitionId(memberId); + MemoryConsumption memoryConsumption = AutoscalerContext.getInstance().getMonitor(member.getClusterId()) + .getNetworkPartitionCtxt(networkPartitionId) + .getPartitionCtxt(member.getPartitionId()) + .getMemberStatsContext(memberId).getMemoryConsumption(); + + if(memoryConsumption == null) { + memoryConsumption = new MemoryConsumption(); + AutoscalerContext.getInstance().getMonitor(member.getClusterId()) .getNetworkPartitionCtxt(networkPartitionId) .getPartitionCtxt(member.getPartitionId()) - .getMemberStatsContext(memberId).getMemoryConsumption(); - - if(memoryConsumption == null) { - memoryConsumption = new MemoryConsumption(); - AutoscalerContext.getInstance().getMonitor(member.getClusterId()) - .getNetworkPartitionCtxt(networkPartitionId) - .getPartitionCtxt(member.getPartitionId()) - .getMemberStatsContext(memberId).setMemoryConsumption(memoryConsumption); - } - return memoryConsumption; - } - else { - if(log.isErrorEnabled()) { - log.error(String.format("Member not found: [member] %s", memberId)); - } - return null; + .getMemberStatsContext(memberId).setMemoryConsumption(memoryConsumption); } + return memoryConsumption; } private String findClusterId(String memberId) { for(Service service: TopologyManager.getTopology().getServices()){ @@ -348,6 +344,10 @@ public class HealthEventMessageDelegator implements Runnable { try{ TopologyManager.acquireReadLock(); Member member = findMember(memberId); + + if(null == member){ + return; + } if(!member.isActive()){ if(log.isDebugEnabled()){ log.debug(String.format("Member activated event has not received for the member %s. Therefore ignoring" + @@ -355,12 +355,9 @@ public class HealthEventMessageDelegator implements Runnable { } return; } - if (null == member) { - // member has already terminated. So no action required - return; - } else{ - nwPartitionCtxt = monitor.getNetworkPartitionCtxt(member); - } + + nwPartitionCtxt = monitor.getNetworkPartitionCtxt(member); + }finally{ TopologyManager.releaseReadLock(); }
