cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [3/3] git commit: updated refs/heads/vmsync to 3716f1f
Date Thu, 23 May 2013 21:19:00 GMT
VirtualMachineManager no longer takes generic types


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

Branch: refs/heads/vmsync
Commit: 3716f1f320301934407602470818150712609583
Parents: 05cb734
Author: Alex Huang <alex.huang@gmail.com>
Authored: Thu May 23 14:21:00 2013 -0700
Committer: Alex Huang <alex.huang@gmail.com>
Committed: Thu May 23 14:21:00 2013 -0700

----------------------------------------------------------------------
 agent/src/com/cloud/agent/mockvm/MockVmMgr.java    |    3 +-
 api/src/com/cloud/vm/VirtualMachine.java           |    6 +-
 .../src/com/cloud/vm/VirtualMachineGuru.java       |    4 +-
 .../src/com/cloud/vm/VirtualMachineManager.java    |   87 +++----
 .../cloudstack/engine/vm/VMEntityManagerImpl.java  |   10 +-
 .../network/lb/ElasticLoadBalancerManagerImpl.java |   35 ++-
 .../lb/InternalLoadBalancerVMManagerImpl.java      |  103 ++++----
 .../internallbvmmgr/InternalLBVMManagerTest.java   |   12 +-
 .../internallbvmmgr/InternalLBVMServiceTest.java   |   14 +-
 .../cloud/network/ovs/OvsTunnelManagerImpl.java    |   58 ++--
 .../consoleproxy/ConsoleProxyManagerImpl.java      |  118 ++++-----
 .../com/cloud/ha/HighAvailabilityManagerImpl.java  |   34 ++--
 .../network/lb/LoadBalancingRulesManagerImpl.java  |   13 +-
 .../router/VirtualNetworkApplianceManagerImpl.java |  109 ++++----
 .../com/cloud/resource/ResourceManagerImpl.java    |    4 +-
 .../src/com/cloud/server/ManagementServerImpl.java |    4 +-
 .../src/com/cloud/servlet/ConsoleProxyServlet.java |   23 +-
 .../cloud/storage/StoragePoolAutomationImpl.java   |   38 ++--
 .../secondary/SecondaryStorageManagerImpl.java     |  156 +++++------
 server/src/com/cloud/user/AccountManagerImpl.java  |   15 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java     |   66 +++---
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |  208 +++++++--------
 .../cloud/vm/snapshot/VMSnapshotManagerImpl.java   |   35 ++--
 server/test/com/cloud/vm/UserVmManagerTest.java    |   41 ++--
 .../cloud/vm/VirtualMachineManagerImplTest.java    |   12 +-
 .../vm/VmWorkMockVirtualMachineManagerImpl.java    |   96 ++-----
 26 files changed, 610 insertions(+), 694 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/agent/src/com/cloud/agent/mockvm/MockVmMgr.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/mockvm/MockVmMgr.java b/agent/src/com/cloud/agent/mockvm/MockVmMgr.java
index c89a135..7fc7ef1 100644
--- a/agent/src/com/cloud/agent/mockvm/MockVmMgr.java
+++ b/agent/src/com/cloud/agent/mockvm/MockVmMgr.java
@@ -140,6 +140,7 @@ public class MockVmMgr implements VmMgr {
         return false;
     }
 
