|
34 | 34 | import javax.inject.Inject; |
35 | 35 | import javax.persistence.TableGenerator; |
36 | 36 |
|
37 | | -import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper; |
| 37 | +import org.apache.cloudstack.framework.config.ConfigKey; |
| 38 | +import org.apache.cloudstack.framework.config.Configurable; |
| 39 | +import org.apache.cloudstack.utils.jsinterpreter.GenericRuleHelper; |
38 | 40 | import org.apache.commons.collections.CollectionUtils; |
39 | 41 |
|
40 | 42 | import com.cloud.agent.api.VgpuTypesInfo; |
|
78 | 80 |
|
79 | 81 | @DB |
80 | 82 | @TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1) |
81 | | -public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao { //FIXME: , ExternalIdDao { |
| 83 | +public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao, Configurable { |
82 | 84 |
|
83 | 85 | private static final String LIST_HOST_IDS_BY_COMPUTETAGS = "SELECT filtered.host_id, COUNT(filtered.tag) AS tag_count " |
84 | 86 | + "FROM (SELECT host_id, tag, is_tag_a_rule FROM host_tags GROUP BY host_id,tag) AS filtered " |
@@ -1350,18 +1352,36 @@ private List<Long> findHostByComputeOfferings(String computeOfferingTags){ |
1350 | 1352 | } |
1351 | 1353 | } |
1352 | 1354 |
|
| 1355 | + @Override |
1353 | 1356 | public List<HostVO> findHostsWithTagRuleThatMatchComputeOfferingTags(String computeOfferingTags) { |
1354 | 1357 | List<HostTagVO> hostTagVOList = _hostTagsDao.findHostRuleTags(); |
1355 | 1358 | List<HostVO> result = new ArrayList<>(); |
1356 | 1359 | for (HostTagVO rule: hostTagVOList) { |
1357 | | - if (TagAsRuleHelper.interpretTagAsRule(rule.getTag(), computeOfferingTags, HostTagsDao.hostTagRuleExecutionTimeout.value())) { |
| 1360 | + if (GenericRuleHelper.interpretTagAsRule(rule.getTag(), computeOfferingTags, HostTagsDao.hostTagRuleExecutionTimeout.value(), |
| 1361 | + HostTagsDao.hostTagRuleExecutionTimeout.key())) { |
1358 | 1362 | result.add(findById(rule.getHostId())); |
1359 | 1363 | } |
1360 | 1364 | } |
1361 | 1365 |
|
1362 | 1366 | return result; |
1363 | 1367 | } |
1364 | 1368 |
|
| 1369 | + @Override |
| 1370 | + public List<HostVO> findHostsWithGuestOsRulesThatDidNotMatchOsOfGuestVm(String templateGuestOSName) { |
| 1371 | + List<DetailVO> hostIdsWithGuestOsRule = _detailsDao.findByName(Host.GUEST_OS_RULE); |
| 1372 | + List<HostVO> hostsWithIncompatibleRules = new ArrayList<>(); |
| 1373 | + for (DetailVO guestOsRule : hostIdsWithGuestOsRule) { |
| 1374 | + if (!GenericRuleHelper.interpretGuestOsRule(guestOsRule.getValue(), templateGuestOSName, HostDao.guestOsRuleExecutionTimeout.value(), |
| 1375 | + HostDao.guestOsRuleExecutionTimeout.key())) { |
| 1376 | + logger.trace("The guest OS rule [{}] of the host with ID [{}] is incompatible with the OS of the VM.", guestOsRule.getHostId(), guestOsRule.getValue()); |
| 1377 | + hostsWithIncompatibleRules.add(findById(guestOsRule.getHostId())); |
| 1378 | + } |
| 1379 | + } |
| 1380 | + logger.trace("The hosts with the following IDs [{}] are incompatible with the VM considering their guest OS rule.", hostsWithIncompatibleRules); |
| 1381 | + return hostsWithIncompatibleRules; |
| 1382 | + } |
| 1383 | + |
| 1384 | + @Override |
1365 | 1385 | public List<Long> findClustersThatMatchHostTagRule(String computeOfferingTags) { |
1366 | 1386 | Set<Long> result = new HashSet<>(); |
1367 | 1387 | List<HostVO> hosts = findHostsWithTagRuleThatMatchComputeOfferingTags(computeOfferingTags); |
@@ -1602,4 +1622,14 @@ private String createSqlFindHostToExecuteCommand(boolean useDisabledHosts) { |
1602 | 1622 | } |
1603 | 1623 | return String.format(sqlFindHostInZoneToExecuteCommand, hostResourceStatus); |
1604 | 1624 | } |
| 1625 | + |
| 1626 | + @Override |
| 1627 | + public ConfigKey<?>[] getConfigKeys() { |
| 1628 | + return new ConfigKey<?>[] {guestOsRuleExecutionTimeout}; |
| 1629 | + } |
| 1630 | + |
| 1631 | + @Override |
| 1632 | + public String getConfigComponentName() { |
| 1633 | + return HostDaoImpl.class.getSimpleName(); |
| 1634 | + } |
1605 | 1635 | } |
0 commit comments