From 04365601dac6d4dfa396e5c86ab7e698906dfb44 Mon Sep 17 00:00:00 2001 From: Likitha Shetty Date: Fri, 3 Apr 2015 15:47:07 +0530 Subject: [PATCH] CLOUDSTACK-8412. VM migration with storage fails. Update MigrateWithStorageCommand to avoid JSON deserialization error. --- .../hypervisor/vmware/resource/VmwareResource.java | 12 ++++++------ .../storage/motion/VmwareStorageMotionStrategy.java | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index b30a572e8d1..87264125fde 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -3036,7 +3036,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa List volumeToList = new ArrayList(); Map volumeDeviceKey = new HashMap(); - Map volToFiler = cmd.getVolumeToFiler(); + List> volToFiler = cmd.getVolumeToFilerAsList(); String tgtHost = cmd.getTargetHost(); String tgtHostMorInfo = tgtHost.split("@")[0]; morTgtHost.setType(tgtHostMorInfo.split(":")[0]); @@ -3064,9 +3064,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa vmName = vmMo.getName(); // Specify destination datastore location for each volume - for (Entry entry : volToFiler.entrySet()) { - volume = entry.getKey(); - filerTo = entry.getValue(); + for (Pair entry : volToFiler) { + volume = entry.first(); + filerTo = entry.second(); s_logger.debug("Preparing spec for volume : " + volume.getName()); morDsAtTarget = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(tgtHyperHost, filerTo.getUuid()); @@ -3195,8 +3195,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } // Update and return volume path for every disk because that could have changed after migration - for (Entry entry : volToFiler.entrySet()) { - volume = entry.getKey(); + for (Pair entry : volToFiler) { + volume = entry.first(); long volumeId = volume.getId(); VirtualDisk[] disks = vmMo.getAllDiskDevice(); for (VirtualDisk disk : disks) { diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java index 24efde79a99..da9764de54d 100644 --- a/plugins/hypervisors/vmware/src/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java +++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java @@ -19,7 +19,7 @@ package org.apache.cloudstack.storage.motion; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -53,6 +53,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.StoragePool; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.VolumeDao; +import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.dao.VMInstanceDao; @@ -130,12 +131,12 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy { // Initiate migration of a virtual machine with it's volumes. try { - Map volumeToFilerto = new HashMap(); + List> volumeToFilerto = new ArrayList>(); for (Map.Entry entry : volumeToPool.entrySet()) { VolumeInfo volume = entry.getKey(); VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId())); StorageFilerTO filerTo = new StorageFilerTO((StoragePool)entry.getValue()); - volumeToFilerto.put(volumeTo, filerTo); + volumeToFilerto.add(new Pair(volumeTo, filerTo)); } // Migration across cluster needs to be done in three phases. @@ -168,12 +169,12 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy { // Initiate migration of a virtual machine with it's volumes. try { - Map volumeToFilerto = new HashMap(); + List> volumeToFilerto = new ArrayList>(); for (Map.Entry entry : volumeToPool.entrySet()) { VolumeInfo volume = entry.getKey(); VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId())); StorageFilerTO filerTo = new StorageFilerTO((StoragePool)entry.getValue()); - volumeToFilerto.put(volumeTo, filerTo); + volumeToFilerto.add(new Pair(volumeTo, filerTo)); } MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid());