From 25281ae7a7209ad71781b29802e97a25535e7be6 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Thu, 5 Sep 2013 14:23:36 -0700 Subject: [PATCH] CLOUDSTACK-4430: Add retry logic back in case of template reload needed for vmware. --- .../orchestration/VolumeOrchestrator.java | 100 +++++++++++------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java index f3183e6ed90..9ff5c260593 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java @@ -399,30 +399,38 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati s_logger.debug("Trying to create " + volume + " on " + pool); } DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); - AsyncCallFuture 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 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() { @@ -998,27 +1006,37 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } VolumeInfo volume = volFactory.getVolume(newVol.getId(), destPool); Long templateId = newVol.getTemplateId(); - AsyncCallFuture 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()); - throw new StorageUnavailableException("Unable to create " + newVol + ":" + result.getResult(), destPool.getId()); + for (int i = 0; i < 2; i++) { + // retry one more time in case of template reload is required for Vmware case + AsyncCallFuture 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 + ":" + 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(newVol, destPool);