From e37732c4deb6810bdc1c2f1166bc95888f3ee045 Mon Sep 17 00:00:00 2001 From: prachi Date: Wed, 22 Feb 2012 16:29:48 -0800 Subject: [PATCH] Bug 13766 - VMs are still running after disabling the zone Reviewed-by: Sheng Yang Changes: - Do not check if allocation_state is 'Enabled' in planner if the caller is Root Admin. - This should let Root Admin create a VM in a disabled Zone. --- .../cloud/deploy/DataCenterDeployment.java | 13 +++++++ api/src/com/cloud/deploy/DeploymentPlan.java | 3 ++ .../src/com/cloud/deploy/FirstFitPlanner.java | 38 +++++++++++++------ .../cloud/vm/VirtualMachineManagerImpl.java | 8 ++-- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/api/src/com/cloud/deploy/DataCenterDeployment.java b/api/src/com/cloud/deploy/DataCenterDeployment.java index 222ab9a23cc..bac8e841bb6 100644 --- a/api/src/com/cloud/deploy/DataCenterDeployment.java +++ b/api/src/com/cloud/deploy/DataCenterDeployment.java @@ -18,6 +18,7 @@ package com.cloud.deploy; import com.cloud.deploy.DeploymentPlanner.ExcludeList; +import com.cloud.vm.ReservationContext; public class DataCenterDeployment implements DeploymentPlan { long _dcId; @@ -28,18 +29,24 @@ public class DataCenterDeployment implements DeploymentPlan { Long _physicalNetworkId; ExcludeList _avoids = null; boolean _recreateDisks; + ReservationContext _context; public DataCenterDeployment(long dataCenterId) { this(dataCenterId, null, null, null, null, null); } public DataCenterDeployment(long dataCenterId, Long podId, Long clusterId, Long hostId, Long poolId, Long physicalNetworkId) { + this(dataCenterId, podId, clusterId, hostId, poolId, physicalNetworkId, null); + } + + public DataCenterDeployment(long dataCenterId, Long podId, Long clusterId, Long hostId, Long poolId, Long physicalNetworkId, ReservationContext context) { _dcId = dataCenterId; _podId = podId; _clusterId = clusterId; _hostId = hostId; _poolId = poolId; _physicalNetworkId = physicalNetworkId; + _context = context; } @Override @@ -81,4 +88,10 @@ public class DataCenterDeployment implements DeploymentPlan { public Long getPhysicalNetworkId() { return _physicalNetworkId; } + + @Override + public ReservationContext getReservationContext() { + return _context; + } + } diff --git a/api/src/com/cloud/deploy/DeploymentPlan.java b/api/src/com/cloud/deploy/DeploymentPlan.java index 91ad5825ba5..1f90635d2d2 100644 --- a/api/src/com/cloud/deploy/DeploymentPlan.java +++ b/api/src/com/cloud/deploy/DeploymentPlan.java @@ -18,6 +18,7 @@ package com.cloud.deploy; import com.cloud.deploy.DeploymentPlanner.ExcludeList; +import com.cloud.vm.ReservationContext; /** * Describes how a VM should be deployed. @@ -65,4 +66,6 @@ public interface DeploymentPlan { public ExcludeList getAvoids(); Long getPhysicalNetworkId(); + + ReservationContext getReservationContext(); } diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java index 1424f753337..a11c0bde033 100755 --- a/server/src/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/com/cloud/deploy/FirstFitPlanner.java @@ -69,11 +69,13 @@ import com.cloud.storage.dao.GuestOSDao; import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.storage.dao.VolumeDao; +import com.cloud.user.AccountManager; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.component.Adapters; import com.cloud.utils.component.Inject; import com.cloud.vm.DiskProfile; +import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.UserVmDao; @@ -97,6 +99,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { @Inject protected ConfigurationDao _configDao; @Inject protected StoragePoolDao _storagePoolDao; @Inject protected CapacityDao _capacityDao; + @Inject protected AccountManager _accountMgr; @Inject(adapter=StoragePoolAllocator.class) protected Adapters _storagePoolAllocators; @@ -152,7 +155,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { } //search for storage under the zone, pod, cluster of the host. - DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), hostIdSpecified, plan.getPoolId(), null); + DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), hostIdSpecified, plan.getPoolId(), null, plan.getReservationContext()); Pair>, List> result = findSuitablePoolsForVolumes(vmProfile, lastPlan, avoid, HostAllocator.RETURN_UPTO_ALL); Map> suitableVolumeStoragePools = result.first(); @@ -507,7 +510,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { s_logger.debug("Checking resources in Cluster: "+clusterId + " under Pod: "+clusterVO.getPodId()); //search for resources(hosts and storage) under this zone, pod, cluster. - DataCenterDeployment potentialPlan = new DataCenterDeployment(plan.getDataCenterId(), clusterVO.getPodId(), clusterVO.getId(), null, plan.getPoolId(), null); + DataCenterDeployment potentialPlan = new DataCenterDeployment(plan.getDataCenterId(), clusterVO.getPodId(), clusterVO.getId(), null, plan.getPoolId(), null, plan.getReservationContext()); //find suitable hosts under this cluster, need as many hosts as we get. List suitableHosts = findSuitableHosts(vmProfile, potentialPlan, avoid, HostAllocator.RETURN_UPTO_ALL); @@ -731,16 +734,18 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { if(s_logger.isDebugEnabled()){ s_logger.debug("We need to allocate new storagepool for this volume"); } - if(!isEnabledForAllocation(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId())){ - if(s_logger.isDebugEnabled()){ - s_logger.debug("Cannot allocate new storagepool for this volume in this cluster, allocation state is disabled"); - s_logger.debug("Cannot deploy to this specified plan, allocation state is disabled, returning."); + if(!isRootAdmin(plan.getReservationContext())){ + if(!isEnabledForAllocation(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId())){ + if(s_logger.isDebugEnabled()){ + s_logger.debug("Cannot allocate new storagepool for this volume in this cluster, allocation state is disabled"); + s_logger.debug("Cannot deploy to this specified plan, allocation state is disabled, returning."); + } + //Cannot find suitable storage pools under this cluster for this volume since allocation_state is disabled. + //- remove any suitable pools found for other volumes. + //All volumes should get suitable pools under this cluster; else we cant use this cluster. + suitableVolumeStoragePools.clear(); + break; } - //Cannot find suitable storage pools under this cluster for this volume since allocation_state is disabled. - //- remove any suitable pools found for other volumes. - //All volumes should get suitable pools under this cluster; else we cant use this cluster. - suitableVolumeStoragePools.clear(); - break; } s_logger.debug("Calling StoragePoolAllocators to find suitable pools"); @@ -798,6 +803,17 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { } + private boolean isRootAdmin(ReservationContext reservationContext) { + if(reservationContext != null){ + if(reservationContext.getAccount() != null){ + return _accountMgr.isRootAdmin(reservationContext.getAccount().getType()); + }else{ + return false; + } + } + return false; + } + @Override public boolean check(VirtualMachineProfile vm, DeploymentPlan plan, DeployDestination dest, ExcludeList exclude) { diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 199b6ae6fa2..1d820f0eb97 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -619,13 +619,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene if (s_logger.isDebugEnabled()) { s_logger.debug("Trying to deploy VM, vm has dcId: " + vm.getDataCenterIdToDeployIn() + " and podId: " + vm.getPodIdToDeployIn()); } - DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterIdToDeployIn(), vm.getPodIdToDeployIn(), null, null, null, null); + DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterIdToDeployIn(), vm.getPodIdToDeployIn(), null, null, null, null, ctx); if(planToDeploy != null && planToDeploy.getDataCenterId() != 0){ if (s_logger.isDebugEnabled()) { s_logger.debug("advanceStart: DeploymentPlan is provided, using dcId:" + planToDeploy.getDataCenterId() + ", podId: " + planToDeploy.getPodId() + ", clusterId: " + planToDeploy.getClusterId() + ", hostId: " + planToDeploy.getHostId() + ", poolId: " + planToDeploy.getPoolId()); } - plan = (DataCenterDeployment) planToDeploy; + plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId(), ctx); } HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType()); @@ -690,9 +690,9 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene + vm, Cluster.class, clusterIdSpecified); } } - plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null); + plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null, ctx); }else{ - plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null); + plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, ctx); if (s_logger.isDebugEnabled()) { s_logger.debug(vol + " is READY, changing deployment plan to use this pool's dcId: " + rootVolDcId + " , podId: " + rootVolPodId + " , and clusterId: " + rootVolClusterId); }