Skip to content

Commit 26d017c

Browse files
code improvements - threads configuration, and api parameter changes to import vm files
1 parent 4bff115 commit 26d017c

8 files changed

Lines changed: 35 additions & 40 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public class ApiConstants {
189189
public static final String FORCED = "forced";
190190
public static final String FORCED_DESTROY_LOCAL_STORAGE = "forcedestroylocalstorage";
191191
public static final String FORCE_DELETE_HOST = "forcedeletehost";
192-
public static final String FORCE_MS_TO_DOWNLOAD_VM_FILES = "forcemstodownloadvmfiles";
192+
public static final String FORCE_MS_TO_IMPORT_VM_FILES = "forcemstoimportvmfiles";
193193
public static final String FORMAT = "format";
194194
public static final String FOR_VIRTUAL_NETWORK = "forvirtualnetwork";
195195
public static final String FOR_SYSTEM_VMS = "forsystemvms";

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportVmCmd.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ public class ImportVmCmd extends ImportUnmanagedInstanceCmd {
153153
description = "(only for importing VMs from VMware to KVM) optional - the temporary storage pool to perform the virt-v2v migration from VMware to KVM.")
154154
private Long convertStoragePoolId;
155155

156-
@Parameter(name = ApiConstants.FORCE_MS_TO_DOWNLOAD_VM_FILES, type = CommandType.BOOLEAN,
157-
description = "(only for importing VMs from VMware to KVM) optional - if true, forces MS to download VM file(s) to temporary storage, else uses Host if ovftool is available, falls back to MS if not.")
158-
private Boolean forceMsToDownloadVmFiles;
156+
@Parameter(name = ApiConstants.FORCE_MS_TO_IMPORT_VM_FILES, type = CommandType.BOOLEAN,
157+
description = "(only for importing VMs from VMware to KVM) optional - if true, forces MS to import VM file(s) to temporary storage, else uses KVM Host if ovftool is available, falls back to MS if not.")
158+
private Boolean forceMsToImportVmFiles;
159159

160160
/////////////////////////////////////////////////////
161161
/////////////////// Accessors ///////////////////////
@@ -205,8 +205,8 @@ public Long getConvertStoragePoolId() {
205205
return convertStoragePoolId;
206206
}
207207

208-
public Boolean getForceMsToDownloadVmFiles() {
209-
return BooleanUtils.toBooleanDefaultIfNull(forceMsToDownloadVmFiles, false);
208+
public Boolean getForceMsToImportVmFiles() {
209+
return BooleanUtils.toBooleanDefaultIfNull(forceMsToImportVmFiles, false);
210210
}
211211

212212
public String getHypervisor() {

api/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManager.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,24 @@ public interface UnmanagedVMsManager extends VmImportService, UnmanageVMService,
4848
ConfigKey.Scope.Global,
4949
null);
5050

51-
ConfigKey<Integer> ThreadsOnMSToDownloadVMwareVMFiles = new ConfigKey<>(Integer.class,
52-
"threads.on.ms.to.download.vmware.vm.files",
51+
ConfigKey<Integer> ThreadsOnMSToImportVMwareVMFiles = new ConfigKey<>(Integer.class,
52+
"threads.on.ms.to.import.vmware.vm.files",
5353
"Advanced",
5454
"0",
55-
"Threads to use on the management server to download VMware VM files per import VM," +
56-
" single disk or less than zero - disabled, zero - uses total disks count, maximum value is 10. Default: 0.",
55+
"Threads to use on the management server when importing VM files from VMWare." +
56+
" -1 or 1 disables threads, 0 uses a thread per VM disk (disabled for single disk) and >1 for manual thread configuration." +
57+
" Max number is 10, Default is 0.",
5758
true,
5859
ConfigKey.Scope.Global,
5960
null);
6061

61-
ConfigKey<Integer> ThreadsOnKVMHostToDownloadVMwareVMFiles = new ConfigKey<>(Integer.class,
62-
"threads.on.kvm.host.to.download.vmware.vm.files",
62+
ConfigKey<Integer> ThreadsOnKVMHostToImportVMwareVMFiles = new ConfigKey<>(Integer.class,
63+
"threads.on.kvm.host.to.import.vmware.vm.files",
6364
"Advanced",
6465
"0",
65-
"Threads to use on the KVM host (by OVF Tool, supported from version >= 4.4.0) to download VMware VM files per import VM," +
66-
" single disk or less than zero - disabled, zero - uses total disks count, value should be less than 100 which is approximated to the number" +
67-
" of CPU cores minus one. Default: 0.",
66+
"Threads to use on the KVM host (by the ovftool, if the version is 4.4.0+) when importing VM files from VMWare." +
67+
" -1 or 1 disables threads, 0 uses a thread per VM disk (disabled for single disk) and >1 for manual thread configuration." +
68+
" Max number is 10, Default is 0.",
6869
true,
6970
ConfigKey.Scope.Global,
7071
null);

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,15 +1264,9 @@ protected String validateConfigurationValue(final String name, String value, fin
12641264
}
12651265
}
12661266

1267-
if (UnmanagedVMsManager.ThreadsOnMSToDownloadVMwareVMFiles.key().equalsIgnoreCase(name)) {
1267+
if (UnmanagedVMsManager.ThreadsOnMSToImportVMwareVMFiles.key().equalsIgnoreCase(name) || UnmanagedVMsManager.ThreadsOnKVMHostToImportVMwareVMFiles.key().equalsIgnoreCase(name)) {
12681268
if (val > 10) {
1269-
throw new InvalidParameterValueException("Please enter a value less than or equals to 10 for the configuration parameter:" + name);
1270-
}
1271-
}
1272-
1273-
if (UnmanagedVMsManager.ThreadsOnKVMHostToDownloadVMwareVMFiles.key().equalsIgnoreCase(name)) {
1274-
if (val >= 100) {
1275-
throw new InvalidParameterValueException("Please enter a value less than 100 for the configuration parameter:" + name);
1269+
throw new InvalidParameterValueException("Please enter a value between 0 and 10 for the configuration parameter: " + name + ", -1 will disable it");
12761270
}
12771271
}
12781272

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,9 +1616,9 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
16161616
String instanceName = getGeneratedInstanceName(owner);
16171617
checkNetworkingBeforeConvertingVmwareInstance(zone, owner, instanceName, hostName, sourceVMwareInstance, nicNetworkMap, nicIpAddressMap, forced);
16181618
UnmanagedInstanceTO convertedInstance;
1619-
if (cmd.getForceMsToDownloadVmFiles() || !conversionSupportAnswer.isOvfExportSupported()) {
1619+
if (cmd.getForceMsToImportVmFiles() || !conversionSupportAnswer.isOvfExportSupported()) {
16201620
// Uses MS for OVF export to temporary conversion location
1621-
int noOfThreads = UnmanagedVMsManager.ThreadsOnMSToDownloadVMwareVMFiles.value();
1621+
int noOfThreads = UnmanagedVMsManager.ThreadsOnMSToImportVMwareVMFiles.value();
16221622
ovfTemplateOnConvertLocation = createOvfTemplateOfSourceVmwareUnmanagedInstance(vcenter, datacenterName, username, password,
16231623
clusterName, sourceHostName, sourceVMwareInstance.getName(), temporaryConvertLocation, noOfThreads);
16241624
convertedInstance = convertVmwareInstanceToKVMWithOVFOnConvertLocation(sourceVMName, sourceVMwareInstance, convertHost, convertStoragePools,
@@ -1636,8 +1636,8 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
16361636
nicNetworkMap, nicIpAddressMap,
16371637
details, false, forced, false);
16381638
long timeElapsedInSecs = (System.currentTimeMillis() - importStartTime) / 1000;
1639-
LOGGER.debug(String.format("VMware VM %s imported successfully to CloudStack instance %s, Time taken: %d secs, OVF files downloaded from %s, Source VMware VM details - OS: %s, Disks: %s, NICs: %s",
1640-
sourceVMName, instanceName, timeElapsedInSecs, (ovfTemplateOnConvertLocation != null)? "MS" : "KVM Host", sourceVMwareInstance.getOperatingSystem(), sourceVMwareInstance.getDisks(), sourceVMwareInstance.getNics()));
1639+
LOGGER.debug(String.format("VMware VM %s imported successfully to CloudStack instance %s (%s), Time taken: %d secs, OVF files imported from %s, Source VMware VM details - OS: %s, PowerState: %s, Disks: %s, NICs: %s",
1640+
sourceVMName, instanceName, displayName, timeElapsedInSecs, (ovfTemplateOnConvertLocation != null)? "MS" : "KVM Host", sourceVMwareInstance.getOperatingSystem(), sourceVMwareInstance.getPowerState(), sourceVMwareInstance.getDisks(), sourceVMwareInstance.getNics()));
16411641
return userVm;
16421642
} catch (CloudRuntimeException e) {
16431643
LOGGER.error(String.format("Error importing VM: %s", e.getMessage()), e);
@@ -1887,7 +1887,7 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvert
18871887
Hypervisor.HypervisorType.KVM, destinationStoragePools, temporaryConvertLocation, null, false, true);
18881888
int timeoutSeconds = UnmanagedVMsManager.ConvertVmwareInstanceToKvmTimeout.value() * 60 * 60;
18891889
cmd.setWait(timeoutSeconds);
1890-
int noOfThreads = UnmanagedVMsManager.ThreadsOnKVMHostToDownloadVMwareVMFiles.value();
1890+
int noOfThreads = UnmanagedVMsManager.ThreadsOnKVMHostToImportVMwareVMFiles.value();
18911891
if (noOfThreads == 0) {
18921892
// Use no. of threads as the disks count
18931893
noOfThreads = sourceVMwareInstance.getDisks().size();
@@ -2647,8 +2647,8 @@ public ConfigKey<?>[] getConfigKeys() {
26472647
UnmanageVMPreserveNic,
26482648
RemoteKvmInstanceDisksCopyTimeout,
26492649
ConvertVmwareInstanceToKvmTimeout,
2650-
ThreadsOnMSToDownloadVMwareVMFiles,
2651-
ThreadsOnKVMHostToDownloadVMwareVMFiles
2650+
ThreadsOnMSToImportVMwareVMFiles,
2651+
ThreadsOnKVMHostToImportVMwareVMFiles
26522652
};
26532653
}
26542654
}

server/src/test/java/com/cloud/configuration/ConfigurationManagerImplTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,17 @@ public void testValidateInvalidScopeForConfiguration() {
327327
public void testValidateConfig_ThreadsOnKVMHostToTransferVMwareVMFiles_Failure() {
328328
ConfigurationVO cfg = mock(ConfigurationVO.class);
329329
when(cfg.getScope()).thenReturn(ConfigKey.Scope.Global.toString());
330-
ConfigKey<Integer> configKey = UnmanagedVMsManager.ThreadsOnKVMHostToDownloadVMwareVMFiles;
330+
ConfigKey<Integer> configKey = UnmanagedVMsManager.ThreadsOnKVMHostToImportVMwareVMFiles;
331331
Mockito.doReturn(cfg).when(configDaoMock).findByName(Mockito.anyString());
332332
Mockito.doReturn(configKey).when(configurationManagerImplSpy._configDepot).get(configKey.key());
333-
configurationManagerImplSpy.validateConfigurationValue(configKey.key(), "100", configKey.scope().toString());
333+
configurationManagerImplSpy.validateConfigurationValue(configKey.key(), "11", configKey.scope().toString());
334334
}
335335

336336
@Test
337337
public void testValidateConfig_ThreadsOnKVMHostToTransferVMwareVMFiles_Success() {
338338
ConfigurationVO cfg = mock(ConfigurationVO.class);
339339
when(cfg.getScope()).thenReturn(ConfigKey.Scope.Global.toString());
340-
ConfigKey<Integer> configKey = UnmanagedVMsManager.ThreadsOnKVMHostToDownloadVMwareVMFiles;
340+
ConfigKey<Integer> configKey = UnmanagedVMsManager.ThreadsOnKVMHostToImportVMwareVMFiles;
341341
Mockito.doReturn(cfg).when(configDaoMock).findByName(Mockito.anyString());
342342
Mockito.doReturn(configKey).when(configurationManagerImplSpy._configDepot).get(configKey.key());
343343
String msg = configurationManagerImplSpy.validateConfigurationValue(configKey.key(), "10", configKey.scope().toString());

ui/public/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@
918918
"label.for": "for",
919919
"label.forbidden": "Forbidden",
920920
"label.forced": "Force",
921-
"label.force.ms.to.download.vm.files": "Force MS to download VM file(s) to temporary storage",
921+
"label.force.ms.to.import.vm.files": "Force MS to import VM file(s) to temporary storage",
922922
"label.force.stop": "Force stop",
923923
"label.force.reboot": "Force reboot",
924924
"label.forceencap": "Force UDP encapsulation of ESP packets",

ui/src/views/tools/ImportUnmanagedInstance.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@
192192
</a-select-option>
193193
</a-select>
194194
</a-form-item>
195-
<a-form-item name="forcemstodownloadvmfiles" ref="forcemstodownloadvmfiles" v-if="selectedVmwareVcenter">
195+
<a-form-item name="forcemstoimportvmfiles" ref="forcemstoimportvmfiles" v-if="selectedVmwareVcenter">
196196
<template #label>
197-
<tooltip-label :title="$t('label.force.ms.to.download.vm.files')" :tooltip="apiParams.forcemstodownloadvmfiles.description"/>
197+
<tooltip-label :title="$t('label.force.ms.to.import.vm.files')" :tooltip="apiParams.forcemstoimportvmfiles.description"/>
198198
</template>
199-
<a-switch v-model:checked="form.forcemstodownloadvmfiles" @change="val => { switches.forceMsToDownloadVmFiles = val }" />
199+
<a-switch v-model:checked="form.forcemstoimportvmfiles" @change="val => { switches.forceMsToImportVmFiles = val }" />
200200
</a-form-item>
201201
<a-form-item name="serviceofferingid" ref="serviceofferingid">
202202
<template #label>
@@ -708,7 +708,7 @@ export default {
708708
rootdiskid: 0,
709709
migrateallowed: this.switches.migrateAllowed,
710710
forced: this.switches.forced,
711-
forcemstodownloadvmfiles: this.switches.forceMsToDownloadVmFiles,
711+
forcemstoimportvmfiles: this.switches.forceMsToImportVmFiles,
712712
domainid: null,
713713
account: null
714714
})
@@ -1102,9 +1102,9 @@ export default {
11021102
if (this.selectedStoragePoolForConversion) {
11031103
params.convertinstancepoolid = this.selectedStoragePoolForConversion
11041104
}
1105-
params.forcemstodownloadvmfiles = values.forcemstodownloadvmfiles
1105+
params.forcemstoimportvmfiles = values.forcemstoimportvmfiles
11061106
}
1107-
var keys = ['hostname', 'domainid', 'projectid', 'account', 'migrateallowed', 'forced', 'forcemstodownloadvmfiles']
1107+
var keys = ['hostname', 'domainid', 'projectid', 'account', 'migrateallowed', 'forced', 'forcemstoimportvmfiles']
11081108
if (this.templateType !== 'auto') {
11091109
keys.push('templateid')
11101110
}

0 commit comments

Comments
 (0)