cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject git commit: updated refs/heads/master to 6ac361e
Date Mon, 22 Jul 2013 23:32:44 GMT
Updated Branches:
  refs/heads/master c9fdee8f2 -> 6ac361e6a


Removed VM generic from VirtualMachineGuru.  Part of the cleanup to make vmsync a simple vm
manager that doesn't understand the different types of vms


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6ac361e6
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6ac361e6
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6ac361e6

Branch: refs/heads/master
Commit: 6ac361e6a297b54e025ac1b121601e653557190f
Parents: c9fdee8
Author: Alex Huang <alex.huang@citrix.com>
Authored: Mon Jul 22 16:32:39 2013 -0700
Committer: Alex Huang <alex.huang@citrix.com>
Committed: Mon Jul 22 16:32:59 2013 -0700

----------------------------------------------------------------------
 .../lb/ElasticLoadBalancerManagerImpl.java      | 13 +--
 .../lb/InternalLoadBalancerVMManagerImpl.java   |  9 +-
 .../consoleproxy/ConsoleProxyManagerImpl.java   | 10 +--
 .../VirtualNetworkApplianceManagerImpl.java     |  9 +-
 .../secondary/SecondaryStorageManagerImpl.java  | 19 ++---
 server/src/com/cloud/vm/UserVmManager.java      |  8 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java  |  9 +-
 server/src/com/cloud/vm/VirtualMachineGuru.java |  5 +-
 .../src/com/cloud/vm/VirtualMachineManager.java |  2 +-
 .../com/cloud/vm/VirtualMachineManagerImpl.java | 90 +++++++++-----------
 .../cloud/vm/VirtualMachineManagerImplTest.java |  4 +-
 11 files changed, 69 insertions(+), 109 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
index 8d32f43..63663fe 100644
--- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
+++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
@@ -139,10 +139,8 @@ import com.cloud.vm.dao.NicDao;
 
 @Component
 @Local(value = { ElasticLoadBalancerManager.class })
-public class ElasticLoadBalancerManagerImpl extends ManagerBase implements
-ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
-    private static final Logger s_logger = Logger
-            .getLogger(ElasticLoadBalancerManagerImpl.class);
+public class ElasticLoadBalancerManagerImpl extends ManagerBase implements ElasticLoadBalancerManager,
VirtualMachineGuru {
+    private static final Logger s_logger = Logger.getLogger(ElasticLoadBalancerManagerImpl.class);
     
     @Inject
     IPAddressDao _ipAddressDao;
@@ -777,11 +775,6 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO>
{
     }
 
     @Override
-    public DomainRouterVO findById(long id) {
-        return _routerDao.findById(id);
-    }
-
-    @Override
     public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination
dest, ReservationContext context) {
         
         List<NicProfile> elbNics = profile.getNics();
@@ -960,7 +953,7 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
     }
 
     @Override