+    @Override
     public MockVm getVm(String vmName) {
         synchronized (this) {
             MockVm vm = vms.get(vmName);
@@ -155,7 +156,7 @@ public class MockVmMgr implements VmMgr {
             if (vm != null)
                 return vm.getState();
         }
-        return State.Unknown;
+        return null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/api/src/com/cloud/vm/VirtualMachine.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/VirtualMachine.java b/api/src/com/cloud/vm/VirtualMachine.java
index 2204ca5..04d7ad6 100755
--- a/api/src/com/cloud/vm/VirtualMachine.java
+++ b/api/src/com/cloud/vm/VirtualMachine.java
@@ -39,11 +39,9 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I
         Stopping(true, "VM is being stopped.  host id has the host that it is being stopped on."),
         Stopped(false, "VM is stopped.  host id should be null."),
         Destroyed(false, "VM is marked for destroy."),
-        Expunging(true, "VM is being   expunged."),
+        Expunging(true, "VM is being expunged."),
         Migrating(true, "VM is being migrated.  host id holds to from host"),
-        Error(false, "VM is in error"),
-        Unknown(false, "VM state is unknown."),
-        Shutdowned(false, "VM is shutdowned from inside");
+        Error(false, "VM is in error");
 
         private final boolean _transitional;
         String _description;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/engine/components-api/src/com/cloud/vm/VirtualMachineGuru.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/vm/VirtualMachineGuru.java b/engine/components-api/src/com/cloud/vm/VirtualMachineGuru.java
index ec122f2..c65a692 100644
--- a/engine/components-api/src/com/cloud/vm/VirtualMachineGuru.java
+++ b/engine/components-api/src/com/cloud/vm/VirtualMachineGuru.java
@@ -62,6 +62,6 @@ public interface VirtualMachineGuru {
      * VM work handlers
      * @param work
      */
-    void vmWorkStart(VmWork work);
-    void vmWorkStop(VmWork work);
+//    void vmWorkStart(VmWork work);
+//    void vmWorkStop(VmWork work);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/engine/components-api/src/com/cloud/vm/VirtualMachineManager.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/vm/VirtualMachineManager.java b/engine/components-api/src/com/cloud/vm/VirtualMachineManager.java
index 06ae204..b7ea215 100644
--- a/engine/components-api/src/com/cloud/vm/VirtualMachineManager.java
+++ b/engine/components-api/src/com/cloud/vm/VirtualMachineManager.java
@@ -55,7 +55,7 @@ import com.cloud.utils.fsm.NoTransitionException;
  */
 public interface VirtualMachineManager extends Manager {
 
-    <T extends VMInstanceVO> T allocate(T vm,
+    VirtualMachine allocate(String vmInstanceName,
             VMTemplateVO template,
             ServiceOfferingVO serviceOffering,
             Pair<? extends DiskOfferingVO, Long> rootDiskOffering,
@@ -64,33 +64,25 @@ public interface VirtualMachineManager extends Manager {
             Map<VirtualMachineProfile.Param, Object> params,
             DeploymentPlan plan,
             HypervisorType hyperType,
-            Account owner) throws InsufficientCapacityException;
+            Account owner);
 
-    <T extends VMInstanceVO> T allocate(T vm,
-            VMTemplateVO template,
-            ServiceOfferingVO serviceOffering,
-            Long rootSize,
-            Pair<DiskOfferingVO, Long> dataDiskOffering,
-            List<Pair<NetworkVO, NicProfile>> networks,
-            DeploymentPlan plan,
-            HypervisorType hyperType,
-            Account owner) throws InsufficientCapacityException;
-
-    <T extends VMInstanceVO> T allocate(T vm,
+    VirtualMachine allocate(String vmInstanceName,
             VMTemplateVO template,
             ServiceOfferingVO serviceOffering,
             List<Pair<NetworkVO, NicProfile>> networkProfiles,
             DeploymentPlan plan,
             HypervisorType hyperType,
-            Account owner) throws InsufficientCapacityException;
+            Account owner);
 
-    <T extends VMInstanceVO> T start(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException;
+    VirtualMachine start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account) throws InsufficientCapacityException,
+            ResourceUnavailableException;
 
-    <T extends VMInstanceVO> T start(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException, ResourceUnavailableException;
+    VirtualMachine start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account, DeploymentPlan planToDeploy)
+            throws InsufficientCapacityException, ResourceUnavailableException;
 
-    <T extends VMInstanceVO> boolean stop(T vm, User caller, Account account) throws ResourceUnavailableException;
+    boolean stop(String vmUuid, User caller, Account account);
 
-    <T extends VMInstanceVO> boolean expunge(T vm, User caller, Account account) throws ResourceUnavailableException;
+    boolean expunge(String vmUuid, User caller, Account account) throws ResourceUnavailableException;
 
     void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru);
     
@@ -102,42 +94,32 @@ public interface VirtualMachineManager extends Manager {
     
     boolean stateTransitTo(VMInstanceVO vm, VirtualMachine.Event e, Long hostId) throws NoTransitionException;
 
-    <T extends VMInstanceVO> T advanceStart(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException;
+    VirtualMachine advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account) throws InsufficientCapacityException,
+            ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException;
 
-    <T extends VMInstanceVO> T advanceStart(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException;
+    VirtualMachine advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account, DeploymentPlan planToDeploy)
+            throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException;
 
-    <T extends VMInstanceVO> boolean advanceStop(T vm, boolean forced, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
+    boolean advanceStop(String vmUuid, boolean forced, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
 
-    <T extends VMInstanceVO> boolean advanceExpunge(T vm, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
+    boolean advanceExpunge(String vmUuid, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
 
-    <T extends VMInstanceVO> boolean remove(T vm, User caller, Account account);
-
-    <T extends VMInstanceVO> boolean destroy(T vm, User caller, Account account) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException;
+    boolean destroy(String vmUuid, User caller, Account account) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException;
 
     boolean migrateAway(VirtualMachine.Type type, long vmid, long hostId) throws InsufficientServerCapacityException, VirtualMachineMigrationException;
 
-    <T extends VMInstanceVO> T migrate(T vm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
+    VirtualMachine migrate(String vmUuid, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException,
+            VirtualMachineMigrationException;
 
-    <T extends VMInstanceVO> T migrateWithStorage(T vm, long srcId, long destId, Map<VolumeVO, StoragePoolVO> volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
+    VirtualMachine migrateWithStorage(String vmUuid, long srcId, long destId, Map<VolumeVO, StoragePoolVO> volumeToPool) throws ResourceUnavailableException,
+            ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
 
-    <T extends VMInstanceVO> T reboot(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException;
+    boolean reboot(String vmUuid, User caller, Account account);
 
-    <T extends VMInstanceVO> T advanceReboot(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException;
+    boolean advanceReboot(String vmUuid, User caller, Account account) throws InsufficientCapacityException,
+            ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException;
 
-    VMInstanceVO findByIdAndType(VirtualMachine.Type type, long vmId);
-
-    /**
-     * Check to see if a virtual machine can be upgraded to the given service offering
-     * 
-     * @param vm
-     * @param offering
-     * @return true if the host can handle the upgrade, false otherwise
-     */
-    boolean isVirtualMachineUpgradable(final VirtualMachine vm, final ServiceOffering offering);
-    
-    VMInstanceVO findById(long vmId);
-
-	<T extends VMInstanceVO> T storageMigration(T vm, StoragePool storagePoolId);
+    VirtualMachine storageMigration(String vmUuid, StoragePool storagePoolId);
 
     /**
      * @param vmInstance
@@ -184,13 +166,6 @@ public interface VirtualMachineManager extends Manager {
     boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException;
 
     /**
-     * @param nic
-     * @param hypervisorType
-     * @return
-     */
-    NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType);
-
-    /**
      * @param profile
      * @param hvGuru
      * @return
@@ -198,23 +173,25 @@ public interface VirtualMachineManager extends Manager {
     VirtualMachineTO toVmTO(VirtualMachineProfile profile);
 
 
-    VMInstanceVO reConfigureVm(VMInstanceVO vm, ServiceOffering newServiceOffering, boolean sameHost)
+    VirtualMachine reConfigureVm(VirtualMachine vm, ServiceOffering newServiceOffering, boolean sameHost)
             throws ResourceUnavailableException, ConcurrentOperationException;
 
-    VMInstanceVO findHostAndMigrate(VirtualMachine.Type vmType, VMInstanceVO vm, Long newSvcOfferingId) throws InsufficientCapacityException,
+    VirtualMachine findHostAndMigrate(String vmUuid, Long newSvcOfferingId) throws InsufficientCapacityException,
             ConcurrentOperationException, ResourceUnavailableException,
             VirtualMachineMigrationException, ManagementServerException;
 
-    <T extends VMInstanceVO> T migrateForScale(T vm, long srcHostId, DeployDestination dest, Long newSvcOfferingId)
+    VirtualMachine migrateForScale(String vmUuid, long srcHostId, DeployDestination dest, Long newSvcOfferingId)
             throws ResourceUnavailableException, ConcurrentOperationException,
             ManagementServerException, VirtualMachineMigrationException;
 
     //
     // VM work handlers
     //
-    <T extends VMInstanceVO> T processVmStartWork(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account, DeploymentPlan planToDeploy)
+    VirtualMachine processVmStartWork(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account, DeploymentPlan planToDeploy)
            throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
 
-    <T extends VMInstanceVO> boolean processVmStopWork(T vm, boolean forced, User user, Account account)
+    boolean processVmStopWork(String vmUuid, boolean forced, User user, Account account)
     	throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException;
+
+    NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
index fe3a821..f29f5c4 100755
--- a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
@@ -239,16 +239,16 @@ public class VMEntityManagerImpl implements VMEntityManager {
             DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(),
                     vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null);
             try {
-                VMInstanceVO vmDeployed = _itMgr.start(vm, params, _userDao.findById(new Long(caller)),
+                VirtualMachine vmDeployed = _itMgr.start(vm.getUuid(), params, _userDao.findById(new Long(caller)),
                         _accountDao.findById(vm.getAccountId()), reservedPlan);
             } catch (Exception ex) {
                 // Retry the deployment without using the reservation plan
-                _itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()),
+                _itMgr.start(vm.getUuid(), params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()),
                         null);
             }
         } else {
             // no reservation found. Let VirtualMachineManager retry
-            _itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), null);
+            _itMgr.start(vm.getUuid(), params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), null);
         }
 
     }
@@ -257,7 +257,7 @@ public class VMEntityManagerImpl implements VMEntityManager {
     public boolean stop(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException {
 
         VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
-        return _itMgr.stop(vm, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()));
+        return _itMgr.stop(vm.getUuid(), _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()));
 
     }
 
@@ -265,7 +265,7 @@ public class VMEntityManagerImpl implements VMEntityManager {
     public boolean destroy(VMEntityVO vmEntityVO, String caller) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException{
 
          VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
-         return _itMgr.destroy(vm, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()));
+        return _itMgr.destroy(vm.getUuid(), _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()));
 
 
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/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 23eaac5..6005e56 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
@@ -134,7 +134,6 @@ import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.VirtualMachineName;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.VirtualMachineProfile.Param;
-import com.cloud.vm.VmWork;
 import com.cloud.vm.dao.DomainRouterDao;
 import com.cloud.vm.dao.NicDao;
 
@@ -458,6 +457,9 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements
             throw new ConcurrentOperationException("Unable to acquire network lock: " + guestNetworkId);
         }
 
+        DomainRouterVO elbVm = null;
+        boolean error = false;
+
         try {
 
             if (_networkModel.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) {
@@ -472,7 +474,6 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements
                     || guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork;
 
             DataCenterDeployment plan = null;
-            DomainRouterVO elbVm = null;
             
             plan = new DataCenterDeployment(dcId, dest.getPod().getId(), null, null, null, null);
 
@@ -510,7 +511,12 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements
                         template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN,
                         _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null);
                 elbVm.setRole(Role.LB);
-                elbVm = _itMgr.allocate(elbVm, template, _elasticLbVmOffering, networks, plan, null, owner);
+                elbVm = _routerDao.persist(elbVm);
+                if (_itMgr.allocate(elbVm.getInstanceName(), template, _elasticLbVmOffering, networks, plan, null, owner) != null) {
+                    elbVm = _routerDao.findById(elbVm.getId());
+                } else {
+                    error = true;
+                }
                 //TODO: create usage stats
             }
 
@@ -521,6 +527,9 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements
 
             return elbVm;
         } finally {
+            if (error && elbVm != null) {
+                _routerDao.remove(elbVm.getId());
+            }
             _networkDao.releaseFromLockTable(guestNetworkId);
         }
     }
@@ -528,7 +537,7 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements
     private DomainRouterVO start(DomainRouterVO elbVm, User user, Account caller, Map<Param, Object> params) throws StorageUnavailableException, InsufficientCapacityException,
     ConcurrentOperationException, ResourceUnavailableException {
         s_logger.debug("Starting ELB VM " + elbVm);
-        if (_itMgr.start(elbVm, params, user, caller) != null) {
+        if (_itMgr.start(elbVm.getUuid(), params, user, caller) != null) {
             return _routerDao.findById(elbVm.getId());
         } else {
             return null;
@@ -538,7 +547,7 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements
     private DomainRouterVO stop(DomainRouterVO elbVm, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException {
         s_logger.debug("Stopping ELB vm " + elbVm);
         try {
-            if (_itMgr.advanceStop( elbVm, forced, user, caller)) {
+            if (_itMgr.advanceStop(elbVm.getUuid(), forced, user, caller)) {
                 return _routerDao.findById(elbVm.getId());
             } else {
                 return null;
@@ -732,7 +741,7 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements
             if (gceed) {
                 try {
                     s_logger.info("Attempting to destroy ELB VM: " + elbVm);
-                    _itMgr.expunge(elbVm, user, _systemAcct);
+                    _itMgr.expunge(elbVm.getUuid(), user, _systemAcct);
                 } catch (ResourceUnavailableException e) {
                     s_logger.warn("Unable to destroy unused ELB vm " + elbVm + " due to ", e);
                     gceed = false;
@@ -985,12 +994,12 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements
     public void prepareStop(VirtualMachineProfile profile) {
     }
     
-    @Override
-    public void vmWorkStart(VmWork work) {
-    }
-    
-    @Override
-    public void vmWorkStop(VmWork work) {
-    }
+//    @Override
+//    public void vmWorkStart(VmWork work) {
+//    }
+//
+//    @Override
+//    public void vmWorkStop(VmWork work) {
+//    }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/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 78a5dd5..fc28c81 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
@@ -113,7 +113,6 @@ import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.VirtualMachineName;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.VirtualMachineProfile.Param;
-import com.cloud.vm.VmWork;
 import com.cloud.vm.dao.DomainRouterDao;
 import com.cloud.vm.dao.NicDao;
 
@@ -526,7 +525,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
 
         _accountMgr.checkAccess(caller, null, true, internalLbVm);
 
-        return _itMgr.expunge(internalLbVm, _accountMgr.getActiveUser(callerUserId), caller);
+        return _itMgr.expunge(internalLbVm.getUuid(), _accountMgr.getActiveUser(callerUserId), caller);
     }
 
     
@@ -547,7 +546,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
     protected VirtualRouter stopInternalLbVm(DomainRouterVO internalLbVm, boolean forced, Account caller, long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException {
         s_logger.debug("Stopping internal lb vm " + internalLbVm);
         try {
-            if (_itMgr.advanceStop(internalLbVm, forced, _accountMgr.getActiveUser(callerUserId), caller)) {
+            if (_itMgr.advanceStop(internalLbVm.getUuid(), forced, _accountMgr.getActiveUser(callerUserId), caller)) {
                 return _internalLbVmDao.findById(internalLbVm.getId());
             } else {
                 return null;
@@ -747,51 +746,51 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
         DomainRouterVO internalLbVm = null;
         for (Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
             HypervisorType hType = iter.next();
-            try {
-                s_logger.debug("Allocating the Internal lb with the hypervisor type " + hType);
-                String templateName = null;
-                switch (hType) {
-                    case XenServer:
-                        templateName = _configServer.getConfigValue(Config.RouterTemplateXen.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
-                        break;
-                    case KVM:
-                        templateName = _configServer.getConfigValue(Config.RouterTemplateKVM.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
-                        break;
-                    case VMware:
-                        templateName = _configServer.getConfigValue(Config.RouterTemplateVmware.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
-                        break;
-                    case Hyperv:
-                        templateName = _configServer.getConfigValue(Config.RouterTemplateHyperv.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
-                        break;
-                    case LXC:
-                        templateName = _configServer.getConfigValue(Config.RouterTemplateLXC.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
-                        break;
-                    default: break;
-                }
-                VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
+            s_logger.debug("Allocating the Internal lb with the hypervisor type " + hType);
+            String templateName = null;
+            switch (hType) {
+            case XenServer:
+                templateName = _configServer.getConfigValue(Config.RouterTemplateXen.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
+                break;
+            case KVM:
+                templateName = _configServer.getConfigValue(Config.RouterTemplateKVM.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
+                break;
+            case VMware:
+                templateName = _configServer.getConfigValue(Config.RouterTemplateVmware.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
+                break;
+            case Hyperv:
+                templateName = _configServer.getConfigValue(Config.RouterTemplateHyperv.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
+                break;
+            case LXC:
+                templateName = _configServer.getConfigValue(Config.RouterTemplateLXC.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
+                break;
+            default:
+                break;
+            }
+            VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
 
-                if (template == null) {
-                    s_logger.debug(hType + " won't support system vm, skip it");
-                    continue;
-                }
+            if (template == null) {
+                s_logger.debug(hType + " won't support system vm, skip it");
+                continue;
+            }
 
-                internalLbVm = new DomainRouterVO(id, routerOffering.getId(), internalLbProviderId,
-                VirtualMachineName.getSystemVmName(id, _instance, _internalLbVmNamePrefix), template.getId(), template.getHypervisorType(),
-                template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false,
-                RedundantState.UNKNOWN, false, false, VirtualMachine.Type.InternalLoadBalancerVm, vpcId);
-                internalLbVm.setRole(Role.INTERNAL_LB_VM);
-                internalLbVm = _itMgr.allocate(internalLbVm, template, routerOffering, networks, plan, null, owner);
-            } catch (InsufficientCapacityException ex) {
+            internalLbVm = new DomainRouterVO(id, routerOffering.getId(), internalLbProviderId,
+                    VirtualMachineName.getSystemVmName(id, _instance, _internalLbVmNamePrefix), template.getId(), template.getHypervisorType(),
+                    template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false,
+                    RedundantState.UNKNOWN, false, false, VirtualMachine.Type.InternalLoadBalancerVm, vpcId);
+            internalLbVm.setRole(Role.INTERNAL_LB_VM);
+            internalLbVm = _internalLbVmDao.persist(internalLbVm);
+            if (_itMgr.allocate(internalLbVm.getInstanceName(), template, routerOffering, networks, plan, null, owner) == null) {
                 if (allocateRetry < 2 && iter.hasNext()) {
+                    allocateRetry++;
+                    _internalLbVmDao.remove(internalLbVm.getId());
                     s_logger.debug("Failed to allocate the Internal lb vm with hypervisor type " + hType + ", retrying one more time");
                     continue;
-                } else {
-                    throw ex;
                 }
-            } finally {
-                allocateRetry++;
             }
 
+            internalLbVm = _internalLbVmDao.findById(internalLbVm.getId());
+
             if (startVm) {
                 try {
                     internalLbVm = startInternalLbVm(internalLbVm, _accountMgr.getSystemAccount(), User.UID_SYSTEM, params);
@@ -823,7 +822,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
             throws StorageUnavailableException, InsufficientCapacityException,
             ConcurrentOperationException, ResourceUnavailableException {
         s_logger.debug("Starting Internal LB VM " + internalLbVm);
-        if (_itMgr.start(internalLbVm, params, _accountMgr.getUserIncludingRemoved(callerUserId), caller, null) != null) {
+        if (_itMgr.start(internalLbVm.getUuid(), params, _accountMgr.getUserIncludingRemoved(callerUserId), caller, null) != null) {
             if (internalLbVm.isStopPending()) {
                 s_logger.info("Clear the stop pending flag of Internal LB VM " + internalLbVm.getHostName() + " after start router successfully!");
                 internalLbVm.setStopPending(false);
@@ -944,15 +943,15 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
         return startInternalLbVm(internalLbVm, caller, callerUserId, null);
     }
 
-    @Override
-    public void vmWorkStart(VmWork work) {
-        // TODO Auto-generated method stub
-
-    }
-
-    @Override
-    public void vmWorkStop(VmWork work) {
-        // TODO Auto-generated method stub
-
-    }
+//    @Override
+//    public void vmWorkStart(VmWork work) {
+//        // TODO Auto-generated method stub
+//
+//    }
+//
+//    @Override
+//    public void vmWorkStop(VmWork work) {
+//        // TODO Auto-generated method stub
+//
+//    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java
index a19a82e..5f37e9d 100644
--- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java
+++ b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java
@@ -5,7 +5,7 @@
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at
-// 
+//
 //   http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing,
@@ -26,8 +26,6 @@ import javax.inject.Inject;
 
 import junit.framework.TestCase;
 
-import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
-import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -35,6 +33,9 @@ import org.mockito.Mockito;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
+import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
+import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
+
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.manager.Commands;
@@ -100,6 +101,7 @@ public class InternalLBVMManagerTest extends TestCase {
     long validVmId = 1L;
     long invalidVmId = 2L;
     
+    @Override
     @Before
     public void setUp() {
         //mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
@@ -156,11 +158,11 @@ public class InternalLBVMManagerTest extends TestCase {
         
         
         try {
-            Mockito.when(_itMgr.expunge(Mockito.any(DomainRouterVO.class), Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true);
+            Mockito.when(_itMgr.expunge("1234", Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true);
         } catch (ResourceUnavailableException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
-        } 
+        }
         
         Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm);
         Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java
index 5a1d56f..ab9af7b 100644
--- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java
+++ b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java
@@ -5,7 +5,7 @@
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at
-// 
+//
 //   http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing,
@@ -23,7 +23,6 @@ import javax.inject.Inject;
 
 import junit.framework.TestCase;
 
-import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -31,6 +30,8 @@ import org.mockito.Mockito;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
+import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
+
 import com.cloud.deploy.DeploymentPlan;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
@@ -47,14 +48,14 @@ import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountVO;
 import com.cloud.user.User;
+import com.cloud.user.UserContext;
 import com.cloud.user.UserVO;
+import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.component.ComponentContext;
 import com.cloud.vm.DomainRouterVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.dao.DomainRouterDao;
-import com.cloud.user.UserContext;
-import com.cloud.user.dao.AccountDao;
 
 
 /**
@@ -80,6 +81,7 @@ public class InternalLBVMServiceTest extends TestCase {
     long nonExistingVmId = 2L;
     long nonInternalLbVmId = 3L;
     
+    @Override
     @Before
     public void setUp() {
         //mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
@@ -111,7 +113,7 @@ public class InternalLBVMServiceTest extends TestCase {
         Mockito.when(_domainRouterDao.findById(nonInternalLbVmId)).thenReturn(nonInternalLbVm);
         
         try {
-            Mockito.when(_itMgr.start(Mockito.any(DomainRouterVO.class),
+            Mockito.when(_itMgr.start(null,
                     Mockito.any(Map.class), Mockito.any(User.class), Mockito.any(Account.class), Mockito.any(DeploymentPlan.class))).thenReturn(validVm);
         } catch (InsufficientCapacityException e) {
             // TODO Auto-generated catch block
@@ -122,7 +124,7 @@ public class InternalLBVMServiceTest extends TestCase {
         }
         
         try {
-            Mockito.when(_itMgr.advanceStop(Mockito.any(DomainRouterVO.class), Mockito.any(Boolean.class), Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true);
+            Mockito.when(_itMgr.advanceStop(null, Mockito.any(Boolean.class), Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true);
         } catch (ResourceUnavailableException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManagerImpl.java b/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManagerImpl.java
index d3db89f..4899b45 100644
--- a/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManagerImpl.java
+++ b/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManagerImpl.java
@@ -68,7 +68,7 @@ import com.cloud.vm.dao.UserVmDao;
 @Component
 @Local(value={OvsTunnelManager.class})
 public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManager {
-	public static final Logger s_logger = 
+	public static final Logger s_logger =
 			Logger.getLogger(OvsTunnelManagerImpl.class.getName());
 	
 	boolean _isEnabled;
@@ -104,7 +104,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
 		OvsTunnelNetworkVO ta = null;
 		try {
 			ta = new OvsTunnelNetworkVO(from, to, key, networkId);
-			OvsTunnelNetworkVO lock = 
+			OvsTunnelNetworkVO lock =
 					_tunnelNetworkDao.acquireInLockTable(Long.valueOf(1));
 			if (lock == null) {
 			    s_logger.warn("Cannot lock table ovs_tunnel_account");
@@ -113,14 +113,14 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
 			_tunnelNetworkDao.persist(ta);
 			_tunnelNetworkDao.releaseFromLockTable(lock.getId());
 		} catch (EntityExistsException e) {
-			s_logger.debug("A record for the tunnel from " + from + 
+			s_logger.debug("A record for the tunnel from " + from +
 						   " to " + to + " already exists");
 		}
 		return ta;
 	}
 
 	@DB
-	protected OvsTunnelInterfaceVO createInterfaceRecord(String ip, 
+	protected OvsTunnelInterfaceVO createInterfaceRecord(String ip,
 			String netmask,String mac,long hostId, String label) {
 		OvsTunnelInterfaceVO ti = null;
 		try {
@@ -144,7 +144,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
 	private String handleFetchInterfaceAnswer(Answer[] answers, Long hostId){
 		OvsFetchInterfaceAnswer ans = (OvsFetchInterfaceAnswer) answers[0];
 		if (ans.getResult()) {
-			if (ans.getIp() != null && 
+			if (ans.getIp() != null &&
 				!("".equals(ans.getIp()))) {
 				OvsTunnelInterfaceVO ti =
 						createInterfaceRecord(ans.getIp(), ans.getNetmask(),
@@ -194,7 +194,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
 		// Fetch fefault name for network label from configuration
 		String physNetLabel = _configDao.getValue(Config.OvsTunnelNetworkDefaultLabel.key());
         Long physNetId = nw.getPhysicalNetworkId();
-        PhysicalNetworkTrafficType physNetTT = 
+        PhysicalNetworkTrafficType physNetTT =
         		_physNetTTDao.findBy(physNetId, TrafficType.Guest);
         HypervisorType hvType = host.getHypervisorType();
         
@@ -202,7 +202,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
         	case XenServer:
         		String label = physNetTT.getXenNetworkLabel();
         		if ((label!=null) && (!label.equals(""))) {
-        			physNetLabel = label; 
+        			physNetLabel = label;
         		}
         		break;
         	default:
@@ -212,7 +212,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
         }
 		
         // Try to fetch GRE endpoint IP address for cloud db
-        // If not found, then find it on the hypervisor            
+        // If not found, then find it on the hypervisor
         OvsTunnelInterfaceVO tunnelIface =
         		_tunnelInterfaceDao.getByHostAndLabel(host.getId(),
         											  physNetLabel);
@@ -221,7 +221,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
         	//for network with label on target host
 			Commands fetchIfaceCmds =
 					new Commands(new OvsFetchInterfaceCommand(physNetLabel));
-			s_logger.debug("Ask host " + host.getId() + 
+			s_logger.debug("Ask host " + host.getId() +
 						   " to retrieve interface for phy net with label:" +
 						   physNetLabel);
 			Answer[] fetchIfaceAnswers = _agentMgr.send(host.getId(),
@@ -241,11 +241,11 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
 			//The GRE key is actually in the host part of the URI
 			String keyStr = network.getBroadcastUri().getHost();
     		// The key is most certainly and int.
-    		// So we feel quite safe in converting it into a string			
+    		// So we feel quite safe in converting it into a string
     		key = Integer.valueOf(keyStr);
     		return key;
 		} catch (NumberFormatException e) {
-			s_logger.debug("Well well, how did '" + key + 
+			s_logger.debug("Well well, how did '" + key +
 					       "' end up in the broadcast URI for the network?");
 			throw new CloudRuntimeException(
 					String.format("Invalid GRE key parsed from" +
@@ -274,7 +274,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
 		// Find active VMs with a NIC on the target network
 		List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(nw.getId(),
 							  State.Running, State.Starting,
-							  State.Stopping, State.Unknown, State.Migrating);
+                State.Stopping, State.Migrating);
 		// Find routers for the network
 		List<DomainRouterVO> routers = _routerDao.findByNetwork(nw.getId());
 		List<VMInstanceVO>ins = new ArrayList<VMInstanceVO>();
@@ -299,24 +299,24 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
             	s_logger.debug("Attempting to create tunnel from:" +
             			hostId + " to:" + rh.longValue());
             	if (ta == null) {
-            		this.createTunnelRecord(hostId, rh.longValue(),
+            		createTunnelRecord(hostId, rh.longValue(),
             				nw.getId(), key);
             	}
                 if (!toHostIds.contains(rh)) {
                     toHostIds.add(rh);
-                } 
+                }
             }
 
             ta = _tunnelNetworkDao.getByFromToNetwork(rh.longValue(),
             		hostId, nw.getId());
-            // Try and create the tunnel even if a previous attempt failed            
+            // Try and create the tunnel even if a previous attempt failed
             if (ta == null || ta.getState().equals("FAILED")) {
             	s_logger.debug("Attempting to create tunnel from:" +
             			rh.longValue() + " to:" + hostId);
             	if (ta == null) {
-            		this.createTunnelRecord(rh.longValue(), hostId,
+            		createTunnelRecord(rh.longValue(), hostId,
             				nw.getId(), key);
-            	} 
+            	}
                 if (!fromHostIds.contains(rh)) {
                     fromHostIds.add(rh);
                 }
@@ -338,9 +338,9 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
 	            								 "endpoint for the GRE tunnel." +
 	            								 "Failure is on host:" + rHost.getId());
 				Commands cmds = new Commands(
-						new OvsCreateTunnelCommand(otherIp, key, 
+						new OvsCreateTunnelCommand(otherIp, key,
 								Long.valueOf(hostId), i, nw.getId(), myIp));
-				s_logger.debug("Ask host " + hostId + 
+				s_logger.debug("Ask host " + hostId +
 						" to create gre tunnel to " + i);
 				Answer[] answers = _agentMgr.send(hostId, cmds);
 				handleCreateTunnelAnswer(answers);
@@ -365,7 +365,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
 			if (noHost) {
 				Commands cmds = new Commands(
 						new OvsSetupBridgeCommand(key, hostId, nw.getId()));
-				s_logger.debug("Ask host " + hostId + 
+				s_logger.debug("Ask host " + hostId +
 						" to configure bridge for network:" + nw.getId());
 				Answer[] answers = _agentMgr.send(hostId, cmds);
 				handleSetupBridgeAnswer(answers);
@@ -373,7 +373,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
 		} catch (Exception e) {
 		    // I really thing we should do a better handling of these exceptions
 			s_logger.warn("Ovs Tunnel network created tunnel failed", e);
-		}	
+		}
 	}
 	
 	@Override
@@ -385,7 +385,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
     public void VmCheckAndCreateTunnel(
     		VirtualMachineProfile vm,
     		Network nw, DeployDestination dest) {
-        CheckAndCreateTunnel(vm.getVirtualMachine(), nw, dest);    
+        CheckAndCreateTunnel(vm.getVirtualMachine(), nw, dest);
     }
 
     @DB
@@ -395,7 +395,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
             OvsTunnelNetworkVO lock = _tunnelNetworkDao.acquireInLockTable(Long.valueOf(1));
             if (lock == null) {
                 s_logger.warn(String.format("failed to lock" +
-                		"ovs_tunnel_account, remove record of " + 
+                		"ovs_tunnel_account, remove record of " +
                          "tunnel(from=%1$s, to=%2$s account=%3$s) failed",
                          from, to, network_id));
                 return;
@@ -406,7 +406,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
             
             s_logger.debug(String.format("Destroy tunnel(account:%1$s," +
             		"from:%2$s, to:%3$s) successful",
-            		network_id, from, to)); 
+            		network_id, from, to));
         } else {
             s_logger.debug(String.format("Destroy tunnel(account:%1$s," +
             		"from:%2$s, to:%3$s) failed",
@@ -431,10 +431,10 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
             _tunnelNetworkDao.releaseFromLockTable(lock.getId());
             
             s_logger.debug(String.format("Destroy bridge for" +
-            		"network %1$s successful", network_id)); 
+            		"network %1$s successful", network_id));
         } else {
         	s_logger.debug(String.format("Destroy bridge for" +
-        			"network %1$s failed", network_id));        
+        			"network %1$s failed", network_id));
         }
     }
 
@@ -468,7 +468,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
                 return;
         }
         try {
-            /* Now we are last one on host, destroy the bridge with all 
+            /* Now we are last one on host, destroy the bridge with all
              * the tunnels for this network  */
         	int key = getGreKey(nw);
             Command cmd = new OvsDestroyBridgeCommand(nw.getId(), key);
@@ -478,7 +478,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
             handleDestroyBridgeAnswer(ans, vm.getHostId(), nw.getId());
             
             /* Then ask hosts have peer tunnel with me to destroy them */
-            List<OvsTunnelNetworkVO> peers = 
+            List<OvsTunnelNetworkVO> peers =
             		_tunnelNetworkDao.listByToNetwork(vm.getHostId(),
             				nw.getId());
             for (OvsTunnelNetworkVO p : peers) {
@@ -486,7 +486,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage
             	if (p.getState().equals("SUCCESS")) {
 	                cmd = new OvsDestroyTunnelCommand(p.getNetworkId(), key,
 	                		p.getPortName());
-	                s_logger.debug("Destroying tunnel to " + vm.getHostId() + 
+	                s_logger.debug("Destroying tunnel to " + vm.getHostId() +
 	                		" from " + p.getFrom());
 	                ans = _agentMgr.send(p.getFrom(), cmd);
 	                handleDestroyTunnelAnswer(ans, p.getFrom(),

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/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 44917fb..8446e67 100755
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -33,7 +33,6 @@ import org.apache.log4j.Logger;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 
-import org.apache.cloudstack.framework.jobs.AsyncJobConstants;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 
@@ -48,7 +47,6 @@ import com.cloud.agent.api.check.CheckSshAnswer;
 import com.cloud.agent.api.check.CheckSshCommand;
 import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
 import com.cloud.agent.manager.Commands;
-import com.cloud.async.AsyncJobExecutionContext;
 import com.cloud.certificate.dao.CertificateDao;
 import com.cloud.cluster.ClusterManager;
 import com.cloud.configuration.Config;
@@ -98,7 +96,6 @@ import com.cloud.resource.ResourceManager;
 import com.cloud.resource.ResourceStateAdapter;
 import com.cloud.resource.ServerResource;
 import com.cloud.resource.UnableDeleteHostException;
-import com.cloud.serializer.SerializerHelper;
 import com.cloud.server.ManagementServer;
 import com.cloud.service.ServiceOfferingVO;
 import com.cloud.service.dao.ServiceOfferingDao;
@@ -113,10 +110,8 @@ import com.cloud.storage.dao.VMTemplateHostDao;
 import com.cloud.template.TemplateManager;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
-import com.cloud.user.AccountVO;
 import com.cloud.user.User;
 import com.cloud.user.UserContext;
-import com.cloud.user.UserVO;
 import com.cloud.utils.DateUtil;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
@@ -143,9 +138,6 @@ import com.cloud.vm.VirtualMachineGuru;
 import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.VirtualMachineName;
 import com.cloud.vm.VirtualMachineProfile;
-import com.cloud.vm.VmWork;
-import com.cloud.vm.VmWorkStart;
-import com.cloud.vm.VmWorkStop;
 import com.cloud.vm.dao.ConsoleProxyDao;
 import com.cloud.vm.dao.UserVmDetailsDao;
 import com.cloud.vm.dao.VMInstanceDao;
@@ -569,7 +561,11 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
             }
 
             if (proxy.getState() == VirtualMachine.State.Stopped) {
-                return _itMgr.start(proxy, null, systemUser, systemAcct);
+                if (_itMgr.start(proxy.getUuid(), null, systemUser, systemAcct) != null) {
+                    return _consoleProxyDao.findById(proxyVmId);
+                } else {
+                    return null;
+                }
             }
 
             // For VMs that are in Stopping, Starting, Migrating state, let client to wait by returning null
@@ -731,12 +727,13 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
 
         ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(),
                 systemAcct.getId(), 0, _serviceOffering.getOfferHA());
-        try {
-            proxy = _itMgr.allocate(proxy, template, _serviceOffering, networks, plan, null, systemAcct);
-        } catch (InsufficientCapacityException e) {
-            s_logger.warn("InsufficientCapacity", e);
-            throw new CloudRuntimeException("Insufficient capacity exception", e);
+        proxy = _consoleProxyDao.persist(proxy);
+        VirtualMachine vm = _itMgr.allocate(proxy.getInstanceName(), template, _serviceOffering, networks, plan, null, systemAcct);
+        if (vm == null) {
+            s_logger.warn("Unable to allocate proxy");
+            throw new CloudRuntimeException("Insufficient capacity exception");
         }
+        proxy = _consoleProxyDao.findById(proxy.getId());
 
         Map<String, Object> context = new HashMap<String, Object>();
         context.put("dc", dc);
@@ -873,7 +870,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
             return false;
         }
         List<ConsoleProxyVO> l = _consoleProxyDao.getProxyListInStates(dcId, VirtualMachine.State.Starting, VirtualMachine.State.Running, VirtualMachine.State.Stopping, VirtualMachine.State.Stopped,
-                VirtualMachine.State.Migrating, VirtualMachine.State.Shutdowned, VirtualMachine.State.Unknown);
+                VirtualMachine.State.Migrating);
 
         String value = _configDao.getValue(Config.ConsoleProxyLaunchMax.key());
         int launchLimit = NumbersUtil.parseInt(value, 10);
@@ -882,7 +879,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
 
     private HypervisorType currentHypervisorType(long dcId) {
         List<ConsoleProxyVO> l = _consoleProxyDao.getProxyListInStates(dcId, VirtualMachine.State.Starting, VirtualMachine.State.Running, VirtualMachine.State.Stopping, VirtualMachine.State.Stopped,
-                VirtualMachine.State.Migrating, VirtualMachine.State.Shutdowned, VirtualMachine.State.Unknown);
+                VirtualMachine.State.Migrating);
 
         return l.size() > 0 ? l.get(0).getHypervisorType() : HypervisorType.Any;
     }
@@ -1041,12 +1038,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
             return false;
         }
 
-        try {
-            return _itMgr.stop(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
-        } catch (ResourceUnavailableException e) {
-            s_logger.warn("Stopping console proxy " + proxy.getHostName() + " failed : exception " + e.toString());
-            return false;
-        }
+        return _itMgr.stop(proxy.getUuid(), _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
     }
 
     @Override
@@ -1165,7 +1157,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
         ConsoleProxyVO proxy = _consoleProxyDao.findById(vmId);
         try {
             //expunge the vm
-            boolean result = _itMgr.expunge(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
+            boolean result = _itMgr.expunge(proxy.getUuid(), _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
             if (result) {
                 HostVO host = _hostDao.findByTypeNameAndZoneId(proxy.getDataCenterId(), proxy.getHostName(),
                         Host.Type.ConsoleProxy);
@@ -1722,44 +1714,44 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
     public void prepareStop(VirtualMachineProfile profile) {
     }
 
-    @Override
-    public void vmWorkStart(VmWork work) {
-    	assert(work instanceof VmWorkStart);
-    	
-        ConsoleProxyVO vm = _consoleProxyDao.findById(work.getVmId());
-    	
-    	UserVO user = _entityMgr.findById(UserVO.class, work.getUserId());
-    	AccountVO account = _entityMgr.findById(AccountVO.class, work.getAccountId());
-    	
-    	try {
-	    	_itMgr.processVmStartWork(vm, ((VmWorkStart)work).getParams(),
-	    		user, account,  ((VmWorkStart)work).getPlan());
-	    	
-    		AsyncJobExecutionContext.getCurrentExecutionContext().completeJobAndJoin(AsyncJobConstants.STATUS_SUCCEEDED, null);
-    	} catch(Exception e) {
-    		s_logger.error("Exception in process VM-start work", e);
-    		String result = SerializerHelper.toObjectSerializedString(e);
-    		AsyncJobExecutionContext.getCurrentExecutionContext().completeJobAndJoin(AsyncJobConstants.STATUS_FAILED, result);
-    	}
-    }
-    
-    @Override
-    public void vmWorkStop(VmWork work) {
-    	assert(work instanceof VmWorkStop);
-    	
-        ConsoleProxyVO vm = _consoleProxyDao.findById(work.getVmId());
-    	
-    	UserVO user = _entityMgr.findById(UserVO.class, work.getUserId());
-    	AccountVO account = _entityMgr.findById(AccountVO.class, work.getAccountId());
-    	
-    	try {
-	    	_itMgr.processVmStopWork(vm, ((VmWorkStop)work).isForceStop(), user, account);
-	    	
-    		AsyncJobExecutionContext.getCurrentExecutionContext().completeJobAndJoin(AsyncJobConstants.STATUS_SUCCEEDED, null);
-    	} catch(Exception e) {
-    		s_logger.error("Exception in process VM-stop work", e);
-    		String result = SerializerHelper.toObjectSerializedString(e);
-    		AsyncJobExecutionContext.getCurrentExecutionContext().completeJobAndJoin(AsyncJobConstants.STATUS_FAILED, result);
-    	}
-    }
+//    @Override
+//    public void vmWorkStart(VmWork work) {
+//    	assert(work instanceof VmWorkStart);
+//
+//        ConsoleProxyVO vm = _consoleProxyDao.findById(work.getVmId());
+//
+//    	UserVO user = _entityMgr.findById(UserVO.class, work.getUserId());
+//    	AccountVO account = _entityMgr.findById(AccountVO.class, work.getAccountId());
+//
+//    	try {
+//	    	_itMgr.processVmStartWork(vm, ((VmWorkStart)work).getParams(),
+//	    		user, account,  ((VmWorkStart)work).getPlan());
+//
+//    		AsyncJobExecutionContext.getCurrentExecutionContext().completeJobAndJoin(AsyncJobConstants.STATUS_SUCCEEDED, null);
+//    	} catch(Exception e) {
+//    		s_logger.error("Exception in process VM-start work", e);
+//    		String result = SerializerHelper.toObjectSerializedString(e);
+//    		AsyncJobExecutionContext.getCurrentExecutionContext().completeJobAndJoin(AsyncJobConstants.STATUS_FAILED, result);
+//    	}
+//    }
+//
+//    @Override
+//    public void vmWorkStop(VmWork work) {
+//    	assert(work instanceof VmWorkStop);
+//
+//        ConsoleProxyVO vm = _consoleProxyDao.findById(work.getVmId());
+//
+//    	UserVO user = _entityMgr.findById(UserVO.class, work.getUserId());
+//    	AccountVO account = _entityMgr.findById(AccountVO.class, work.getAccountId());
+//
+//    	try {
+//	    	_itMgr.processVmStopWork(vm, ((VmWorkStop)work).isForceStop(), user, account);
+//
+//    		AsyncJobExecutionContext.getCurrentExecutionContext().completeJobAndJoin(AsyncJobConstants.STATUS_SUCCEEDED, null);
+//    	} catch(Exception e) {
+//    		s_logger.error("Exception in process VM-stop work", e);
+//    		String result = SerializerHelper.toObjectSerializedString(e);
+//    		AsyncJobExecutionContext.getCurrentExecutionContext().completeJobAndJoin(AsyncJobConstants.STATUS_FAILED, result);
+//    	}
+//    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
index 5edca3b..929f5e8 100755
--- a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
+++ b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
@@ -284,7 +284,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
         if (hostId == null) {
             try {
                 s_logger.debug("Found a vm that is scheduled to be restarted but has no host id: " + vm);
-                _itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
+                _itMgr.advanceStop(vm.getUuid(), true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
             } catch (ResourceUnavailableException e) {
                 assert false : "How do we hit this when force is true?";
             throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
@@ -294,7 +294,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
             } catch (ConcurrentOperationException e) {
                 assert false : "How do we hit this when force is true?";
             throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
-            }            
+            }
             return;
         }
 
@@ -328,7 +328,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
             }
 
             try {
-                _itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
+                _itMgr.advanceStop(vm.getUuid(), true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
             } catch (ResourceUnavailableException e) {
                 assert false : "How do we hit this when force is true?";
             throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
@@ -338,7 +338,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
             } catch (ConcurrentOperationException e) {
                 assert false : "How do we hit this when force is true?";
             throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
-            }        
+            }
         }
 
         List<HaWorkVO> items = _haDao.findPreviousHA(vm.getId());
@@ -386,7 +386,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
 
         long vmId = work.getInstanceId();
 
-        VMInstanceVO vm = _itMgr.findByIdAndType(work.getType(), work.getInstanceId());
+        VMInstanceVO vm = _instanceDao.findById(work.getInstanceId());
         if (vm == null) {
             s_logger.info("Unable to find vm: " + vmId);
             return null;
@@ -473,7 +473,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
                 }
 
                 try {
-                    _itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
+                    _itMgr.advanceStop(vm.getUuid(), true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
                 } catch (ResourceUnavailableException e) {
                     assert false : "How do we hit this when force is true?";
                 throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
@@ -490,7 +490,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
             } else {
                 s_logger.debug("How come that HA step is Investigating and the host is removed? Calling forced Stop on Vm anyways");
                 try {
-                    _itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
+                    _itMgr.advanceStop(vm.getUuid(), true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
                 } catch (ResourceUnavailableException e) {
                     assert false : "How do we hit this when force is true?";
                 throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
@@ -504,7 +504,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
             }
         }
 
-        vm = _itMgr.findByIdAndType(vm.getType(), vm.getId());
+        vm = _instanceDao.findById(vm.getId());
 
         if (!_forceHA && !vm.isHaEnabled()) {
             if (s_logger.isDebugEnabled()) {
@@ -513,7 +513,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
             return null; // VM doesn't require HA
         }
 
-        if (!this.volumeMgr.canVmRestartOnAnotherServer(vm.getId())) {
+        if (!volumeMgr.canVmRestartOnAnotherServer(vm.getId())) {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("VM can not restart on another server.");
             }
@@ -530,7 +530,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
             if (_haTag != null) {
                 params.put(VirtualMachineProfile.Param.HaTag, _haTag);
             }
-            VMInstanceVO started = _itMgr.advanceStart(vm, params, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
+            VirtualMachine started = _itMgr.advanceStart(vm.getUuid(), params, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
 
             if (started != null) {
                 s_logger.info("VM is now restarted: " + vmId + " on " + started.getHostId());
@@ -557,7 +557,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
             _alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodIdToDeployIn(), "Unable to restart " + vm.getHostName() + " which was running on host " + hostDesc,
                     "The Storage is unavailable for trying to restart VM, name: " + vm.getHostName() + ", id: " + vmId + " which was running on host " + hostDesc);
         }
-        vm = _itMgr.findByIdAndType(vm.getType(), vm.getId());
+        vm = _instanceDao.findById(vm.getId());
         work.setUpdateTime(vm.getUpdated());
         work.setPreviousState(vm.getState());
         return (System.currentTimeMillis() >> 10) + _restartRetryInterval;
@@ -603,7 +603,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
     }
 
     protected Long destroyVM(HaWorkVO work) {
-        final VMInstanceVO vm = _itMgr.findByIdAndType(work.getType(), work.getInstanceId());
+        final VMInstanceVO vm = _instanceDao.findById(work.getInstanceId());
         s_logger.info("Destroying " + vm.toString());
         try {
             if (vm.getState() != State.Destroyed) {
@@ -612,7 +612,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
             }
 
             if (vm.getHostId() != null) {
-                if (_itMgr.destroy(vm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) {
+                if (_itMgr.destroy(vm.getUuid(), _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) {
                     s_logger.info("Successfully destroy " + vm);
                     return null;
                 }
@@ -636,7 +636,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
     }
 
     protected Long stopVM(final HaWorkVO work) throws ConcurrentOperationException {
-        VMInstanceVO vm = _itMgr.findByIdAndType(work.getType(), work.getInstanceId());
+        VMInstanceVO vm = _instanceDao.findById(work.getInstanceId());
         if (vm == null) {
             s_logger.info("No longer can find VM " + work.getInstanceId() + ". Throwing away " + work);
             work.setStep(Step.Done);
@@ -645,7 +645,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
         s_logger.info("Stopping " + vm);
         try {
             if (work.getWorkType() == WorkType.Stop) {
-                if (_itMgr.advanceStop(vm, false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) {
+                if (_itMgr.advanceStop(vm.getUuid(), false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) {
                     s_logger.info("Successfully stopped " + vm);
                     return null;
                 }
@@ -654,7 +654,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
                     s_logger.info(vm + " is different now.  Scheduled Host: " + work.getHostId() + " Current Host: " + (vm.getHostId() != null ? vm.getHostId() : "none") + " State: " + vm.getState());
                     return null;
                 }
-                if (_itMgr.advanceStop(vm, false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) {
+                if (_itMgr.advanceStop(vm.getUuid(), false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) {
                     s_logger.info("Stop for " + vm + " was successful");
                     return null;
                 }
@@ -663,7 +663,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
                     s_logger.info(vm + " is different now.  Scheduled Host: " + work.getHostId() + " Current Host: " + (vm.getHostId() != null ? vm.getHostId() : "none") + " State: " + vm.getState());
                     return null;
                 }
-                if (_itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) {
+                if (_itMgr.advanceStop(vm.getUuid(), true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) {
                     s_logger.info("Stop for " + vm + " was successful");
                     return null;
                 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index 520dd76..4e01cdb 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -30,6 +30,12 @@ import java.util.Set;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBHealthCheckPolicyCmd;
 import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBStickinessPolicyCmd;
@@ -41,8 +47,6 @@ import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRul
 import org.apache.cloudstack.api.response.ServiceResponse;
 import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
 import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
 
 import com.cloud.agent.api.to.LoadBalancerTO;
 import com.cloud.configuration.Config;
@@ -155,8 +159,6 @@ import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.dao.NicDao;
 import com.cloud.vm.dao.UserVmDao;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
 
 @Component
 @Local(value = { LoadBalancingRulesManager.class, LoadBalancingRulesService.class })
@@ -872,7 +874,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
                     if (lbrules.size() > 0) {
                         isHandled = false;
                         for (LoadBalancingServiceProvider lbElement : _lbProviders) {
-                            stateRules = lbElement.updateHealthChecks(network, (List<LoadBalancingRule>) lbrules);
+                            stateRules = lbElement.updateHealthChecks(network, lbrules);
                             if (stateRules != null && stateRules.size() > 0) {
                                 for (LoadBalancerTO lbto : stateRules) {
                                     LoadBalancerVO ulb = _lbDao.findByUuid(lbto.getUuid());
@@ -1837,7 +1839,6 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
             case Destroyed:
             case Expunging:
             case Error:
-            case Unknown:
                 continue;
             }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/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 104c3c6..5883ca5 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -246,7 +246,6 @@ import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.VirtualMachineName;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.VirtualMachineProfile.Param;
-import com.cloud.vm.VmWork;
 import com.cloud.vm.dao.DomainRouterDao;
 import com.cloud.vm.dao.NicDao;
 import com.cloud.vm.dao.NicIpAliasDao;
@@ -419,7 +418,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         _accountMgr.checkAccess(caller, null, true, router);
 
-        boolean result = _itMgr.expunge(router, _accountMgr.getActiveUser(callerUserId), _accountMgr.getAccount(router.getAccountId()));
+        boolean result = _itMgr.expunge(router.getUuid(), _accountMgr.getActiveUser(callerUserId), _accountMgr.getAccount(router.getAccountId()));
 
         if (result) {
             return router;
@@ -1604,59 +1603,59 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         DomainRouterVO router = null;
         for (Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
             HypervisorType hType = iter.next();
-            try {
-                s_logger.debug("Allocating the domR with the hypervisor type " + hType);
-                String templateName = null;
-                switch (hType) {
-                case XenServer:
-                    templateName = _configServer.getConfigValue(Config.RouterTemplateXen.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
-                    break;
-                case KVM:
-                    templateName = _configServer.getConfigValue(Config.RouterTemplateKVM.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
-                    break;
-                case VMware:
-                    templateName = _configServer
-                            .getConfigValue(Config.RouterTemplateVmware.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
-                    break;
-                case Hyperv:
-                    templateName = _configServer
-                            .getConfigValue(Config.RouterTemplateHyperv.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
-                    break;
-                case LXC:
-                    templateName = _configServer.getConfigValue(Config.RouterTemplateLXC.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
-                    break;
-                default:
-                    break;
-                }
-                VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
+            s_logger.debug("Allocating the domR with the hypervisor type " + hType);
+            String templateName = null;
+            switch (hType) {
+            case XenServer:
+                templateName = _configServer.getConfigValue(Config.RouterTemplateXen.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
+                break;
+            case KVM:
+                templateName = _configServer.getConfigValue(Config.RouterTemplateKVM.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
+                break;
+            case VMware:
+                templateName = _configServer
+                        .getConfigValue(Config.RouterTemplateVmware.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
+                break;
+            case Hyperv:
+                templateName = _configServer
+                        .getConfigValue(Config.RouterTemplateHyperv.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
+                break;
+            case LXC:
+                templateName = _configServer.getConfigValue(Config.RouterTemplateLXC.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
+                break;
+            default:
+                break;
+            }
+            VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
 
-                if (template == null) {
-                    s_logger.debug(hType + " won't support system vm, skip it");
-                    continue;
-                }
+            if (template == null) {
+                s_logger.debug(hType + " won't support system vm, skip it");
+                continue;
+            }
 
-                boolean offerHA = routerOffering.getOfferHA();
-                /* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */
-                if (isRedundant) {
-                    offerHA = false;
-                }
+            boolean offerHA = routerOffering.getOfferHA();
+            /* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */
+            if (isRedundant) {
+                offerHA = false;
+            }
 
-                router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(),
-                        VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(),
-                        template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false,
-                        RedundantState.UNKNOWN, offerHA, false, vpcId);
-                router.setRole(Role.VIRTUAL_ROUTER);
-                router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner);
-            } catch (InsufficientCapacityException ex) {
+            router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(),
+                    VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(),
+                    template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false,
+                    RedundantState.UNKNOWN, offerHA, false, vpcId);
+            router.setRole(Role.VIRTUAL_ROUTER);
+            router = _routerDao.persist(router);
+            if (_itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, plan, null, owner) == null) {
                 if (allocateRetry < 2 && iter.hasNext()) {
+                    _routerDao.remove(router.getId());
+                    allocateRetry++;
                     s_logger.debug("Failed to allocate the VR with hypervisor type " + hType + ", retrying one more time");
                     continue;
                 } else {
-                    throw ex;
+                    throw new CloudRuntimeException("Failed to allocate a VR");
                 }
-            } finally {
-                allocateRetry++;
             }
+            router = _routerDao.findById(router.getId());
 
             if (startRouter) {
                 try {
@@ -2697,7 +2696,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             throws StorageUnavailableException, InsufficientCapacityException,
             ConcurrentOperationException, ResourceUnavailableException {
         s_logger.debug("Starting router " + router);
-        if (_itMgr.start(router, params, user, caller, planToDeploy) != null) {
+        if (_itMgr.start(router.getUuid(), params, user, caller, planToDeploy) != null) {
             if (router.isStopPending()) {
                 s_logger.info("Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!");
                 router.setStopPending(false);
@@ -2719,7 +2718,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     public DomainRouterVO stop(VirtualRouter router, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException {
         s_logger.debug("Stopping router " + router);
         try {
-            if (_itMgr.advanceStop((DomainRouterVO)router, forced, user, caller)) {
+            if (_itMgr.advanceStop(router.getUuid(), forced, user, caller)) {
                 return _routerDao.findById(router.getId());
             } else {
                 return null;
@@ -3985,13 +3984,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         }
     }
 
-    @Override
-    public void vmWorkStart(VmWork work) {
-    }
-
-    @Override
-    public void vmWorkStop(VmWork work) {
-    }
+//    @Override
+//    public void vmWorkStart(VmWork work) {
+//    }
+//
+//    @Override
+//    public void vmWorkStop(VmWork work) {
+//    }
 
     @Override
     public VirtualRouter findRouter(long routerId) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java
index 5cf5931..fd9bb47 100755
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -2321,7 +2321,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
 						.listByStoragePool(storagePool.getId());
                 for (VMInstanceVO vm : vmsOnLocalStorage) {
                     try {
-						if (!_vmMgr.destroy(vm, caller,
+                        if (!_vmMgr.destroy(vm.getUuid(), caller,
 								_accountMgr.getAccount(vm.getAccountId()))) {
 							String errorMsg = "There was an error Destory the vm: "
 									+ vm
@@ -2354,7 +2354,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
 									+ " as a part of deleteHost id="
 									+ host.getId());
                             try {
-								if (!_vmMgr.advanceStop(vm, true, caller,
+                                if (!_vmMgr.advanceStop(vm.getUuid(), true, caller,
 										_accountMgr.getAccount(vm
 												.getAccountId()))) {
 									String errorMsg = "There was an error stopping the vm: "

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3716f1f3/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 1f1e158..84d02ab 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -2191,7 +2191,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
 
         User caller = _userDao.findById(UserContext.current().getCallerUserId());
 
-        if (_itMgr.advanceStop(systemVm, isForced, caller, UserContext.current().getCaller())) {
+        if (_itMgr.advanceStop(systemVm.getUuid(), isForced, caller, UserContext.current().getCaller())) {
             return _consoleProxyDao.findById(systemVm.getId());
         }
         return null;
@@ -3072,7 +3072,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
 
         User caller = _userDao.findById(UserContext.current().getCallerUserId());
 
-        if (_itMgr.advanceStop(systemVm, isForced, caller, UserContext.current().getCaller())) {
+        if (_itMgr.advanceStop(systemVm.getUuid(), isForced, caller, UserContext.current().getCaller())) {
             return _secStorageVmDao.findById(systemVm.getId());
         }
         return null;


Mime
View raw message