diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 5d5f7694601..eb4f8152029 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -526,7 +526,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS } protected AgentAttache handleDirectConnect(ServerResource resource, StartupCommand[] startup, Map details, boolean old, List hostTags, String allocationState) - throws ConnectionException { + throws ConnectionException { if (startup == null) { return null; } @@ -784,7 +784,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS @Override public List discoverHosts(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, String hypervisorType, List hostTags) - throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException { + throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException { return discoverHostsFull(dcId, podId, clusterId, clusterName, url, username, password, hypervisorType, hostTags, null, null); } @@ -1104,7 +1104,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS } 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() - + "in this host " + host.getPrivateIpAddress(); + + "in this host " + host.getPrivateIpAddress(); s_logger.info(msg); _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Unable to eject host " + host.getGuid(), msg); } @@ -2204,7 +2204,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS } public HostVO createHost(final StartupCommand startup, ServerResource resource, Map details, boolean directFirst, List hostTags, String allocationState) - throws IllegalArgumentException { + throws IllegalArgumentException { Host.Type type = null; if (startup instanceof StartupStorageCommand) { @@ -2324,7 +2324,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS } public HostVO createHost(final StartupCommand[] startup, ServerResource resource, Map details, boolean directFirst, List hostTags, String allocationState) - throws IllegalArgumentException { + throws IllegalArgumentException { StartupCommand firstCmd = startup[0]; HostVO result = createHost(firstCmd, resource, details, directFirst, hostTags, allocationState); if (result == null) { @@ -2664,7 +2664,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS capacityCPU.addAnd("dataCenterId", SearchCriteria.Op.EQ, server.getDataCenterId()); capacityCPU.addAnd("podId", SearchCriteria.Op.EQ, server.getPodId()); capacityCPU.addAnd("capacityType", SearchCriteria.Op.EQ, CapacityVO.CAPACITY_TYPE_CPU); - List capacityVOCpus = _capacityDao.search(capacitySC, null); + List capacityVOCpus = _capacityDao.search(capacityCPU, null); if (capacityVOCpus != null && !capacityVOCpus.isEmpty()) { CapacityVO CapacityVOCpu = capacityVOCpus.get(0); diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index 7ffebd2a1e4..dd8fbce5d33 100644 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -68,7 +68,7 @@ public class CapacityManagerImpl implements CapacityManager , StateListener params) throws ConfigurationException { @@ -109,7 +109,7 @@ public class CapacityManagerImpl implements CapacityManager , StateListener= cpu && reservedMem >= ram) { capacityCpu.setReservedCapacity(reservedCpu - cpu); capacityMem.setReservedCapacity(reservedMem - ram); @@ -242,9 +242,9 @@ public class CapacityManagerImpl implements CapacityManager , StateListener= 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"; - } - } + long totalMem = capacityMem.getTotalCapacity(); - 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."); - } + + 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"; + } } - - 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 { @@ -458,16 +473,16 @@ public class CapacityManagerImpl implements CapacityManager , StateListener