Skip to content

Commit 22fec2a

Browse files
committed
external planner to adhere arch, enabled clusters
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 51bd0b1 commit 22fec2a

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

engine/schema/src/main/java/com/cloud/dc/dao/ClusterDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ public interface ClusterDao extends GenericDao<ClusterVO, Long> {
5959
List<ClusterVO> listClustersByArchAndZoneId(long zoneId, CPU.CPUArch arch);
6060

6161
List<String> listDistinctStorageAccessGroups(String name, String keyword);
62+
63+
List<Long> listEnabledClusterIdsByZoneHypervisorArch(Long zoneId, HypervisorType hypervisorType, CPU.CPUArch arch);
6264
}

engine/schema/src/main/java/com/cloud/dc/dao/ClusterDaoImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,28 @@ public List<String> listDistinctStorageAccessGroups(String name, String keyword)
378378

379379
return customSearch(sc, null);
380380
}
381+
382+
@Override
383+
public List<Long> listEnabledClusterIdsByZoneHypervisorArch(Long zoneId, HypervisorType hypervisorType, CPU.CPUArch arch) {
384+
GenericSearchBuilder<ClusterVO, Long> sb = createSearchBuilder(Long.class);
385+
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
386+
sb.and("allocationState", sb.entity().getAllocationState(), Op.EQ);
387+
sb.and("managedState", sb.entity().getManagedState(), Op.EQ);
388+
sb.and("hypervisor", sb.entity().getHypervisorType(), Op.EQ);
389+
sb.and("arch", sb.entity().getArch(), Op.EQ);
390+
sb.done();
391+
SearchCriteria<Long> sc = sb.create();
392+
sc.setParameters("allocationState", Grouping.AllocationState.Enabled);
393+
sc.setParameters("allocationState", Managed.ManagedState.Managed);
394+
if (zoneId != null) {
395+
sc.setParameters("zoneId", zoneId);
396+
}
397+
if (hypervisorType != null) {
398+
sc.setParameters("hypervisor", hypervisorType);
399+
}
400+
if (arch != null) {
401+
sc.setParameters("arch", arch);
402+
}
403+
return customSearch(sc, null);
404+
}
381405
}

plugins/hypervisors/external/src/main/java/org/apache/cloudstack/agent/manager/ExternalServerPlanner.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
import javax.inject.Inject;
2525
import javax.naming.ConfigurationException;
2626

27+
import org.apache.cloudstack.extension.ExtensionResourceMap;
2728
import org.apache.cloudstack.framework.extensions.dao.ExtensionDao;
2829
import org.apache.cloudstack.framework.extensions.dao.ExtensionResourceMapDao;
2930
import org.apache.cloudstack.framework.extensions.vo.ExtensionVO;
3031
import org.apache.commons.collections.CollectionUtils;
3132

32-
import com.cloud.dc.ClusterVO;
3333
import com.cloud.dc.DataCenter;
3434
import com.cloud.dc.Pod;
3535
import com.cloud.dc.dao.ClusterDao;
@@ -39,7 +39,6 @@
3939
import com.cloud.deploy.DeploymentPlan;
4040
import com.cloud.deploy.DeploymentPlanner;
4141
import com.cloud.exception.InsufficientServerCapacityException;
42-
import org.apache.cloudstack.extension.ExtensionResourceMap;
4342
import com.cloud.host.Host;
4443
import com.cloud.host.HostVO;
4544
import com.cloud.host.dao.HostDao;
@@ -103,22 +102,24 @@ public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan pl
103102
}
104103
}
105104

106-
List<ClusterVO> clusters = clusterDao.listByDcHyType(vm.getDataCenterId(), HypervisorType.External.name());
105+
List<Long> clusterIds = clusterDao.listEnabledClusterIdsByZoneHypervisorArch(vm.getDataCenterId(),
106+
HypervisorType.External, vmProfile.getTemplate().getArch());
107107
List<Long> extensionClusterIds = extensionResourceMapDao.listResourceIdsByExtensionIdAndType(extensionId,
108108
ExtensionResourceMap.ResourceType.Cluster);
109109
if (CollectionUtils.isEmpty(extensionClusterIds)) {
110110
logger.error("No clusters associated with {} to plan deployment of external instance {}",
111111
vmProfile.getInstanceName());
112112
return null;
113113
}
114-
clusters = clusters.stream()
115-
.filter(c -> extensionClusterIds.contains(c.getId()))
114+
clusterIds = clusterIds.stream()
115+
.filter(extensionClusterIds::contains)
116116
.collect(Collectors.toList());
117-
logger.debug("Found {} clusters associated with {}", clusters.size(), extensionVO);
117+
logger.debug("Found {} clusters associated with {}", clusterIds.size(), extensionVO);
118118
HostVO target = null;
119119
List<HostVO> hosts;
120-
for (ClusterVO cluster : clusters) {
121-
hosts = resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
120+
for (Long clusterId : clusterIds) {
121+
hosts = resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, clusterId, null,
122+
vm.getDataCenterId());
122123
if (hostTag != null) {
123124
for (HostVO host : hosts) {
124125
hostDao.loadHostTags(host);

0 commit comments

Comments
 (0)