More changes for 9387:

Checks in StorageManagerImpl :: prepare() method to avoid NPE's if DeployDestination passed in is null.
This commit is contained in:
prachi 2011-04-12 15:23:11 -07:00
parent fc35aed2c9
commit e2451f6b15
1 changed files with 15 additions and 0 deletions

View File

@ -2454,6 +2454,18 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
@Override
public void prepare(VirtualMachineProfile<? extends VirtualMachine> 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<VolumeVO> 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()) {