Browse Source

Resolve CE-style 4.4+ edge images to their PE-style agent app templates on discovery

pull/16261/head
Nikita Mazurenko 2 months ago
parent
commit
6b58730a45
  1. 9
      application/src/main/java/org/thingsboard/server/service/agent/compose/ComposeAgentAppCreator.java
  2. 2
      application/src/main/java/org/thingsboard/server/service/agent/template/AgentAppTemplateSyncService.java
  3. 32
      application/src/test/java/org/thingsboard/server/service/agent/compose/ComposeAgentAppCreatorTest.java
  4. 8
      dao/src/main/java/org/thingsboard/server/dao/edge/EdgeEditionStyle.java

9
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;
}

2
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<AppVersionDescriptor> filterCurrentlySupportedVersions(List<AppVersionDescriptor> descriptors) {

32
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);

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

Loading…
Cancel
Save