mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-15 18:12:35 +01:00
CLOUDSTACK-2107
If the scaling up fails on the host the vm is running on try to migrate it to other hosts in the cluster and try scaling. CLOUDSTACK-3349 For deciding the host in the cluster try the new deployment manager now Signed off by : nitin mehta<nitin.mehta@citrix.com>
This commit is contained in:
parent
4e823e3a3e
commit
90a15bfff6
@ -1180,28 +1180,34 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
|
||||
boolean success = false;
|
||||
if(vmInstance.getState().equals(State.Running)){
|
||||
int retry = _scaleRetry;
|
||||
ExcludeList excludes = new ExcludeList();
|
||||
boolean enableDynamicallyScaleVm = Boolean.parseBoolean(_configServer.getConfigValue(Config.EnableDynamicallyScaleVm.key(), Config.ConfigurationParameterScope.zone.toString(), vmInstance.getDataCenterId()));
|
||||
if(!enableDynamicallyScaleVm){
|
||||
throw new PermissionDeniedException("Dynamically scaling virtual machines is disabled for this zone, please contact your admin");
|
||||
}
|
||||
|
||||
// Increment CPU and Memory count accordingly.
|
||||
if (newCpu > currentCpu) {
|
||||
_resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.cpu, new Long (newCpu - currentCpu));
|
||||
}
|
||||
if (newMemory > currentMemory) {
|
||||
_resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.memory, new Long (newMemory - currentMemory));
|
||||
}
|
||||
|
||||
while (retry-- != 0) { // It's != so that it can match -1.
|
||||
try{
|
||||
// #1 Check existing host has capacity
|
||||
boolean existingHostHasCapacity = _capacityMgr.checkIfHostHasCapacity(vmInstance.getHostId(), newServiceOffering.getSpeed() - currentServiceOffering.getSpeed(),
|
||||
(newServiceOffering.getRamSize() - currentServiceOffering.getRamSize()) * 1024L * 1024L, false, ApiDBUtils.getCpuOverprovisioningFactor(), 1f, false); // TO DO fill it with mem.
|
||||
boolean existingHostHasCapacity = false;
|
||||
|
||||
// #2 migrate the vm if host doesn't have capacity
|
||||
// Increment CPU and Memory count accordingly.
|
||||
if (newCpu > currentCpu) {
|
||||
_resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.cpu, new Long (newCpu - currentCpu));
|
||||
}
|
||||
if (newMemory > currentMemory) {
|
||||
_resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.memory, new Long (newMemory - currentMemory));
|
||||
}
|
||||
|
||||
// #1 Check existing host has capacity
|
||||
if( !excludes.shouldAvoid(ApiDBUtils.findHostById(vmInstance.getHostId())) ){
|
||||
existingHostHasCapacity = _capacityMgr.checkIfHostHasCapacity(vmInstance.getHostId(), newServiceOffering.getSpeed() - currentServiceOffering.getSpeed(),
|
||||
(newServiceOffering.getRamSize() - currentServiceOffering.getRamSize()) * 1024L * 1024L, false, ApiDBUtils.getCpuOverprovisioningFactor(), 1f, false); // TO DO fill it with mem.
|
||||
excludes.addHost(vmInstance.getHostId());
|
||||
}
|
||||
|
||||
// #2 migrate the vm if host doesn't have capacity or is in avoid set
|
||||
if (!existingHostHasCapacity){
|
||||
vmInstance = _itMgr.findHostAndMigrate(vmInstance.getType(), vmInstance, newServiceOfferingId);
|
||||
vmInstance = _itMgr.findHostAndMigrate(vmInstance.getType(), vmInstance, newServiceOfferingId, excludes);
|
||||
}
|
||||
|
||||
// #3 scale the vm now
|
||||
@ -1220,7 +1226,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
|
||||
s_logger.warn("Received exception while scaling ",e);
|
||||
} catch (ManagementServerException e) {
|
||||
s_logger.warn("Received exception while scaling ",e);
|
||||
}finally{
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Received exception while scaling ",e);
|
||||
}
|
||||
finally{
|
||||
if(!success){
|
||||
_itMgr.upgradeVmDb(vmId, currentServiceOffering.getId()); // rollback
|
||||
// Decrement CPU and Memory count accordingly.
|
||||
|
||||
@ -20,6 +20,7 @@ import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.deploy.DeploymentPlanner;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
|
||||
import com.cloud.agent.api.to.NicTO;
|
||||
@ -194,7 +195,7 @@ public interface VirtualMachineManager extends Manager {
|
||||
VMInstanceVO reConfigureVm(VMInstanceVO vm, ServiceOffering newServiceOffering, boolean sameHost)
|
||||
throws ResourceUnavailableException, ConcurrentOperationException;
|
||||
|
||||
VMInstanceVO findHostAndMigrate(VirtualMachine.Type vmType, VMInstanceVO vm, Long newSvcOfferingId) throws InsufficientCapacityException,
|
||||
VMInstanceVO findHostAndMigrate(VirtualMachine.Type vmType, VMInstanceVO vm, Long newSvcOfferingId, DeploymentPlanner.ExcludeList excludeHostList) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException,
|
||||
VirtualMachineMigrationException, ManagementServerException;
|
||||
|
||||
|
||||
@ -3007,7 +3007,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMInstanceVO findHostAndMigrate(VirtualMachine.Type vmType, VMInstanceVO vm, Long newSvcOfferingId)
|
||||
public VMInstanceVO findHostAndMigrate(VirtualMachine.Type vmType, VMInstanceVO vm, Long newSvcOfferingId, ExcludeList excludes)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, VirtualMachineMigrationException, ManagementServerException {
|
||||
|
||||
VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
|
||||
@ -3019,27 +3019,22 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
}
|
||||
Host host = _hostDao.findById(srcHostId);
|
||||
DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, null, null);
|
||||
ExcludeList excludes = new ExcludeList();
|
||||
excludes.addHost(vm.getHostId());
|
||||
vm.setServiceOfferingId(newSvcOfferingId); // Need to find the destination host based on new svc offering
|
||||
|
||||
DeployDestination dest = null;
|
||||
|
||||
for (DeploymentPlanner planner : _planners) {
|
||||
if (planner.canHandle(profile, plan, excludes)) {
|
||||
dest = planner.plan(profile, plan, excludes);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
dest = _dpMgr.planDeployment(profile, plan, excludes);
|
||||
} catch (AffinityConflictException e2) {
|
||||
s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2);
|
||||
throw new CloudRuntimeException(
|
||||
"Unable to create deployment, affinity rules associted to the VM conflict");
|
||||
}
|
||||
|
||||
if (dest != null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Planner " + planner + " found " + dest + " for scaling the vm to.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (dest != null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Planner " + planner + " was unable to find anything.");
|
||||
s_logger.debug(" Found " + dest + " for scaling the vm to.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ import java.util.Map;
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.deploy.DeploymentPlanner;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -281,7 +282,7 @@ public class MockVirtualMachineManagerImpl extends ManagerBase implements Virtua
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMInstanceVO findHostAndMigrate(VirtualMachine.Type vmType, VMInstanceVO vm, Long newSvcOfferingId) throws InsufficientCapacityException,
|
||||
public VMInstanceVO findHostAndMigrate(Type vmType, VMInstanceVO vm, Long newSvcOfferingId, DeploymentPlanner.ExcludeList excludeHostList) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException,
|
||||
VirtualMachineMigrationException, ManagementServerException{
|
||||
return null;
|
||||
|
||||
@ -26,6 +26,7 @@ import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlanner;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.server.ConfigurationServer;
|
||||
@ -45,9 +46,6 @@ import com.cloud.agent.api.MigrateWithStorageCompleteAnswer;
|
||||
import com.cloud.agent.api.MigrateWithStorageCompleteCommand;
|
||||
import com.cloud.agent.api.CheckVirtualMachineAnswer;
|
||||
import com.cloud.agent.api.CheckVirtualMachineCommand;
|
||||
import com.cloud.capacity.CapacityManager;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
@ -56,16 +54,12 @@ import com.cloud.exception.ManagementServerException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.VirtualMachineMigrationException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.HypervisorGuru;
|
||||
import com.cloud.hypervisor.HypervisorGuruManager;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.StoragePoolHostVO;
|
||||
import com.cloud.storage.VolumeManager;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.DiskOfferingDao;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
@ -77,10 +71,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.UserVmDetailsDao;
|
||||
import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd;
|
||||
import org.apache.cloudstack.api.command.user.vm.ScaleVMCmd;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.cloud.vm.snapshot.VMSnapshotManager;
|
||||
import com.cloud.vm.VirtualMachine.Event;
|
||||
@ -97,7 +88,6 @@ import org.mockito.Spy;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
@ -281,7 +271,8 @@ public class VirtualMachineManagerImplTest {
|
||||
|
||||
when(_vmInstance.getHostId()).thenReturn(null);
|
||||
when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
|
||||
_vmMgr.findHostAndMigrate(VirtualMachine.Type.User, _vmInstance, 2l);
|
||||
DeploymentPlanner.ExcludeList excludeHostList = new DeploymentPlanner.ExcludeList();
|
||||
_vmMgr.findHostAndMigrate(VirtualMachine.Type.User, _vmInstance, 2l, excludeHostList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user