From 36a505f21351b862bf09f2781e006e48f8952ad1 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Mon, 17 Nov 2025 10:34:30 +0200 Subject: [PATCH] Edge install instructions - refactored to use EdgeVersion from proto instead of package version --- .../BaseEdgeInstallUpgradeInstructionsService.java | 9 ++++++--- .../DefaultEdgeInstallInstructionsService.java | 5 +---- .../DefaultEdgeUpgradeInstructionsService.java | 12 +++--------- .../instructions/EdgeInstallInstructionsService.java | 2 +- .../instructions/EdgeUpgradeInstructionsService.java | 2 +- .../server/service/update/DefaultUpdateService.java | 4 ++-- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/edge/instructions/BaseEdgeInstallUpgradeInstructionsService.java b/application/src/main/java/org/thingsboard/server/service/edge/instructions/BaseEdgeInstallUpgradeInstructionsService.java index e8910492a3..7fa8f12a8e 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/instructions/BaseEdgeInstallUpgradeInstructionsService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/instructions/BaseEdgeInstallUpgradeInstructionsService.java @@ -18,7 +18,7 @@ package org.thingsboard.server.service.edge.instructions; import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; +import org.thingsboard.server.gen.edge.v1.EdgeVersion; import org.thingsboard.server.service.install.InstallScripts; import java.io.IOException; @@ -35,9 +35,12 @@ public abstract class BaseEdgeInstallUpgradeInstructionsService { private final InstallScripts installScripts; - @Value("${app.version:unknown}") @Setter - protected String appVersion; + protected String edgeVersion = convertEdgeVersionToDocsFormat(EdgeVersion.V_4_2_0.name()); + + protected String convertEdgeVersionToDocsFormat(String edgeVersion) { + return edgeVersion.replace("_", ".").substring(2); + } protected String readFile(Path file) { try { diff --git a/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallInstructionsService.java b/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallInstructionsService.java index e16a8be5b5..67bf256a38 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallInstructionsService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallInstructionsService.java @@ -65,9 +65,7 @@ public class DefaultEdgeInstallInstructionsService extends BaseEdgeInstallUpgrad dockerInstallInstructions = dockerInstallInstructions.replace("${EXTRA_HOSTS}", ""); dockerInstallInstructions = dockerInstallInstructions.replace("${BASE_URL}", baseUrl); } - String edgeVersion = appVersion + "EDGE"; - edgeVersion = edgeVersion.replace("-SNAPSHOT", ""); - dockerInstallInstructions = dockerInstallInstructions.replace("${TB_EDGE_VERSION}", edgeVersion); + dockerInstallInstructions = dockerInstallInstructions.replace("${TB_EDGE_VERSION}", edgeVersion + "EDGE"); dockerInstallInstructions = replacePlaceholders(dockerInstallInstructions, edge); return new EdgeInstructions(dockerInstallInstructions); } @@ -76,7 +74,6 @@ public class DefaultEdgeInstallInstructionsService extends BaseEdgeInstallUpgrad String ubuntuInstallInstructions = readFile(resolveFile(os, "instructions.md")); ubuntuInstallInstructions = replacePlaceholders(ubuntuInstallInstructions, edge); ubuntuInstallInstructions = ubuntuInstallInstructions.replace("${BASE_URL}", request.getServerName()); - String edgeVersion = appVersion.replace("-SNAPSHOT", ""); ubuntuInstallInstructions = ubuntuInstallInstructions.replace("${TB_EDGE_VERSION}", edgeVersion); ubuntuInstallInstructions = ubuntuInstallInstructions.replace("${TB_EDGE_TAG}", getTagVersion(edgeVersion)); return new EdgeInstructions(ubuntuInstallInstructions); diff --git a/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeUpgradeInstructionsService.java b/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeUpgradeInstructionsService.java index 2df75d603b..7199d70893 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeUpgradeInstructionsService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeUpgradeInstructionsService.java @@ -52,12 +52,11 @@ public class DefaultEdgeUpgradeInstructionsService extends BaseEdgeInstallUpgrad @Override public EdgeInstructions getUpgradeInstructions(String edgeVersion, String upgradeMethod) { - String tbVersion = appVersion.replace("-SNAPSHOT", ""); String currentEdgeVersion = convertEdgeVersionToDocsFormat(edgeVersion); return switch (upgradeMethod.toLowerCase()) { - case "docker" -> getDockerUpgradeInstructions(tbVersion, currentEdgeVersion); + case "docker" -> getDockerUpgradeInstructions(this.edgeVersion, currentEdgeVersion); case "ubuntu", "centos" -> - getLinuxUpgradeInstructions(tbVersion, currentEdgeVersion, upgradeMethod.toLowerCase()); + getLinuxUpgradeInstructions(this.edgeVersion, currentEdgeVersion, upgradeMethod.toLowerCase()); default -> throw new IllegalArgumentException("Unsupported upgrade method for Edge: " + upgradeMethod); }; } @@ -74,8 +73,7 @@ public class DefaultEdgeUpgradeInstructionsService extends BaseEdgeInstallUpgrad Optional attributeKvEntryOpt = attributesService.find(tenantId, edgeId, AttributeScope.SERVER_SCOPE, DataConstants.EDGE_VERSION_ATTR_KEY).get(); if (attributeKvEntryOpt.isPresent()) { String edgeVersionFormatted = convertEdgeVersionToDocsFormat(attributeKvEntryOpt.get().getValueAsString()); - String appVersionFormatted = appVersion.replace("-SNAPSHOT", ""); - return isVersionGreaterOrEqualsThan(edgeVersionFormatted, "3.6.0") && !isVersionGreaterOrEqualsThan(edgeVersionFormatted, appVersionFormatted); + return isVersionGreaterOrEqualsThan(edgeVersionFormatted, "3.6.0") && !isVersionGreaterOrEqualsThan(edgeVersionFormatted, edgeVersion); } return false; } @@ -155,10 +153,6 @@ public class DefaultEdgeUpgradeInstructionsService extends BaseEdgeInstallUpgrad return new EdgeInstructions(result.toString()); } - private String convertEdgeVersionToDocsFormat(String edgeVersion) { - return edgeVersion.replace("_", ".").substring(2); - } - @Override protected String getBaseDirName() { return UPGRADE_DIR; diff --git a/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallInstructionsService.java b/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallInstructionsService.java index d1719422ce..98c0fce058 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallInstructionsService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallInstructionsService.java @@ -23,6 +23,6 @@ public interface EdgeInstallInstructionsService { EdgeInstructions getInstallInstructions(Edge edge, String installationMethod, HttpServletRequest request); - void setAppVersion(String version); + void setEdgeVersion(String version); } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeUpgradeInstructionsService.java b/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeUpgradeInstructionsService.java index 9ae68ab2d0..7ee7697743 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeUpgradeInstructionsService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeUpgradeInstructionsService.java @@ -28,7 +28,7 @@ public interface EdgeUpgradeInstructionsService { void updateInstructionMap(Map upgradeVersions); - void setAppVersion(String version); + void setEdgeVersion(String version); boolean isUpgradeAvailable(TenantId tenantId, EdgeId edgeId) throws Exception; diff --git a/application/src/main/java/org/thingsboard/server/service/update/DefaultUpdateService.java b/application/src/main/java/org/thingsboard/server/service/update/DefaultUpdateService.java index 3c5ab63cd2..ab32d42d27 100644 --- a/application/src/main/java/org/thingsboard/server/service/update/DefaultUpdateService.java +++ b/application/src/main/java/org/thingsboard/server/service/update/DefaultUpdateService.java @@ -152,8 +152,8 @@ public class DefaultUpdateService implements UpdateService { ObjectNode edgeRequest = JacksonUtil.newObjectNode().put(VERSION_PARAM, version); String edgeInstallVersion = restClient.postForObject(UPDATE_SERVER_BASE_URL + "/api/v1/edge/installMapping", new HttpEntity<>(edgeRequest.toString(), headers), String.class); if (edgeInstallVersion != null) { - edgeInstallInstructionsService.setAppVersion(edgeInstallVersion); - edgeUpgradeInstructionsService.setAppVersion(edgeInstallVersion); + edgeInstallInstructionsService.setEdgeVersion(edgeInstallVersion); + edgeUpgradeInstructionsService.setEdgeVersion(edgeInstallVersion); } EdgeUpgradeMessage edgeUpgradeMessage = restClient.postForObject(UPDATE_SERVER_BASE_URL + "/api/v1/edge/upgradeMapping", new HttpEntity<>(edgeRequest.toString(), headers), EdgeUpgradeMessage.class); if (edgeUpgradeMessage != null) {