diff --git a/cuebot/src/main/java/com/imageworks/spcue/dispatcher/HostReportHandler.java b/cuebot/src/main/java/com/imageworks/spcue/dispatcher/HostReportHandler.java index 7bd73ef3d..cb9618db7 100644 --- a/cuebot/src/main/java/com/imageworks/spcue/dispatcher/HostReportHandler.java +++ b/cuebot/src/main/java/com/imageworks/spcue/dispatcher/HostReportHandler.java @@ -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()); diff --git a/cuebot/src/main/java/com/imageworks/spcue/service/HostManager.java b/cuebot/src/main/java/com/imageworks/spcue/service/HostManager.java index 76d5282b2..5913a7861 100644 --- a/cuebot/src/main/java/com/imageworks/spcue/service/HostManager.java +++ b/cuebot/src/main/java/com/imageworks/spcue/service/HostManager.java @@ -1,4 +1,3 @@ - /* * Copyright Contributors to the OpenCue Project * @@ -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); } diff --git a/cuebot/src/main/java/com/imageworks/spcue/service/HostManagerService.java b/cuebot/src/main/java/com/imageworks/spcue/service/HostManagerService.java index 1432f7169..e7cee2248 100644 --- a/cuebot/src/main/java/com/imageworks/spcue/service/HostManagerService.java +++ b/cuebot/src/main/java/com/imageworks/spcue/service/HostManagerService.java @@ -1,4 +1,3 @@ - /* * Copyright Contributors to the OpenCue Project * @@ -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; @@ -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()); + } } diff --git a/cuebot/src/test/java/com/imageworks/spcue/test/dao/postgres/HostDaoTests.java b/cuebot/src/test/java/com/imageworks/spcue/test/dao/postgres/HostDaoTests.java index 77f0b2799..796617fdc 100644 --- a/cuebot/src/test/java/com/imageworks/spcue/test/dao/postgres/HostDaoTests.java +++ b/cuebot/src/test/java/com/imageworks/spcue/test/dao/postgres/HostDaoTests.java @@ -1,4 +1,3 @@ - /* * Copyright Contributors to the OpenCue Project * @@ -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 @@ -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)); } @@ -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); + } }