From 273c912bb6d4ff5dcbe3e59a04a765a2ac8bae8a Mon Sep 17 00:00:00 2001 From: Likitha Shetty Date: Thu, 21 Nov 2013 09:35:10 +0530 Subject: [PATCH] CLOUDSTACK-1868. GetVmStatsCommand throws NullPointerException with VMWare. --- .../vmware/resource/VmwareResource.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 26ef0475a83..69f1b741278 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -6526,19 +6526,21 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa for(int i=0; i infos = ((PerfEntityMetric)values.get(i)).getSampleInfo(); - int endMs = infos.get(infos.size()-1).getTimestamp().getSecond() * 1000 + infos.get(infos.size()-1).getTimestamp().getMillisecond(); - int beginMs = infos.get(0).getTimestamp().getSecond() * 1000 + infos.get(0).getTimestamp().getMillisecond(); - sampleDuration = (endMs - beginMs) /1000; - List vals = ((PerfEntityMetric)values.get(i)).getValue(); - for(int vi = 0; ((vals!= null) && (vi < vals.size())); ++vi){ - if(vals.get(vi) instanceof PerfMetricIntSeries) { - PerfMetricIntSeries val = (PerfMetricIntSeries)vals.get(vi); - List perfValues = val.getValue(); - if (vals.get(vi).getId().getCounterId() == rxPerfCounterInfo.getKey()) { - networkReadKBs = sampleDuration * perfValues.get(3); //get the average RX rate multiplied by sampled duration - } - if (vals.get(vi).getId().getCounterId() == txPerfCounterInfo.getKey()) { - networkWriteKBs = sampleDuration * perfValues.get(3);//get the average TX rate multiplied by sampled duration + if (infos != null && infos.size() > 0) { + int endMs = infos.get(infos.size()-1).getTimestamp().getSecond() * 1000 + infos.get(infos.size()-1).getTimestamp().getMillisecond(); + int beginMs = infos.get(0).getTimestamp().getSecond() * 1000 + infos.get(0).getTimestamp().getMillisecond(); + sampleDuration = (endMs - beginMs) /1000; + List vals = ((PerfEntityMetric)values.get(i)).getValue(); + for(int vi = 0; ((vals!= null) && (vi < vals.size())); ++vi){ + if(vals.get(vi) instanceof PerfMetricIntSeries) { + PerfMetricIntSeries val = (PerfMetricIntSeries)vals.get(vi); + List perfValues = val.getValue(); + if (vals.get(vi).getId().getCounterId() == rxPerfCounterInfo.getKey()) { + networkReadKBs = sampleDuration * perfValues.get(3); //get the average RX rate multiplied by sampled duration + } + if (vals.get(vi).getId().getCounterId() == txPerfCounterInfo.getKey()) { + networkWriteKBs = sampleDuration * perfValues.get(3);//get the average TX rate multiplied by sampled duration + } } } }