Updated Branches: refs/heads/4.2-forward 8451d3532 -> 9f870eee0
CLOUDSTACK-4430: Add retry logic back in case of template reload needed for vmware. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9f870eee Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9f870eee Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9f870eee Branch: refs/heads/4.2-forward Commit: 9f870eee0e7e3fe69c97241c25eaa0400ee0c562 Parents: 8451d35 Author: Min Chen <[email protected]> Authored: Wed Sep 4 15:02:28 2013 -0700 Committer: Min Chen <[email protected]> Committed: Wed Sep 4 15:02:28 2013 -0700 ---------------------------------------------------------------------- .../com/cloud/storage/VolumeManagerImpl.java | 107 +++++++++++-------- 1 file changed, 63 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f870eee/server/src/com/cloud/storage/VolumeManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index 1d6b44f..4569202 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -681,30 +681,39 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { s_logger.debug("Trying to create " + volume + " on " + pool); } DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); - AsyncCallFuture<VolumeApiResult> future = null; - boolean isNotCreatedFromTemplate = volume.getTemplateId() == null ? true : false; - if (isNotCreatedFromTemplate) { - future = volService.createVolumeAsync(volume, store); - } else { - TemplateInfo templ = tmplFactory.getTemplate(template.getId(), DataStoreRole.Image); - future = volService.createVolumeFromTemplateAsync(volume, store.getId(), templ); - } - try { - VolumeApiResult result = future.get(); - if (result.isFailed()) { - s_logger.debug("create volume failed: " + result.getResult()); - throw new CloudRuntimeException("create volume failed:" + result.getResult()); + for (int i = 0; i < 2; i++) { + // retry one more time in case of template reload is required for Vmware case + AsyncCallFuture<VolumeApiResult> future = null; + boolean isNotCreatedFromTemplate = volume.getTemplateId() == null ? true : false; + if (isNotCreatedFromTemplate) { + future = volService.createVolumeAsync(volume, store); + } else { + TemplateInfo templ = tmplFactory.getTemplate(template.getId(), DataStoreRole.Image); + future = volService.createVolumeFromTemplateAsync(volume, store.getId(), templ); } + try { + VolumeApiResult result = future.get(); + if (result.isFailed()) { + if (result.getResult().contains("request template reload") && (i == 0)) { + s_logger.debug("Retry template re-deploy for vmware"); + continue; + } else { + s_logger.debug("create volume failed: " + result.getResult()); + throw new CloudRuntimeException("create volume failed:" + result.getResult()); + } + } - return result.getVolume(); - } catch (InterruptedException e) { - s_logger.error("create volume failed", e); - throw new CloudRuntimeException("create volume failed", e); - } catch (ExecutionException e) { - s_logger.error("create volume failed", e); - throw new CloudRuntimeException("create volume failed", e); + return result.getVolume(); + } catch (InterruptedException e) { + s_logger.error("create volume failed", e); + throw new CloudRuntimeException("create volume failed", e); + } catch (ExecutionException e) { + s_logger.error("create volume failed", e); + throw new CloudRuntimeException("create volume failed", e); + } } - + + throw new CloudRuntimeException("create volume failed even after template re-deploy"); } public String getRandomVolumeName() { @@ -2528,31 +2537,41 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { } VolumeInfo volume = volFactory.getVolume(newVol.getId(), destPool); Long templateId = newVol.getTemplateId(); - AsyncCallFuture<VolumeApiResult> future = null; - if (templateId == null) { - future = volService.createVolumeAsync(volume, destPool); - } else { - TemplateInfo templ = tmplFactory.getTemplate(templateId, DataStoreRole.Image); - future = volService.createVolumeFromTemplateAsync(volume, destPool.getId(), templ); - } - VolumeApiResult result = null; - try { - result = future.get(); - if (result.isFailed()) { - s_logger.debug("Unable to create " - + newVol + ":" + result.getResult()); + for (int i = 0; i < 2; i++) { + // retry one more time in case of template reload is required for Vmware case + AsyncCallFuture<VolumeApiResult> future = null; + if (templateId == null) { + future = volService.createVolumeAsync(volume, destPool); + } else { + TemplateInfo templ = tmplFactory.getTemplate(templateId, DataStoreRole.Image); + future = volService.createVolumeFromTemplateAsync(volume, destPool.getId(), templ); + } + VolumeApiResult result = null; + try { + result = future.get(); + if (result.isFailed()) { + if (result.getResult().contains("request template reload") && (i == 0)) { + s_logger.debug("Retry template re-deploy for vmware"); + continue; + } + else { + s_logger.debug("Unable to create " + + newVol + ":" + result.getResult()); + throw new StorageUnavailableException("Unable to create " + + newVol + ":" + result.getResult(), destPool.getId()); + } + } + newVol = _volsDao.findById(newVol.getId()); + break; //break out of template-redeploy retry loop + } catch (InterruptedException e) { + s_logger.error("Unable to create " + newVol, e); throw new StorageUnavailableException("Unable to create " - + newVol + ":" + result.getResult(), destPool.getId()); + + newVol + ":" + e.toString(), destPool.getId()); + } catch (ExecutionException e) { + s_logger.error("Unable to create " + newVol, e); + throw new StorageUnavailableException("Unable to create " + + newVol + ":" + e.toString(), destPool.getId()); } - newVol = _volsDao.findById(newVol.getId()); - } catch (InterruptedException e) { - s_logger.error("Unable to create " + newVol, e); - throw new StorageUnavailableException("Unable to create " - + newVol + ":" + e.toString(), destPool.getId()); - } catch (ExecutionException e) { - s_logger.error("Unable to create " + newVol, e); - throw new StorageUnavailableException("Unable to create " - + newVol + ":" + e.toString(), destPool.getId()); } return new Pair<VolumeVO, DataStore>(newVol, destPool);
