Browse Source

Resolve edge template version suffix per edition and accept CE-style tb-edge image in agent apps

pull/16261/head
Nikita Mazurenko 2 months ago
parent
commit
e266a8ef4e
  1. 17
      application/src/main/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncService.java
  2. 19
      application/src/test/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncServiceTest.java
  3. 5
      common/data/src/main/java/org/thingsboard/server/common/data/agent/AgentApplicationType.java
  4. 8
      common/data/src/test/java/org/thingsboard/server/common/data/agent/AgentApplicationTypeTest.java
  5. 2
      dao/src/main/java/org/thingsboard/server/dao/edge/EdgeEditionStyle.java

17
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<AppVersionDescriptor> 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<AppVersionDescriptor> appendVersionSuffix(List<AppVersionDescriptor> 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<AppVersionDescriptor> appendEdgeVersionSuffix(List<AppVersionDescriptor> 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<AppVersionDescriptor> filterCurrentlySupportedVersions(List<AppVersionDescriptor> descriptors) {
if (CollectionsUtil.isEmpty(descriptors)) {
return descriptors;

19
application/src/test/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncServiceTest.java

@ -135,10 +135,10 @@ class AgentAppTemplateSyncServiceTest {
}
@Test
void appendVersionSuffixRewritesBothVersionAndNextVersion() {
List<AppVersionDescriptor> result = AgentAppTemplateSyncService.appendVersionSuffix(List.of(
void appendEdgeVersionSuffixRewritesBothVersionAndNextVersion() {
List<AppVersionDescriptor> 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<AppVersionDescriptor> 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);
}
}

5
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());

8
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) {

2
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) {

Loading…
Cancel
Save