|
25 | 25 | import java.util.Collections;
|
26 | 26 | import java.util.Date;
|
27 | 27 | import java.util.HashMap;
|
| 28 | +import java.util.Iterator; |
28 | 29 | import java.util.LinkedHashMap;
|
29 | 30 | import java.util.List;
|
30 | 31 | import java.util.Map;
|
|
82 | 83 | import com.cloud.deploy.DataCenterDeployment;
|
83 | 84 | import com.cloud.deploy.DeployDestination;
|
84 | 85 | import com.cloud.deploy.DeploymentPlanner;
|
| 86 | +import com.cloud.deploy.DeploymentPlanningManager; |
85 | 87 | import com.cloud.event.ActionEvent;
|
86 | 88 | import com.cloud.event.EventTypes;
|
87 | 89 | import com.cloud.exception.ConcurrentOperationException;
|
|
155 | 157 | import com.cloud.vm.VirtualMachineManager;
|
156 | 158 | import com.cloud.vm.VirtualMachineName;
|
157 | 159 | import com.cloud.vm.VirtualMachineProfile;
|
| 160 | +import com.cloud.vm.VirtualMachineProfileImpl; |
158 | 161 | import com.cloud.vm.dao.SecondaryStorageVmDao;
|
159 | 162 | import com.cloud.vm.dao.UserVmDetailsDao;
|
160 | 163 | import com.cloud.vm.dao.VMInstanceDao;
|
@@ -254,6 +257,8 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
254 | 257 | private IndirectAgentLB indirectAgentLB;
|
255 | 258 | @Inject
|
256 | 259 | private CAManager caManager;
|
| 260 | + @Inject |
| 261 | + DeploymentPlanningManager deploymentPlanningManager; |
257 | 262 | private int _secStorageVmMtuSize;
|
258 | 263 |
|
259 | 264 | private String _instance;
|
@@ -686,26 +691,26 @@ protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, Seco
|
686 | 691 | serviceOffering = _offeringDao.findDefaultSystemOffering(ServiceOffering.ssvmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId));
|
687 | 692 | }
|
688 | 693 | SecondaryStorageVmVO secStorageVm = null;
|
689 |
| - InsufficientCapacityException lastException = null; |
690 |
| - for (VMTemplateVO template : templates) { |
691 |
| - secStorageVm = createOrUpdateSecondaryStorageVm(secStorageVm, id, dataCenterId, name, serviceOffering, |
| 694 | + for (final Iterator<VMTemplateVO> templateIterator = templates.iterator(); templateIterator.hasNext();) { |
| 695 | + VMTemplateVO template = templateIterator.next(); |
| 696 | + secStorageVm = createOrUpdateSecondaryStorageVm(secStorageVm, dataCenterId, id, name, serviceOffering, |
692 | 697 | template, systemAcct, role);
|
693 | 698 | try {
|
694 | 699 | _itMgr.allocate(name, template, serviceOffering, networks, plan, null);
|
695 | 700 | secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
|
696 |
| - lastException = null; |
| 701 | + final VirtualMachineProfileImpl vmProfile = |
| 702 | + new VirtualMachineProfileImpl(secStorageVm, template, serviceOffering, systemAcct, null); |
| 703 | + deploymentPlanningManager.planDeployment(vmProfile, plan, new DeploymentPlanner.ExcludeList(), null); |
697 | 704 | break;
|
698 | 705 | } catch (InsufficientCapacityException e) {
|
699 |
| - String errorMessage = String.format("Unable to allocate secondary storage VM [%s] due to [%s].", name, e.getMessage()); |
700 |
| - logger.warn(errorMessage, e); |
701 |
| - lastException = e; |
| 706 | + if (templateIterator.hasNext()) { |
| 707 | + logger.debug("Unable to allocate secondary storage {} with {} due to [{}]. Retrying with another template", secStorageVm, template, e.getMessage(), e); |
| 708 | + continue; |
| 709 | + } |
| 710 | + throw new CloudRuntimeException("Failed to allocate secondary storage VM [%s] in zone [%s] with available templates", e); |
702 | 711 | }
|
703 | 712 | }
|
704 | 713 |
|
705 |
| - if (lastException != null) { |
706 |
| - throw new CloudRuntimeException("Failed to allocate secondary storage VM [%s] on zone [%s] with available templates"); |
707 |
| - } |
708 |
| - |
709 | 714 | Map<String, Object> context = new HashMap<>();
|
710 | 715 | context.put("secStorageVmId", secStorageVm.getId());
|
711 | 716 | return context;
|
|
0 commit comments