}
}
} else {
if (vol.getPoolId() == null) {
throw new StorageUnavailableException("Volume has no pool associate and also no storage pool assigned in DeployDestination, Unable to create " + vol, Volume.class, vol.getId());
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("No need to recreate the volume: " + vol + ", since it already has a pool assigned: " + vol.getPoolId() + ", adding disk to VM");
}
StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
vm.addDisk(new VolumeTO(vol, pool));
}
}
for (VolumeVO vol : recreateVols) {
VolumeVO newVol;
StoragePool existingPool = null;
if (recreate && (dest.getStorageForDisks() == null || dest.getStorageForDisks().get(vol) == null)) {
existingPool = _storagePoolDao.findById(vol.getPoolId());
s_logger.debug("existing pool: " + existingPool.getId());
}
if (vol.getState() == Volume.State.Allocated || vol.getState() == Volume.State.Creating) {
newVol = vol;
} else {
newVol = switchVolume(vol, vm);
// update the volume->storagePool map since volumeId has changed
if (dest.getStorageForDisks() != null && dest.getStorageForDisks().containsKey(vol)) {
StoragePool poolWithOldVol = dest.getStorageForDisks().get(vol);
dest.getStorageForDisks().put(newVol, poolWithOldVol);
dest.getStorageForDisks().remove(vol);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Created new volume " + newVol + " for old volume " + vol);
}
}
try {
stateTransitTo(newVol, Volume.Event.CreateRequested);
} catch (NoTransitionException e) {
throw new CloudRuntimeException("Unable to create " + e.toString());
}
Pair<VolumeTO, StoragePool> created = createVolume(newVol, _diskOfferingDao.findById(newVol.getDiskOfferingId()), vm, vols, dest, existingPool);
if (created == null) {
Long poolId = newVol.getPoolId();
newVol.setPoolId(null);
try {
stateTransitTo(newVol, Volume.Event.OperationFailed);
} catch (NoTransitionException e) {
throw new CloudRuntimeException("Unable to update the failure on a volume: " + newVol, e);
}
throw new StorageUnavailableException("Unable to create " + newVol, poolId == null ? -1L : poolId);
}
created.first().setDeviceId(newVol.getDeviceId().intValue());
newVol.setFolder(created.second().getPath());
newVol.setPath(created.first().getPath());
newVol.setSize(created.first().getSize());