Changed workflow for storing volumes in sec storage

This commit is contained in:
Pearl Dsilva 2020-08-04 17:45:09 +05:30 committed by Harikrishna Patnala
parent 1b18554794
commit e211b92324
4 changed files with 30 additions and 36 deletions

View File

@ -152,7 +152,7 @@ public class CreateDiskOfferingCmd extends BaseCmd {
since = "4.14")
private String cacheMode;
@Parameter(name = ApiConstants.STORAGE_POLICY, type = CommandType.UUID, entityType = VsphereStoragePoliciesResponse.class,required = false, description = "Name of the storage policy defined at vCenter, this is applicable only for VMware")
@Parameter(name = ApiConstants.STORAGE_POLICY, type = CommandType.UUID, entityType = VsphereStoragePoliciesResponse.class,required = false, description = "Name of the storage policy defined at vCenter, this is applicable only for VMware", since = "4.15")
private Long storagePolicy;
/////////////////////////////////////////////////////

View File

@ -217,7 +217,7 @@ public class CreateServiceOfferingCmd extends BaseCmd {
since = "4.13")
private Integer minMemory;
@Parameter(name = ApiConstants.STORAGE_POLICY, type = CommandType.UUID, entityType = VsphereStoragePoliciesResponse.class,required = false, description = "Name of the storage policy defined at vCenter, this is applicable only for VMware")
@Parameter(name = ApiConstants.STORAGE_POLICY, type = CommandType.UUID, entityType = VsphereStoragePoliciesResponse.class,required = false, description = "Name of the storage policy defined at vCenter, this is applicable only for VMware", since = "4.15")
private Long storagePolicy;
/////////////////////////////////////////////////////

View File

