mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Bug 9666 - hostId and spoolId overlap in op_host_capacity table
Changes: - When a host connects, we check if it has a CPU and RAM entry in capacity table. If the entry is found, the values are updated if possible. If the entry is not found a new one is inserted. - The searchCriteria used to check if CPU entry is present was wrong. We were passing in a criteria which did not specify capacityType. So for hostId >= 200, the serach would return capacity entries of storage pools also since poolIDs start from 200 onwards. - Since an entry was found (although the wrong one), we tried to update it. But update does not happen since the capacity ranges dont match. And a new insert for CPU also does not happen since an entry is found. - So as a result CPU entries are never inserted in the table for hostIds >=200 - As a fix, corrected the search criteria. - During VM deployment, when the entry is not found, we get a NPE. Added a null check to avoid that.
This commit is contained in:
parent
c6965f06cc
commit
1d4a59ce73
@ -74,7 +74,6 @@ import com.cloud.agent.manager.allocator.PodAllocator;
|
|||||||
import com.cloud.agent.transport.Request;
|
import com.cloud.agent.transport.Request;
|
||||||
import com.cloud.agent.transport.Response;
|
import com.cloud.agent.transport.Response;
|
||||||
import com.cloud.alert.AlertManager;
|
import com.cloud.alert.AlertManager;
|
||||||
import com.cloud.api.ApiConstants;
|
|
||||||
import com.cloud.api.commands.AddClusterCmd;
|
import com.cloud.api.commands.AddClusterCmd;
|
||||||
import com.cloud.api.commands.AddHostCmd;
|
import com.cloud.api.commands.AddHostCmd;
|
||||||
import com.cloud.api.commands.AddSecondaryStorageCmd;
|
import com.cloud.api.commands.AddSecondaryStorageCmd;
|
||||||
@ -541,7 +540,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected AgentAttache handleDirectConnect(ServerResource resource, StartupCommand[] startup, Map<String, String> details, boolean old, List<String> hostTags, String allocationState)
|
protected AgentAttache handleDirectConnect(ServerResource resource, StartupCommand[] startup, Map<String, String> details, boolean old, List<String> hostTags, String allocationState)
|
||||||
throws ConnectionException {
|
throws ConnectionException {
|
||||||
if (startup == null) {
|
if (startup == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -567,7 +566,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||||||
String url = cmd.getUrl();
|
String url = cmd.getUrl();
|
||||||
String username = cmd.getUsername();
|
String username = cmd.getUsername();
|
||||||
String password = cmd.getPassword();
|
String password = cmd.getPassword();
|
||||||
|
|
||||||
url = URLDecoder.decode(url);
|
url = URLDecoder.decode(url);
|
||||||
|
|
||||||
URI uri = null;
|
URI uri = null;
|
||||||
@ -807,7 +806,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HostVO> discoverHosts(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, String hypervisorType, List<String> hostTags)
|
public List<HostVO> discoverHosts(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, String hypervisorType, List<String> hostTags)
|
||||||
throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
|
throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
|
||||||
return discoverHostsFull(dcId, podId, clusterId, clusterName, url, username, password, hypervisorType, hostTags, null, null);
|
return discoverHostsFull(dcId, podId, clusterId, clusterName, url, username, password, hypervisorType, hostTags, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1162,7 +1161,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||||||
}
|
}
|
||||||
if (!success) {
|
if (!success) {
|
||||||
String msg = "Unable to eject host " + host.getGuid() + " due to there is no host up in this cluster, please execute xe pool-eject host-uuid=" + host.getGuid()
|
String msg = "Unable to eject host " + host.getGuid() + " due to there is no host up in this cluster, please execute xe pool-eject host-uuid=" + host.getGuid()
|
||||||
+ "in this host " + host.getPrivateIpAddress();
|
+ "in this host " + host.getPrivateIpAddress();
|
||||||
s_logger.warn(msg);
|
s_logger.warn(msg);
|
||||||
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Unable to eject host " + host.getGuid(), msg);
|
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Unable to eject host " + host.getGuid(), msg);
|
||||||
}
|
}
|
||||||
@ -2271,7 +2270,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HostVO createHost(final StartupCommand startup, ServerResource resource, Map<String, String> details, boolean directFirst, List<String> hostTags, String allocationState)
|
public HostVO createHost(final StartupCommand startup, ServerResource resource, Map<String, String> details, boolean directFirst, List<String> hostTags, String allocationState)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
Host.Type type = null;
|
Host.Type type = null;
|
||||||
|
|
||||||
if (startup instanceof StartupStorageCommand) {
|
if (startup instanceof StartupStorageCommand) {
|
||||||
@ -2394,7 +2393,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HostVO createHost(final StartupCommand[] startup, ServerResource resource, Map<String, String> details, boolean directFirst, List<String> hostTags, String allocationState)
|
public HostVO createHost(final StartupCommand[] startup, ServerResource resource, Map<String, String> details, boolean directFirst, List<String> hostTags, String allocationState)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
StartupCommand firstCmd = startup[0];
|
StartupCommand firstCmd = startup[0];
|
||||||
HostVO result = createHost(firstCmd, resource, details, directFirst, hostTags, allocationState);
|
HostVO result = createHost(firstCmd, resource, details, directFirst, hostTags, allocationState);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
@ -2735,7 +2734,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||||||
capacityCPU.addAnd("dataCenterId", SearchCriteria.Op.EQ, server.getDataCenterId());
|
capacityCPU.addAnd("dataCenterId", SearchCriteria.Op.EQ, server.getDataCenterId());
|
||||||
capacityCPU.addAnd("podId", SearchCriteria.Op.EQ, server.getPodId());
|
capacityCPU.addAnd("podId", SearchCriteria.Op.EQ, server.getPodId());
|
||||||
capacityCPU.addAnd("capacityType", SearchCriteria.Op.EQ, CapacityVO.CAPACITY_TYPE_CPU);
|
capacityCPU.addAnd("capacityType", SearchCriteria.Op.EQ, CapacityVO.CAPACITY_TYPE_CPU);
|
||||||
List<CapacityVO> capacityVOCpus = _capacityDao.search(capacitySC, null);
|
List<CapacityVO> capacityVOCpus = _capacityDao.search(capacityCPU, null);
|
||||||
|
|
||||||
if (capacityVOCpus != null && !capacityVOCpus.isEmpty()) {
|
if (capacityVOCpus != null && !capacityVOCpus.isEmpty()) {
|
||||||
CapacityVO CapacityVOCpu = capacityVOCpus.get(0);
|
CapacityVO CapacityVOCpu = capacityVOCpus.get(0);
|
||||||
|
|||||||
@ -34,7 +34,6 @@ import com.cloud.configuration.Config;
|
|||||||
import com.cloud.configuration.dao.ConfigurationDao;
|
import com.cloud.configuration.dao.ConfigurationDao;
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
import com.cloud.host.Status;
|
|
||||||
import com.cloud.host.dao.HostDao;
|
import com.cloud.host.dao.HostDao;
|
||||||
import com.cloud.offering.ServiceOffering;
|
import com.cloud.offering.ServiceOffering;
|
||||||
import com.cloud.service.ServiceOfferingVO;
|
import com.cloud.service.ServiceOfferingVO;
|
||||||
@ -44,7 +43,6 @@ import com.cloud.utils.NumbersUtil;
|
|||||||
import com.cloud.utils.component.Inject;
|
import com.cloud.utils.component.Inject;
|
||||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||||
import com.cloud.utils.db.DB;
|
import com.cloud.utils.db.DB;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
|
||||||
import com.cloud.utils.db.Transaction;
|
import com.cloud.utils.db.Transaction;
|
||||||
import com.cloud.utils.fsm.StateListener;
|
import com.cloud.utils.fsm.StateListener;
|
||||||
import com.cloud.vm.VMInstanceVO;
|
import com.cloud.vm.VMInstanceVO;
|
||||||
@ -68,7 +66,7 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
private int _vmCapacityReleaseInterval;
|
private int _vmCapacityReleaseInterval;
|
||||||
private ScheduledExecutorService _executor;
|
private ScheduledExecutorService _executor;
|
||||||
private boolean _stopped;
|
private boolean _stopped;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||||
@ -109,7 +107,7 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
if (capacityCpu == null || capacityMemory == null || svo == null) {
|
if (capacityCpu == null || capacityMemory == null || svo == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
try {
|
try {
|
||||||
txn.start();
|
txn.start();
|
||||||
@ -127,7 +125,7 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
long actualTotalCpu = capacityCpu.getTotalCapacity();
|
long actualTotalCpu = capacityCpu.getTotalCapacity();
|
||||||
String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
|
String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
|
||||||
float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
|
float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
|
||||||
long totalCpu = (long)(actualTotalCpu * cpuOverprovisioningFactor);
|
long totalCpu = (long)(actualTotalCpu * cpuOverprovisioningFactor);
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
|
s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
|
||||||
}
|
}
|
||||||
@ -177,15 +175,15 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DB
|
@DB
|
||||||
@Override
|
@Override
|
||||||
public void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost) {
|
public void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost) {
|
||||||
|
|
||||||
long hostId = vm.getHostId();
|
long hostId = vm.getHostId();
|
||||||
|
|
||||||
ServiceOfferingVO svo = _offeringsDao.findById(vm.getServiceOfferingId());
|
ServiceOfferingVO svo = _offeringsDao.findById(vm.getServiceOfferingId());
|
||||||
|
|
||||||
CapacityVO capacityCpu = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_CPU);
|
CapacityVO capacityCpu = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_CPU);
|
||||||
CapacityVO capacityMem = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_MEMORY);
|
CapacityVO capacityMem = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_MEMORY);
|
||||||
|
|
||||||
@ -195,10 +193,10 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
|
|
||||||
int cpu = svo.getCpu() * svo.getSpeed();
|
int cpu = svo.getCpu() * svo.getSpeed();
|
||||||
long ram = svo.getRamSize() * 1024L * 1024L;
|
long ram = svo.getRamSize() * 1024L * 1024L;
|
||||||
|
|
||||||
String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
|
String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
|
||||||
float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
|
float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
|
||||||
|
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -211,30 +209,30 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
long reservedCpu = capacityCpu.getReservedCapacity();
|
long reservedCpu = capacityCpu.getReservedCapacity();
|
||||||
long reservedMem = capacityMem.getReservedCapacity();
|
long reservedMem = capacityMem.getReservedCapacity();
|
||||||
long actualTotalCpu = capacityCpu.getTotalCapacity();
|
long actualTotalCpu = capacityCpu.getTotalCapacity();
|
||||||
long totalCpu = (long)(actualTotalCpu * cpuOverprovisioningFactor);
|
long totalCpu = (long)(actualTotalCpu * cpuOverprovisioningFactor);
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
|
s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
|
||||||
}
|
}
|
||||||
long totalMem = capacityMem.getTotalCapacity();
|
long totalMem = capacityMem.getTotalCapacity();
|
||||||
|
|
||||||
long freeCpu = totalCpu - (reservedCpu + usedCpu);
|
|
||||||
long freeMem = totalMem - (reservedMem + usedMem);
|
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
long freeCpu = totalCpu - (reservedCpu + usedCpu);
|
||||||
s_logger.debug("We are allocating VM, increasing the used capacity of this host:"+ hostId);
|
long freeMem = totalMem - (reservedMem + usedMem);
|
||||||
s_logger.debug("Current Used CPU: "+usedCpu + " , Free CPU:"+freeCpu+" ,Requested CPU: "+cpu);
|
|
||||||
s_logger.debug("Current Used RAM: "+usedMem + " , Free RAM:"+freeMem+" ,Requested RAM: "+ram);
|
if (s_logger.isDebugEnabled()) {
|
||||||
}
|
s_logger.debug("We are allocating VM, increasing the used capacity of this host:"+ hostId);
|
||||||
|
s_logger.debug("Current Used CPU: "+usedCpu + " , Free CPU:"+freeCpu+" ,Requested CPU: "+cpu);
|
||||||
|
s_logger.debug("Current Used RAM: "+usedMem + " , Free RAM:"+freeMem+" ,Requested RAM: "+ram);
|
||||||
|
}
|
||||||
capacityCpu.setUsedCapacity(usedCpu + cpu);
|
capacityCpu.setUsedCapacity(usedCpu + cpu);
|
||||||
capacityMem.setUsedCapacity(usedMem + ram);
|
capacityMem.setUsedCapacity(usedMem + ram);
|
||||||
|
|
||||||
if (fromLastHost) {
|
if (fromLastHost) {
|
||||||
/*alloc from reserved*/
|
/*alloc from reserved*/
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("We are allocating VM to the last host again, so adjusting the reserved capacity if it is not less than required");
|
s_logger.debug("We are allocating VM to the last host again, so adjusting the reserved capacity if it is not less than required");
|
||||||
s_logger.debug("Reserved CPU: "+reservedCpu + " , Requested CPU: "+cpu);
|
s_logger.debug("Reserved CPU: "+reservedCpu + " , Requested CPU: "+cpu);
|
||||||
s_logger.debug("Reserved RAM: "+reservedMem + " , Requested RAM: "+ram);
|
s_logger.debug("Reserved RAM: "+reservedMem + " , Requested RAM: "+ram);
|
||||||
}
|
}
|
||||||
if (reservedCpu >= cpu && reservedMem >= ram) {
|
if (reservedCpu >= cpu && reservedMem >= ram) {
|
||||||
capacityCpu.setReservedCapacity(reservedCpu - cpu);
|
capacityCpu.setReservedCapacity(reservedCpu - cpu);
|
||||||
capacityMem.setReservedCapacity(reservedMem - ram);
|
capacityMem.setReservedCapacity(reservedMem - ram);
|
||||||
@ -242,9 +240,9 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
} else {
|
} else {
|
||||||
/*alloc from free resource*/
|
/*alloc from free resource*/
|
||||||
if (!((reservedCpu + usedCpu + cpu <= totalCpu) && (reservedMem + usedMem + ram <= totalMem))) {
|
if (!((reservedCpu + usedCpu + cpu <= totalCpu) && (reservedMem + usedMem + ram <= totalMem))) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Host doesnt seem to have enough free capacity, but increasing the used capacity anyways, since the VM is already starting on this host ");
|
s_logger.debug("Host doesnt seem to have enough free capacity, but increasing the used capacity anyways, since the VM is already starting on this host ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,101 +263,116 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOverprovisioningFactor){
|
public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOverprovisioningFactor){
|
||||||
boolean hasCapacity = false;
|
boolean hasCapacity = false;
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Checking if host: " + hostId + " has enough capacity for requested CPU: "+ cpu + " and requested RAM: "+ ram + " , cpuOverprovisioningFactor: "+cpuOverprovisioningFactor);
|
s_logger.debug("Checking if host: " + hostId + " has enough capacity for requested CPU: "+ cpu + " and requested RAM: "+ ram + " , cpuOverprovisioningFactor: "+cpuOverprovisioningFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
CapacityVO capacityCpu = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_CPU);
|
|
||||||
CapacityVO capacityMem = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_MEMORY);
|
|
||||||
|
|
||||||
long usedCpu = capacityCpu.getUsedCapacity();
|
CapacityVO capacityCpu = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_CPU);
|
||||||
long usedMem = capacityMem.getUsedCapacity();
|
CapacityVO capacityMem = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_MEMORY);
|
||||||
long reservedCpu = capacityCpu.getReservedCapacity();
|
|
||||||
long reservedMem = capacityMem.getReservedCapacity();
|
if (capacityCpu == null || capacityMem == null) {
|
||||||
|
if(capacityCpu == null){
|
||||||
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
s_logger.debug("Cannot checkIfHostHasCapacity, Capacity entry for CPU not found in Db, for hostId: "+ hostId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(capacityMem == null){
|
||||||
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
s_logger.debug("Cannot checkIfHostHasCapacity, Capacity entry for RAM not found in Db, for hostId: "+ hostId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
long usedCpu = capacityCpu.getUsedCapacity();
|
||||||
|
long usedMem = capacityMem.getUsedCapacity();
|
||||||
|
long reservedCpu = capacityCpu.getReservedCapacity();
|
||||||
|
long reservedMem = capacityMem.getReservedCapacity();
|
||||||
long actualTotalCpu = capacityCpu.getTotalCapacity();
|
long actualTotalCpu = capacityCpu.getTotalCapacity();
|
||||||
long totalCpu = (long)(actualTotalCpu * cpuOverprovisioningFactor);
|
long totalCpu = (long)(actualTotalCpu * cpuOverprovisioningFactor);
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
|
s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
long totalMem = capacityMem.getTotalCapacity();
|
long totalMem = capacityMem.getTotalCapacity();
|
||||||
|
|
||||||
|
|
||||||
String failureReason = "";
|
|
||||||
if (checkFromReservedCapacity) {
|
|
||||||
long freeCpu = reservedCpu;
|
|
||||||
long freeMem = reservedMem;
|
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
|
||||||
s_logger.debug("We need to allocate to the last host again, so checking if there is enough reserved capacity");
|
|
||||||
s_logger.debug("Reserved CPU: "+freeCpu + " , Requested CPU: "+cpu);
|
|
||||||
s_logger.debug("Reserved RAM: "+freeMem + " , Requested RAM: "+ram);
|
|
||||||
}
|
|
||||||
/*alloc from reserved*/
|
|
||||||
if (reservedCpu >= cpu){
|
|
||||||
if(reservedMem >= ram) {
|
|
||||||
hasCapacity = true;
|
|
||||||
}else{
|
|
||||||
failureReason = "Host does not have enough reserved RAM available";
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
failureReason = "Host does not have enough reserved CPU available";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
long freeCpu = totalCpu - (reservedCpu + usedCpu);
|
|
||||||
long freeMem = totalMem - (reservedMem + usedMem);
|
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
|
||||||
s_logger.debug("Free CPU: "+freeCpu + " , Requested CPU: "+cpu);
|
|
||||||
s_logger.debug("Free RAM: "+freeMem + " , Requested RAM: "+ram);
|
|
||||||
}
|
|
||||||
/*alloc from free resource*/
|
|
||||||
if ((reservedCpu + usedCpu + cpu <= totalCpu)) {
|
|
||||||
if((reservedMem + usedMem + ram <= totalMem)){
|
|
||||||
hasCapacity = true;
|
|
||||||
}else{
|
|
||||||
failureReason = "Host does not have enough RAM available";
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
failureReason = "Host does not have enough CPU available";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasCapacity) {
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
String failureReason = "";
|
||||||
s_logger.debug("Host has enough CPU and RAM available");
|
if (checkFromReservedCapacity) {
|
||||||
}
|
long freeCpu = reservedCpu;
|
||||||
|
long freeMem = reservedMem;
|
||||||
s_logger.debug("STATS: Can alloc CPU from host: " + hostId + ", used: " + usedCpu + ", reserved: " +
|
|
||||||
reservedCpu + ", actual total: "+actualTotalCpu + ", total with overprovisioning: " + totalCpu +
|
if (s_logger.isDebugEnabled()) {
|
||||||
"; requested cpu:" + cpu + ",alloc_from_last_host?:" + checkFromReservedCapacity);
|
s_logger.debug("We need to allocate to the last host again, so checking if there is enough reserved capacity");
|
||||||
|
s_logger.debug("Reserved CPU: "+freeCpu + " , Requested CPU: "+cpu);
|
||||||
s_logger.debug("STATS: Can alloc MEM from host: " + hostId + ", used: " + usedMem + ", reserved: " +
|
s_logger.debug("Reserved RAM: "+freeMem + " , Requested RAM: "+ram);
|
||||||
reservedMem + ", total: " + totalMem + "; requested mem: " + ram + ",alloc_from_last_host?:" + checkFromReservedCapacity);
|
}
|
||||||
} else {
|
/*alloc from reserved*/
|
||||||
|
if (reservedCpu >= cpu){
|
||||||
if (checkFromReservedCapacity) {
|
if(reservedMem >= ram) {
|
||||||
s_logger.debug("STATS: Failed to alloc resource from host: " + hostId + " reservedCpu: " + reservedCpu + ", requested cpu: " + cpu +
|
hasCapacity = true;
|
||||||
", reservedMem: " + reservedMem + ", requested mem: " + ram);
|
}else{
|
||||||
} else {
|
failureReason = "Host does not have enough reserved RAM available";
|
||||||
s_logger.debug("STATS: Failed to alloc resource from host: " + hostId + " reservedCpu: " + reservedCpu + ", used cpu: " + usedCpu + ", requested cpu: " + cpu +
|
}
|
||||||
", actual total cpu: "+actualTotalCpu + ", total cpu with overprovisioning: " + totalCpu +
|
}else{
|
||||||
", reservedMem: " + reservedMem + ", used Mem: " + usedMem + ", requested mem: " + ram + ", total Mem:" + totalMem);
|
failureReason = "Host does not have enough reserved CPU available";
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (s_logger.isDebugEnabled()) {
|
long freeCpu = totalCpu - (reservedCpu + usedCpu);
|
||||||
s_logger.debug(failureReason + ", cannot allocate to this host.");
|
long freeMem = totalMem - (reservedMem + usedMem);
|
||||||
}
|
|
||||||
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
s_logger.debug("Free CPU: "+freeCpu + " , Requested CPU: "+cpu);
|
||||||
|
s_logger.debug("Free RAM: "+freeMem + " , Requested RAM: "+ram);
|
||||||
|
}
|
||||||
|
/*alloc from free resource*/
|
||||||
|
if ((reservedCpu + usedCpu + cpu <= totalCpu)) {
|
||||||
|
if((reservedMem + usedMem + ram <= totalMem)){
|
||||||
|
hasCapacity = true;
|
||||||
|
}else{
|
||||||
|
failureReason = "Host does not have enough RAM available";
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
failureReason = "Host does not have enough CPU available";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasCapacity;
|
if (hasCapacity) {
|
||||||
|
if (s_logger.isDebugEnabled()) {
|
||||||
}
|
s_logger.debug("Host has enough CPU and RAM available");
|
||||||
|
}
|
||||||
|
|
||||||
|
s_logger.debug("STATS: Can alloc CPU from host: " + hostId + ", used: " + usedCpu + ", reserved: " +
|
||||||
|
reservedCpu + ", actual total: "+actualTotalCpu + ", total with overprovisioning: " + totalCpu +
|
||||||
|
"; requested cpu:" + cpu + ",alloc_from_last_host?:" + checkFromReservedCapacity);
|
||||||
|
|
||||||
|
s_logger.debug("STATS: Can alloc MEM from host: " + hostId + ", used: " + usedMem + ", reserved: " +
|
||||||
|
reservedMem + ", total: " + totalMem + "; requested mem: " + ram + ",alloc_from_last_host?:" + checkFromReservedCapacity);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (checkFromReservedCapacity) {
|
||||||
|
s_logger.debug("STATS: Failed to alloc resource from host: " + hostId + " reservedCpu: " + reservedCpu + ", requested cpu: " + cpu +
|
||||||
|
", reservedMem: " + reservedMem + ", requested mem: " + ram);
|
||||||
|
} else {
|
||||||
|
s_logger.debug("STATS: Failed to alloc resource from host: " + hostId + " reservedCpu: " + reservedCpu + ", used cpu: " + usedCpu + ", requested cpu: " + cpu +
|
||||||
|
", actual total cpu: "+actualTotalCpu + ", total cpu with overprovisioning: " + totalCpu +
|
||||||
|
", reservedMem: " + reservedMem + ", used Mem: " + usedMem + ", requested mem: " + ram + ", total Mem:" + totalMem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
s_logger.debug(failureReason + ", cannot allocate to this host.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasCapacity;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public class HostCapacityCollector implements Runnable {
|
public class HostCapacityCollector implements Runnable {
|
||||||
|
|
||||||
@ -453,16 +466,16 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
Event event, State newState, VirtualMachine vm, boolean transitionStatus, Long id) {
|
Event event, State newState, VirtualMachine vm, boolean transitionStatus, Long id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean postStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vm, boolean status, Long oldHostId) {
|
public boolean postStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vm, boolean status, Long oldHostId) {
|
||||||
if (!status) {
|
if (!status) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_logger.debug("VM state transitted from :" + oldState + " to " + newState + " with event: " + event +
|
s_logger.debug("VM state transitted from :" + oldState + " to " + newState + " with event: " + event +
|
||||||
"vm's original host id: " + vm.getLastHostId() + " new host id: " + vm.getHostId() + " host id before state transition: " + oldHostId);
|
"vm's original host id: " + vm.getLastHostId() + " new host id: " + vm.getHostId() + " host id before state transition: " + oldHostId);
|
||||||
|
|
||||||
|
|
||||||
if (oldState == State.Starting) {
|
if (oldState == State.Starting) {
|
||||||
if (event == Event.OperationFailed) {
|
if (event == Event.OperationFailed) {
|
||||||
@ -474,18 +487,18 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
}
|
}
|
||||||
} else if (oldState == State.Running) {
|
} else if (oldState == State.Running) {
|
||||||
if (event == Event.AgentReportStopped) {
|
if (event == Event.AgentReportStopped) {
|
||||||
releaseVmCapacity(vm, false, true, oldHostId);
|
releaseVmCapacity(vm, false, true, oldHostId);
|
||||||
}
|
}
|
||||||
} else if (oldState == State.Migrating) {
|
} else if (oldState == State.Migrating) {
|
||||||
if (event == Event.AgentReportStopped) {
|
if (event == Event.AgentReportStopped) {
|
||||||
/*Release capacity from original host*/
|
/*Release capacity from original host*/
|
||||||
releaseVmCapacity(vm, false, false, vm.getLastHostId());
|
releaseVmCapacity(vm, false, false, vm.getLastHostId());
|
||||||
releaseVmCapacity(vm, false, true, oldHostId);
|
releaseVmCapacity(vm, false, true, oldHostId);
|
||||||
} else if (event == Event.OperationFailed) {
|
} else if (event == Event.OperationFailed) {
|
||||||
/*Release from dest host*/
|
/*Release from dest host*/
|
||||||
releaseVmCapacity(vm, false, false, oldHostId);
|
releaseVmCapacity(vm, false, false, oldHostId);
|
||||||
} else if (event == Event.OperationSucceeded) {
|
} else if (event == Event.OperationSucceeded) {
|
||||||
releaseVmCapacity(vm, false, false, vm.getLastHostId());
|
releaseVmCapacity(vm, false, false, vm.getLastHostId());
|
||||||
}
|
}
|
||||||
} else if (oldState == State.Stopping) {
|
} else if (oldState == State.Stopping) {
|
||||||
if (event == Event.AgentReportStopped || event == Event.OperationSucceeded) {
|
if (event == Event.AgentReportStopped || event == Event.OperationSucceeded) {
|
||||||
@ -496,18 +509,18 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
|
|||||||
releaseVmCapacity(vm, true, false, vm.getLastHostId());
|
releaseVmCapacity(vm, true, false, vm.getLastHostId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if((newState == State.Starting || newState == State.Migrating) && vm.getHostId() != null){
|
|
||||||
boolean fromLastHost = false;
|
if((newState == State.Starting || newState == State.Migrating) && vm.getHostId() != null){
|
||||||
if(vm.getLastHostId() == vm.getHostId()){
|
boolean fromLastHost = false;
|
||||||
s_logger.debug("VM starting again on the last host it was stopped on");
|
if(vm.getLastHostId() == vm.getHostId()){
|
||||||
fromLastHost = true;
|
s_logger.debug("VM starting again on the last host it was stopped on");
|
||||||
}
|
fromLastHost = true;
|
||||||
allocateVmCapacity(vm,fromLastHost);
|
}
|
||||||
|
allocateVmCapacity(vm,fromLastHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user