2626import java .util .Formatter ;
2727import java .util .HashMap ;
2828import java .util .HashSet ;
29+ import java .util .Iterator ;
2930import java .util .List ;
3031import java .util .Map ;
3132import java .util .Set ;
7475import com .cloud .dc .HostPodVO ;
7576import com .cloud .dc .dao .DataCenterDao ;
7677import com .cloud .dc .dao .HostPodDao ;
78+ import com .cloud .deploy .DeployDestination ;
7779import com .cloud .event .EventState ;
7880import com .cloud .event .EventTypes ;
7981import com .cloud .event .EventVO ;
145147import com .cloud .vm .UserVmVO ;
146148import com .cloud .vm .VMInstanceVO ;
147149import com .cloud .vm .VirtualMachine ;
150+ import com .cloud .vm .VirtualMachineProfile ;
148151import com .cloud .vm .dao .ConsoleProxyDao ;
149152import com .cloud .vm .dao .UserVmDao ;
150153import com .cloud .vm .dao .VMInstanceDao ;
@@ -170,7 +173,9 @@ public class StorageManagerImpl implements StorageManager {
170173 @ Inject protected ConsoleProxyDao _consoleProxyDao ;
171174 @ Inject protected DetailsDao _detailsDao ;
172175 @ Inject protected SnapshotDao _snapshotDao ;
176+ @ Inject (adapter =StoragePoolAllocator .class )
173177 protected Adapters <StoragePoolAllocator > _storagePoolAllocators ;
178+ @ Inject (adapter =StoragePoolDiscoverer .class )
174179 protected Adapters <StoragePoolDiscoverer > _discoverers ;
175180 @ Inject protected StoragePoolHostDao _storagePoolHostDao ;
176181 @ Inject protected AlertManager _alertMgr ;
@@ -267,6 +272,87 @@ public VolumeVO allocateIsoInstalledVm(VMInstanceVO vm, VMTemplateVO template, D
267272 return vols .get (0 );
268273 }
269274
275+ @ Override
276+ public VolumeTO [] prepare (VirtualMachineProfile vm , DeployDestination dest ) {
277+ List <VolumeVO > vols = _volsDao .findCreatedByInstance (vm .getId ());
278+ List <VolumeVO > recreateVols = new ArrayList <VolumeVO >(vols .size ());
279+ Host host = dest .getHost ();
280+
281+ VolumeTO [] disks = new VolumeTO [vols .size ()];
282+ int i = 0 ;
283+ Iterator <VolumeVO > it = vols .iterator ();
284+ while (it .hasNext ()) {
285+ VolumeVO vol = it .next ();
286+ if (vol .isRecreatable ()) {
287+ it .remove ();
288+ //if we have a system vm
289+ //get the storage pool
290+ //if pool is in maintenance
291+ //add to recreate vols, and continue
292+ if (vm .getType ().equals (VirtualMachine .Type .ConsoleProxy ) || vm .getType ().equals (VirtualMachine .Type .DomainRouter ) || vm .getType ().equals (VirtualMachine .Type .SecondaryStorageVm ))
293+ {
294+ StoragePoolVO sp = _storagePoolDao .findById (vol .getPoolId ());
295+
296+ if (sp !=null && sp .getStatus ().equals (Status .PrepareForMaintenance ))
297+ {
298+ recreateVols .add (vol );
299+ continue ;
300+ }
301+ }
302+
303+ StoragePoolHostVO ph = _storagePoolHostDao .findByPoolHost (vol .getPoolId (), host .getId ());
304+ if (ph == null ) {
305+ if (s_logger .isDebugEnabled ()) {
306+ s_logger .debug ("Must recreate " + vol + " since " + vol .getPoolId () + " has is not hooked up with host " + host .getId ());
307+ }
308+ recreateVols .add (vol );
309+ }
310+ }
311+ }
312+
313+ for (VolumeVO vol : recreateVols ) {
314+ VolumeVO create = allocateDuplicateVolume (vol );
315+ vols .add (vol );
316+ }
317+
318+ /*
319+ create.setDiskOfferingId(vol.getDiskOfferingId());
320+ create.setDeviceId(vol.getDeviceId());
321+ create = _volsDao.persist(create);
322+ VMTemplateVO template = _templateDao.findById(create.getTemplateId());
323+ DataCenterVO dc = _dcDao.findById(create.getDataCenterId());
324+ HostPodVO pod = _podDao.findById(host.getPodId());
325+ DiskOfferingVO diskOffering = null;
326+ diskOffering = _diskOfferingDao.findById(vol.getDiskOfferingId());
327+ ServiceOfferingVO offering;
328+ if (vm instanceof UserVmVO) {
329+ offering = _offeringDao.findById(((UserVmVO)vm).getServiceOfferingId());
330+ } else {
331+ offering = _offeringDao.findById(vol.getDiskOfferingId());
332+ }
333+ VolumeVO created = createVolume(create, vm, template, dc, pod, host.getClusterId(), offering, diskOffering, new ArrayList<StoragePoolVO>(),0);
334+ if (created == null) {
335+ break;
336+ }
337+ createds.add(created);
338+
339+ for (VolumeVO vol : recreateVols) {
340+ _volsDao.remove(vol.getId());
341+ }
342+ disks[i++] = null;
343+ }
344+ */
345+ return disks ;
346+ }
347+
348+ VolumeVO allocateDuplicateVolume (VolumeVO oldVol ) {
349+ VolumeVO newVol = new VolumeVO (oldVol .getVolumeType (), oldVol .getName (), oldVol .getDataCenterId (), oldVol .getDomainId (), oldVol .getAccountId (), oldVol .getDiskOfferingId (), oldVol .getSize ());
350+ newVol .setTemplateId (oldVol .getTemplateId ());
351+ newVol .setDeviceId (oldVol .getDeviceId ());
352+ newVol .setInstanceId (oldVol .getInstanceId ());
353+ return _volsDao .persist (newVol );
354+ }
355+
270356
271357 @ Override
272358 public List <VolumeVO > prepare (VMInstanceVO vm , HostVO host ) {
@@ -392,7 +478,7 @@ protected StoragePoolVO findStoragePool(DiskProfile dskCh, final DataCenterVO dc
392478 Enumeration <StoragePoolAllocator > en = _storagePoolAllocators .enumeration ();
393479 while (en .hasMoreElements ()) {
394480 final StoragePoolAllocator allocator = en .nextElement ();
395- final StoragePool pool = allocator .allocateToPool (dskCh , offering , dc , pod , clusterId , vm , template , avoid );
481+ final StoragePool pool = allocator .allocateToPool (dskCh , dc , pod , clusterId , vm , template , avoid );
396482 if (pool != null ) {
397483 return (StoragePoolVO ) pool ;
398484 }
@@ -1056,13 +1142,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
10561142 return false ;
10571143 }
10581144
1059- _storagePoolAllocators = locator .getAdapters (StoragePoolAllocator .class );
1060- if (!_storagePoolAllocators .isSet ()) {
1061- throw new ConfigurationException ("Unable to get any storage pool allocators." );
1062- }
1063-
1064- _discoverers = locator .getAdapters (StoragePoolDiscoverer .class );
1065-
10661145 Map <String , String > configs = configDao .getConfiguration ("management-server" , params );
10671146
10681147
0 commit comments