From 6b58730a4513250facd426791bc078ad7e32ea5f Mon Sep 17 00:00:00 2001 From: Nikita Mazurenko Date: Wed, 7 Oct 2026 12:54:06 +0200 Subject: [PATCH] Resolve CE-style 4.4+ edge images to their PE-style agent app templates on discovery --- .../agent/compose/ComposeAgentAppCreator.java | 9 ++++++ .../template/AgentAppTemplateSyncService.java | 2 +- .../compose/ComposeAgentAppCreatorTest.java | 32 +++++++++++++++++++ .../server/dao/edge/EdgeEditionStyle.java | 8 +++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/thingsboard/server/service/agent/compose/ComposeAgentAppCreator.java b/application/src/main/java/org/thingsboard/server/service/agent/compose/ComposeAgentAppCreator.java index e74a0cdb51..21b0376d6c 100644 --- a/application/src/main/java/org/thingsboard/server/service/agent/compose/ComposeAgentAppCreator.java +++ b/application/src/main/java/org/thingsboard/server/service/agent/compose/ComposeAgentAppCreator.java @@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.RegexUtils; +import org.thingsboard.common.util.TbVersionUtils; import org.thingsboard.server.common.data.agent.Agent; import org.thingsboard.server.common.data.agent.AgentAppEventActionType; import org.thingsboard.server.common.data.agent.AgentAppProfileRelationInfo; @@ -24,6 +25,7 @@ import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.dao.agent.AgentAppProfileService; import org.thingsboard.server.dao.agent.AgentAppRelationService; import org.thingsboard.server.dao.agent.AgentService; +import org.thingsboard.server.dao.edge.EdgeEditionStyle; import org.thingsboard.server.gen.agent.v1.ComposeState; import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.service.agent.AgentAppProvisioner; @@ -103,6 +105,13 @@ public class ComposeAgentAppCreator { private AgentAppTemplate resolveTemplate(ComposeInfo composeInfo) { AgentAppTemplate byAppType = templateService.findByAppTypeAndConfigTypeAndCurrentVersion( composeInfo.appType(), AgentAppConfigType.DOCKER_COMPOSE, composeInfo.version()); + if (byAppType == null && composeInfo.appType() == AgentApplicationType.EDGE && composeInfo.version() != null + && TbVersionUtils.compare(TbVersionUtils.extractStartingDigits(composeInfo.version()), "4.4") >= 0) { + // from 4.4 the same edge release may be published under both edition styles (e.g. 4.4.0EDGEPE and the CE-style 4.4.0EDGE), + // while its template is registered under one of them only; below 4.4 a CE-style tag is Community Edge and stays GENERIC + byAppType = templateService.findByAppTypeAndConfigTypeAndCurrentVersion(AgentApplicationType.EDGE, + AgentAppConfigType.DOCKER_COMPOSE, EdgeEditionStyle.withVersionSuffix(TbVersionUtils.extractStartingDigits(composeInfo.version()))); + } if (byAppType != null) { return byAppType; } diff --git a/application/src/main/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncService.java b/application/src/main/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncService.java index 56cb5d5e62..b265e28e7c 100644 --- a/application/src/main/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncService.java +++ b/application/src/main/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncService.java @@ -231,7 +231,7 @@ public class AgentAppTemplateSyncService { } private static String withEdgeVersionSuffix(String version) { - return version == null ? null : version + EdgeEditionStyle.getEdgeEditionStyle(version).getVersionSuffix(); + return version == null ? null : EdgeEditionStyle.withVersionSuffix(version); } List filterCurrentlySupportedVersions(List descriptors) { diff --git a/application/src/test/java/org/thingsboard/server/service/agent/compose/ComposeAgentAppCreatorTest.java b/application/src/test/java/org/thingsboard/server/service/agent/compose/ComposeAgentAppCreatorTest.java index 42f0700a8c..dfb21bce27 100644 --- a/application/src/test/java/org/thingsboard/server/service/agent/compose/ComposeAgentAppCreatorTest.java +++ b/application/src/test/java/org/thingsboard/server/service/agent/compose/ComposeAgentAppCreatorTest.java @@ -181,6 +181,38 @@ class ComposeAgentAppCreatorTest { assertThat(created.getTemplateVersion()).isEqualTo(AgentApplicationType.GENERIC.getDefaultVersion()); } + @Test + void ceStyleEdgeTag_resolvesTemplateRegisteredUnderPeStyleTag() { + AgentAppTemplate peStyleTemplate = template(AgentApplicationType.EDGE, "4.4.0EDGEPE"); + when(templateService.findByAppTypeAndConfigTypeAndCurrentVersion( + AgentApplicationType.EDGE, AgentAppConfigType.DOCKER_COMPOSE, "4.4.0EDGE")).thenReturn(null); + when(templateService.findByAppTypeAndConfigTypeAndCurrentVersion( + AgentApplicationType.EDGE, AgentAppConfigType.DOCKER_COMPOSE, "4.4.0EDGEPE")).thenReturn(peStyleTemplate); + when(appProfileService.findProfileRelationInfosByAgentProfileIdAndAppTypeAndTemplateVersion( + TENANT_ID, AGENT_PROFILE_ID, AgentApplicationType.EDGE, "4.4.0EDGEPE")).thenReturn(List.of()); + + AgentApplication created = creator.createApp(TENANT_ID, AGENT_ID, PROJECT_NAME, + compose("{\"services\":{\"tb-edge\":{\"image\":\"thingsboard/tb-edge:4.4.0EDGE\"}}}")); + + assertThat(created.getAppType()).isEqualTo(AgentApplicationType.EDGE); + assertThat(created.getTemplateVersion()).isEqualTo("4.4.0EDGEPE"); + + // below 4.4 a CE-style tag is Community Edge: no fallback to the PE-style template, the app stays GENERIC + AgentAppTemplate generic = template(AgentApplicationType.GENERIC, AgentApplicationType.GENERIC.getDefaultVersion()); + when(templateService.findByAppTypeAndConfigTypeAndCurrentVersion( + AgentApplicationType.EDGE, AgentAppConfigType.DOCKER_COMPOSE, "4.2.0EDGE")).thenReturn(null); + when(templateService.findByAppTypeAndConfigTypeAndCurrentVersion( + AgentApplicationType.EDGE, AgentAppConfigType.DOCKER_COMPOSE, "4.2.0EDGEPE")).thenReturn(template(AgentApplicationType.EDGE, "4.2.0EDGEPE")); + when(templateService.findByAppTypeAndConfigTypeAndCurrentVersion( + AgentApplicationType.GENERIC, AgentAppConfigType.DOCKER_COMPOSE, AgentApplicationType.GENERIC.getDefaultVersion())).thenReturn(generic); + + AgentApplication community = creator.createApp(TENANT_ID, AGENT_ID, PROJECT_NAME, + compose("{\"services\":{\"tb-edge\":{\"image\":\"thingsboard/tb-edge:4.2.0EDGE\"}}}")); + + assertThat(community.getAppType()).isEqualTo(AgentApplicationType.GENERIC); + assertThat(community.getTemplateVersion()).isEqualTo(AgentApplicationType.GENERIC.getDefaultVersion()); + } + @Test void noTemplateAtAll_returnsNull() { when(templateService.findByAppTypeAndConfigTypeAndCurrentVersion(any(), any(), any())).thenReturn(null); diff --git a/dao/src/main/java/org/thingsboard/server/dao/edge/EdgeEditionStyle.java b/dao/src/main/java/org/thingsboard/server/dao/edge/EdgeEditionStyle.java index b51d275ab7..6cfcb5df2d 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/edge/EdgeEditionStyle.java +++ b/dao/src/main/java/org/thingsboard/server/dao/edge/EdgeEditionStyle.java @@ -20,6 +20,14 @@ public enum EdgeEditionStyle { return TbVersionUtils.compare(edgeVersion, "4.4.0.1") >= 0 ? CE : PE; } + /** + * The edge version with the tag suffix its release is published under, e.g. {@code 4.4.0EDGEPE}, {@code 4.4.0.1EDGE}. + * Agent app templates are registered under these versions. + */ + public static String withVersionSuffix(String edgeVersion) { + return edgeVersion + getEdgeEditionStyle(edgeVersion).getVersionSuffix(); + } + public String replacePlaceholders(String instructions) { return instructions .replace("${TB_EDGE_REPO}", dockerRepo)