diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 2ba6b3eecbb..63c51cdc8a0 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -74,7 +74,6 @@ import com.cloud.agent.manager.allocator.PodAllocator; import com.cloud.agent.transport.Request; import com.cloud.agent.transport.Response; import com.cloud.alert.AlertManager; -import com.cloud.api.ApiConstants; import com.cloud.api.commands.AddClusterCmd; import com.cloud.api.commands.AddHostCmd; 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 details, boolean old, List hostTags, String allocationState) - throws ConnectionException { + throws ConnectionException { if (startup == null) { return null; } @@ -567,7 +566,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS String url = cmd.getUrl(); String username = cmd.getUsername(); String password = cmd.getPassword(); - + url = URLDecoder.decode(url); URI uri = null; @@ -807,7 +806,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); } @@ -1162,7 +1161,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.warn(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 details, boolean directFirst, List hostTags, String allocationState) - throws IllegalArgumentException { + throws IllegalArgumentException { Host.Type type = null; if (startup instanceof StartupStorageCommand) { @@ -2394,7 +2393,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) { @@ -2735,7 +2734,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 a009228638c..6eb9c077928 100644 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -34,7 +34,6 @@ import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.host.Host; import com.cloud.host.HostVO; -import com.cloud.host.Status; import com.cloud.host.dao.HostDao; import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; @@ -44,7 +43,6 @@ import com.cloud.utils.NumbersUtil; import com.cloud.utils.component.Inject; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.DB; -import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; import com.cloud.utils.fsm.StateListener; import com.cloud.vm.VMInstanceVO; @@ -68,7 +66,7 @@ public class CapacityManagerImpl implements CapacityManager , StateListener params) throws ConfigurationException { @@ -109,7 +107,7 @@ public class CapacityManagerImpl implements CapacityManager , StateListener= cpu && reservedMem >= ram) { capacityCpu.setReservedCapacity(reservedCpu - cpu); capacityMem.setReservedCapacity(reservedMem - ram); @@ -242,9 +240,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 { @@ -453,16 +466,16 @@ public class CapacityManagerImpl implements CapacityManager , StateListener