Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ public void handleHostReport(HostReport report, boolean isBoot) {
*/
if (isBoot) {
hostManager.setHostResources(host, report);

// Update host tags during boot to ensure they're current
hostManager.updateHostTags(host, report.getHost());
}

dispatchSupport.determineIdleCores(host, report.getHost().getLoad());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright Contributors to the OpenCue Project
*
Expand Down Expand Up @@ -245,4 +244,12 @@ void setHostStatistics(HostInterface host, long totalMemory, long freeMemory, lo
* @param report
*/
void setHostResources(DispatchHost host, HostReport report);

/**
* Updates host tags during boot to ensure they're current.
*
* @param host DispatchHost
* @param rhost RenderHost with updated tag information
*/
void updateHostTags(DispatchHost host, RenderHost rhost);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright Contributors to the OpenCue Project
*
Expand Down Expand Up @@ -172,12 +171,12 @@ public DispatchHost createHost(RenderHost rhost, AllocationEntity alloc) {

if (rhost.getTagsCount() > 0) {
for (String tag : rhost.getTagsList()) {
hostDao.tagHost(host, tag, HostTagType.MANUAL);
hostDao.tagHost(host, tag, HostTagType.HARDWARE);
}
}

// Don't tag anything with hardware yet, we don't watch new procs
// that report in to automatically start running frames.
// RQD tags (version, platform) are tagged as HARDWARE type since they represent
// technical characteristics of the host, not manual user assignments

hostDao.recalcuateTags(host.id);
return host;
Expand Down Expand Up @@ -408,4 +407,26 @@ public SubscriptionDao getSubscriptionDao() {
public void setSubscriptionDao(SubscriptionDao subscriptionDao) {
this.subscriptionDao = subscriptionDao;
}

@Override
@Transactional(propagation = Propagation.REQUIRED)
public void updateHostTags(DispatchHost host, RenderHost rhost) {
// Remove existing hardware tags and re-add current tags from report
hostDao.removeTagsByType(host, HostTagType.HARDWARE);

if (rhost.getTagsCount() > 0) {
for (String tag : rhost.getTagsList()) {
// Remove tag by name, regardless of type.
// It avoids duplicates if the host was first registered with
// an older version of Cuebot where those tags were of MANUAL type.
hostDao.removeTag(host, tag);
hostDao.tagHost(host, tag, HostTagType.HARDWARE);
}
}

hostDao.recalcuateTags(host.getHostId());

logger.info("Updated hardware tags for host {} with tags: {}", host.getName(),
rhost.getTagsList());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright Contributors to the OpenCue Project
*
Expand Down Expand Up @@ -471,7 +470,7 @@ public void testUpdateHostSetManualTags() {

String tag = jdbcTemplate.queryForObject("SELECT str_tags FROM host WHERE pk_host=?",
String.class, host.id);
assertEquals("unassigned beta 64bit frick jack linux", tag);
assertEquals("unassigned 64bit linux beta frick jack", tag);
}

@Test
Expand All @@ -493,18 +492,18 @@ public void testChangeTags() {

String tag = jdbcTemplate.queryForObject("SELECT str_tags FROM host WHERE pk_host=?",
String.class, host.id);
assertEquals("unassigned beta 64bit linux", tag);
assertEquals("unassigned 64bit linux beta", tag);

hostDao.removeTag(host, "linux");
hostDao.recalcuateTags(host.id);

assertEquals("unassigned beta 64bit", jdbcTemplate.queryForObject(
assertEquals("unassigned 64bit beta", jdbcTemplate.queryForObject(
"SELECT str_tags FROM host WHERE pk_host=?", String.class, host.id));

hostDao.tagHost(host, "32bit", HostTagType.MANUAL);
hostDao.recalcuateTags(host.id);

assertEquals("unassigned beta 32bit 64bit", jdbcTemplate.queryForObject(
assertEquals("unassigned 64bit beta 32bit", jdbcTemplate.queryForObject(
"SELECT str_tags FROM host WHERE pk_host=?", String.class, host.id));
}

Expand Down Expand Up @@ -548,4 +547,55 @@ public void testIsNimby() {
DispatchHost host = hostManager.createHost(buildRenderHost(TEST_HOST));
assertFalse(hostDao.isNimbyHost(host));
}

@Test
@Transactional
@Rollback(true)
public void testUpdateHostTagsOnlyAffectsHardwareTags() {
// Create initial host with default RQD tags (linux, 64bit)
DispatchHost host = hostManager.createHost(buildRenderHost(TEST_HOST));

// Add some manual tags
hostDao.tagHost(host, "manual_tag1", HostTagType.MANUAL);
hostDao.tagHost(host, "manual_tag2", HostTagType.MANUAL);
hostDao.recalcuateTags(host.id);

String initialTags = jdbcTemplate
.queryForObject("SELECT str_tags FROM host WHERE pk_host=?", String.class, host.id);
assertEquals("unassigned 64bit linux beta manual_tag1 manual_tag2", initialTags);

// Create updated RenderHost with different hardware tags
RenderHost updatedRHost = buildRenderHost(TEST_HOST).toBuilder().clearTags()
.addTags("rqdv-2").addTags("windows").build();
hostManager.updateHostTags(host, updatedRHost);

// Check that hardware tags were updated but manual tags were preserved
String updatedTags = jdbcTemplate
.queryForObject("SELECT str_tags FROM host WHERE pk_host=?", String.class, host.id);
assertEquals("unassigned rqdv-2 windows beta manual_tag1 manual_tag2", updatedTags);
}

@Test
@Transactional
@Rollback(true)
public void testUpdateHostTagsRemovesManualDuplicates() {
// Create initial host with a manual tag that will become a hardware tag
DispatchHost host = hostManager.createHost(buildRenderHost(TEST_HOST));
hostDao.tagHost(host, "foo", HostTagType.MANUAL);
hostDao.recalcuateTags(host.id);

String initialTags = jdbcTemplate
.queryForObject("SELECT str_tags FROM host WHERE pk_host=?", String.class, host.id);
assertEquals("unassigned 64bit linux beta foo", initialTags);

// Update hardware tags to include "foo"
RenderHost updatedRHost = buildRenderHost(TEST_HOST).toBuilder().clearTags().addTags("foo")
.addTags("linux").build();
hostManager.updateHostTags(host, updatedRHost);

// Ensure "foo" appears only once and as a hardware tag
String updatedTags = jdbcTemplate
.queryForObject("SELECT str_tags FROM host WHERE pk_host=?", String.class, host.id);
assertEquals("unassigned foo linux beta", updatedTags);
}
}
Loading