You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pr...@apache.org on 2013/01/22 22:19:38 UTC

[2/14] git commit: Deploy, Start, Stop, Destroy VM orchestration service changes

Deploy, Start, Stop, Destroy VM orchestration service changes


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

Branch: refs/heads/javelin
Commit: 94e8090bf344717191c72c27b2a794ce197c10ff
Parents: ee39ec8
Author: Prachi Damle <pr...@cloud.com>
Authored: Tue Jan 15 23:08:00 2013 -0800
Committer: Prachi Damle <pr...@cloud.com>
Committed: Tue Jan 22 12:54:04 2013 -0800

----------------------------------------------------------------------
 api/src/com/cloud/vm/VirtualMachine.java           |    2 +-
 core/src/com/cloud/vm/UserVmVO.java                |    4 +-
 core/src/com/cloud/vm/VMInstanceVO.java            |   11 +-
 .../cloud/entity/api/VirtualMachineEntity.java     |   24 ++-
 .../engine/service/api/OrchestrationService.java   |    8 +-
 .../engine/cloud/entity/api/VMEntityManager.java   |   16 ++
 .../cloud/entity/api/VMEntityManagerImpl.java      |  191 ++++++++++++++-
 .../cloud/entity/api/VirtualMachineEntityImpl.java |   33 ++--
 .../engine/cloud/entity/api/db/VMComputeTagVO.java |   51 ++++
 .../engine/cloud/entity/api/db/VMEntityVO.java     |   26 ++-
 .../engine/cloud/entity/api/db/VMNetworkMapVO.java |   55 ++++
 .../cloud/entity/api/db/VMReservationVO.java       |  111 +++++++++
 .../cloud/entity/api/db/VMRootDiskTagVO.java       |   51 ++++
 .../cloud/entity/api/db/VolumeReservationVO.java   |   83 +++++++
 .../cloud/entity/api/db/dao/VMComputeTagDao.java   |   15 ++
 .../entity/api/db/dao/VMComputeTagDaoImpl.java     |   71 ++++++
 .../cloud/entity/api/db/dao/VMEntityDao.java       |   41 +++
 .../cloud/entity/api/db/dao/VMEntityDaoImpl.java   |  152 ++++++++++++
 .../cloud/entity/api/db/dao/VMNetworkMapDao.java   |   15 ++
 .../entity/api/db/dao/VMNetworkMapDaoImpl.java     |   69 ++++++
 .../cloud/entity/api/db/dao/VMReservationDao.java  |   18 ++
 .../entity/api/db/dao/VMReservationDaoImpl.java    |   93 +++++++
 .../cloud/entity/api/db/dao/VMRootDiskTagDao.java  |   15 ++
 .../entity/api/db/dao/VMRootDiskTagDaoImpl.java    |   70 ++++++
 .../entity/api/db/dao/VolumeReservationDao.java    |   15 ++
 .../api/db/dao/VolumeReservationDaoImpl.java       |   52 ++++
 .../entity/api/DataCenterResourceManagerImpl.java  |    8 +-
 .../datacenter/entity/api/db/dao/ClusterDao.java   |    1 -
 .../entity/api/db/dao/ClusterDaoImpl.java          |   20 +-
 .../entity/api/db/dao/DataCenterDao.java           |    1 -
 .../entity/api/db/dao/DataCenterDaoImpl.java       |    8 +-
 .../datacenter/entity/api/db/dao/HostDao.java      |    2 -
 .../datacenter/entity/api/db/dao/HostDaoImpl.java  |  169 ++++++-------
 .../datacenter/entity/api/db/dao/HostPodDao.java   |    3 -
 .../entity/api/db/dao/HostPodDaoImpl.java          |    8 +-
 .../platform/orchestration/CloudOrchestrator.java  |   55 +++--
 server/src/com/cloud/deploy/FirstFitPlanner.java   |   46 ++--
 .../network/security/SecurityManagerMBeanImpl.java |    2 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java     |   44 ++--
 server/src/com/cloud/vm/dao/VMInstanceDao.java     |    2 -
 server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java |    5 -
 setup/db/4.1-new-db-schema.sql                     |   25 ++
 42 files changed, 1462 insertions(+), 229 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/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 3a10b03..83f1612 100755
--- a/api/src/com/cloud/vm/VirtualMachine.java
+++ b/api/src/com/cloud/vm/VirtualMachine.java
@@ -284,7 +284,7 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I
 
     public long getServiceOfferingId();
     
