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 fd339ddb5f..9a70064ea8 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 @@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.EdgeUpgradeMessageV2; import org.thingsboard.server.common.data.agent.AgentApplicationType; import org.thingsboard.server.common.data.agent.config.AgentAppConfigType; import org.thingsboard.server.common.data.util.CollectionsUtil; +import org.thingsboard.server.dao.edge.EdgeEditionStyle; import org.thingsboard.server.dao.sql.agent.AppTemplateRegistry; import org.thingsboard.server.queue.util.AfterStartUp; import org.thingsboard.server.queue.util.TbCoreComponent; @@ -68,7 +69,6 @@ public class AgentAppTemplateSyncService { private static final int APP_TYPE_GROUP_NUM = 1; private static final int CONFIG_TYPE_GROUP_NUM = 2; private static final String REPO_KEY = "agent-app-templates"; - private static final String EDGE_IMAGE_VERSION_SUFFIX = "EDGEPE"; private static final Duration UPDATE_SERVER_CONNECT_TIMEOUT = Duration.ofSeconds(10); private static final Duration UPDATE_SERVER_READ_TIMEOUT = Duration.ofSeconds(30); @@ -169,8 +169,8 @@ public class AgentAppTemplateSyncService { private List resolveDescriptors(AgentApplicationType appType) { return switch (appType) { - case EDGE -> appendVersionSuffix(filterCurrentlySupportedVersions( - filterVersionsWithoutTemplates(edgeDescriptors(), minSupportedEdgeVersion, appType)), EDGE_IMAGE_VERSION_SUFFIX); + case EDGE -> appendEdgeVersionSuffix(filterCurrentlySupportedVersions( + filterVersionsWithoutTemplates(edgeDescriptors(), minSupportedEdgeVersion, appType))); case GATEWAY -> filterVersionsWithoutTemplates( buildDescriptors(gatewayVersionGraph(), "gatewayVersions", "nextGatewayVersion", false), minSupportedGatewayVersion, appType); @@ -178,18 +178,23 @@ public class AgentAppTemplateSyncService { }; } - static List appendVersionSuffix(List descriptors, String suffix) { + // edge image tags carry an edition suffix that depends on the version itself (e.g. 4.4.0EDGEPE vs 4.4.1EDGE) + static List appendEdgeVersionSuffix(List descriptors) { if (CollectionsUtil.isEmpty(descriptors)) { return descriptors; } return descriptors.stream() .map(d -> new AppVersionDescriptor( - d.getVersion() + suffix, - d.getNextVersion() == null ? null : d.getNextVersion() + suffix, + withEdgeVersionSuffix(d.getVersion()), + withEdgeVersionSuffix(d.getNextVersion()), d.isRequiresUpdateDb())) .collect(Collectors.toList()); } + private static String withEdgeVersionSuffix(String version) { + return version == null ? null : version + EdgeEditionStyle.getEdgeEditionStyle(version).getVersionSuffix(); + } + List filterCurrentlySupportedVersions(List descriptors) { if (CollectionsUtil.isEmpty(descriptors)) { return descriptors; diff --git a/application/src/test/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncServiceTest.java b/application/src/test/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncServiceTest.java index 4f345aff4f..677c6e3baf 100644 --- a/application/src/test/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncServiceTest.java +++ b/application/src/test/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncServiceTest.java @@ -135,10 +135,10 @@ class AgentAppTemplateSyncServiceTest { } @Test - void appendVersionSuffixRewritesBothVersionAndNextVersion() { - List result = AgentAppTemplateSyncService.appendVersionSuffix(List.of( + void appendEdgeVersionSuffixRewritesBothVersionAndNextVersion() { + List result = AgentAppTemplateSyncService.appendEdgeVersionSuffix(List.of( new AppVersionDescriptor("4.1.0", "4.2.0", true), - new AppVersionDescriptor("4.2.0", null, false)), "EDGEPE"); + new AppVersionDescriptor("4.2.0", null, false))); assertThat(result).extracting(AppVersionDescriptor::getVersion) .containsExactly("4.1.0EDGEPE", "4.2.0EDGEPE"); @@ -146,4 +146,17 @@ class AgentAppTemplateSyncServiceTest { assertThat(result.get(0).isRequiresUpdateDb()).isTrue(); assertThat(result.get(1).getNextVersion()).isNull(); } + + @Test + void appendEdgeVersionSuffixSwitchesToCeStyleFrom441() { + List result = AgentAppTemplateSyncService.appendEdgeVersionSuffix(List.of( + new AppVersionDescriptor("4.4.0", "4.4.0.1", false), + new AppVersionDescriptor("4.4.0.1", "4.4.1", true), + new AppVersionDescriptor("4.4.1", null, false))); + + assertThat(result).extracting(AppVersionDescriptor::getVersion) + .containsExactly("4.4.0EDGEPE", "4.4.0.1EDGEPE", "4.4.1EDGE"); + assertThat(result).extracting(AppVersionDescriptor::getNextVersion) + .containsExactly("4.4.0.1EDGEPE", "4.4.1EDGE", null); + } } diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/agent/AgentApplicationType.java b/common/data/src/main/java/org/thingsboard/server/common/data/agent/AgentApplicationType.java index eddc7da972..1e22b7ee44 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/agent/AgentApplicationType.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/agent/AgentApplicationType.java @@ -15,8 +15,9 @@ public enum AgentApplicationType { // GENERIC has no version graph; its single template is materialized and registered under this defaultVersion. GENERIC(null, "default", null, Collections.emptyList()), // the leading "(?:[^/\s]+/)*" accepts optional registry/namespace segments, so an image pulled through a - // private mirror still matches: patterns are applied with Matcher.matches() over the whole image reference - EDGE("(?:[^/\\s]+/)*thingsboard/tb-edge-pe:.+", null, EntityType.EDGE, + // private mirror still matches: patterns are applied with Matcher.matches() over the whole image reference; + // edge accepts both the CE-style "tb-edge" repo and the legacy "tb-edge-pe" one + EDGE("(?:[^/\\s]+/)*thingsboard/tb-edge(?:-pe)?:.+", null, EntityType.EDGE, List.of("CLOUD_ROUTING_KEY", "CLOUD_ROUTING_SECRET")), GATEWAY("(?:[^/\\s]+/)*thingsboard/tb-gateway:.+", null, EntityType.DEVICE, gatewayCredentialEnvKeys()); diff --git a/common/data/src/test/java/org/thingsboard/server/common/data/agent/AgentApplicationTypeTest.java b/common/data/src/test/java/org/thingsboard/server/common/data/agent/AgentApplicationTypeTest.java index 2be1697cfd..f9be8d8408 100644 --- a/common/data/src/test/java/org/thingsboard/server/common/data/agent/AgentApplicationTypeTest.java +++ b/common/data/src/test/java/org/thingsboard/server/common/data/agent/AgentApplicationTypeTest.java @@ -15,7 +15,9 @@ class AgentApplicationTypeTest { "thingsboard/tb-edge-pe:4.2.0", "registry.example.com/thingsboard/tb-edge-pe:4.2.0", "registry.example.com:5000/thingsboard/tb-edge-pe:4.2.0", - "my-mirror/proxy/thingsboard/tb-edge-pe:4.2.0" + "my-mirror/proxy/thingsboard/tb-edge-pe:4.2.0", + "thingsboard/tb-edge:4.5.0EDGE", + "registry.example.com/thingsboard/tb-edge:4.5.0EDGE" }) void edgePatternAcceptsDockerHubAndMirroredImages(String image) { assertThat(AgentApplicationType.EDGE.getMainImagePattern().matcher(image).matches()).isTrue(); @@ -33,8 +35,10 @@ class AgentApplicationTypeTest { @ParameterizedTest @ValueSource(strings = { "thingsboard/tb-edge-pe", - "thingsboard/tb-edge:4.2.0", + "thingsboard/tb-edge", + "thingsboard/tb-edge-foo:4.2.0", "someone/tb-edge-pe:4.2.0", + "someone/tb-edge:4.5.0EDGE", "registry.example.com/thingsboard/tb-gateway:3.8.0" }) void edgePatternStillRejectsAnythingButTheEdgeImage(String image) { 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 178d22dfac..382aa1ced1 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 @@ -15,7 +15,7 @@ public enum EdgeEditionStyle { private final String packageSuffix; public static EdgeEditionStyle getEdgeEditionStyle(String edgeVersion) { - return TbVersionUtils.compare(edgeVersion, "4.4") > 0 ? CE : PE; + return TbVersionUtils.compare(edgeVersion, "4.4.1") >= 0 ? CE : PE; } public String replacePlaceholders(String instructions) {