diff --git a/server/src/com/cloud/server/StatsCollector.java b/server/src/com/cloud/server/StatsCollector.java index 2be8a0efb65..748f01a5eac 100755 --- a/server/src/com/cloud/server/StatsCollector.java +++ b/server/src/com/cloud/server/StatsCollector.java @@ -334,32 +334,34 @@ public class StatsCollector { } ConcurrentHashMap volumeStats = new ConcurrentHashMap(); for (Iterator iter = commandsByPool.keySet().iterator(); iter.hasNext();) { - Long poolId = iter.next(); - List commandsList = commandsByPool.get(poolId); - - long[] volumeIdArray = new long[commandsList.size()]; - Commands commands = new Commands(OnError.Continue); - for (int i = 0; i < commandsList.size(); i++) { - VolumeCommand vCommand = commandsList.get(i); - volumeIdArray[i] = vCommand.volumeId; - commands.addCommand(vCommand.command); - } - - List poolhosts = _storagePoolHostDao.listByPoolId(poolId); - for(StoragePoolHostVO poolhost : poolhosts) { - Answer[] answers = _agentMgr.send(poolhost.getHostId(), commands); - if (answers != null) { - long totalBytes = 0L; - for (int i = 0; i < answers.length; i++) { - if (answers[i].getResult()) { - VolumeStats vStats = (VolumeStats)answers[i]; - volumeStats.put(volumeIdArray[i], vStats); - totalBytes += vStats.getBytesUsed(); - } - } - break; - } - } + Long poolId = iter.next(); + if(poolId != null) { + List commandsList = commandsByPool.get(poolId); + + long[] volumeIdArray = new long[commandsList.size()]; + Commands commands = new Commands(OnError.Continue); + for (int i = 0; i < commandsList.size(); i++) { + VolumeCommand vCommand = commandsList.get(i); + volumeIdArray[i] = vCommand.volumeId; + commands.addCommand(vCommand.command); + } + + List poolhosts = _storagePoolHostDao.listByPoolId(poolId); + for(StoragePoolHostVO poolhost : poolhosts) { + Answer[] answers = _agentMgr.send(poolhost.getHostId(), commands); + if (answers != null) { + long totalBytes = 0L; + for (int i = 0; i < answers.length; i++) { + if (answers[i].getResult()) { + VolumeStats vStats = (VolumeStats)answers[i]; + volumeStats.put(volumeIdArray[i], vStats); + totalBytes += vStats.getBytesUsed(); + } + } + break; + } + } + } } // We replace the existing volumeStats so that it does not grow with no bounds