|
39 | 39 | import com.cloud.hypervisor.vmware.mo.CustomFieldConstants; |
40 | 40 | import com.cloud.hypervisor.vmware.mo.DatacenterMO; |
41 | 41 | import com.cloud.hypervisor.vmware.mo.DatastoreMO; |
| 42 | +import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper; |
42 | 43 | import com.cloud.hypervisor.vmware.mo.VirtualMachineMO; |
43 | 44 | import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost; |
44 | 45 | import com.cloud.hypervisor.vmware.util.VmwareContext; |
@@ -122,11 +123,11 @@ public Answer execute(VmwareHostService hostService, PrimaryStorageDownloadComma |
122 | 123 |
|
123 | 124 | DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter()); |
124 | 125 | VirtualMachineMO templateMo = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUuidName), true); |
125 | | - |
126 | | - if (templateMo == null) { |
127 | | - if(s_logger.isInfoEnabled()) |
128 | | - s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName); |
129 | | - ManagedObjectReference morDs = hyperHost.findDatastore(cmd.getPoolUuid()); |
| 126 | + |
| 127 | + if (templateMo == null) { |
| 128 | + if(s_logger.isInfoEnabled()) |
| 129 | + s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName); |
| 130 | + ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPoolUuid()); |
130 | 131 | assert (morDs != null); |
131 | 132 | DatastoreMO primaryStorageDatastoreMo = new DatastoreMO(context, morDs); |
132 | 133 |
|
@@ -170,10 +171,9 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd) |
170 | 171 |
|
171 | 172 | VmwareContext context = hostService.getServiceContext(cmd); |
172 | 173 | VirtualMachineMO vmMo = null; |
173 | | - |
174 | | - try { |
175 | | - VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); |
176 | | - morDs = hyperHost.findDatastore(cmd.getPool().getUuid()); |
| 174 | + try { |
| 175 | + VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); |
| 176 | + morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPool().getUuid()); |
177 | 177 |
|
178 | 178 | try { |
179 | 179 | vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); |
@@ -340,79 +340,79 @@ public Answer execute(VmwareHostService hostService, CopyVolumeCommand cmd) { |
340 | 340 | hyperHost, cmd, vmName, volumeId, cmd.getPool().getUuid(), volumePath, |
341 | 341 | secondaryStorageURL, |
342 | 342 | hostService.getWorkerName(context, cmd, 0)); |
343 | | - } else { |
344 | | - StorageFilerTO poolTO = cmd.getPool(); |
345 | | - |
346 | | - ManagedObjectReference morDatastore = hyperHost.findDatastore(poolTO.getUuid()); |
347 | | - if (morDatastore == null) { |
348 | | - morDatastore = hyperHost.mountDatastore( |
349 | | - false, |
350 | | - poolTO.getHost(), 0, poolTO.getPath(), |
351 | | - poolTO.getUuid()); |
352 | | - |
353 | | - if (morDatastore == null) { |
354 | | - throw new Exception("Unable to mount storage pool on host. storeUrl: " + poolTO.getHost() + ":/" + poolTO.getPath()); |
355 | | - } |
356 | | - } |
357 | | - |
358 | | - result = copyVolumeFromSecStorage( |
359 | | - hyperHost, volumeId, |
360 | | - new DatastoreMO(context, morDatastore), |
361 | | - secondaryStorageURL, volumePath); |
362 | | - } |
363 | | - return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second()); |
364 | | - } catch (Throwable e) { |
365 | | - if (e instanceof RemoteException) { |
366 | | - hostService.invalidateServiceContext(context); |
367 | | - } |
368 | | - |
369 | | - String msg = "Unable to execute CopyVolumeCommand due to exception"; |
370 | | - s_logger.error(msg, e); |
371 | | - return new CopyVolumeAnswer(cmd, false, "CopyVolumeCommand failed due to exception: " + StringUtils.getExceptionStackInfo(e), null, null); |
372 | | - } |
373 | | - } |
374 | | - |
375 | | - @Override |
376 | | - public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCommand cmd) { |
377 | | - |
378 | | - String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel(); |
379 | | - Long accountId = cmd.getAccountId(); |
380 | | - Long volumeId = cmd.getVolumeId(); |
381 | | - String secondaryStorageUrl = cmd.getSecondaryStorageUrl(); |
382 | | - String backedUpSnapshotUuid = cmd.getSnapshotUuid(); |
383 | | - |
384 | | - String details = null; |
385 | | - boolean success = false; |
386 | | - String newVolumeName = UUID.randomUUID().toString().replaceAll("-", ""); |
387 | | - |
388 | | - VmwareContext context = hostService.getServiceContext(cmd); |
389 | | - try { |
390 | | - VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); |
391 | | - |
392 | | - ManagedObjectReference morPrimaryDs = hyperHost.findDatastore(primaryStorageNameLabel); |
393 | | - if (morPrimaryDs == null) { |
394 | | - String msg = "Unable to find datastore: " + primaryStorageNameLabel; |
395 | | - s_logger.error(msg); |
396 | | - throw new Exception(msg); |
397 | | - } |
398 | | - |
399 | | - DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs); |
400 | | - details = createVolumeFromSnapshot(hyperHost, primaryDsMo, |
401 | | - newVolumeName, accountId, volumeId, secondaryStorageUrl, backedUpSnapshotUuid); |
402 | | - if (details == null) { |
403 | | - success = true; |
404 | | - } |
405 | | - } catch (Throwable e) { |
406 | | - if (e instanceof RemoteException) { |
407 | | - hostService.invalidateServiceContext(context); |
408 | | - } |
409 | | - |
410 | | - s_logger.error("Unexpecpted exception ", e); |
411 | | - details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e); |
412 | | - } |
413 | | - |
414 | | - return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName); |
415 | | - } |
| 343 | + } else { |
| 344 | + StorageFilerTO poolTO = cmd.getPool(); |
| 345 | + |
| 346 | + ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolTO.getUuid()); |
| 347 | + if (morDatastore == null) { |
| 348 | + morDatastore = hyperHost.mountDatastore( |
| 349 | + false, |
| 350 | + poolTO.getHost(), 0, poolTO.getPath(), |
| 351 | + poolTO.getUuid().replace("-", "")); |
| 352 | + |
| 353 | + if (morDatastore == null) { |
| 354 | + throw new Exception("Unable to mount storage pool on host. storeUrl: " + poolTO.getHost() + ":/" + poolTO.getPath()); |
| 355 | + } |
| 356 | + } |
| 357 | + |
| 358 | + result = copyVolumeFromSecStorage( |
| 359 | + hyperHost, volumeId, |
| 360 | + new DatastoreMO(context, morDatastore), |
| 361 | + secondaryStorageURL, volumePath); |
| 362 | + } |
| 363 | + return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second()); |
| 364 | + } catch (Throwable e) { |
| 365 | + if (e instanceof RemoteException) { |
| 366 | + hostService.invalidateServiceContext(context); |
| 367 | + } |
| 368 | + |
| 369 | + String msg = "Unable to execute CopyVolumeCommand due to exception"; |
| 370 | + s_logger.error(msg, e); |
| 371 | + return new CopyVolumeAnswer(cmd, false, "CopyVolumeCommand failed due to exception: " + StringUtils.getExceptionStackInfo(e), null, null); |
| 372 | + } |
| 373 | + } |
| 374 | + |
| 375 | + @Override |
| 376 | + public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCommand cmd) { |
| 377 | + |
| 378 | + String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel(); |
| 379 | + Long accountId = cmd.getAccountId(); |
| 380 | + Long volumeId = cmd.getVolumeId(); |
| 381 | + String secondaryStorageUrl = cmd.getSecondaryStorageUrl(); |
| 382 | + String backedUpSnapshotUuid = cmd.getSnapshotUuid(); |
| 383 | + |
| 384 | + String details = null; |
| 385 | + boolean success = false; |
| 386 | + String newVolumeName = UUID.randomUUID().toString().replaceAll("-", ""); |
| 387 | + |
| 388 | + VmwareContext context = hostService.getServiceContext(cmd); |
| 389 | + try { |
| 390 | + VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); |
| 391 | + |
| 392 | + ManagedObjectReference morPrimaryDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStorageNameLabel); |
| 393 | + if (morPrimaryDs == null) { |
| 394 | + String msg = "Unable to find datastore: " + primaryStorageNameLabel; |
| 395 | + s_logger.error(msg); |
| 396 | + throw new Exception(msg); |
| 397 | + } |
| 398 | + |
| 399 | + DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs); |
| 400 | + details = createVolumeFromSnapshot(hyperHost, primaryDsMo, |
| 401 | + newVolumeName, accountId, volumeId, secondaryStorageUrl, backedUpSnapshotUuid); |
| 402 | + if (details == null) { |
| 403 | + success = true; |
| 404 | + } |
| 405 | + } catch (Throwable e) { |
| 406 | + if (e instanceof RemoteException) { |
| 407 | + hostService.invalidateServiceContext(context); |
| 408 | + } |
| 409 | + |
| 410 | + s_logger.error("Unexpecpted exception ", e); |
| 411 | + details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e); |
| 412 | + } |
| 413 | + |
| 414 | + return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName); |
| 415 | + } |
416 | 416 |
|
417 | 417 | // templateName: name in secondary storage |
418 | 418 | // templateUuid: will be used at hypervisor layer |
@@ -783,7 +783,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic |
783 | 783 | String exportName = UUID.randomUUID().toString(); |
784 | 784 |
|
785 | 785 | try { |
786 | | - ManagedObjectReference morDs = hyperHost.findDatastore(poolId); |
| 786 | + ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolId); |
787 | 787 |
|
788 | 788 | if (morDs == null) { |
789 | 789 | String msg = "Unable to find volumes's storage pool for copy volume operation"; |
|
0 commit comments