Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7A31211891 for ; Tue, 13 May 2014 08:52:47 +0000 (UTC) Received: (qmail 30120 invoked by uid 500); 13 May 2014 08:52:47 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 30087 invoked by uid 500); 13 May 2014 08:52:47 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 30076 invoked by uid 99); 13 May 2014 08:52:47 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 May 2014 08:52:47 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C1A9A24800; Tue, 13 May 2014 08:52:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dahn@apache.org To: commits@cloudstack.apache.org Date: Tue, 13 May 2014 08:52:46 -0000 Message-Id: <9d33314670464533ace7fdd59507a680@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: updated refs/heads/4.4 to 820f872 Repository: cloudstack Updated Branches: refs/heads/4.4 7bd0b92ea -> 820f8724f CLOUDSTACK-6510: Fix gson serialization exception in storage migration. Gson couldn't serialize a map with volume and storagepool objects for logging. Fixed by using volume and storage pool ids instead of objects in the map. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f0dcf474 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f0dcf474 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f0dcf474 Branch: refs/heads/4.4 Commit: f0dcf474f2f46075a01f4323eb9f9950466b3d28 Parents: 7bd0b92 Author: Devdeep Singh Authored: Mon May 5 16:59:39 2014 +0530 Committer: Daan Hoogland Committed: Tue May 13 10:51:42 2014 +0200 ---------------------------------------------------------------------- .../src/com/cloud/vm/VirtualMachineManager.java | 3 +- .../com/cloud/vm/VirtualMachineManagerImpl.java | 61 ++++++++++++-------- .../com/cloud/vm/VmWorkMigrateWithStorage.java | 9 +-- .../cloud/vm/VirtualMachineManagerImplTest.java | 10 ++-- server/src/com/cloud/vm/UserVmManagerImpl.java | 4 +- 5 files changed, 48 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f0dcf474/engine/api/src/com/cloud/vm/VirtualMachineManager.java ---------------------------------------------------------------------- diff --git a/engine/api/src/com/cloud/vm/VirtualMachineManager.java b/engine/api/src/com/cloud/vm/VirtualMachineManager.java index f070210..b1e5258 100644 --- a/engine/api/src/com/cloud/vm/VirtualMachineManager.java +++ b/engine/api/src/com/cloud/vm/VirtualMachineManager.java @@ -39,7 +39,6 @@ import com.cloud.network.Network; import com.cloud.offering.DiskOfferingInfo; import com.cloud.offering.ServiceOffering; import com.cloud.storage.StoragePool; -import com.cloud.storage.Volume; import com.cloud.template.VirtualMachineTemplate; import com.cloud.utils.component.Manager; import com.cloud.utils.fsm.NoTransitionException; @@ -113,7 +112,7 @@ public interface VirtualMachineManager extends Manager { void migrate(String vmUuid, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException; - void migrateWithStorage(String vmUuid, long srcId, long destId, Map volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException; + void migrateWithStorage(String vmUuid, long srcId, long destId, Map volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException; void reboot(String vmUuid, Map params) throws InsufficientCapacityException, ResourceUnavailableException; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f0dcf474/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index 6b646bc..d8abdfb 100755 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -26,6 +26,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -1964,24 +1965,26 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - private Map getPoolListForVolumesForMigration(VirtualMachineProfile profile, Host host, Map volumeToPool) { + private Map getPoolListForVolumesForMigration(VirtualMachineProfile profile, Host host, Map volumeToPool) { List allVolumes = _volsDao.findUsableVolumesForInstance(profile.getId()); + Map volumeToPoolObjectMap = new HashMap (); for (VolumeVO volume : allVolumes) { - StoragePool pool = volumeToPool.get(volume); - DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); + Long poolId = volumeToPool.get(Long.valueOf(volume.getId())); + StoragePoolVO pool = _storagePoolDao.findById(poolId); StoragePoolVO currentPool = _storagePoolDao.findById(volume.getPoolId()); + DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); if (pool != null) { // Check if pool is accessible from the destination host and disk offering with which the volume was // created is compliant with the pool type. if (_poolHostDao.findByPoolHost(pool.getId(), host.getId()) == null || pool.isLocal() != diskOffering.getUseLocalStorage()) { // Cannot find a pool for the volume. Throw an exception. throw new CloudRuntimeException("Cannot migrate volume " + volume + " to storage pool " + pool + " while migrating vm to host " + host + - ". Either the pool is not accessible from the " + "host or because of the offering with which the volume is created it cannot be placed on " + + ". Either the pool is not accessible from the host or because of the offering with which the volume is created it cannot be placed on " + "the given pool."); } else if (pool.getId() == currentPool.getId()) { - // If the pool to migrate too is the same as current pool, remove the volume from the list of - // volumes to be migrated. - volumeToPool.remove(volume); + // If the pool to migrate too is the same as current pool, the volume doesn't need to be migrated. + } else { + volumeToPoolObjectMap.put(volume, pool); } } else { // Find a suitable pool for the volume. Call the storage pool allocator to find the list of pools. @@ -1990,23 +1993,33 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac ExcludeList avoid = new ExcludeList(); boolean currentPoolAvailable = false; + List poolList = new ArrayList(); for (StoragePoolAllocator allocator : _storagePoolAllocators) { - List poolList = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL); - if (poolList != null && !poolList.isEmpty()) { - // Volume needs to be migrated. Pick the first pool from the list. Add a mapping to migrate the - // volume to a pool only if it is required; that is the current pool on which the volume resides - // is not available on the destination host. - if (poolList.contains(currentPool)) { + List poolListFromAllocator = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL); + if (poolListFromAllocator != null && !poolListFromAllocator.isEmpty()) { + poolList.addAll(poolListFromAllocator); + } + } + + if (poolList != null && !poolList.isEmpty()) { + // Volume needs to be migrated. Pick the first pool from the list. Add a mapping to migrate the + // volume to a pool only if it is required; that is the current pool on which the volume resides + // is not available on the destination host. + Iterator iter = poolList.iterator(); + while (iter.hasNext()) { + if (currentPool.getId() == iter.next().getId()) { currentPoolAvailable = true; - } else { - volumeToPool.put(volume, _storagePoolDao.findByUuid(poolList.get(0).getUuid())); + break; } + } - break; + if (!currentPoolAvailable) { + volumeToPoolObjectMap.put(volume, _storagePoolDao.findByUuid(poolList.get(0).getUuid())); } } - if (!currentPoolAvailable && !volumeToPool.containsKey(volume)) { + + if (!currentPoolAvailable && !volumeToPoolObjectMap.containsKey(volume)) { // Cannot find a pool for the volume. Throw an exception. throw new CloudRuntimeException("Cannot find a storage pool which is available for volume " + volume + " while migrating virtual machine " + profile.getVirtualMachine() + " to host " + host); @@ -2014,7 +2027,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - return volumeToPool; + return volumeToPoolObjectMap; } private void moveVmToMigratingState(T vm, Long hostId, ItWorkVO work) throws ConcurrentOperationException { @@ -2044,7 +2057,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public void migrateWithStorage(String vmUuid, long srcHostId, long destHostId, Map volumeToPool) + public void migrateWithStorage(String vmUuid, long srcHostId, long destHostId, Map volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException { AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext(); @@ -2088,7 +2101,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - private void orchestrateMigrateWithStorage(String vmUuid, long srcHostId, long destHostId, Map volumeToPool) throws ResourceUnavailableException, + private void orchestrateMigrateWithStorage(String vmUuid, long srcHostId, long destHostId, Map volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException { VMInstanceVO vm = _vmDao.findByUuid(vmUuid); @@ -2104,11 +2117,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // Create a map of which volume should go in which storage pool. VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); - volumeToPool = getPoolListForVolumesForMigration(profile, destHost, volumeToPool); + Map volumeToPoolMap = getPoolListForVolumesForMigration(profile, destHost, volumeToPool); // If none of the volumes have to be migrated, fail the call. Administrator needs to make a call for migrating // a vm and not migrating a vm with storage. - if (volumeToPool.isEmpty()) { + if (volumeToPoolMap == null || volumeToPoolMap.isEmpty()) { throw new InvalidParameterValueException("Migration of the vm " + vm + "from host " + srcHost + " to destination host " + destHost + " doesn't involve migrating the volumes."); } @@ -2138,7 +2151,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac boolean migrated = false; try { // Migrate the vm and its volume. - volumeMgr.migrateVolumes(vm, to, srcHost, destHost, volumeToPool); + volumeMgr.migrateVolumes(vm, to, srcHost, destHost, volumeToPoolMap); // Put the vm back to running state. moveVmOutofMigratingStateOnSuccess(vm, destHost.getId(), work); @@ -4768,7 +4781,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public Outcome migrateVmWithStorageThroughJobQueue( final String vmUuid, final long srcHostId, final long destHostId, - final Map volumeToPool) { + final Map volumeToPool) { final CallContext context = CallContext.current(); final User user = context.getCallingUser(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f0dcf474/engine/orchestration/src/com/cloud/vm/VmWorkMigrateWithStorage.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkMigrateWithStorage.java b/engine/orchestration/src/com/cloud/vm/VmWorkMigrateWithStorage.java index ee30c74..52fe9f2 100644 --- a/engine/orchestration/src/com/cloud/vm/VmWorkMigrateWithStorage.java +++ b/engine/orchestration/src/com/cloud/vm/VmWorkMigrateWithStorage.java @@ -18,18 +18,15 @@ package com.cloud.vm; import java.util.Map; -import com.cloud.storage.StoragePool; -import com.cloud.storage.Volume; - public class VmWorkMigrateWithStorage extends VmWork { private static final long serialVersionUID = -5626053872453569165L; long srcHostId; long destHostId; - Map volumeToPool; + Map volumeToPool; public VmWorkMigrateWithStorage(long userId, long accountId, long vmId, String handlerName, long srcHostId, - long destHostId, Map volumeToPool) { + long destHostId, Map volumeToPool) { super(userId, accountId, vmId, handlerName); @@ -46,7 +43,7 @@ public class VmWorkMigrateWithStorage extends VmWork { return destHostId; } - public Map getVolumeToPool() { + public Map getVolumeToPool() { return volumeToPool; } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f0dcf474/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java b/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java index a8cf6c0..c39c6d1 100644 --- a/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java +++ b/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java @@ -84,10 +84,8 @@ import com.cloud.hypervisor.HypervisorGuruManager; import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; -import com.cloud.storage.StoragePool; import com.cloud.storage.StoragePoolHostVO; import com.cloud.storage.VMTemplateVO; -import com.cloud.storage.Volume; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.StoragePoolHostDao; @@ -196,7 +194,7 @@ public class VirtualMachineManagerImplTest { @Mock HostVO _destHostMock; @Mock - Map _volumeToPoolMock; + Map _volumeToPoolMock; @Mock EntityManager _entityMgr; @Mock @@ -355,11 +353,13 @@ public class VirtualMachineManagerImplTest { // Mock the disk offering and pool objects for a volume. when(_volumeMock.getDiskOfferingId()).thenReturn(5L); when(_volumeMock.getPoolId()).thenReturn(200L); + when(_volumeMock.getId()).thenReturn(5L); when(_diskOfferingDao.findById(anyLong())).thenReturn(_diskOfferingMock); - when(_storagePoolDao.findById(anyLong())).thenReturn(_srcStoragePoolMock); + when(_storagePoolDao.findById(200L)).thenReturn(_srcStoragePoolMock); + when(_storagePoolDao.findById(201L)).thenReturn(_destStoragePoolMock); // Mock the volume to pool mapping. - when(_volumeToPoolMock.get(_volumeMock)).thenReturn(_destStoragePoolMock); + when(_volumeToPoolMock.get(5L)).thenReturn(201L); when(_destStoragePoolMock.getId()).thenReturn(201L); when(_srcStoragePoolMock.getId()).thenReturn(200L); when(_destStoragePoolMock.isLocal()).thenReturn(false); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f0dcf474/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index f0169eb..9fa4353 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -4085,7 +4085,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } List vmVolumes = _volsDao.findUsableVolumesForInstance(vm.getId()); - Map volToPoolObjectMap = new HashMap(); + Map volToPoolObjectMap = new HashMap(); if (!isVMUsingLocalStorage(vm) && destinationHost.getClusterId().equals(srcHost.getClusterId())) { if (volumeToPool.isEmpty()) { // If the destination host is in the same cluster and volumes do not have to be migrated across pools @@ -4109,7 +4109,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir if (!vmVolumes.contains(volume)) { throw new InvalidParameterValueException("There volume " + volume + " doesn't belong to " + "the virtual machine " + vm + " that has to be migrated"); } - volToPoolObjectMap.put(volume, pool); + volToPoolObjectMap.put(Long.valueOf(volume.getId()), Long.valueOf(pool.getId())); } } }