|
16 | 16 | // under the License. |
17 | 17 | package org.apache.cloudstack.engine.cloud.entity.api; |
18 | 18 |
|
19 | | -import java.util.HashMap; |
20 | 19 | import java.util.List; |
21 | 20 | import java.util.Map; |
22 | 21 | import java.util.UUID; |
|
30 | 29 | import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao; |
31 | 30 | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; |
32 | 31 | import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
| 32 | +import org.apache.log4j.Logger; |
33 | 33 | import org.springframework.stereotype.Component; |
34 | 34 |
|
35 | 35 | import com.cloud.dc.DataCenter; |
|
46 | 46 | import com.cloud.exception.InsufficientServerCapacityException; |
47 | 47 | import com.cloud.exception.OperationTimedoutException; |
48 | 48 | import com.cloud.exception.ResourceUnavailableException; |
49 | | -import com.cloud.hypervisor.Hypervisor.HypervisorType; |
50 | 49 | import com.cloud.network.dao.NetworkDao; |
51 | 50 | import com.cloud.org.Cluster; |
52 | 51 | import com.cloud.service.dao.ServiceOfferingDao; |
53 | 52 | import com.cloud.storage.StoragePool; |
54 | | -import com.cloud.storage.Volume; |
55 | 53 | import com.cloud.storage.VolumeVO; |
56 | 54 | import com.cloud.storage.dao.DiskOfferingDao; |
57 | 55 | import com.cloud.storage.dao.VMTemplateDao; |
|
69 | 67 | @Component |
70 | 68 | public class VMEntityManagerImpl implements VMEntityManager { |
71 | 69 |
|
| 70 | + private static final Logger s_logger = Logger.getLogger(VMEntityManagerImpl.class); |
| 71 | + |
72 | 72 | @Inject |
73 | 73 | protected VMInstanceDao _vmDao; |
74 | 74 | @Inject |
@@ -190,28 +190,15 @@ public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, |
190 | 190 | } |
191 | 191 |
|
192 | 192 | if (dest != null) { |
193 | | - if (_dpMgr.finalizeReservation(dest, vmProfile, plan, exclude)) { |
194 | | - // save destination with VMEntityVO |
195 | | - VMReservationVO vmReservation = new VMReservationVO(vm.getId(), dest.getDataCenter().getId(), dest |
196 | | - .getPod().getId(), dest.getCluster().getId(), dest.getHost().getId()); |
197 | | - Map<Long, Long> volumeReservationMap = new HashMap<Long, Long>(); |
198 | | - |
199 | | - if (vm.getHypervisorType() != HypervisorType.BareMetal) { |
200 | | - for (Volume vo : dest.getStorageForDisks().keySet()) { |
201 | | - volumeReservationMap.put(vo.getId(), dest.getStorageForDisks().get(vo).getId()); |
202 | | - } |
203 | | - vmReservation.setVolumeReservation(volumeReservationMap); |
204 | | - } |
205 | | - |
206 | | - vmEntityVO.setVmReservation(vmReservation); |
207 | | - _vmEntityDao.persist(vmEntityVO); |
208 | | - |
209 | | - return vmReservation.getUuid(); |
| 193 | + String reservationId = _dpMgr.finalizeReservation(dest, vmProfile, plan, exclude); |
| 194 | + if(reservationId != null){ |
| 195 | + return reservationId; |
210 | 196 | } else { |
211 | | - try { |
212 | | - Thread.sleep(10000); |
213 | | - } catch (final InterruptedException e) { |
| 197 | + if (s_logger.isDebugEnabled()) { |
| 198 | + s_logger.debug("Cannot finalize the VM reservation for this destination found, retrying"); |
214 | 199 | } |
| 200 | + |
| 201 | + exclude.addHost(dest.getHost().getId()); |
215 | 202 | continue; |
216 | 203 | } |
217 | 204 | } else if (planChangedByReadyVolume) { |
|
0 commit comments