@ -1015,11 +1015,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
workerVm.attachDisk(new String[] {datastoreVolumePath}, morDs);
vmMo = workerVm;
clonedWorkerVMNeeded = false;
} else {
vmMo.createSnapshot(exportName, "Temporary snapshot for copy-volume command", false, false);
}
exportVolumeToSecondaryStorage(vmMo, volumePath, secStorageUrl, destVolumePath, exportName, hostService.getWorkerName(hyperHost.getContext(), cmd, 1), _nfsVersion, clonedWorkerVMNeeded);
exportVolumeToSecondaryStorage(hyperHost.getContext(), vmMo, hyperHost, volumePath, secStorageUrl, destVolumePath, exportName, hostService.getWorkerName(hyperHost.getContext(), cmd, 1), _nfsVersion, clonedWorkerVMNeeded);
return new Pair<>(destVolumePath, exportName);
} finally {
@ -1104,7 +1102,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
}
}
private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vmMo, String installPath, long templateId, String templateUniqueName,
private Ternary<String, Long, Long> createTemplateFromVolume(VmwareContext context, VirtualMachineMO vmMo, VmwareHypervisorHost hyperHost, String installPath, long templateId, String templateUniqueName,
String secStorageUrl, String volumePath, String workerVmName, String nfsVersion) throws Exception {
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, nfsVersion);
@ -1131,8 +1129,6 @@ public class VmwareStorageProcessor implements StorageProcessor {
throw new Exception(msg);
}
VmwareContext context = hostService.getServiceContext(null);
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
ManagedObjectReference morPool = hyperHost.getHyperHostOwnerResourcePool();
vmMo.createFullCloneWithSpecificDisk(templateUniqueName, dcMo.getVmFolder(), morPool, VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), volumeDeviceInfo);
@ -1184,8 +1180,6 @@ public class VmwareStorageProcessor implements StorageProcessor {
clonedVm.detachAllDisks();
clonedVm.destroy();
}
vmMo.removeSnapshot(templateUniqueName, false);
}
}
@ -1211,7 +1205,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
if (volume.getVmName() == null) {
ManagedObjectReference secMorDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, volume.getDataStore().getUuid());
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), secMorDs);
workerVmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, "workervm"+volume.getUuid(), null);
workerVmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, "workervm"+volume.getUuid());
if (workerVmMo == null) {
throw new Exception("Unable to find created worker VM");
}
@ -1244,9 +1238,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
}
Ternary<String, Long, Long> result =
createTemplateFromVolume(vmMo, template.getPath(), template.getId(), template.getName(), secondaryStoragePoolURL, volumePath,
createTemplateFromVolume(context, vmMo, hyperHost, template.getPath(), template.getId(), template.getName(), secondaryStoragePoolURL, volumePath,
hostService.getWorkerName(context, cmd, 0), _nfsVersion);
TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(result.first());
newTemplate.setFormat(ImageFormat.OVA);
@ -1568,7 +1561,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
ManagedObjectReference dsMor = hyperHost.findDatastoreByName(dsFile.getDatastoreName());
DatastoreMO dsMo = new DatastoreMO(context, dsMor);
VirtualMachineMO workerVM = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName, null);
VirtualMachineMO workerVM = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName);
if (workerVM == null) {
throw new CloudRuntimeException("Failed to find the newly created worker VM: " + workerVMName);
@ -1706,7 +1699,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
}
// return Pair<String(divice bus name), String[](disk chain)>
private Pair<String, String[]> exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volumePath, String secStorageUrl, String secStorageDir,
private Pair<String, String[]> exportVolumeToSecondaryStorage(VmwareContext context, VirtualMachineMO vmMo, VmwareHypervisorHost hyperHost, String volumePath, String secStorageUrl, String secStorageDir,
String exportName, String workerVmName, String nfsVersion, boolean clonedWorkerVMNeeded) throws Exception {
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, nfsVersion);
@ -1739,13 +1732,18 @@ public class VmwareStorageProcessor implements StorageProcessor {
String disks[] = vmMo.getCurrentSnapshotDiskChainDatastorePaths(diskDevice);
if (clonedWorkerVMNeeded) {
// 4 MB is the minimum requirement for VM memory in VMware
Pair<VirtualMachineMO, String[]> cloneResult =
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, diskDevice, VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), virtualHardwareVersion);
clonedVm = cloneResult.first();
clonedVm.exportVm(exportPath, exportName, false, false);
} else {
vmMo.exportVm(exportPath, exportName, false, false);
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
ManagedObjectReference morPool = hyperHost.getHyperHostOwnerResourcePool();
vmMo.createFullCloneWithSpecificDisk(exportName, dcMo.getVmFolder(), morPool, VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), volumeDeviceInfo);
clonedVm = dcMo.findVm(exportName);
if (clonedVm == null) {
String msg = "Failed to clone VM. volume path: " + volumePath;
s_logger.error(msg);
throw new Exception(msg);
}
}
vmMo.exportVm(exportPath, exportName, false, false);
return new Pair<>(diskDevice, disks);
} finally {
if (clonedVm != null) {
@ -1756,12 +1754,12 @@ public class VmwareStorageProcessor implements StorageProcessor {
}
// Ternary<String(backup uuid in secondary storage), String(device bus name), String[](original disk chain in the snapshot)>
private Ternary<String, String, String[]> backupSnapshotToSecondaryStorage(VirtualMachineMO vmMo, String installPath, String volumePath, String snapshotUuid,
private Ternary<String, String, String[]> backupSnapshotToSecondaryStorage(VmwareContext context, VirtualMachineMO vmMo, VmwareHypervisorHost hypervisorHost, String installPath, String volumePath, String snapshotUuid,
String secStorageUrl, String prevSnapshotUuid, String prevBackupUuid, String workerVmName,
String nfsVersion) throws Exception {
String backupUuid = UUID.randomUUID().toString();
Pair<String, String[]> snapshotInfo = exportVolumeToSecondaryStorage(vmMo, volumePath, secStorageUrl, installPath, backupUuid, workerVmName, nfsVersion, true);
Pair<String, String[]> snapshotInfo = exportVolumeToSecondaryStorage(context, vmMo, hypervisorHost, volumePath, secStorageUrl, installPath, backupUuid, workerVmName, nfsVersion, true);
return new Ternary<>(backupUuid, snapshotInfo.first(), snapshotInfo.second());
}
@ -1830,12 +1828,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
hasOwnerVm = true;
}
if (!vmMo.createSnapshot(snapshotUuid, "Snapshot taken for " + srcSnapshot.getName(), false, false)) {
throw new Exception("Failed to take snapshot " + srcSnapshot.getName() + " on vm: " + vmName);
}
backupResult =
backupSnapshotToSecondaryStorage(vmMo, destSnapshot.getPath(), srcSnapshot.getVolume().getPath(), snapshotUuid, secondaryStorageUrl,
backupSnapshotToSecondaryStorage(context, vmMo, hyperHost, destSnapshot.getPath(), srcSnapshot.getVolume().getPath(), snapshotUuid, secondaryStorageUrl,
prevSnapshotUuid, prevBackupUuid, hostService.getWorkerName(context, cmd, 1), _nfsVersion);
snapshotBackupUuid = backupResult.first();
@ -1916,7 +1910,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
}
}
} else {
s_logger.error("Can not find the snapshot we just used ?!");
s_logger.info("No snapshots created to be deleted!");
}
}
@ -2281,7 +2275,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
* String dummyVmName = hostService.getWorkerName(context, cmd, 0);
try {
s_logger.info("Create worker VM " + dummyVmName);
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null);
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName);
if (vmMo == null) {
throw new Exception("Unable to create a dummy VM for volume creation");
}
@ -2966,7 +2960,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
VirtualMachineMO vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null);
VirtualMachineMO vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName);
if (vmMo == null) {
throw new Exception("Unable to create a dummy VM for volume creation");

View File

@ -303,7 +303,7 @@ public class VirtualMachineMO extends BaseMO {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
s_logger.debug("[ignored] interupted while powering of vm.");
s_logger.debug("[ignored] interrupted while powering of vm.");
}
}
@ -336,7 +336,7 @@ public class VirtualMachineMO extends BaseMO {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
s_logger.debug("[ignored] interupted while powering of vm unconditionaly.");
s_logger.debug("[ignored] interrupted while powering of vm unconditionally.");
}
}
return true;
@ -370,7 +370,7 @@ public class VirtualMachineMO extends BaseMO {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
s_logger.debug("[ignored] interupted while pausing after power off.");
s_logger.debug("[ignored] interrupted while pausing after power off.");
}
} else {
break;
@ -1780,7 +1780,7 @@ public class VirtualMachineMO extends BaseMO {
command.add((new File(name).getName()));
}
s_logger.info("Package OVA with commmand: " + command.toString());
s_logger.info("Package OVA with command: " + command.toString());
command.execute();
// to be safe, physically test existence of the target OVA file
@ -1793,7 +1793,7 @@ public class VirtualMachineMO extends BaseMO {
success = true;
}
}
s_logger.info("volss: copy vmdk and ovf file finishes " + System.currentTimeMillis());
s_logger.info("volss: copy vmdk and ovf file finished " + System.currentTimeMillis());
} catch (Throwable e) {
s_logger.error("Unexpected exception ", e);
} finally {