|
37 | 37 |
|
38 | 38 | import com.cloud.vm.VirtualMachine; |
39 | 39 | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; |
40 | | -import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper; |
| 40 | +import org.apache.cloudstack.framework.config.ConfigKey; |
| 41 | +import org.apache.cloudstack.framework.config.Configurable; |
| 42 | +import org.apache.cloudstack.utils.jsinterpreter.GenericRuleHelper; |
41 | 43 | import org.apache.commons.collections.CollectionUtils; |
42 | 44 |
|
43 | 45 | import com.cloud.agent.api.VgpuTypesInfo; |
|
84 | 86 |
|
85 | 87 | @DB |
86 | 88 | @TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1) |
87 | | -public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao { //FIXME: , ExternalIdDao { |
| 89 | +public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao, Configurable { |
88 | 90 |
|
89 | 91 | private static final String LIST_HOST_IDS_BY_HOST_TAGS = "SELECT filtered.host_id, COUNT(filtered.tag) AS tag_count " |
90 | 92 | + "FROM (SELECT host_id, tag, is_tag_a_rule FROM host_tags GROUP BY host_id,tag,is_tag_a_rule) AS filtered " |
@@ -1520,18 +1522,37 @@ private List<Long> findHostIdsByHostTags(String hostTags){ |
1520 | 1522 | } |
1521 | 1523 | } |
1522 | 1524 |
|
| 1525 | + @Override |
1523 | 1526 | public List<HostVO> findHostsWithTagRuleThatMatchComputeOfferingTags(String computeOfferingTags) { |
1524 | 1527 | List<HostTagVO> hostTagVOList = _hostTagsDao.findHostRuleTags(); |
1525 | 1528 | List<HostVO> result = new ArrayList<>(); |
1526 | 1529 | for (HostTagVO rule: hostTagVOList) { |
1527 | | - if (TagAsRuleHelper.interpretTagAsRule(rule.getTag(), computeOfferingTags, HostTagsDao.hostTagRuleExecutionTimeout.value())) { |
| 1530 | + if (GenericRuleHelper.interpretTagAsRule(rule.getTag(), computeOfferingTags, HostTagsDao.hostTagRuleExecutionTimeout.value(), |
| 1531 | + HostTagsDao.hostTagRuleExecutionTimeout.key())) { |
1528 | 1532 | result.add(findById(rule.getHostId())); |
1529 | 1533 | } |
1530 | 1534 | } |
1531 | 1535 |
|
1532 | 1536 | return result; |
1533 | 1537 | } |
1534 | 1538 |
|
| 1539 | + @Override |
| 1540 | + public List<HostVO> findHostsWithGuestOsRulesThatDidNotMatchOsOfGuestVm(String templateGuestOSName) { |
| 1541 | + List<DetailVO> hostIdsWithGuestOsRule = _detailsDao.findByName(Host.GUEST_OS_RULE); |
| 1542 | + List<HostVO> hostsWithIncompatibleRules = new ArrayList<>(); |
| 1543 | + for (DetailVO guestOsRule : hostIdsWithGuestOsRule) { |
| 1544 | + if (!GenericRuleHelper.interpretGuestOsRule(guestOsRule.getValue(), templateGuestOSName, HostDao.guestOsRuleExecutionTimeout.value(), |
| 1545 | + HostDao.guestOsRuleExecutionTimeout.key())) { |
| 1546 | + logger.trace("The guest OS rule [{}] of the host with ID [{}] is incompatible with the OS of the VM.", |
| 1547 | + guestOsRule.getHostId(), guestOsRule.getValue()); |
| 1548 | + hostsWithIncompatibleRules.add(findById(guestOsRule.getHostId())); |
| 1549 | + } |
| 1550 | + } |
| 1551 | + logger.trace("The hosts with the following IDs [{}] are incompatible with the VM considering their guest OS rule.", |
| 1552 | + hostsWithIncompatibleRules); |
| 1553 | + return hostsWithIncompatibleRules; |
| 1554 | + } |
| 1555 | + |
1535 | 1556 | public List<Long> findClustersThatMatchHostTagRule(String computeOfferingTags) { |
1536 | 1557 | Set<Long> result = new HashSet<>(); |
1537 | 1558 | List<HostVO> hosts = findHostsWithTagRuleThatMatchComputeOfferingTags(computeOfferingTags); |
@@ -1984,4 +2005,14 @@ public List<String> listDistinctStorageAccessGroups(String name, String keyword) |
1984 | 2005 |
|
1985 | 2006 | return customSearch(sc, null); |
1986 | 2007 | } |
| 2008 | + |
| 2009 | + @Override |
| 2010 | + public ConfigKey<?>[] getConfigKeys() { |
| 2011 | + return new ConfigKey<?>[] {guestOsRuleExecutionTimeout}; |
| 2012 | + } |
| 2013 | + |
| 2014 | + @Override |
| 2015 | + public String getConfigComponentName() { |
| 2016 | + return HostDaoImpl.class.getSimpleName(); |
| 2017 | + } |
1987 | 2018 | } |
0 commit comments