Skip to content

Commit 868b7dd

Browse files
committed
Refactor from copilot code review
1 parent 7742df2 commit 868b7dd

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

engine/schema/src/main/java/com/cloud/host/dao/HostTagsDao.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@ public interface HostTagsDao extends GenericDao<HostTagVO, Long> {
4646

4747
List<HostTagVO> searchByIds(Long... hostTagIds);
4848

49+
/**
50+
* List all host tags defined on hosts within a cluster
51+
*/
4952
List<String> listByClusterId(Long clusterId);
5053
}

engine/schema/src/main/java/com/cloud/host/dao/HostTagsDaoImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.cloudstack.framework.config.ConfigKey;
2424
import org.apache.cloudstack.framework.config.Configurable;
2525
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
26+
import org.apache.commons.collections4.CollectionUtils;
2627
import org.apache.commons.lang3.StringUtils;
2728
import org.springframework.beans.factory.annotation.Autowired;
2829
import org.springframework.stereotype.Component;
@@ -79,7 +80,7 @@ public HostTagsDaoImpl() {
7980

8081
tagSearch = createSearchBuilder(String.class);
8182
tagSearch.selectFields(tagSearch.entity().getTag());
82-
tagSearch.and("idIN", tagSearch.entity().getId(), SearchCriteria.Op.IN);
83+
tagSearch.and("hostIdIN", tagSearch.entity().getHostId(), SearchCriteria.Op.IN);
8384
tagSearch.done();
8485
}
8586

@@ -248,8 +249,11 @@ public List<HostTagVO> searchByIds(Long... tagIds) {
248249
@Override
249250
public List<String> listByClusterId(Long clusterId) {
250251
List<Long> hostIds = hostDao.listIdsByClusterId(clusterId);
252+
if (CollectionUtils.isEmpty(hostIds)) {
253+
return new ArrayList<>();
254+
}
251255
SearchCriteria<String> sc = tagSearch.create();
252-
sc.setParameters("idIN", hostIds.toArray());
256+
sc.setParameters("hostIdIN", hostIds.toArray());
253257
return customSearch(sc, null);
254258
}
255259
}

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4502,7 +4502,7 @@ protected void addVmCurrentClusterHostTags(VMInstanceVO vmInstance, List<String>
45024502
}
45034503
List<String> clusterTags = _hostTagDao.listByClusterId(host.getClusterId());
45044504
if (CollectionUtils.isEmpty(clusterTags)) {
4505-
logger.warn("No host tags defined for hosts in the cluster " + host.getClusterId());
4505+
logger.debug("No host tags defined for hosts in the cluster " + host.getClusterId());
45064506
return;
45074507
}
45084508
Set<String> existingTagsSet = new HashSet<>(hostTags);

0 commit comments

Comments
 (0)