Skip to content

Commit 1e84fa4

Browse files
author
Kelven Yang
committed
bug CS-14964: use shorter UUID for datastore names
1 parent b6e5530 commit 1e84fa4

3 files changed

Lines changed: 535 additions & 529 deletions

File tree

‎core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java‎

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.cloud.hypervisor.vmware.mo.CustomFieldConstants;
4040
import com.cloud.hypervisor.vmware.mo.DatacenterMO;
4141
import com.cloud.hypervisor.vmware.mo.DatastoreMO;
42+
import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
4243
import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
4344
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
4445
import com.cloud.hypervisor.vmware.util.VmwareContext;
@@ -122,11 +123,11 @@ public Answer execute(VmwareHostService hostService, PrimaryStorageDownloadComma
122123

123124
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
124125
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());
130131
assert (morDs != null);
131132
DatastoreMO primaryStorageDatastoreMo = new DatastoreMO(context, morDs);
132133

@@ -170,10 +171,9 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd)
170171

171172
VmwareContext context = hostService.getServiceContext(cmd);
172173
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());
177177

178178
try {
179179
vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
@@ -340,79 +340,79 @@ public Answer execute(VmwareHostService hostService, CopyVolumeCommand cmd) {
340340
hyperHost, cmd, vmName, volumeId, cmd.getPool().getUuid(), volumePath,
341341
secondaryStorageURL,
342342
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+
}
416416

417417
// templateName: name in secondary storage
418418
// templateUuid: will be used at hypervisor layer
@@ -783,7 +783,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
783783
String exportName = UUID.randomUUID().toString();
784784

785785
try {
786-
ManagedObjectReference morDs = hyperHost.findDatastore(poolId);
786+
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolId);
787787

788788
if (morDs == null) {
789789
String msg = "Unable to find volumes's storage pool for copy volume operation";

0 commit comments

Comments
 (0)