Skip to content

Commit 640fa6b

Browse files
committed
Fix a bug in converting Enum type to String.
1 parent 105bf71 commit 640fa6b

5 files changed

Lines changed: 38 additions & 18 deletions

File tree

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd)
192192
workerVMName = hostService.getWorkerName(context, cmd, 0);
193193

194194
// attach a volume to dummay wrapper VM for taking snapshot and exporting the VM for backup
195-
if (!hyperHost.createBlankVm(workerVMName, 1, 512, 0, false, 4, 0, VirtualMachineGuestOsIdentifier.OTHER_GUEST.toString(), morDs, false)) {
195+
if (!hyperHost.createBlankVm(workerVMName, 1, 512, 0, false, 4, 0, VirtualMachineGuestOsIdentifier.OTHER_GUEST.value(), morDs, false)) {
196196
String msg = "Unable to create worker VM to execute BackupSnapshotCommand";
197197
s_logger.error(msg);
198198
throw new Exception(msg);
@@ -804,7 +804,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
804804
vmConfig.setName(workerVmName);
805805
vmConfig.setMemoryMB((long) 4);
806806
vmConfig.setNumCPUs(1);
807-
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.toString());
807+
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value());
808808
VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo();
809809
fileInfo.setVmPathName(String.format("[%s]", dsMo.getName()));
810810
vmConfig.setFiles(fileInfo);

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,7 +2094,7 @@ protected StartAnswer execute(StartCommand cmd) {
20942094

20952095
if (!hyperHost.createBlankVm(vmName, vmSpec.getCpus(), vmSpec.getSpeed().intValue(),
20962096
getReserveCpuMHz(vmSpec.getSpeed().intValue()), vmSpec.getLimitCpuUse(), ramMb, getReserveMemMB(ramMb),
2097-
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).toString(), rootDiskDataStoreDetails.first(), false)) {
2097+
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), rootDiskDataStoreDetails.first(), false)) {
20982098
throw new Exception("Failed to create VM. vmName: " + vmName);
20992099
}
21002100
}
@@ -2126,7 +2126,7 @@ protected StartAnswer execute(StartCommand cmd) {
21262126
int ramMb = (int) (vmSpec.getMinRam() / (1024 * 1024));
21272127
VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getSpeed().intValue(),
21282128
getReserveCpuMHz(vmSpec.getSpeed().intValue()), ramMb, getReserveMemMB(ramMb),
2129-
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).toString(), vmSpec.getLimitCpuUse());
2129+
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), vmSpec.getLimitCpuUse());
21302130

21312131
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[totalChangeDevices];
21322132
int i = 0;
@@ -3935,7 +3935,7 @@ protected VirtualMachineMO prepareVolumeHostDummyVm(VmwareHypervisorHost hyperHo
39353935
vmConfig.setName(vmName);
39363936
vmConfig.setMemoryMB((long) 4); // vmware request minimum of 4 MB
39373937
vmConfig.setNumCPUs(1);
3938-
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.toString());
3938+
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value());
39393939
VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo();
39403940
fileInfo.setVmPathName(String.format("[%s]", dsMo.getName()));
39413941
vmConfig.setFiles(fileInfo);

‎vmware-base/src/com/cloud/hypervisor/vmware/mo/HttpNfcLeaseMO.java‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@
2020
import java.io.FileInputStream;
2121
import java.io.IOException;
2222
import java.io.InputStreamReader;
23+
import java.rmi.RemoteException;
24+
import java.util.Arrays;
2325
import java.util.List;
2426

2527
import org.apache.log4j.Logger;
28+
import org.w3c.dom.Element;
2629

2730
import com.cloud.hypervisor.vmware.util.VmwareContext;
2831
import com.vmware.vim25.HttpNfcLeaseInfo;
2932
import com.vmware.vim25.HttpNfcLeaseManifestEntry;
3033
import com.vmware.vim25.HttpNfcLeaseState;
3134
import com.vmware.vim25.ManagedObjectReference;
35+
import com.vmware.vim25.ObjectSpec;
3236
import com.vmware.vim25.OvfCreateImportSpecResult;
3337
import com.vmware.vim25.OvfFileItem;
38+
import com.vmware.vim25.PropertyFilterSpec;
39+
import com.vmware.vim25.PropertySpec;
3440

3541
public class HttpNfcLeaseMO extends BaseMO {
3642
private static final Logger s_logger = Logger.getLogger(HttpNfcLeaseMO.class);
@@ -44,7 +50,19 @@ public HttpNfcLeaseMO(VmwareContext context, String morType, String morValue) {
4450
}
4551

4652
public HttpNfcLeaseState getState() throws Exception {
47-
return (HttpNfcLeaseState)_context.getVimClient().getDynamicProperty(_mor, "state");
53+
Object stateProp = _context.getVimClient().getDynamicProperty(_mor, "state");
54+
// Due to some issue in JAX-WS De-serialization getting the information
55+
// from the nodes
56+
assert (stateProp.toString().contains("val: null"));
57+
String stateVal = null;
58+
Element stateElement = (Element) stateProp;
59+
if (stateElement != null && stateElement.getFirstChild() != null) {
60+
stateVal = stateElement.getFirstChild().getTextContent();
61+
}
62+
if (stateVal != null) {
63+
return HttpNfcLeaseState.fromValue(stateVal);
64+
}
65+
return HttpNfcLeaseState.ERROR;
4866
}
4967

5068
public HttpNfcLeaseState waitState(HttpNfcLeaseState[] states) throws Exception {
@@ -59,6 +77,8 @@ public HttpNfcLeaseState waitState(HttpNfcLeaseState[] states) throws Exception
5977
}
6078
}
6179