-    public long getDiskOfferingId();
+    public Long getDiskOfferingId();
 
     Type getType();
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/core/src/com/cloud/vm/UserVmVO.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/vm/UserVmVO.java b/core/src/com/cloud/vm/UserVmVO.java
index 05a4bd1..a16eaf9 100755
--- a/core/src/com/cloud/vm/UserVmVO.java
+++ b/core/src/com/cloud/vm/UserVmVO.java
@@ -78,8 +78,8 @@ public class UserVmVO extends VMInstanceVO implements UserVm {
                     long accountId,
                     long serviceOfferingId,
                     String userData,
-                    String name) {
-        super(id, serviceOfferingId, name, instanceName, Type.User, templateId, hypervisorType, guestOsId, domainId, accountId, haEnabled, limitCpuUse);
+                    String name, Long diskOfferingId) {
+        super(id, serviceOfferingId, name, instanceName, Type.User, templateId, hypervisorType, guestOsId, domainId, accountId, haEnabled, limitCpuUse, diskOfferingId);
         this.userData = userData;
         this.displayName = displayName;
     	this.details = new HashMap<String, String>();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/core/src/com/cloud/vm/VMInstanceVO.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/vm/VMInstanceVO.java b/core/src/com/cloud/vm/VMInstanceVO.java
index 474c788..36c3347 100644
--- a/core/src/com/cloud/vm/VMInstanceVO.java
+++ b/core/src/com/cloud/vm/VMInstanceVO.java
@@ -155,6 +155,9 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
     protected String uuid = UUID.randomUUID().toString();
     ;
 
+    @Column(name="disk_offering_id")
+    protected Long diskOfferingId;
+    
     public VMInstanceVO(long id,
             long serviceOfferingId,
             String name,
@@ -195,9 +198,10 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
             long domainId,
             long accountId,
             boolean haEnabled,
-            boolean limitResourceUse) {
+            boolean limitResourceUse, Long diskOfferingId) {
         this(id, serviceOfferingId, name, instanceName, type, vmTemplateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
         this.limitCpuUse = limitResourceUse;
+        this.diskOfferingId = diskOfferingId;
     }
 
     protected VMInstanceVO() {
@@ -472,9 +476,8 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
     }
 
 	@Override
-	public long getDiskOfferingId() {
-		// TODO Auto-generated method stub
-		return 0;
+	public Long getDiskOfferingId() {
+		return diskOfferingId;
 	}
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntity.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntity.java b/engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntity.java
index 964bcaa..1fd4e54 100755
--- a/engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntity.java
+++ b/engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntity.java
@@ -28,9 +28,15 @@ import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.cloudstack.engine.entity.api.CloudStackEntity;
 
-import com.cloud.deploy.DeployDestination;
+
+import com.cloud.deploy.DeploymentPlan;
 import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.vm.VirtualMachine;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.CloudException;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+
 
 /**
  * VirtualMachineEntity represents a Virtual Machine in Cloud Orchestration 
@@ -78,33 +84,33 @@ public interface VirtualMachineEntity extends CloudStackEntity {
     void delTag();
 
     /**
-     * Start the virtual machine with a given deploy destination
+     * Start the virtual machine with a given deployment plan
      * @param plannerToUse the Deployment Planner that should be used 
-     * @param dest destination to which to deploy the machine
+     * @param plan plan to which to deploy the machine
      * @param exclude list of areas to exclude
      * @return a reservation id
      */
-    String reserve(String plannerToUse, @BeanParam DeployDestination dest, ExcludeList exclude);
+    String reserve(String plannerToUse, @BeanParam DeploymentPlan plan, ExcludeList exclude, String caller) throws InsufficientCapacityException, ResourceUnavailableException;
 
     /**
      * Migrate this VM to a certain destination.
      * 
      * @param reservationId reservation id from reserve call.
      */
-    void migrateTo(String reservationId);
+    void migrateTo(String reservationId, String caller);
 
     /**
      * Deploy this virtual machine according to the reservation from before.
      * @param reservationId reservation id from reserve call.
      * 
      */
-    void deploy(String reservationId);
+    void deploy(String reservationId, String caller) throws InsufficientCapacityException, ResourceUnavailableException;
 
     /**
      * Stop the virtual machine
      * 
      */
-    void stop();
+    boolean stop(String caller) throws ResourceUnavailableException, CloudException;
 
     /**
      * Cleans up after any botched starts.  CloudStack Orchestration Platform
@@ -116,7 +122,7 @@ public interface VirtualMachineEntity extends CloudStackEntity {
     /**
      * Destroys the VM.
      */
-    void destroy();
+    boolean destroy(String caller) throws AgentUnavailableException, CloudException, ConcurrentOperationException;
 
     /**
      * Duplicate this VM in the database so that it will start new

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java b/engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java
index 1daf53a..64ef063 100755
--- a/engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java
+++ b/engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java
@@ -20,6 +20,7 @@ package org.apache.cloudstack.engine.service.api;
 
 import java.net.URL;
 import java.util.List;
+import java.util.Map;
 
 import javax.ws.rs.DELETE;
 import javax.ws.rs.POST;
@@ -35,6 +36,7 @@ import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
 import com.cloud.deploy.DeploymentPlan;
 import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.hypervisor.Hypervisor;
+import com.cloud.vm.NicProfile;
 
 @Path("orchestration")
 @Produces({"application/json", "application/xml"})
@@ -70,7 +72,7 @@ public interface OrchestrationService {
             @QueryParam("disk-size") Long diskSize,
             @QueryParam("compute-tags") List<String> computeTags,
             @QueryParam("root-disk-tags") List<String> rootDiskTags,
-            @QueryParam("networks") List<String> networks,
+            @QueryParam("network-nic-map") Map<String, NicProfile> networkNicMap,
             @QueryParam("deploymentplan") DeploymentPlan plan
             ) throws InsufficientCapacityException;
 
@@ -89,7 +91,7 @@ public interface OrchestrationService {
             @QueryParam("disk-size") Long diskSize,
             @QueryParam("compute-tags") List<String> computeTags,
             @QueryParam("root-disk-tags") List<String> rootDiskTags,
-            @QueryParam("networks") List<String> networks,
+            @QueryParam("network-nic-map") Map<String, NicProfile> networkNicMap,
     		@QueryParam("deploymentplan") DeploymentPlan plan
     		) throws InsufficientCapacityException;
 
@@ -107,4 +109,6 @@ public interface OrchestrationService {
 
     @POST
     TemplateEntity registerTemplate(String name, URL path, String os, Hypervisor hypervisor);
+    
+    VirtualMachineEntity getVirtualMachine(@QueryParam("id") String id);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManager.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManager.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManager.java
index 37545e8..8e58e73 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManager.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManager.java
@@ -18,9 +18,25 @@ package org.apache.cloudstack.engine.cloud.entity.api;
 
 import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
 
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.OperationTimedoutException;
+import com.cloud.exception.ResourceUnavailableException;
+
 public interface VMEntityManager {
 
 	VMEntityVO loadVirtualMachine(String vmId);
 
 	void saveVirtualMachine(VMEntityVO vmInstanceVO);
+
+	String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan plan, ExcludeList exclude) throws InsufficientCapacityException, ResourceUnavailableException;
+
+    void deployVirtualMachine(String reservationId, String caller) throws InsufficientCapacityException, ResourceUnavailableException;
+
+    boolean stopvirtualmachine(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException;
+
+    boolean destroyVirtualMachine(VMEntityVO vmEntityVO, String caller) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
index 05c39bc..b1db242 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
@@ -16,12 +16,94 @@
 // under the License.
 package org.apache.cloudstack.engine.cloud.entity.api;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.inject.Inject;
+
 import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO;
+import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMEntityDao;
+import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
 import org.springframework.stereotype.Component;
 
+import com.cloud.dc.DataCenter;
+import com.cloud.deploy.DataCenterDeployment;
+import com.cloud.deploy.DeployDestination;
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InsufficientServerCapacityException;
+import com.cloud.exception.OperationTimedoutException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.org.Cluster;
+import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.storage.StoragePoolVO;
+import com.cloud.storage.Volume;
+import com.cloud.storage.VolumeVO;
+import com.cloud.storage.dao.DiskOfferingDao;
+import com.cloud.storage.dao.StoragePoolDao;
+import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachineManager;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.VirtualMachineProfileImpl;
+import com.cloud.vm.dao.VMInstanceDao;
+
 @Component
 public class VMEntityManagerImpl implements VMEntityManager {
 
+    @Inject
+    protected VMInstanceDao _vmDao;
+    @Inject
+    protected VMTemplateDao _templateDao = null;
+    
+    @Inject
+    protected ServiceOfferingDao _serviceOfferingDao;
+    
+    @Inject
+    protected DiskOfferingDao _diskOfferingDao = null;
+    
+    @Inject
+    protected NetworkDao _networkDao;
+    
+    @Inject
+    protected AccountDao _accountDao = null;
+
+    @Inject
+    protected UserDao _userDao = null;
+
+    @Inject 
+    protected VMEntityDao _vmEntityDao;
+    
+    @Inject 
+    protected VMReservationDao _reservationDao;
+    
+    @Inject
+    protected VirtualMachineManager _itMgr;
+    
+    @Inject
+    protected List<DeploymentPlanner> _planners;
+    
+    @Inject
+    protected VolumeDao _volsDao;
+    
+    @Inject
+    protected StoragePoolDao _storagePoolDao;
+    
 	@Override
 	public VMEntityVO loadVirtualMachine(String vmId) {
 		// TODO Auto-generated method stub
@@ -29,9 +111,114 @@ public class VMEntityManagerImpl implements VMEntityManager {
 	}
 
 	@Override
-	public void saveVirtualMachine(VMEntityVO vmInstanceVO) {
-		// TODO Auto-generated method stub
+	public void saveVirtualMachine(VMEntityVO entity) {
+	    _vmEntityDao.persist(entity);
 		
 	}
 
+    @Override
+    public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude) 
+            throws InsufficientCapacityException, ResourceUnavailableException {
+
+        //call planner and get the deployDestination.
+        //load vm instance and offerings and call virtualMachineManagerImpl
+        //FIXME: profile should work on VirtualMachineEntity
+        VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
+        VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
+        DeploymentPlan plan = planToDeploy;
+        
+        List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
+        if(!vols.isEmpty()){
+            VolumeVO vol = vols.get(0);
+            StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
+            if (!pool.isInMaintenance()) {
+                long rootVolDcId = pool.getDataCenterId();
+                Long rootVolPodId = pool.getPodId();
+                Long rootVolClusterId = pool.getClusterId();
+                if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
+                    Long clusterIdSpecified = planToDeploy.getClusterId();
+                    if (clusterIdSpecified != null && rootVolClusterId != null) {
+                        if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) {
+                            // cannot satisfy the plan passed in to the
+                            // planner
+                            throw new ResourceUnavailableException("Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for "
+                                    + vm, Cluster.class, clusterIdSpecified);
+                        }
+                    }
+                    plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null, null);
+                }else{
+                    plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, null);
+
+                }
+            }
+        
+        }
+        
+        DeploymentPlanner planner = ComponentContext.getCompanent(plannerToUse);
+        DeployDestination dest = null;
+        
+        if (planner.canHandle(vmProfile, plan, exclude)) {
+            dest = planner.plan(vmProfile, plan, exclude);
+        } 
+
+        if (dest != null) {
+           //save destination with VMEntityVO
+            VMReservationVO vmReservation = new VMReservationVO(vm.getId(), dest.getDataCenter().getId(), dest.getPod().getId(), dest.getCluster().getId(), dest.getHost().getId());
+            Map<Long,Long> volumeReservationMap = new HashMap<Long,Long>();
+            for(Volume vo : dest.getStorageForDisks().keySet()){
+                volumeReservationMap.put(vo.getId(), dest.getStorageForDisks().get(vo).getId());
+            }
+            vmReservation.setVolumeReservation(volumeReservationMap);
+
+            vmEntityVO.setVmReservation(vmReservation);
+            _vmEntityDao.persist(vmEntityVO);
+            
+            return vmReservation.getUuid();
+        }else{
+            throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId());
+        }
+        
+    }
+
+    @Override
+    public void deployVirtualMachine(String reservationId, String caller) throws InsufficientCapacityException, ResourceUnavailableException{
+        //grab the VM Id and destination using the reservationId.
+        
+        VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
+        long vmId = vmReservation.getVmId();
+        
+        VMInstanceVO vm = _vmDao.findById(vmId);
+        //Pass it down
+        Long poolId = null;
+        Map<Long,Long> storage = vmReservation.getVolumeReservation();
+        if(storage != null){
+            Long[] array = new Long[storage.keySet().size()];
+            storage.keySet().toArray(array);
+            poolId = array[0];
+        }
+        
+        DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterIdToDeployIn(), vmReservation.getPodId(), vmReservation.getClusterId(),
+                vmReservation.getHostId(), poolId , null);
+        
+        VMInstanceVO vmDeployed = _itMgr.start(vm, null, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), plan);
+        
+    }
+
+    @Override
+    public boolean stopvirtualmachine(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()));
+
+    }
+
+    @Override
+    public boolean destroyVirtualMachine(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()));
+
+            
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java
index 2b308d1..13358d8 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java
@@ -24,10 +24,17 @@ import java.util.Map;
 import javax.inject.Inject;
 
 import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
+import org.springframework.stereotype.Component;
 
-import com.cloud.deploy.DeployDestination;
+import com.cloud.deploy.DeploymentPlan;
 import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.OperationTimedoutException;
+import com.cloud.exception.ResourceUnavailableException;
 
+@Component
 public class VirtualMachineEntityImpl implements VirtualMachineEntity {
 	
 	@Inject private VMEntityManager manager;
@@ -185,28 +192,25 @@ public class VirtualMachineEntityImpl implements VirtualMachineEntity {
 	}
 
 	@Override
-	public String reserve(String plannerToUse, DeployDestination dest,
-			ExcludeList exclude) {
-		// TODO Auto-generated method stub
-		return null;
+	public String reserve(String plannerToUse, DeploymentPlan plan,
+			ExcludeList exclude, String caller) throws InsufficientCapacityException, ResourceUnavailableException {
+		return manager.reserveVirtualMachine(this.vmEntityVO, plannerToUse, plan, exclude);
 	}
 
 	@Override
-	public void migrateTo(String reservationId) {
+	public void migrateTo(String reservationId, String caller) {
 		// TODO Auto-generated method stub
 
 	}
 
 	@Override
-	public void deploy(String reservationId) {
-		// TODO Auto-generated method stub
-
+	public void deploy(String reservationId, String caller) throws InsufficientCapacityException, ResourceUnavailableException{
+	    manager.deployVirtualMachine(reservationId, caller);
 	}
 
 	@Override
-	public void stop() {
-		// TODO Auto-generated method stub
-
+	public boolean stop(String caller) throws ResourceUnavailableException{
+	    return manager.stopvirtualmachine(this.vmEntityVO, caller);
 	}
 
 	@Override
@@ -216,9 +220,8 @@ public class VirtualMachineEntityImpl implements VirtualMachineEntity {
 	}
 
 	@Override
-	public void destroy() {
-		// TODO Auto-generated method stub
-
+	public boolean destroy(String caller) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
+		return manager.destroyVirtualMachine(this.vmEntityVO, caller);
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMComputeTagVO.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMComputeTagVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMComputeTagVO.java
new file mode 100644
index 0000000..b271c8a
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMComputeTagVO.java
@@ -0,0 +1,51 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name = "vm_compute_tags")
+public class VMComputeTagVO implements InternalIdentity{
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "vm_id")
+    private long vmId;
+
+    @Column(name = "compute_tag")
+    private String computeTag;
+
+    /**
+     * There should never be a public constructor for this class. Since it's
+     * only here to define the table for the DAO class.
+     */
+    protected VMComputeTagVO() {
+    }
+
+    public VMComputeTagVO(long vmId, String tag) {
+        this.vmId = vmId;
+        this.computeTag = tag;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public long getVmId() {
+        return vmId;
+    }
+
+    public String getComputeTag() {
+        return computeTag;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
index 93ac691..fec1c97 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
@@ -182,6 +182,12 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
     @Transient
     List<String> networkIds;
 
+    @Column(name="disk_offering_id")
+    protected Long diskOfferingId;
+    
+    @Transient
+    private VMReservationVO vmReservation;
+    
 
     public VMEntityVO(long id,
             long serviceOfferingId,
@@ -193,7 +199,7 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
             long guestOSId,
             long domainId,
             long accountId,
-            boolean haEnabled) {
+            boolean haEnabled, Long diskOfferingId) {
         this.id = id;
         this.hostName = name != null ? name : this.uuid;
         if (vmTemplateId != null) {
@@ -210,6 +216,7 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
         this.serviceOfferingId = serviceOfferingId;
         this.hypervisorType = hypervisorType;
         this.limitCpuUse = false;
+        this.diskOfferingId = diskOfferingId;
     }
 
     public VMEntityVO(long id,
@@ -224,7 +231,7 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
             long accountId,
             boolean haEnabled,
             boolean limitResourceUse) {
-        this(id, serviceOfferingId, name, instanceName, type, vmTemplateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
+        this(id, serviceOfferingId, name, instanceName, type, vmTemplateId, hypervisorType, guestOSId, domainId, accountId, haEnabled, null);
         this.limitCpuUse = limitResourceUse;
     }
 
@@ -557,10 +564,17 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
         this.networkIds = networkIds;
     }
 
-    @Override
-    public long getDiskOfferingId() {
-        // TODO Auto-generated method stub
-        return 0;
+	@Override
+	public Long getDiskOfferingId() {
+		return diskOfferingId;
+	}
+
+    public VMReservationVO getVmReservation() {
+        return vmReservation;
+    }
+
+    public void setVmReservation(VMReservationVO vmReservation) {
+        this.vmReservation = vmReservation;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMNetworkMapVO.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMNetworkMapVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMNetworkMapVO.java
new file mode 100644
index 0000000..a28072f
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMNetworkMapVO.java
@@ -0,0 +1,55 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db;
+
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import org.apache.cloudstack.api.InternalIdentity;
+
+
+@Entity
+@Table(name = "vm_network_map")
+public class VMNetworkMapVO implements InternalIdentity{
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "vm_id")
+    private long vmId;
+
+    @Column(name="network_id")
+    private long networkId;
+
+   
+    /**
+     * There should never be a public constructor for this class. Since it's
+     * only here to define the table for the DAO class.
+     */
+    protected VMNetworkMapVO() {
+    }
+
+    public VMNetworkMapVO(long vmId, long networkId) {
+        this.vmId = vmId;
+        this.networkId = networkId;
+    }
+    
+    
+    public long getId() {
+        return id;
+    }
+
+    public long getVmId() {
+        return vmId;
+    }
+
+    
+    public long getNetworkId() {
+        return networkId;
+    }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMReservationVO.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMReservationVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMReservationVO.java
new file mode 100644
index 0000000..211fbeb
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMReservationVO.java
@@ -0,0 +1,111 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = "vm_reservation")
+public class VMReservationVO implements Identity, InternalIdentity{
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "vm_id")
+    private long vmId;
+
+    @Column(name="uuid")
+    private String uuid;
+    
+    @Column(name="data_center_id")
+    private long dataCenterId;
+
+    @Column(name="pod_id")
+    private long podId;
+    
+    @Column(name="cluster_id")
+    private long clusterId;
+    
+    @Column(name="host_id")
+    private long hostId;
+    
+    @Column(name=GenericDao.CREATED_COLUMN)
+    private Date created;
+
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    private Date removed;
+
+    // VolumeId -> poolId 
+    @Transient
+    Map<Long,Long> volumeReservationMap;
+    
+    /**
+     * There should never be a public constructor for this class. Since it's
+     * only here to define the table for the DAO class.
+     */
+    protected VMReservationVO() {
+    }
+
+    public VMReservationVO(long vmId, long dataCenterId, long podId, long clusterId, long hostId) {
+        this.vmId = vmId;
+        this.dataCenterId = dataCenterId;
+        this.podId = podId;
+        this.clusterId = clusterId;
+        this.hostId = hostId;
+        this.uuid = UUID.randomUUID().toString();
+    }
+    
+    
+    public long getId() {
+        return id;
+    }
+
+    public long getVmId() {
+        return vmId;
+    }
+
+    @Override
+    public String getUuid() {
+        return uuid;
+    }
+    
+    public long getDataCenterId() {
+        return dataCenterId;
+    }
+
+    public Long getPodId() {
+        return podId;
+    }
+    
+    public Long getClusterId() {
+        return clusterId;
+    }
+
+    public Long getHostId() {
+        return hostId;
+    }
+
+    public Map<Long,Long> getVolumeReservation(){
+        return volumeReservationMap;
+    }
+    
+    public void setVolumeReservation(Map<Long,Long> volumeReservationMap){
+        this.volumeReservationMap = volumeReservationMap;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMRootDiskTagVO.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMRootDiskTagVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMRootDiskTagVO.java
new file mode 100644
index 0000000..92863c7
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMRootDiskTagVO.java
@@ -0,0 +1,51 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name = "vm_root_disk_tags")
+public class VMRootDiskTagVO implements InternalIdentity {
+    
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "vm_id")
+    private long vmId;
+
+    @Column(name = "compute_tag")
+    private String rootDiskTag;
+
+    /**
+     * There should never be a public constructor for this class. Since it's
+     * only here to define the table for the DAO class.
+     */
+    protected VMRootDiskTagVO() {
+    }
+
+    public VMRootDiskTagVO(long vmId, String rootDiskTag) {
+        this.vmId = vmId;
+        this.rootDiskTag = rootDiskTag;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public long getVmId() {
+        return vmId;
+    }
+
+    public String getRootDiskTag() {
+        return rootDiskTag;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VolumeReservationVO.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VolumeReservationVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VolumeReservationVO.java
new file mode 100644
index 0000000..a746a94
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VolumeReservationVO.java
@@ -0,0 +1,83 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db;
+
+import java.util.Date;
+import java.util.Map;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = "volume_reservation")
+public class VolumeReservationVO implements InternalIdentity{
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "vm_reservation_id")
+    private long vmReservationId;
+    
+    @Column(name = "vm_id")
+    private long vmId;
+    
+    @Column(name="volume_id")
+    private long volumeId;
+
+    @Column(name="pool_id")
+    private long poolId;
+    
+    // VolumeId -> poolId 
+    @Transient
+    Map<String, String> volumeReservationMap;
+    
+    /**
+     * There should never be a public constructor for this class. Since it's
+     * only here to define the table for the DAO class.
+     */
+    protected VolumeReservationVO() {
+    }
+
+    public VolumeReservationVO(long vmId, long volumeId, long poolId) {
+        this.vmId = vmId;
+        this.volumeId = volumeId;
+        this.poolId = poolId;
+    }
+    
+    
+    public long getId() {
+        return id;
+    }
+
+    public long getVmId() {
+        return vmId;
+    }
+
+    public long geVmReservationId() {
+        return vmReservationId;
+    }
+    
+    public long getVolumeId() {
+        return volumeId;
+    }
+
+    public Long getPoolId() {
+        return poolId;
+    }
+
+
+    public Map<String,String> getVolumeReservation(){
+        return volumeReservationMap;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDao.java
new file mode 100644
index 0000000..33ff836
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDao.java
@@ -0,0 +1,15 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+import java.util.List;
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMComputeTagVO;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface VMComputeTagDao extends GenericDao<VMComputeTagVO, Long>{
+
+    void persist(long vmId, List<String> computeTags);
+    
+    List<String> getComputeTags(long vmId);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDaoImpl.java
new file mode 100644
index 0000000..2fa5a4c
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDaoImpl.java
@@ -0,0 +1,71 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Local;
+
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMComputeTagVO;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = { VMComputeTagDao.class })
+public class VMComputeTagDaoImpl extends GenericDaoBase<VMComputeTagVO, Long> implements VMComputeTagDao {
+
+    protected SearchBuilder<VMComputeTagVO> VmIdSearch;
+    
+    public VMComputeTagDaoImpl() {
+    }
+    
+    @PostConstruct
+    public void init() {
+        VmIdSearch = createSearchBuilder();
+        VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ);
+        VmIdSearch.done();
+        
+    }
+    
+    @Override
+    public void persist(long vmId, List<String> computeTags) {
+        Transaction txn = Transaction.currentTxn();
+
+        txn.start();
+        SearchCriteria<VMComputeTagVO> sc = VmIdSearch.create();
+        sc.setParameters("vmId", vmId);
+        expunge(sc);
+        
+        for (String tag : computeTags) {
+            tag = tag.trim();
+            if(tag.length() > 0) {
+                VMComputeTagVO vo = new VMComputeTagVO(vmId, tag);
+                persist(vo);
+            }
+        }
+        txn.commit();
+    }
+
+    @Override
+    public List<String> getComputeTags(long vmId) {
+        
+        SearchCriteria<VMComputeTagVO> sc = VmIdSearch.create();
+        sc.setParameters("vmId", vmId);
+        
+        List<VMComputeTagVO> results = search(sc, null);
+        List<String> computeTags = new ArrayList<String>(results.size());
+        for (VMComputeTagVO result : results) {
+            computeTags.add(result.getComputeTag());
+        }
+
+        return computeTags;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDao.java
new file mode 100644
index 0000000..aa063dc
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDao.java
@@ -0,0 +1,41 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// 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,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
+
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.fsm.StateDao;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachine.State;
+import com.cloud.vm.VirtualMachine.Type;
+
+
+/*
+ * Data Access Object for vm_instance table
+ */
+public interface VMEntityDao extends GenericDao<VMEntityVO, Long> {
+  
+    void loadVmReservation(VMEntityVO vm);
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDaoImpl.java
new file mode 100644
index 0000000..b97c422
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDaoImpl.java
@@ -0,0 +1,152 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// 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,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.NetworkVO;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.Transaction;
+import com.cloud.vm.NicProfile;
+
+
+
+@Component
+@Local(value = { VMEntityDao.class })
+public class VMEntityDaoImpl extends GenericDaoBase<VMEntityVO, Long> implements VMEntityDao {
+
+    public static final Logger s_logger = Logger.getLogger(VMEntityDaoImpl.class);
+
+    
+    @Inject protected VMReservationDaoImpl _vmReservationDao;
+
+    @Inject protected VMComputeTagDaoImpl _vmComputeTagDao;
+    
+    @Inject protected VMRootDiskTagDaoImpl _vmRootDiskTagsDao;
+    
+    @Inject protected VMNetworkMapDaoImpl _vmNetworkMapDao;
+
+    
+    @Inject
+    protected NetworkDao _networkDao;
+    
+    public VMEntityDaoImpl() {
+    }
+    
+    @PostConstruct
+    protected void init() {
+
+    }
+
+    @Override
+    public void loadVmReservation(VMEntityVO vm) {
+        VMReservationVO vmReservation = _vmReservationDao.findByVmId(vm.getId());
+        vm.setVmReservation(vmReservation);
+    }
+
+    @Override
+    @DB
+    public VMEntityVO persist(VMEntityVO vm) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+
+        VMEntityVO dbVO = super.persist(vm);
+
+        saveVmNetworks(vm);
+        loadVmNetworks(dbVO);
+        saveVmReservation(vm);
+        loadVmReservation(dbVO);
+        saveComputeTags(vm.getId(), vm.getComputeTags());
+        loadComputeTags(dbVO);
+        saveRootDiskTags(vm.getId(), vm.getRootDiskTags());
+        loadRootDiskTags(dbVO);
+
+        txn.commit();
+
+        return dbVO;
+    }
+
+    private void loadVmNetworks(VMEntityVO dbVO) {
+        List<Long> networksIds = _vmNetworkMapDao.getNetworks(dbVO.getId());
+        
+        List<String> networks = new ArrayList<String>();
+        for(Long networkId : networksIds){
+            NetworkVO network = _networkDao.findById(networkId);
+            if(network != null){
+                networks.add(network.getUuid());
+            }
+        }
+        
+        dbVO.setNetworkIds(networks);
+        
+    }
+
+    private void saveVmNetworks(VMEntityVO vm) {
+        List<Long> networks = new ArrayList<Long>();
+        
+        for(String uuid : vm.getNetworkIds()){
+            NetworkVO network = _networkDao.findByUuid(uuid);
+            if(network != null){
+                networks.add(network.getId());
+            }
+        }
+        _vmNetworkMapDao.persist(vm.getId(), networks);
+        
+    }
+
+    private void loadRootDiskTags(VMEntityVO dbVO) {
+        List<String> rootDiskTags = _vmRootDiskTagsDao.getRootDiskTags(dbVO.getId());
+        dbVO.setRootDiskTags(rootDiskTags);
+        
+    }
+
+    private void loadComputeTags(VMEntityVO dbVO) {
+        List<String> computeTags = _vmComputeTagDao.getComputeTags(dbVO.getId());
+        dbVO.setComputeTags(computeTags);
+        
+    }
+
+    private void saveRootDiskTags(long vmId, List<String> rootDiskTags) {
+        _vmRootDiskTagsDao.persist(vmId, rootDiskTags);
+        
+    }
+
+    private void saveComputeTags(long vmId, List<String> computeTags) {
+        _vmComputeTagDao.persist(vmId, computeTags);        
+    }
+
+    private void saveVmReservation(VMEntityVO vm) {
+        _vmReservationDao.persist(vm.getVmReservation());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java
new file mode 100644
index 0000000..bb482d3
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java
@@ -0,0 +1,15 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+import java.util.List;
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMNetworkMapVO;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface VMNetworkMapDao extends GenericDao<VMNetworkMapVO, Long>{
+
+    void persist(long vmId, List<Long> networks);
+    
+    List<Long> getNetworks(long vmId);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java
new file mode 100644
index 0000000..08d2ab2
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java
@@ -0,0 +1,69 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.PostConstruct;
+import javax.ejb.Local;
+import javax.inject.Inject;
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMNetworkMapVO;
+import org.springframework.stereotype.Component;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = { VMNetworkMapDao.class })
+public class VMNetworkMapDaoImpl extends GenericDaoBase<VMNetworkMapVO, Long> implements VMNetworkMapDao {
+
+    protected SearchBuilder<VMNetworkMapVO> VmIdSearch;
+    
+    @Inject
+    protected NetworkDao _networkDao;
+    
+    public VMNetworkMapDaoImpl() {
+    }
+    
+    @PostConstruct
+    public void init() {
+        VmIdSearch = createSearchBuilder();
+        VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ);
+        VmIdSearch.done();
+        
+    }
+    
+    @Override
+    public void persist(long vmId, List<Long> networks) {
+        Transaction txn = Transaction.currentTxn();
+
+        txn.start();
+        SearchCriteria<VMNetworkMapVO> sc = VmIdSearch.create();
+        sc.setParameters("vmId", vmId);
+        expunge(sc);
+        
+        for (Long networkId : networks) {
+            VMNetworkMapVO vo = new VMNetworkMapVO(vmId, networkId);
+            persist(vo);
+        }
+
+        txn.commit();
+    }
+
+    @Override
+    public List<Long> getNetworks(long vmId) {
+        
+        SearchCriteria<VMNetworkMapVO> sc = VmIdSearch.create();
+        sc.setParameters("vmId", vmId);
+        
+        List<VMNetworkMapVO> results = search(sc, null);
+        List<Long> networks = new ArrayList<Long>(results.size());
+        for (VMNetworkMapVO result : results) {
+            networks.add(result.getNetworkId());
+        }
+
+        return networks;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDao.java
new file mode 100644
index 0000000..06f308d
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDao.java
@@ -0,0 +1,18 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+
+import java.util.Map;
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface VMReservationDao extends GenericDao<VMReservationVO, Long>{
+    
+    VMReservationVO findByVmId(long vmId);
+
+    void loadVolumeReservation(VMReservationVO reservation);
+    
+    VMReservationVO findByReservationId(String reservationId);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDaoImpl.java
new file mode 100644
index 0000000..10f5610
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDaoImpl.java
@@ -0,0 +1,93 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO;
+import org.apache.cloudstack.engine.cloud.entity.api.db.VolumeReservationVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.host.dao.HostTagsDaoImpl;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = { VMReservationDao.class })
+public class VMReservationDaoImpl extends GenericDaoBase<VMReservationVO, Long> implements VMReservationDao {
+
+    protected SearchBuilder<VMReservationVO> VmIdSearch;
+    
+    @Inject protected VolumeReservationDaoImpl _volumeReservationDao;
+    
+    public VMReservationDaoImpl() {
+    }
+    
+    @PostConstruct
+    public void init() {
+        VmIdSearch = createSearchBuilder();
+        VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ);
+        VmIdSearch.done();
+    }
+    
+    @Override
+    public VMReservationVO findByVmId(long vmId) {
+        SearchCriteria<VMReservationVO> sc = VmIdSearch.create("vmId", vmId);
+        VMReservationVO vmRes = findOneBy(sc);
+        loadVolumeReservation(vmRes);
+        return vmRes;
+    }
+    
+    
+    @Override
+    public void loadVolumeReservation(VMReservationVO reservation){
+        List<VolumeReservationVO> volumeResList = _volumeReservationDao.listVolumeReservation(reservation.getId());
+        Map<Long, Long> volumeReservationMap = new HashMap<Long,Long>();
+        
+        for(VolumeReservationVO res : volumeResList){
+            volumeReservationMap.put(res.getVolumeId(), res.getPoolId());
+        }
+        reservation.setVolumeReservation(volumeReservationMap);
+    }
+    
+    @Override
+    @DB
+    public VMReservationVO persist(VMReservationVO reservation) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+
+        VMReservationVO dbVO = super.persist(reservation);
+
+        saveVolumeReservation(reservation);
+        loadVolumeReservation(dbVO);
+
+        txn.commit();
+
+        return dbVO;
+    }
+
+    private void saveVolumeReservation(VMReservationVO reservation) {
+        
+        for(Long volumeId : reservation.getVolumeReservation().keySet()){
+            VolumeReservationVO volumeReservation = new VolumeReservationVO(reservation.getVmId(), volumeId, reservation.getVolumeReservation().get(volumeId));
+            _volumeReservationDao.persist(volumeReservation);
+        }
+        
+    }
+
+    @Override
+    public VMReservationVO findByReservationId(String reservationId) {
+        VMReservationVO vmRes = super.findByUuid(reservationId);
+        loadVolumeReservation(vmRes);
+        return vmRes;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDao.java
new file mode 100644
index 0000000..8761119
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDao.java
@@ -0,0 +1,15 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+import java.util.List;
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMRootDiskTagVO;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface VMRootDiskTagDao extends GenericDao<VMRootDiskTagVO, Long>{
+
+    void persist(long vmId, List<String> diskTags);
+    
+    List<String> getRootDiskTags(long vmId);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDaoImpl.java
new file mode 100644
index 0000000..b65993d
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDaoImpl.java
@@ -0,0 +1,70 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Local;
+
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMRootDiskTagVO;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = { VMRootDiskTagDao.class })
+public class VMRootDiskTagDaoImpl extends GenericDaoBase<VMRootDiskTagVO, Long> implements VMRootDiskTagDao {
+
+    protected SearchBuilder<VMRootDiskTagVO> VmIdSearch;
+    
+    public VMRootDiskTagDaoImpl() {
+    }
+    
+    @PostConstruct
+    public void init() {
+        VmIdSearch = createSearchBuilder();
+        VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ);
+        VmIdSearch.done();
+        
+    }
+    
+    @Override
+    public void persist(long vmId, List<String> rootDiskTags) {
+        Transaction txn = Transaction.currentTxn();
+
+        txn.start();
+        SearchCriteria<VMRootDiskTagVO> sc = VmIdSearch.create();
+        sc.setParameters("vmId", vmId);
+        expunge(sc);
+        
+        for (String tag : rootDiskTags) {
+            tag = tag.trim();
+            if(tag.length() > 0) {
+                VMRootDiskTagVO vo = new VMRootDiskTagVO(vmId, tag);
+                persist(vo);
+            }
+        }
+        txn.commit();
+    }
+
+
+    @Override
+    public List<String> getRootDiskTags(long vmId) {
+        SearchCriteria<VMRootDiskTagVO> sc = VmIdSearch.create();
+        sc.setParameters("vmId", vmId);
+        
+        List<VMRootDiskTagVO> results = search(sc, null);
+        List<String> computeTags = new ArrayList<String>(results.size());
+        for (VMRootDiskTagVO result : results) {
+            computeTags.add(result.getRootDiskTag());
+        }
+        return computeTags;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDao.java
new file mode 100644
index 0000000..d4aee47
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDao.java
@@ -0,0 +1,15 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+import java.util.List;
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VolumeReservationVO;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface VolumeReservationDao extends GenericDao<VolumeReservationVO, Long>{
+
+   VolumeReservationVO findByVmId(long vmId);
+   
+   List<VolumeReservationVO> listVolumeReservation(long vmReservationId);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDaoImpl.java
new file mode 100644
index 0000000..ea96eda
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDaoImpl.java
@@ -0,0 +1,52 @@
+package org.apache.cloudstack.engine.cloud.entity.api.db.dao;
+
+
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO;
+import org.apache.cloudstack.engine.cloud.entity.api.db.VolumeReservationVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.host.dao.HostTagsDaoImpl;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+@Component
+@Local(value = { VolumeReservationDao.class })
+public class VolumeReservationDaoImpl extends GenericDaoBase<VolumeReservationVO, Long> implements VolumeReservationDao {
+
+    protected SearchBuilder<VolumeReservationVO> VmIdSearch;
+    protected SearchBuilder<VolumeReservationVO> VmReservationIdSearch;
+    
+    public VolumeReservationDaoImpl() {
+    }
+    
+    @PostConstruct
+    public void init() {
+        VmIdSearch = createSearchBuilder();
+        VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ);
+        VmIdSearch.done();
+        
+        VmReservationIdSearch = createSearchBuilder();
+        VmReservationIdSearch.and("vmReservationId", VmReservationIdSearch.entity().geVmReservationId(), SearchCriteria.Op.EQ);
+        VmReservationIdSearch.done();
+    }
+    
+    @Override
+    public VolumeReservationVO findByVmId(long vmId) {
+        SearchCriteria<VolumeReservationVO> sc = VmIdSearch.create("vmId", vmId);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public List<VolumeReservationVO> listVolumeReservation(long vmReservationId) {
+        SearchCriteria<VolumeReservationVO> sc = VmReservationIdSearch.create("vmReservationId", vmReservationId);
+        return listBy(sc);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java
index dc5b57f..a659c5d 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java
@@ -55,7 +55,7 @@ public class DataCenterResourceManagerImpl implements DataCenterResourceManager
 
 	@Override
 	public DataCenterVO loadDataCenter(String dataCenterId) {
-    	DataCenterVO dataCenterVO = _dataCenterDao.findByUUID(dataCenterId);
+    	DataCenterVO dataCenterVO = _dataCenterDao.findByUuid(dataCenterId);
     	if(dataCenterVO == null){
     		throw new InvalidParameterValueException("Zone does not exist");
     	}
@@ -86,7 +86,7 @@ public class DataCenterResourceManagerImpl implements DataCenterResourceManager
 
 	@Override
 	public HostPodVO loadPod(String uuid) {
-		HostPodVO pod = _podDao.findByUUID(uuid);
+		HostPodVO pod = _podDao.findByUuid(uuid);
     	if(pod == null){
     		throw new InvalidParameterValueException("Pod does not exist");
     	}
@@ -95,7 +95,7 @@ public class DataCenterResourceManagerImpl implements DataCenterResourceManager
 
 	@Override
 	public ClusterVO loadCluster(String uuid) {
-		ClusterVO cluster = _clusterDao.findByUUID(uuid);
+		ClusterVO cluster = _clusterDao.findByUuid(uuid);
     	if(cluster == null){
     		throw new InvalidParameterValueException("Pod does not exist");
     	}
@@ -114,7 +114,7 @@ public class DataCenterResourceManagerImpl implements DataCenterResourceManager
 
 	@Override
 	public HostVO loadHost(String uuid) {
-		HostVO host = _hostDao.findByUUID(uuid);
+		HostVO host = _hostDao.findByUuid(uuid);
     	if(host == null){
     		throw new InvalidParameterValueException("Host does not exist");
     	}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java
index 771b64d..dba4734 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java
@@ -34,5 +34,4 @@ public interface ClusterDao extends GenericDao<ClusterVO, Long>, StateDao<DataCe
     Map<Long, List<Long>> getPodClusterIdMap(List<Long> clusterIds);
     List<Long> listDisabledClusters(long zoneId, Long podId);
     List<Long> listClustersWithDisabledPods(long zoneId);
-	ClusterVO findByUUID(String uuid);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
index f33c673..3ab6cee 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
@@ -252,20 +252,12 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
         return result;
     }
 
-
-    @Override
-    public ClusterVO findByUUID(String uuid) {
-        SearchCriteria<ClusterVO> sc = UUIDSearch.create();
-        sc.setParameters("uuid", uuid);
-        return findOneBy(sc);
-    }
-
-    @Override
-    public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity clusterEntity, Object data) {
-
-        ClusterVO vo = findById(clusterEntity.getId());
-
-        Date oldUpdatedTime = vo.getLastUpdated();
+	@Override
+	public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity clusterEntity, Object data) {
+		
+		ClusterVO vo = findById(clusterEntity.getId());
+		
+		Date oldUpdatedTime = vo.getLastUpdated();
 
         SearchCriteria<ClusterVO> sc = StateChangeSearch.create();
         sc.setParameters("id", vo.getId());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDao.java
index f34533e..ce4ccfc 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDao.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDao.java
@@ -52,5 +52,4 @@ public interface DataCenterDao extends GenericDao<DataCenterVO, Long>, StateDao<
 
 	List<DataCenterVO> findByKeyword(String keyword);
 
-	DataCenterVO findByUUID(String uuid);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java
index 3a0d2c8..8329143 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java
@@ -75,13 +75,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
         return findOneBy(sc);
     }
 
-    @Override
-    public DataCenterVO findByUUID(String uuid) {
-        SearchCriteria<DataCenterVO> sc = UUIDSearch.create();
-        sc.setParameters("uuid", uuid);
-        return findOneBy(sc);
-    }
-
+    
     @Override
     public DataCenterVO findByToken(String zoneToken){
         SearchCriteria<DataCenterVO> sc = TokenSearch.create();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDao.java
index e3437af..fed7c6e 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDao.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDao.java
@@ -82,6 +82,4 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<DataCenterRe
      * @return
      */
     List<HostVO> listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag);
-
-	HostVO findByUUID(String uuid);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java
index f33bc21..dbbf342 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java
@@ -725,94 +725,85 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
         return findOneBy(sc);
     }
 
-    @Override
-    public List<HostVO> findHypervisorHostInCluster(long clusterId) {
-        SearchCriteria<HostVO> sc = TypeClusterStatusSearch.create();
-        sc.setParameters("type", Host.Type.Routing);
-        sc.setParameters("cluster", clusterId);
-        sc.setParameters("status", Status.Up);
-        sc.setParameters("resourceState", ResourceState.Enabled);
-
-        return listBy(sc);
-    }
-
-    @Override
-    public List<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> lockRows(
-            SearchCriteria<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> sc,
-            Filter filter, boolean exclusive) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO lockOneRandomRow(
-            SearchCriteria<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> sc,
-            boolean exclusive) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    @Override
-    public List<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> search(
-            SearchCriteria<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> sc,
-            Filter filter) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public List<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> search(
-            SearchCriteria<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> sc,
-            Filter filter, boolean enable_query_cache) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public List<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> searchIncludingRemoved(
-            SearchCriteria<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> sc,
-            Filter filter, Boolean lock, boolean cache) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public List<HostVO> searchIncludingRemoved(
-            SearchCriteria<HostVO> sc,
-            Filter filter, Boolean lock, boolean cache,
-            boolean enable_query_cache) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    @Override
-    public int remove(
-            SearchCriteria<HostVO> sc) {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-    @Override
-    public int expunge(SearchCriteria<HostVO> sc) {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-    @Override
-    public HostVO findOneBy(SearchCriteria<HostVO> sc) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-
-    @Override
-    public HostVO findByUUID(String uuid) {
-        SearchCriteria<HostVO> sc = UUIDSearch.create();
-        sc.setParameters("uuid", uuid);
-        return findOneBy(sc);
-    }
+	@Override
+	public List<HostVO> findHypervisorHostInCluster(long clusterId) {
+		 SearchCriteria<HostVO> sc = TypeClusterStatusSearch.create();
+		 sc.setParameters("type", Host.Type.Routing);
+		 sc.setParameters("cluster", clusterId);
+		 sc.setParameters("status", Status.Up);
+		 sc.setParameters("resourceState", ResourceState.Enabled);
+		
+		return listBy(sc);
+	}
+
+	@Override
+	public List<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> lockRows(
+			SearchCriteria<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> sc,
+			Filter filter, boolean exclusive) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO lockOneRandomRow(
+			SearchCriteria<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> sc,
+			boolean exclusive) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+
+	@Override
+	public List<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> search(
+			SearchCriteria<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> sc,
+			Filter filter) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public List<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> search(
+			SearchCriteria<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> sc,
+			Filter filter, boolean enable_query_cache) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public List<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> searchIncludingRemoved(
+			SearchCriteria<org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO> sc,
+			Filter filter, Boolean lock, boolean cache) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public List<HostVO> searchIncludingRemoved(
+			SearchCriteria<HostVO> sc,
+			Filter filter, Boolean lock, boolean cache,
+			boolean enable_query_cache) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+
+	@Override
+	public int remove(
+			SearchCriteria<HostVO> sc) {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public int expunge(SearchCriteria<HostVO> sc) {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public HostVO findOneBy(SearchCriteria<HostVO> sc) {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java
index bfdbaae..a5482ca 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java
@@ -30,7 +30,4 @@ public interface HostPodDao extends GenericDao<HostPodVO, Long>, StateDao<DataCe
 	public HashMap<Long, List<Object>> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip);
 
     public List<Long> listDisabledPods(long zoneId);
-
-	public HostPodVO findByUUID(String uuid);
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/94e8090b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
index b39fdc3..0bb270c 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
@@ -146,13 +146,7 @@ public class HostPodDaoImpl extends GenericDaoBase<HostPodVO, Long> implements H
         return customSearch(sc, null);
     }
 
-	@Override
-	public HostPodVO findByUUID(String uuid) {
-    	SearchCriteria<HostPodVO> sc = UUIDSearch.create();
-    	sc.setParameters("uuid", uuid);
-        return findOneBy(sc);
-	}
-	
+
 	@Override
 	public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity podEntity, Object data) {