|
36 | 36 | import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
37 | 37 | import org.apache.cloudstack.network.router.deployment.RouterDeploymentDefinition; |
38 | 38 | import org.apache.cloudstack.utils.CloudStackVersion; |
| 39 | +import org.apache.commons.collections.CollectionUtils; |
39 | 40 | import org.apache.log4j.Logger; |
40 | 41 |
|
41 | 42 | import com.cloud.agent.AgentManager; |
42 | 43 | import com.cloud.agent.api.Answer; |
43 | 44 | import com.cloud.agent.api.to.NicTO; |
44 | 45 | import com.cloud.agent.manager.Commands; |
45 | 46 | import com.cloud.alert.AlertManager; |
| 47 | +import com.cloud.capacity.CapacityManager; |
46 | 48 | import com.cloud.configuration.Config; |
47 | 49 | import com.cloud.dc.ClusterVO; |
48 | 50 | import com.cloud.dc.DataCenter; |
@@ -168,6 +170,8 @@ public class NetworkHelperImpl implements NetworkHelper { |
168 | 170 | RouterHealthCheckResultDao _routerHealthCheckResultDao; |
169 | 171 | @Inject |
170 | 172 | Ipv6Service ipv6Service; |
| 173 | + @Inject |
| 174 | + CapacityManager capacityMgr; |
171 | 175 |
|
172 | 176 | protected final Map<HypervisorType, ConfigKey<String>> hypervisorsMap = new HashMap<>(); |
173 | 177 |
|
@@ -535,6 +539,10 @@ public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploy |
535 | 539 | } |
536 | 540 | } |
537 | 541 |
|
| 542 | + if (!checkIfZoneHasCapacity(routerDeploymentDefinition.getDest().getDataCenter(), hType, routerOffering)) { |
| 543 | + continue; |
| 544 | + } |
| 545 | + |
538 | 546 | router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id, |
539 | 547 | s_vmInstanceName), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), |
540 | 548 | userId, routerDeploymentDefinition.isRedundant(), RedundantState.UNKNOWN, offerHA, false, vpcId); |
@@ -577,6 +585,22 @@ public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploy |
577 | 585 | return router; |
578 | 586 | } |
579 | 587 |
|
| 588 | + private boolean checkIfZoneHasCapacity(final DataCenter zone, final HypervisorType hypervisorType, final ServiceOfferingVO routerOffering) { |
| 589 | + List <HostVO> hosts = _hostDao.listByDataCenterIdAndHypervisorType(zone.getId(), hypervisorType); |
| 590 | + if (CollectionUtils.isEmpty(hosts)) { |
| 591 | + s_logger.debug("Zone " + zone + " has no host available which is enabled and in Up state"); |
| 592 | + return false; |
| 593 | + } |
| 594 | + for (HostVO host : hosts) { |
| 595 | + Pair<Boolean, Boolean> cpuCapabilityAndCapacity = capacityMgr.checkIfHostHasCpuCapabilityAndCapacity(host, routerOffering, false); |
| 596 | + if (cpuCapabilityAndCapacity.first() && cpuCapabilityAndCapacity.second()) { |
| 597 | + return true; |
| 598 | + } |
| 599 | + } |
| 600 | + s_logger.debug("Zone " + zone + " has no host which has enough capacity"); |
| 601 | + return false; |
| 602 | + } |
| 603 | + |
580 | 604 | protected void filterSupportedHypervisors(final List<HypervisorType> hypervisors) { |
581 | 605 | // For non vpc we keep them all assuming all types in the list are |
582 | 606 | // supported |
|
0 commit comments