From 1e505e08883f4735c70e9d0de03d24efe990ed2a Mon Sep 17 00:00:00 2001 From: atrbgithub Date: Thu, 5 Nov 2015 11:53:55 +0000 Subject: [PATCH] Fix for CLOUDSTACK-8937 - XenServer migrations with storage failing in clustered management server environment --- .../XenServer610MigrateWithStorageCommandWrapper.java | 11 +++++------ .../motion/XenServerStorageMotionStrategy.java | 9 +++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java index 2a79d26b0451..195ea6a98352 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java @@ -41,6 +41,7 @@ import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.Pair; import com.xensource.xenapi.Connection; import com.xensource.xenapi.Host; import com.xensource.xenapi.Network; @@ -60,7 +61,7 @@ public final class XenServer610MigrateWithStorageCommandWrapper extends CommandW public Answer execute(final MigrateWithStorageCommand command, final XenServer610Resource xenServer610Resource) { final Connection connection = xenServer610Resource.getConnection(); final VirtualMachineTO vmSpec = command.getVirtualMachine(); - final Map volumeToFiler = command.getVolumeToFiler(); + final List> volToFiler = command.getVolumeToFilerAsList(); final String vmName = vmSpec.getName(); Task task = null; @@ -83,10 +84,8 @@ public Answer execute(final MigrateWithStorageCommand command, final XenServer61 // Create the vif map. The vm stays in the same cluster so we have to pass an empty vif map. final Map vifMap = new HashMap(); final Map vdiMap = new HashMap(); - for (final Map.Entry entry : volumeToFiler.entrySet()) { - final VolumeTO volume = entry.getKey(); - final StorageFilerTO sotrageFiler = entry.getValue(); - vdiMap.put(xenServer610Resource.getVDIbyUuid(connection, volume.getPath()), xenServer610Resource.getStorageRepository(connection, sotrageFiler.getUuid())); + for (final Pair entry : volToFiler) { + vdiMap.put(xenServer610Resource.getVDIbyUuid(connection, entry.first().getPath()), xenServer610Resource.getStorageRepository(connection, entry.second().getUuid())); } // Get the vm to migrate. @@ -136,4 +135,4 @@ public Answer execute(final MigrateWithStorageCommand command, final XenServer61 } } } -} \ No newline at end of file +} diff --git a/plugins/hypervisors/xenserver/src/org/apache/cloudstack/storage/motion/XenServerStorageMotionStrategy.java b/plugins/hypervisors/xenserver/src/org/apache/cloudstack/storage/motion/XenServerStorageMotionStrategy.java index c8367dd3ac1a..99174e221f4c 100644 --- a/plugins/hypervisors/xenserver/src/org/apache/cloudstack/storage/motion/XenServerStorageMotionStrategy.java +++ b/plugins/hypervisors/xenserver/src/org/apache/cloudstack/storage/motion/XenServerStorageMotionStrategy.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.storage.motion; import java.util.HashMap; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -59,6 +60,7 @@ import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.VolumeDao; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.Pair; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.dao.VMInstanceDao; @@ -193,15 +195,14 @@ private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachine // 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); + MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto,destHost.getGuid()); MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer)agentMgr.send(destHost.getId(), command); if (answer == null) { s_logger.error("Migration with storage of vm " + vm + " failed.");