Skip to content

Commit 410caeb

Browse files
committed
PR7877: check if zone has enough capacity in VR deployment (not start)
1 parent 524aa20 commit 410caeb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

server/src/main/java/com/cloud/network/router/NetworkHelperImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3737
import org.apache.cloudstack.network.router.deployment.RouterDeploymentDefinition;
3838
import org.apache.cloudstack.utils.CloudStackVersion;
39+
import org.apache.commons.collections.CollectionUtils;
3940
import org.apache.log4j.Logger;
4041

4142
import com.cloud.agent.AgentManager;
4243
import com.cloud.agent.api.Answer;
4344
import com.cloud.agent.api.to.NicTO;
4445
import com.cloud.agent.manager.Commands;
4546
import com.cloud.alert.AlertManager;
47+
import com.cloud.capacity.CapacityManager;
4648
import com.cloud.configuration.Config;
4749
import com.cloud.dc.ClusterVO;
4850
import com.cloud.dc.DataCenter;
@@ -168,6 +170,8 @@ public class NetworkHelperImpl implements NetworkHelper {
168170
RouterHealthCheckResultDao _routerHealthCheckResultDao;
169171
@Inject
170172
Ipv6Service ipv6Service;
173+
@Inject
174+
CapacityManager capacityMgr;
171175

172176
protected final Map<HypervisorType, ConfigKey<String>> hypervisorsMap = new HashMap<>();
173177

@@ -535,6 +539,10 @@ public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploy
535539
}
536540
}
537541

542+
if (!checkIfZoneHasCapacity(routerDeploymentDefinition.getDest().getDataCenter(), hType, routerOffering)) {
543+
continue;
544+
}
545+
538546
router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id,
539547
s_vmInstanceName), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(),
540548
userId, routerDeploymentDefinition.isRedundant(), RedundantState.UNKNOWN, offerHA, false, vpcId);
@@ -577,6 +585,22 @@ public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploy
577585
return router;
578586
}
579587

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+
580604
protected void filterSupportedHypervisors(final List<HypervisorType> hypervisors) {
581605
// For non vpc we keep them all assuming all types in the list are
582606
// supported

0 commit comments

Comments
 (0)