80+
81+
6282
public HttpNfcLeaseInfo getLeaseInfo() throws Exception {
6383
return (HttpNfcLeaseInfo)_context.getVimClient().getDynamicProperty(_mor, "info");
6484
}

‎vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,14 +571,14 @@ public boolean createLinkedClone(String cloneName, ManagedObjectReference morBas
571571
VirtualMachineRelocateSpecDiskLocator loc = new VirtualMachineRelocateSpecDiskLocator();
572572
loc.setDatastore(morDs);
573573
loc.setDiskId(independentDisks[i].getKey());
574-
loc.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING.toString());
574+
loc.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING.value());
575575
diskLocator.add(loc);
576576
}
577577

578-
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.CREATE_NEW_CHILD_DISK_BACKING.toString());
578+
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.CREATE_NEW_CHILD_DISK_BACKING.value());
579579
rSpec.getDisk().addAll(diskLocator);
580580
} else {
581-
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.CREATE_NEW_CHILD_DISK_BACKING.toString());
581+
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.CREATE_NEW_CHILD_DISK_BACKING.value());
582582
}
583583
rSpec.setPool(morResourcePool);
584584

@@ -868,7 +868,7 @@ public void createDisk(String vmdkDatastorePath, VirtualDiskType diskType, Virtu
868868
|| diskType == VirtualDiskType.EAGER_ZEROED_THICK) {
869869

870870
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
871-
backingInfo.setDiskMode(diskMode.PERSISTENT.toString());
871+
backingInfo.setDiskMode(diskMode.PERSISTENT.value());
872872
if(diskType == VirtualDiskType.THIN) {
873873
backingInfo.setThinProvisioned(true);
874874
} else {
@@ -894,7 +894,7 @@ public void createDisk(String vmdkDatastorePath, VirtualDiskType diskType, Virtu
894894
}
895895
backingInfo.setDeviceName(rdmDeviceName);
896896
if(diskType == VirtualDiskType.RDM) {
897-
backingInfo.setDiskMode(diskMode.PERSISTENT.toString());
897+
backingInfo.setDiskMode(diskMode.PERSISTENT.value());
898898
}
899899

900900
backingInfo.setDatastore(morDs);
@@ -1894,10 +1894,10 @@ public VirtualDisk[] getAllIndependentDiskDevice() throws Exception {
18941894
}
18951895

18961896
public int tryGetIDEDeviceControllerKey() throws Exception {
1897-
VirtualDevice[] devices = (VirtualDevice [])_context.getVimClient().
1897+
List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
18981898
getDynamicProperty(_mor, "config.hardware.device");
18991899

1900-
if(devices != null && devices.length > 0) {
1900+
if(devices != null && devices.size() > 0) {
19011901
for(VirtualDevice device : devices) {
19021902
if(device instanceof VirtualIDEController) {
19031903
return ((VirtualIDEController)device).getKey();

‎vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int control
169169
VirtualDisk disk = new VirtualDisk();
170170

171171
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
172-
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.toString());
172+
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
173173
backingInfo.setThinProvisioned(true);
174174
backingInfo.setEagerlyScrub(false);
175175
backingInfo.setDatastore(morDs);
@@ -273,7 +273,7 @@ public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int control
273273
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
274274
backingInfo.setDatastore(morDs);
275275
backingInfo.setFileName(vmdkDatastorePathChain[0]);
276-
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.toString());
276+
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
277277
if(vmdkDatastorePathChain.length > 1) {
278278
String[] parentDisks = new String[vmdkDatastorePathChain.length - 1];
279279
for(int i = 0; i < vmdkDatastorePathChain.length - 1; i++)
@@ -313,7 +313,7 @@ public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int control
313313
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
314314
backingInfo.setDatastore(vmdkDatastorePathChain[0].second());
315315
backingInfo.setFileName(vmdkDatastorePathChain[0].first());
316-
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.toString());
316+
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
317317
if(vmdkDatastorePathChain.length > 1) {
318318
Pair<String, ManagedObjectReference>[] parentDisks = new Pair[vmdkDatastorePathChain.length - 1];
319319
for(int i = 0; i < vmdkDatastorePathChain.length - 1; i++)
@@ -346,7 +346,7 @@ private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingI
346346

347347
VirtualDiskFlatVer2BackingInfo parentBacking = new VirtualDiskFlatVer2BackingInfo();
348348
parentBacking.setDatastore(morDs);
349-
parentBacking.setDiskMode(VirtualDiskMode.PERSISTENT.toString());
349+
parentBacking.setDiskMode(VirtualDiskMode.PERSISTENT.value());
350350

351351
if(parentDatastorePathList.length > 1) {
352352
String[] nextDatastorePathList = new String[parentDatastorePathList.length -1];
@@ -364,7 +364,7 @@ private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingI
364364

365365
VirtualDiskFlatVer2BackingInfo parentBacking = new VirtualDiskFlatVer2BackingInfo();
366366
parentBacking.setDatastore(parentDatastorePathList[0].second());
367-
parentBacking.setDiskMode(VirtualDiskMode.PERSISTENT.toString());
367+
parentBacking.setDiskMode(VirtualDiskMode.PERSISTENT.value());
368368

369369
if(parentDatastorePathList.length > 1) {
370370
Pair<String, ManagedObjectReference>[] nextDatastorePathList = new Pair[parentDatastorePathList.length -1];

0 commit comments

Comments
 (0)