From 47f43df01b1f64e6798eb0155175936b5fd206ae Mon Sep 17 00:00:00 2001 From: prachi Date: Tue, 12 Apr 2011 15:23:11 -0700 Subject: [PATCH] More changes for 9387: Checks in StorageManagerImpl :: prepare() method to avoid NPE's if DeployDestination passed in is null. --- .../src/com/cloud/storage/StorageManagerImpl.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index e46093cd396..31e70cbc7bd 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -2477,6 +2477,18 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag @Override public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException { + + if(dest == null){ + if (s_logger.isDebugEnabled()) { + s_logger.debug("DeployDestination cannot be null, cannot prepare Volumes for the vm: "+ vm); + } + throw new CloudRuntimeException("Unable to prepare Volume for vm because DeployDestination is null"); + }else if(dest.getStorageForDisks() == null){ + if (s_logger.isDebugEnabled()) { + s_logger.debug("DeployDestination has no storage pools specified, cannot prepare Volumes for the vm: "+ vm); + } + throw new CloudRuntimeException("Unable to prepare Volume for vm because DeployDestination DeployDestination has no storage pools specified"); + } List vols = _volsDao.findUsableVolumesForInstance(vm.getId()); if (s_logger.isDebugEnabled()) { s_logger.debug("Preparing " + vols.size() + " volumes for " + vm); @@ -2489,6 +2501,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag recreateVols.add(vol); }else{ StoragePool assignedPool = dest.getStorageForDisks().get(vol); + if(assignedPool == null){ + throw new StorageUnavailableException("No storage pool assigned in DeployDestination, Unable to create " + vol, -1L); + } if(vol.getPoolId() != assignedPool.getId()){ if (vol.isRecreatable()) { if (s_logger.isDebugEnabled()) {