diff --git a/application/src/main/data/json/edge/instructions/upgrade/upgrade_db.md b/application/src/main/data/json/edge/instructions/upgrade/upgrade_db.md index d3a28fb20b..6e7beb1425 100644 --- a/application/src/main/data/json/edge/instructions/upgrade/upgrade_db.md +++ b/application/src/main/data/json/edge/instructions/upgrade/upgrade_db.md @@ -3,6 +3,6 @@ Execute regular upgrade script: ```bash -sudo /usr/share/tb-edge/bin/install/upgrade.sh --fromVersion=${CURRENT_TB_EDGE_VERSION} +sudo /usr/share/tb-edge/bin/install/upgrade.sh --fromVersion=${FROM_TB_EDGE_VERSION} {:copy-code} ``` diff --git a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java index a1291d9440..7556ab589b 100644 --- a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java +++ b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java @@ -59,8 +59,8 @@ import org.thingsboard.server.dao.exception.IncorrectParameterException; import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.service.edge.EdgeBulkImportService; -import org.thingsboard.server.service.edge.instructions.EdgeInstallService; -import org.thingsboard.server.service.edge.instructions.EdgeUpgradeService; +import org.thingsboard.server.service.edge.instructions.EdgeInstallInstructionsService; +import org.thingsboard.server.service.edge.instructions.EdgeUpgradeInstructionsService; import org.thingsboard.server.service.edge.rpc.EdgeRpcService; import org.thingsboard.server.service.entitiy.edge.TbEdgeService; import org.thingsboard.server.service.security.model.SecurityUser; @@ -102,8 +102,8 @@ public class EdgeController extends BaseController { private final EdgeBulkImportService edgeBulkImportService; private final TbEdgeService tbEdgeService; private final Optional edgeRpcServiceOpt; - private final Optional edgeInstallServiceOpt; - private final Optional edgeUpgradeServiceOpt; + private final Optional edgeInstallServiceOpt; + private final Optional edgeUpgradeServiceOpt; public static final String EDGE_ID = "edgeId"; public static final String EDGE_SECURITY_CHECK = "If the user has the authority of 'Tenant Administrator', the server checks that the edge is owned by the same tenant. " + @@ -564,7 +564,7 @@ public class EdgeController extends BaseController { public EdgeInstructions getEdgeInstallInstructions( @ApiParam(value = EDGE_ID_PARAM_DESCRIPTION, required = true) @PathVariable("edgeId") String strEdgeId, - @ApiParam(value = "Installation method ('docker', 'ubuntu' or 'centos')", allowableValues = "docker,ubuntu,centos") + @ApiParam(value = "Installation method ('docker', 'ubuntu' or 'centos')", allowableValues = "docker, ubuntu, centos") @PathVariable("method") String installationMethod, HttpServletRequest request) throws ThingsboardException { if (isEdgesEnabled() && edgeInstallServiceOpt.isPresent()) { @@ -578,7 +578,7 @@ public class EdgeController extends BaseController { } @ApiOperation(value = "Get Edge Upgrade Instructions (getEdgeUpgradeInstructions)", - notes = "Get an upgrade instructions for provided edge id." + TENANT_AUTHORITY_PARAGRAPH, + notes = "Get an upgrade instructions for provided edge version." + TENANT_AUTHORITY_PARAGRAPH, produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") @RequestMapping(value = "/edge/instructions/upgrade/{edgeVersion}/{method}", method = RequestMethod.GET) @@ -586,7 +586,7 @@ public class EdgeController extends BaseController { public EdgeInstructions getEdgeUpgradeInstructions( @ApiParam(value = "Edge version", required = true) @PathVariable("edgeVersion") String edgeVersion, - @ApiParam(value = "Installation method ('docker', 'ubuntu' or 'centos')", allowableValues = "docker,ubuntu,centos") + @ApiParam(value = "Upgrade method ('docker', 'ubuntu' or 'centos')", allowableValues = "docker, ubuntu, centos") @PathVariable("method") String method) throws Exception { if (isEdgesEnabled() && edgeUpgradeServiceOpt.isPresent()) { return checkNotNull(edgeUpgradeServiceOpt.get().getUpgradeInstructions(edgeVersion, method)); diff --git a/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallService.java b/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallInstructionsService.java similarity index 98% rename from application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallService.java rename to application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallInstructionsService.java index 8ebc5322c7..9da2b2abe8 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallInstructionsService.java @@ -36,7 +36,7 @@ import java.nio.file.Paths; @RequiredArgsConstructor @ConditionalOnProperty(prefix = "edges", value = "enabled", havingValue = "true") @TbCoreComponent -public class DefaultEdgeInstallService implements EdgeInstallService { +public class DefaultEdgeInstallInstructionsService implements EdgeInstallInstructionsService { private static final String EDGE_DIR = "edge"; private static final String INSTRUCTIONS_DIR = "instructions"; diff --git a/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeUpgradeService.java b/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeUpgradeService.java index 8586ad5b4d..7ad9e94977 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeUpgradeService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeUpgradeService.java @@ -37,7 +37,7 @@ import java.util.HashMap; @RequiredArgsConstructor @ConditionalOnProperty(prefix = "edges", value = "enabled", havingValue = "true") @TbCoreComponent -public class DefaultEdgeUpgradeService implements EdgeUpgradeService { +public class DefaultEdgeUpgradeService implements EdgeUpgradeInstructionsService { private static final HashMap upgradeVersionHashMap; @@ -96,7 +96,7 @@ public class DefaultEdgeUpgradeService implements EdgeUpgradeService { ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CLEAR_DOCKER_UPGRADE}", rmUpgrade); } ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${TB_EDGE_VERSION}", edgeVersion + "EDGE"); - ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CURRENT_TB_EDGE_VERSION}", currentEdgeVersion + "EDGE"); + ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${FROM_TB_EDGE_VERSION}", currentEdgeVersion + "EDGE"); currentEdgeVersion = edgeVersion; upgradeInfo = upgradeVersionHashMap.get(upgradeInfo.getNextVersion()); result.append(ubuntuUpgradeInstructions); @@ -125,9 +125,9 @@ public class DefaultEdgeUpgradeService implements EdgeUpgradeService { ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${UPGRADE_DB}", ""); } ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${TB_EDGE_TAG}", getTagVersion(edgeVersion)); - ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CURRENT_TB_EDGE_TAG}", getTagVersion(currentEdgeVersion)); + ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${FROM_TB_EDGE_TAG}", getTagVersion(currentEdgeVersion)); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${TB_EDGE_VERSION}", edgeVersion); - ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CURRENT_TB_EDGE_VERSION}", currentEdgeVersion); + ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${FROM_TB_EDGE_VERSION}", currentEdgeVersion); currentEdgeVersion = edgeVersion; upgradeInfo = upgradeVersionHashMap.get(upgradeInfo.getNextVersion()); result.append(ubuntuUpgradeInstructions); diff --git a/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallService.java b/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallInstructionsService.java similarity index 95% rename from application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallService.java rename to application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallInstructionsService.java index 996e14f16e..af97d7a393 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallInstructionsService.java @@ -20,7 +20,7 @@ import org.thingsboard.server.common.data.edge.EdgeInstructions; import javax.servlet.http.HttpServletRequest; -public interface EdgeInstallService { +public interface EdgeInstallInstructionsService { EdgeInstructions getInstallInstructions(Edge edge, String installationMethod, HttpServletRequest request); } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeUpgradeService.java b/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeUpgradeInstructionsService.java similarity index 94% rename from application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeUpgradeService.java rename to application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeUpgradeInstructionsService.java index b7747655ef..61abd113dc 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeUpgradeService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeUpgradeInstructionsService.java @@ -17,7 +17,7 @@ package org.thingsboard.server.service.edge.instructions; import org.thingsboard.server.common.data.edge.EdgeInstructions; -public interface EdgeUpgradeService { +public interface EdgeUpgradeInstructionsService { EdgeInstructions getUpgradeInstructions(String edgeVersion, String upgradeMethod); } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java index 32d648c045..4593384594 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java @@ -775,7 +775,8 @@ public final class EdgeGrpcSession implements Closeable { try { if (edge.getSecret().equals(request.getEdgeSecret())) { sessionOpenListener.accept(edge.getId(), this); - this.edgeVersion = processGetAndSaveEdgeVersion(request.getEdgeVersion()); + this.edgeVersion = request.getEdgeVersion(); + processSaveEdgeVersionAsAttribute(request.getEdgeVersion().name()); return ConnectResponseMsg.newBuilder() .setResponseCode(ConnectResponseCode.ACCEPTED) .setErrorMsg("") @@ -801,10 +802,9 @@ public final class EdgeGrpcSession implements Closeable { .setConfiguration(EdgeConfiguration.getDefaultInstance()).build(); } - private EdgeVersion processGetAndSaveEdgeVersion(EdgeVersion edgeVersion) { - AttributeKvEntry attributeKvEntry = new BaseAttributeKvEntry(new StringDataEntry("edgeVersion", edgeVersion.name()), System.currentTimeMillis()); + private void processSaveEdgeVersionAsAttribute(String edgeVersion) { + AttributeKvEntry attributeKvEntry = new BaseAttributeKvEntry(new StringDataEntry("edgeVersion", edgeVersion), System.currentTimeMillis()); ctx.getAttributesService().save(this.tenantId, this.edge.getId(), DataConstants.SERVER_SCOPE, attributeKvEntry); - return edgeVersion; } @Override diff --git a/application/src/test/java/org/thingsboard/server/controller/EdgeControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/EdgeControllerTest.java index c41d835251..836b5903a5 100644 --- a/application/src/test/java/org/thingsboard/server/controller/EdgeControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/EdgeControllerTest.java @@ -68,6 +68,7 @@ import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; import org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg; +import org.thingsboard.server.gen.edge.v1.EdgeVersion; import org.thingsboard.server.gen.edge.v1.QueueUpdateMsg; import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; import org.thingsboard.server.gen.edge.v1.SyncCompletedMsg; @@ -125,7 +126,7 @@ public class EdgeControllerTest extends AbstractControllerTest { } @After - public void teardownEdgeTest() throws Exception { + public void teardownEdgeTest() { executor.shutdownNow(); } @@ -1155,4 +1156,15 @@ public class EdgeControllerTest extends AbstractControllerTest { Assert.assertTrue(installInstructions.contains("l7q4zsjplzwhk16geqxy")); Assert.assertTrue(installInstructions.contains("7390c3a6-69b0-9910-d155-b90aca4b772e")); } + + @Test + public void testGetEdgeUpgradeInstructions() throws Exception { + Edge edge = constructEdge("Edge for Test Docker Upgrade Instructions", "default"); + Edge savedEdge = doPost("/api/edge", edge, Edge.class); + String body = "{\"edgeVersion\": \"V_3_6_0\"}"; + doPostAsync("/api/plugins/telemetry/EDGE/" + savedEdge.getId().getId() + "/attributes/SERVER_SCOPE", body, String.class, status().isOk()); + String upgradeInstructions = doGet("/api/edge/instructions/upgrade/" + EdgeVersion.V_3_6_0.name() + "/docker", String.class); + Assert.assertTrue(upgradeInstructions.contains("Upgrading to 3.6.1EDGE")); + Assert.assertTrue(upgradeInstructions.contains("Upgrading to 3.6.2EDGE")); + } } diff --git a/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java b/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java index a9b12865a2..973c50c1d2 100644 --- a/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java +++ b/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java @@ -111,7 +111,7 @@ public class EdgeGrpcClient implements EdgeRpcClient { .setConnectRequestMsg(ConnectRequestMsg.newBuilder() .setEdgeRoutingKey(edgeKey) .setEdgeSecret(edgeSecret) - .setEdgeVersion(EdgeVersion.V_3_6_1) + .setEdgeVersion(EdgeVersion.V_3_6_2) .setMaxInboundMessageSize(maxInboundMessageSize) .build()) .build()); diff --git a/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java b/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java index d90a58fde8..de35623a4e 100644 --- a/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java +++ b/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java @@ -3241,12 +3241,18 @@ public class RestClient implements Closeable { }).getBody(); } - public Optional getEdgeDockerInstallInstructions(EdgeId edgeId, String method) { + public Optional getEdgeInstallInstructions(EdgeId edgeId, String method) { ResponseEntity edgeInstallInstructionsResult = restTemplate.getForEntity(baseURL + "/api/edge/instructions/install/{edgeId}/{method}", EdgeInstructions.class, edgeId.getId(), method); return Optional.ofNullable(edgeInstallInstructionsResult.getBody()); } + public Optional getEdgeUpgradeInstructions(String edgeVersion, String method) { + ResponseEntity edgeUpgradeInstructionsResult = + restTemplate.getForEntity(baseURL + "/api/edge/instructions/upgrade/{edgeVersion}/{method}", EdgeInstructions.class, edgeVersion, method); + return Optional.ofNullable(edgeUpgradeInstructionsResult.getBody()); + } + public UUID saveEntitiesVersion(VersionCreateRequest request) { return restTemplate.postForEntity(baseURL + "/api/entities/vc/version", request, UUID.class).getBody(); }