From e2451f6b15d95e36aa4b6e2b3aa3b2b74cf14cea 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 77b254da694..9c72c02e262 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -2454,6 +2454,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); @@ -2466,6 +2478,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()) {