-    public void finalizeExpunge(DomainRouterVO vm) {
+    public void finalizeExpunge(VirtualMachine vm) {
         // no-op
         
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
index 481bbca..a731f56 100644
--- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
+++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
@@ -120,7 +120,7 @@ import com.cloud.vm.dao.NicDao;
 @Component
 @Local(value = { InternalLoadBalancerVMManager.class, InternalLoadBalancerVMService.class})
 public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
-    InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
+        InternalLoadBalancerVMManager, VirtualMachineGuru {
     private static final Logger s_logger = Logger
             .getLogger(InternalLoadBalancerVMManagerImpl.class);
     static final private String _internalLbVmNamePrefix = "b";
@@ -151,11 +151,6 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
     @Inject ConfigurationServer _configServer;
 
     @Override
-    public DomainRouterVO findById(long id) {
-        return _internalLbVmDao.findById(id);
-    }
-
-    @Override
     public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile,
             DeployDestination dest, ReservationContext context) {
 
@@ -339,7 +334,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
     }
 
     @Override
-    public void finalizeExpunge(DomainRouterVO vm) {
+    public void finalizeExpunge(VirtualMachine vm) {
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index 5aeb6dc..1c31177 100755
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -155,7 +155,7 @@ import com.cloud.vm.dao.VMInstanceDao;
 //
 @Local(value = { ConsoleProxyManager.class, ConsoleProxyService.class })
 public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxyManager,
-        VirtualMachineGuru<ConsoleProxyVO>, SystemVmLoadScanHandler<Long>, ResourceStateAdapter
{
+        VirtualMachineGuru, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
     private static final Logger s_logger = Logger.getLogger(ConsoleProxyManagerImpl.class);
 
     private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30 seconds
@@ -1468,7 +1468,8 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements
ConsoleProxy
     }
 
     @Override
-    public void finalizeExpunge(ConsoleProxyVO proxy) {
+    public void finalizeExpunge(VirtualMachine vm) {
+        ConsoleProxyVO proxy = _consoleProxyDao.findById(vm.getId());
         proxy.setPublicIpAddress(null);
         proxy.setPublicMacAddress(null);
         proxy.setPublicNetmask(null);
@@ -1478,11 +1479,6 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements
ConsoleProxy
     }
 
     @Override
-    public ConsoleProxyVO findById(long id) {
-        return _consoleProxyDao.findById(id);
-    }
-
-    @Override
     public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) {
         //release elastic IP here if assigned
         IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index ef7f50b..89db3c2 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -261,7 +261,7 @@ import com.cloud.vm.dao.VMInstanceDao;
 @Component
 @Local(value = { VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class
})
 public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager,
VirtualNetworkApplianceService,
-                            VirtualMachineGuru<DomainRouterVO>, Listener {
+        VirtualMachineGuru, Listener {
     private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class);
 
     @Inject
@@ -2639,7 +2639,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
     }
 
     @Override
-    public void finalizeExpunge(DomainRouterVO vm) {
+    public void finalizeExpunge(VirtualMachine vm) {
     }
 
 
@@ -3065,11 +3065,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
         return result;
     }
 
-    @Override
-    public DomainRouterVO findById(long id) {
-        return _routerDao.findById(id);
-    }
-
     @Override @ActionEvent(eventType = EventTypes.EVENT_ROUTER_START, eventDescription =
"starting router Vm", async = true)
     public VirtualRouter startRouter(long id) throws ResourceUnavailableException, InsufficientCapacityException,
ConcurrentOperationException{
         return startRouter(id, true);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
index 037eb25..127a824 100755
--- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
+++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
@@ -155,7 +155,7 @@ import com.cloud.vm.dao.VMInstanceDao;
 // because sooner or later, it will be driven into Running state
 //
 @Local(value = { SecondaryStorageVmManager.class })
-public class SecondaryStorageManagerImpl extends ManagerBase implements SecondaryStorageVmManager,
VirtualMachineGuru<SecondaryStorageVmVO>, SystemVmLoadScanHandler<Long>, ResourceStateAdapter
{
+public class SecondaryStorageManagerImpl extends ManagerBase implements SecondaryStorageVmManager,
VirtualMachineGuru, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
     private static final Logger s_logger = Logger.getLogger(SecondaryStorageManagerImpl.class);
 
     private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30
@@ -1003,11 +1003,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements
Secondar
     }
 
     @Override
-    public SecondaryStorageVmVO findById(long id) {
-        return _secStorageVmDao.findById(id);
-    }
-
-    @Override
     public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination
dest, ReservationContext context) {
 
         SecondaryStorageVmVO vm = _secStorageVmDao.findById(profile.getId());
@@ -1197,11 +1192,13 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements
Secondar
     }
 
     @Override
-    public void finalizeExpunge(SecondaryStorageVmVO vm) {
-        vm.setPublicIpAddress(null);
-        vm.setPublicMacAddress(null);
-        vm.setPublicNetmask(null);
-        _secStorageVmDao.update(vm.getId(), vm);
+    public void finalizeExpunge(VirtualMachine vm) {
+        SecondaryStorageVmVO ssvm = _secStorageVmDao.findByUuid(vm.getUuid());
+
+        ssvm.setPublicIpAddress(null);
+        ssvm.setPublicMacAddress(null);
+        ssvm.setPublicNetmask(null);
+        _secStorageVmDao.update(ssvm.getId(), ssvm);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/server/src/com/cloud/vm/UserVmManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManager.java b/server/src/com/cloud/vm/UserVmManager.java
index 348017a..635d15e 100755
--- a/server/src/com/cloud/vm/UserVmManager.java
+++ b/server/src/com/cloud/vm/UserVmManager.java
@@ -23,7 +23,11 @@ import java.util.Map;
 import com.cloud.agent.api.VmDiskStatsEntry;
 import com.cloud.agent.api.VmStatsEntry;
 import com.cloud.api.query.vo.UserVmJoinVO;
-import com.cloud.exception.*;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ManagementServerException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.exception.VirtualMachineMigrationException;
 import com.cloud.projects.Project.ListProjectResourcesCriteria;
 import com.cloud.server.Criteria;
 import com.cloud.user.Account;
@@ -34,7 +38,7 @@ import com.cloud.utils.Pair;
  *
  * 
  */
-public interface UserVmManager extends VirtualMachineGuru<UserVmVO>, UserVmService{
+public interface UserVmManager extends UserVmService {
 
 	static final int MAX_USER_DATA_LENGTH_BYTES = 2048;
     /**

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/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 1493871..a4508ee 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -254,7 +254,7 @@ import com.cloud.vm.snapshot.VMSnapshotVO;
 import com.cloud.vm.snapshot.dao.VMSnapshotDao;
 
 @Local(value = { UserVmManager.class, UserVmService.class })
-public class UserVmManagerImpl extends ManagerBase implements UserVmManager, UserVmService
{
+public class UserVmManagerImpl extends ManagerBase implements UserVmManager, VirtualMachineGuru,
UserVmService {
     private static final Logger s_logger = Logger
             .getLogger(UserVmManagerImpl.class);
 
@@ -3083,12 +3083,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Use
     }
 
     @Override
-    public void finalizeExpunge(UserVmVO vm) {
-    }
-
-    @Override
-    public UserVmVO findById(long id) {
-        return _vmDao.findById(id);
+    public void finalizeExpunge(VirtualMachine vm) {
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/server/src/com/cloud/vm/VirtualMachineGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java
index 3318b46..3fb065b 100644
--- a/server/src/com/cloud/vm/VirtualMachineGuru.java
+++ b/server/src/com/cloud/vm/VirtualMachineGuru.java
@@ -25,8 +25,7 @@ import com.cloud.exception.ResourceUnavailableException;
  * A VirtualMachineGuru knows how to process a certain type of virtual machine.
  *
  */
-public interface VirtualMachineGuru<T extends VirtualMachine> {
-    T findById(long id);
+public interface VirtualMachineGuru {
     
     boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination
dest, ReservationContext context);
     
@@ -52,7 +51,7 @@ public interface VirtualMachineGuru<T extends VirtualMachine> {
     
     void finalizeStop(VirtualMachineProfile profile, StopAnswer answer);
     
-    void finalizeExpunge(T vm);
+    void finalizeExpunge(VirtualMachine vm);
     
     /**
      * Prepare Vm for Stop

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/server/src/com/cloud/vm/VirtualMachineManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java
index 0086bdb..4982bcb 100644
--- a/server/src/com/cloud/vm/VirtualMachineManager.java
+++ b/server/src/com/cloud/vm/VirtualMachineManager.java
@@ -80,7 +80,7 @@ public interface VirtualMachineManager extends Manager {
 
     <T extends VMInstanceVO> boolean expunge(T vm, User caller, Account account) throws
ResourceUnavailableException;
 
-    <T extends VMInstanceVO> void registerGuru(VirtualMachine.Type type, VirtualMachineGuru<T>
guru);
+    void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru);
 
     boolean stateTransitTo(VMInstanceVO vm, VirtualMachine.Event e, Long hostId) throws NoTransitionException;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 7edd7d2..fc55ee5 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -19,7 +19,6 @@ package com.cloud.vm;
 
 import java.net.URI;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -325,7 +324,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     @Inject
     DeploymentPlanningManager _dpMgr;
 
-    Map<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>> _vmGurus
= new HashMap<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>>();
+    Map<VirtualMachine.Type, VirtualMachineGuru> _vmGurus = new HashMap<VirtualMachine.Type,
VirtualMachineGuru>();
     protected StateMachine2<State, VirtualMachine.Event, VirtualMachine> _stateMachine;
 
     ScheduledExecutorService _executor = null;
@@ -341,7 +340,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     protected boolean _forceStop;
 
     @Override
-    public <T extends VMInstanceVO> void registerGuru(VirtualMachine.Type type, VirtualMachineGuru<T>
guru) {
+    public void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru) {
         synchronized (_vmGurus) {
             _vmGurus.put(type, guru);
         }
@@ -414,9 +413,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         allocate(vmInstanceName, template, serviceOffering, new Pair<DiskOfferingVO, Long>(serviceOffering,
null), null, networks, null, plan, hyperType);
     }
 
-    @SuppressWarnings("unchecked")
-    private <T extends VMInstanceVO> VirtualMachineGuru<T> getVmGuru(T vm) {
-        return (VirtualMachineGuru<T>) _vmGurus.get(vm.getType());
+    private VirtualMachineGuru getVmGuru(VirtualMachine vm) {
+        return _vmGurus.get(vm.getType());
     }
 
     @Override
@@ -482,7 +480,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         List<VolumeVO> rootVol = _volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT);
         volumeMgr.cleanupVolumes(vm.getId());
 
-        VirtualMachineGuru<T> guru = getVmGuru(vm);
+        VirtualMachineGuru guru = getVmGuru(vm);
         guru.finalizeExpunge(vm);
         //remove the overcommit detials from the uservm details
         _uservmDetailsDao.deleteDetails(vm.getId());
@@ -762,8 +760,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
-        long vmId = vm.getId();
-        VirtualMachineGuru<?> vmGuru = getVmGuru(vm);
+        VirtualMachineGuru vmGuru = getVmGuru(vm);
 
         Ternary<VMInstanceVO, ReservationContext, ItWorkVO> start = changeToStartState(vmGuru,
vm, caller, account);
         if (start == null) {
@@ -1045,8 +1042,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             throw new CloudRuntimeException("Unable to start instance '" + vm.getHostName()
                     + "' (" + vm.getUuid() + "), see management server log for details");
         }
-
-        return;
     }
 
     @Override
@@ -1194,7 +1189,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             return true;
         }
 
-        VirtualMachineGuru<T> vmGuru = getVmGuru(vm);
+        VirtualMachineGuru vmGuru = getVmGuru(vm);
         VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
 
         try {
@@ -1429,11 +1424,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
 
     @Override
-    public <T extends VMInstanceVO> T storageMigration(T vm, StoragePool destPool)
{
-        VirtualMachineGuru<T> vmGuru = getVmGuru(vm);
-
-        long vmId = vm.getId();
-        vm = vmGuru.findById(vmId);
+    public <T extends VMInstanceVO> T storageMigration(T vmm, StoragePool destPool)
{
+        VMInstanceVO vm = _vmDao.findByUuid(vmm.getUuid());
 
         try {
             stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null);
@@ -1483,12 +1475,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             }
         }
 
-        return vm;
+        return vmm;
     }
 
     @Override
-    public <T extends VMInstanceVO> T migrate(T vm, long srcHostId, DeployDestination
dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException,
+    public <T extends VMInstanceVO> T migrate(T vmm, long srcHostId, DeployDestination
dest) throws ResourceUnavailableException, ConcurrentOperationException,
+            ManagementServerException,
     VirtualMachineMigrationException {
+        VMInstanceVO vm = _vmDao.findByUuid(vmm.getUuid());
+        if (vm == null) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Unable to find the vm " + vm);
+            }
+            throw new CloudRuntimeException("Unable to find a virtual machine with id " +
vmm.getUuid());
+        }
+
         s_logger.info("Migrating " + vm + " to " + dest);
 
         long dstHostId = dest.getHost().getId();
@@ -1503,16 +1504,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             throw new CloudRuntimeException("Source and destination host are not in same
cluster, unable to migrate to host: " + dest.getHost().getId());
         }
 
-        VirtualMachineGuru<T> vmGuru = getVmGuru(vm);
-
-        long vmId = vm.getId();
-        vm = vmGuru.findById(vmId);
-        if (vm == null) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Unable to find the vm " + vm);
-            }
-            throw new ManagementServerException("Unable to find a virtual machine with id
" + vmId);
-        }
+        VirtualMachineGuru vmGuru = getVmGuru(vm);
 
         if (vm.getState() != State.Running) {
             if (s_logger.isDebugEnabled()) {
@@ -1620,7 +1612,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             }
 
             migrated = true;
-            return vm;
+            return vmm;
         } finally {
             if (!migrated) {
                 s_logger.info("Migration was unsuccessful.  Cleaning up: " + vm);
@@ -1736,13 +1728,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
 
     @Override
-    public <T extends VMInstanceVO> T migrateWithStorage(T vm, long srcHostId, long
destHostId,
+    public <T extends VMInstanceVO> T migrateWithStorage(T vmm, long srcHostId, long
destHostId,
             Map<VolumeVO, StoragePoolVO> volumeToPool) throws ResourceUnavailableException,
ConcurrentOperationException,
             ManagementServerException, VirtualMachineMigrationException {
+        VMInstanceVO vm = _vmDao.findByUuid(vmm.getUuid());
 
         HostVO srcHost = _hostDao.findById(srcHostId);
         HostVO destHost = _hostDao.findById(destHostId);
-        VirtualMachineGuru<T> vmGuru = getVmGuru(vm);
+        VirtualMachineGuru vmGuru = getVmGuru(vm);
 
         DataCenterVO dc = _dcDao.findById(destHost.getDataCenterId());
         HostPodVO pod = _podDao.findById(destHost.getPodId());
@@ -1750,8 +1743,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         DeployDestination destination = new DeployDestination(dc, pod, cluster, destHost);
 
         // Create a map of which volume should go in which storage pool.
-        long vmId = vm.getId();
-        vm = vmGuru.findById(vmId);
         VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
         volumeToPool = getPoolListForVolumesForMigration(profile, destHost, volumeToPool);
 
@@ -1809,7 +1800,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             }
 
             migrated = true;
-            return vm;
+            return vmm;
         } finally {
             if (!migrated) {
                 s_logger.info("Migration was unsuccessful.  Cleaning up: " + vm);
@@ -1831,6 +1822,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         }
     }
 
+    @Override
     public VirtualMachineTO toVmTO(VirtualMachineProfile profile) {
         HypervisorGuru hvGuru = _hvGuruMgr.getGuru(profile.getVirtualMachine().getHypervisorType());
         VirtualMachineTO to = hvGuru.implement(profile);
@@ -1878,8 +1870,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
 
     @Override
     public boolean migrateAway(VirtualMachine.Type vmType, long vmId, long srcHostId) throws
InsufficientServerCapacityException, VirtualMachineMigrationException {
-        VirtualMachineGuru<? extends VMInstanceVO> vmGuru = _vmGurus.get(vmType);
-        VMInstanceVO vm = vmGuru.findById(vmId);
+        VMInstanceVO vm = _vmDao.findById(vmId);
         if (vm == null) {
             s_logger.debug("Unable to find a VM for " + vmId);
             return true;
@@ -2028,8 +2019,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
 
     @Override
     public VMInstanceVO findByIdAndType(VirtualMachine.Type type, long vmId) {
-        VirtualMachineGuru<? extends VMInstanceVO> guru = _vmGurus.get(type);
-        return guru.findById(vmId);
+        return _vmDao.findById(vmId);
     }
 
     public Command cleanup(VirtualMachine vm) {
@@ -2302,7 +2292,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         if (newStates == null) {
             return map;
         }
-        Collection<VirtualMachineGuru<? extends VMInstanceVO>> vmGurus = _vmGurus.values();
         boolean is_alien_vm = true;
         long alien_vm_count = -1;
         for (Map.Entry<String, Pair<String, State>> entry : newStates.entrySet())
{
@@ -2541,10 +2530,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
 
     private void ensureVmRunningContext(long hostId, VMInstanceVO vm, Event cause) throws
OperationTimedoutException, ResourceUnavailableException, NoTransitionException, InsufficientAddressCapacityException
{
-        VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vm);
+        VirtualMachineGuru vmGuru = getVmGuru(vm);
 
         s_logger.debug("VM state is starting on full sync so updating it to running");
-        vm = findByIdAndType(vm.getType(), vm.getId());
+        vm = _vmDao.findById(vm.getId());
 
         // grab outstanding work item if any
         ItWorkVO work = _workDao.findByOutstandingWork(vm.getId(), vm.getState());
@@ -2561,7 +2550,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         }
 
         s_logger.debug("VM's " + vm + " state is starting on full sync so updating it to
Running");
-        vm = vmGuru.findById(vm.getId()); // this should ensure vm has the most
+        vm = _vmDao.findById(vm.getId()); // this should ensure vm has the most
         // up to date info
 
         VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
@@ -2764,7 +2753,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         public String hostUuid;
         public VMInstanceVO vm;
 
-        @SuppressWarnings("unchecked")
         public AgentVmInfo(String name, VMInstanceVO vm, State state, String host) {
             this.name = name;
             this.state = state;
@@ -2899,8 +2887,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
 
             //4) plug the nic to the vm
-            VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
-
             s_logger.debug("Plugging nic for vm " + vm + " in network " + network);
 
             boolean result = false;
@@ -2954,7 +2940,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         DataCenter dc = _configMgr.getZone(network.getDataCenterId());
         Host host = _hostDao.findById(vm.getHostId());
         DeployDestination dest = new DeployDestination(dc, null, null, host);
-        VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
         HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
         VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
 
@@ -3018,7 +3003,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         DataCenter dc = _configMgr.getZone(network.getDataCenterId());
         Host host = _hostDao.findById(vm.getHostId());
         DeployDestination dest = new DeployDestination(dc, null, null, host);
-        VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
         HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
         VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
 
@@ -3138,8 +3122,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
 
     @Override
-    public <T extends VMInstanceVO> T migrateForScale(T vm, long srcHostId, DeployDestination
dest, Long oldSvcOfferingId) throws ResourceUnavailableException, ConcurrentOperationException,
ManagementServerException,
+    public <T extends VMInstanceVO> T migrateForScale(T vmm, long srcHostId, DeployDestination
dest, Long oldSvcOfferingId) throws ResourceUnavailableException,
+            ConcurrentOperationException, ManagementServerException,
     VirtualMachineMigrationException {
+        VMInstanceVO vm = _vmDao.findByUuid(vmm.getUuid());
         s_logger.info("Migrating " + vm + " to " + dest);
 
         vm.getServiceOfferingId();
@@ -3155,10 +3141,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             throw new CloudRuntimeException("Source and destination host are not in same
cluster, unable to migrate to host: " + dest.getHost().getId());
         }
 
-        VirtualMachineGuru<T> vmGuru = getVmGuru(vm);
+        VirtualMachineGuru vmGuru = getVmGuru(vm);
 
         long vmId = vm.getId();
-        vm = vmGuru.findById(vmId);
+        vm = _vmDao.findByUuid(vmm.getUuid());
         if (vm == null) {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Unable to find the vm " + vm);
@@ -3267,7 +3253,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             }
 
             migrated = true;
-            return vm;
+            return vmm;
         } finally {
             if (!migrated) {
                 s_logger.info("Migration was unsuccessful.  Cleaning up: " + vm);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ac361e6/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java b/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java
index a49b0e0..fba95b3 100644
--- a/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java
+++ b/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java
@@ -223,6 +223,7 @@ public class VirtualMachineManagerImplTest {
             when(_workDao.update("1", _work)).thenReturn(true);
             when(_work.getId()).thenReturn("1");
             doNothing().when(_work).setStep(ItWorkVO.Step.Done);
+        when(_vmInstanceDao.findByUuid(any(String.class))).thenReturn(_vmMock);
             //doNothing().when(_volsDao).detachVolume(anyLong());
             //when(_work.setStep(ItWorkVO.Step.Done)).thenReturn("1");
 
@@ -332,10 +333,9 @@ public class VirtualMachineManagerImplTest {
         doNothing().when(_work).setStep(ItWorkVO.Step.Done);
 
         // Mock the vm guru and the user vm object that gets returned.
-        _vmMgr._vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru<? extends
VMInstanceVO>>();
+        _vmMgr._vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru>();
         UserVmManagerImpl userVmManager = mock(UserVmManagerImpl.class);
         _vmMgr.registerGuru(VirtualMachine.Type.User, userVmManager);
-        when(userVmManager.findById(anyLong())).thenReturn(_vmMock);
 
         // Mock the iteration over all the volumes of an instance.
         Iterator<VolumeVO> volumeIterator = mock(Iterator.class);


Mime
View raw message