Edge install instructions update. Use Java 17. Fix tag usage
This commit is contained in:
		
							parent
							
								
									9e16594611
								
							
						
					
					
						commit
						b48387a733
					
				@ -8,15 +8,15 @@ sudo yum install -y nano wget
 | 
			
		||||
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
#### Install Java 11 (OpenJDK)
 | 
			
		||||
ThingsBoard service is running on Java 11. Follow these instructions to install OpenJDK 11:
 | 
			
		||||
#### Install Java 17 (OpenJDK)
 | 
			
		||||
ThingsBoard service is running on Java 17. Follow these instructions to install OpenJDK 17:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
sudo yum install java-11-openjdk
 | 
			
		||||
sudo yum install java-17-openjdk
 | 
			
		||||
{:copy-code}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Please don't forget to configure your operating system to use OpenJDK 11 by default.
 | 
			
		||||
Please don't forget to configure your operating system to use OpenJDK 17 by default.
 | 
			
		||||
You can configure which version is the default using the following command:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
@ -34,7 +34,7 @@ java -version
 | 
			
		||||
Expected command output is:
 | 
			
		||||
 | 
			
		||||
```text
 | 
			
		||||
openjdk version "11.0.xx"
 | 
			
		||||
openjdk version "17.x.xx"
 | 
			
		||||
OpenJDK Runtime Environment (...)
 | 
			
		||||
OpenJDK 64-Bit Server VM (build ...)
 | 
			
		||||
```
 | 
			
		||||
@ -144,14 +144,14 @@ CREATE DATABASE tb_edge;
 | 
			
		||||
Download installation package:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
wget https://github.com/thingsboard/thingsboard-edge/releases/download/v${TB_EDGE_VERSION}/tb-edge-${TB_EDGE_VERSION}.rpm
 | 
			
		||||
wget https://github.com/thingsboard/thingsboard-edge/releases/download/v${TB_EDGE_TAG}/tb-edge-${TB_EDGE_TAG}.rpm
 | 
			
		||||
{:copy-code}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Go to the download repository and install ThingsBoard Edge service:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
sudo rpm -Uvh tb-edge-${TB_EDGE_VERSION}.rpm
 | 
			
		||||
sudo rpm -Uvh tb-edge-${TB_EDGE_TAG}.rpm
 | 
			
		||||
{:copy-code}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,15 +1,15 @@
 | 
			
		||||
Here is the list of commands, that can be used to quickly install ThingsBoard Edge on Ubuntu Server and connect to the server.
 | 
			
		||||
 | 
			
		||||
#### Install Java 11 (OpenJDK)
 | 
			
		||||
ThingsBoard service is running on Java 11. Follow these instructions to install OpenJDK 11:
 | 
			
		||||
#### Install Java 17 (OpenJDK)
 | 
			
		||||
ThingsBoard service is running on Java 17. Follow these instructions to install OpenJDK 17:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
sudo apt update
 | 
			
		||||
sudo apt install openjdk-11-jdk
 | 
			
		||||
sudo apt install openjdk-17-jdk
 | 
			
		||||
{:copy-code}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Please don't forget to configure your operating system to use OpenJDK 11 by default.
 | 
			
		||||
Please don't forget to configure your operating system to use OpenJDK 17 by default.
 | 
			
		||||
You can configure which version is the default using the following command:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
@ -27,7 +27,7 @@ java -version
 | 
			
		||||
Expected command output is:
 | 
			
		||||
 | 
			
		||||
```text
 | 
			
		||||
openjdk version "11.0.xx"
 | 
			
		||||
openjdk version "17.x.xx"
 | 
			
		||||
OpenJDK Runtime Environment (...)
 | 
			
		||||
OpenJDK 64-Bit Server VM (build ...)
 | 
			
		||||
```
 | 
			
		||||
@ -76,14 +76,14 @@ CREATE DATABASE tb_edge;
 | 
			
		||||
Download installation package:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
wget https://github.com/thingsboard/thingsboard-edge/releases/download/v${TB_EDGE_VERSION}/tb-edge-${TB_EDGE_VERSION}.deb
 | 
			
		||||
wget https://github.com/thingsboard/thingsboard-edge/releases/download/v${TB_EDGE_TAG}/tb-edge-${TB_EDGE_TAG}.deb
 | 
			
		||||
{:copy-code}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Go to the download repository and install ThingsBoard Edge service:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
sudo dpkg -i tb-edge-${TB_EDGE_VERSION}.deb
 | 
			
		||||
sudo dpkg -i tb-edge-${TB_EDGE_TAG}.deb
 | 
			
		||||
{:copy-code}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,65 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Copyright © 2016-2024 The Thingsboard Authors
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
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.service.install.InstallScripts;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.nio.file.Files;
 | 
			
		||||
import java.nio.file.Path;
 | 
			
		||||
import java.nio.file.Paths;
 | 
			
		||||
 | 
			
		||||
@Slf4j
 | 
			
		||||
@RequiredArgsConstructor
 | 
			
		||||
public abstract class BaseEdgeInstallUpgradeInstructionsService {
 | 
			
		||||
 | 
			
		||||
    private static final String EDGE_DIR = "edge";
 | 
			
		||||
    private static final String INSTRUCTIONS_DIR = "instructions";
 | 
			
		||||
 | 
			
		||||
    private final InstallScripts installScripts;
 | 
			
		||||
 | 
			
		||||
    @Value("${app.version:unknown}")
 | 
			
		||||
    @Setter
 | 
			
		||||
    protected String appVersion;
 | 
			
		||||
 | 
			
		||||
    protected String readFile(Path file) {
 | 
			
		||||
        try {
 | 
			
		||||
            return Files.readString(file);
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            log.warn("Failed to read file: {}", file, e);
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected String getTagVersion(String version) {
 | 
			
		||||
        return version.endsWith(".0") ? version.substring(0, version.length() - 2) : version;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected Path resolveFile(String subDir, String... subDirs) {
 | 
			
		||||
        return getEdgeInstructionsDir().resolve(Paths.get(subDir, subDirs));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected Path getEdgeInstructionsDir() {
 | 
			
		||||
        return Paths.get(installScripts.getDataDir(), InstallScripts.JSON_DIR, EDGE_DIR, INSTRUCTIONS_DIR, getBaseDirName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected abstract String getBaseDirName();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -15,8 +15,7 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.service.edge.instructions;
 | 
			
		||||
 | 
			
		||||
import lombok.RequiredArgsConstructor;
 | 
			
		||||
import lombok.Setter;
 | 
			
		||||
import jakarta.servlet.http.HttpServletRequest;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Value;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 | 
			
		||||
@ -27,47 +26,32 @@ import org.thingsboard.server.dao.util.DeviceConnectivityUtil;
 | 
			
		||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
			
		||||
import org.thingsboard.server.service.install.InstallScripts;
 | 
			
		||||
 | 
			
		||||
import jakarta.servlet.http.HttpServletRequest;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.nio.file.Files;
 | 
			
		||||
import java.nio.file.Path;
 | 
			
		||||
import java.nio.file.Paths;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@Slf4j
 | 
			
		||||
@RequiredArgsConstructor
 | 
			
		||||
@ConditionalOnProperty(prefix = "edges", value = "enabled", havingValue = "true")
 | 
			
		||||
@TbCoreComponent
 | 
			
		||||
public class DefaultEdgeInstallInstructionsService implements EdgeInstallInstructionsService {
 | 
			
		||||
public class DefaultEdgeInstallInstructionsService extends BaseEdgeInstallUpgradeInstructionsService implements EdgeInstallInstructionsService {
 | 
			
		||||
 | 
			
		||||
    private static final String EDGE_DIR = "edge";
 | 
			
		||||
    private static final String INSTRUCTIONS_DIR = "instructions";
 | 
			
		||||
    private static final String INSTALL_DIR = "install";
 | 
			
		||||
 | 
			
		||||
    private final InstallScripts installScripts;
 | 
			
		||||
 | 
			
		||||
    @Value("${edges.rpc.port}")
 | 
			
		||||
    private int rpcPort;
 | 
			
		||||
 | 
			
		||||
    @Value("${edges.rpc.ssl.enabled}")
 | 
			
		||||
    private boolean sslEnabled;
 | 
			
		||||
 | 
			
		||||
    @Value("${app.version:unknown}")
 | 
			
		||||
    @Setter
 | 
			
		||||
    private String appVersion;
 | 
			
		||||
    public DefaultEdgeInstallInstructionsService(InstallScripts installScripts) {
 | 
			
		||||
        super(installScripts);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public EdgeInstructions getInstallInstructions(Edge edge, String installationMethod, HttpServletRequest request) {
 | 
			
		||||
        switch (installationMethod.toLowerCase()) {
 | 
			
		||||
            case "docker":
 | 
			
		||||
                return getDockerInstallInstructions(edge, request);
 | 
			
		||||
            case "ubuntu":
 | 
			
		||||
                return getUbuntuInstallInstructions(edge, request);
 | 
			
		||||
            case "centos":
 | 
			
		||||
                return getCentosInstallInstructions(edge, request);
 | 
			
		||||
            default:
 | 
			
		||||
                throw new IllegalArgumentException("Unsupported installation method for Edge: " + installationMethod);
 | 
			
		||||
        }
 | 
			
		||||
        return switch (installationMethod.toLowerCase()) {
 | 
			
		||||
            case "docker" -> getDockerInstallInstructions(edge, request);
 | 
			
		||||
            case "ubuntu", "centos" -> getLinuxInstallInstructions(edge, request, installationMethod.toLowerCase());
 | 
			
		||||
            default ->
 | 
			
		||||
                    throw new IllegalArgumentException("Unsupported installation method for Edge: " + installationMethod);
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private EdgeInstructions getDockerInstallInstructions(Edge edge, HttpServletRequest request) {
 | 
			
		||||
@ -88,25 +72,16 @@ public class DefaultEdgeInstallInstructionsService implements EdgeInstallInstruc
 | 
			
		||||
        return new EdgeInstructions(dockerInstallInstructions);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private EdgeInstructions getUbuntuInstallInstructions(Edge edge, HttpServletRequest request) {
 | 
			
		||||
        String ubuntuInstallInstructions = readFile(resolveFile("ubuntu", "instructions.md"));
 | 
			
		||||
    private EdgeInstructions getLinuxInstallInstructions(Edge edge, HttpServletRequest request, String os) {
 | 
			
		||||
        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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private EdgeInstructions getCentosInstallInstructions(Edge edge, HttpServletRequest request) {
 | 
			
		||||
        String centosInstallInstructions = readFile(resolveFile("centos", "instructions.md"));
 | 
			
		||||
        centosInstallInstructions = replacePlaceholders(centosInstallInstructions, edge);
 | 
			
		||||
        centosInstallInstructions = centosInstallInstructions.replace("${BASE_URL}", request.getServerName());
 | 
			
		||||
        String edgeVersion = appVersion.replace("-SNAPSHOT", "");
 | 
			
		||||
        centosInstallInstructions = centosInstallInstructions.replace("${TB_EDGE_VERSION}", edgeVersion);
 | 
			
		||||
        return new EdgeInstructions(centosInstallInstructions);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String replacePlaceholders(String instructions, Edge edge) {
 | 
			
		||||
        instructions = instructions.replace("${CLOUD_ROUTING_KEY}", edge.getRoutingKey());
 | 
			
		||||
        instructions = instructions.replace("${CLOUD_ROUTING_SECRET}", edge.getSecret());
 | 
			
		||||
@ -115,20 +90,8 @@ public class DefaultEdgeInstallInstructionsService implements EdgeInstallInstruc
 | 
			
		||||
        return instructions;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String readFile(Path file) {
 | 
			
		||||
        try {
 | 
			
		||||
            return Files.readString(file);
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            log.warn("Failed to read file: {}", file, e);
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Path resolveFile(String subDir, String... subDirs) {
 | 
			
		||||
        return getEdgeInstallInstructionsDir().resolve(Paths.get(subDir, subDirs));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Path getEdgeInstallInstructionsDir() {
 | 
			
		||||
        return Paths.get(installScripts.getDataDir(), InstallScripts.JSON_DIR, EDGE_DIR, INSTRUCTIONS_DIR, INSTALL_DIR);
 | 
			
		||||
    @Override
 | 
			
		||||
    protected String getBaseDirName() {
 | 
			
		||||
        return INSTALL_DIR;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -15,7 +15,6 @@
 | 
			
		||||
 */
 | 
			
		||||
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;
 | 
			
		||||
@ -32,47 +31,37 @@ import org.thingsboard.server.dao.attributes.AttributesService;
 | 
			
		||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
			
		||||
import org.thingsboard.server.service.install.InstallScripts;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.nio.file.Files;
 | 
			
		||||
import java.nio.file.Path;
 | 
			
		||||
import java.nio.file.Paths;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@Slf4j
 | 
			
		||||
@RequiredArgsConstructor
 | 
			
		||||
@ConditionalOnProperty(prefix = "edges", value = "enabled", havingValue = "true")
 | 
			
		||||
@TbCoreComponent
 | 
			
		||||
public class DefaultEdgeUpgradeInstructionsService implements EdgeUpgradeInstructionsService {
 | 
			
		||||
public class DefaultEdgeUpgradeInstructionsService extends BaseEdgeInstallUpgradeInstructionsService implements EdgeUpgradeInstructionsService {
 | 
			
		||||
 | 
			
		||||
    private static final Map<String, EdgeUpgradeInfo> upgradeVersionHashMap = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    private static final String EDGE_DIR = "edge";
 | 
			
		||||
    private static final String INSTRUCTIONS_DIR = "instructions";
 | 
			
		||||
    private static final String UPGRADE_DIR = "upgrade";
 | 
			
		||||
 | 
			
		||||
    private final InstallScripts installScripts;
 | 
			
		||||
    private final AttributesService attributesService;
 | 
			
		||||
 | 
			
		||||
    @Value("${app.version:unknown}")
 | 
			
		||||
    @Setter
 | 
			
		||||
    private String appVersion;
 | 
			
		||||
    public DefaultEdgeUpgradeInstructionsService(AttributesService attributesService, InstallScripts installScripts) {
 | 
			
		||||
        super(installScripts);
 | 
			
		||||
        this.attributesService = attributesService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public EdgeInstructions getUpgradeInstructions(String edgeVersion, String upgradeMethod) {
 | 
			
		||||
        String tbVersion = appVersion.replace("-SNAPSHOT", "");
 | 
			
		||||
        String currentEdgeVersion = convertEdgeVersionToDocsFormat(edgeVersion);
 | 
			
		||||
        switch (upgradeMethod.toLowerCase()) {
 | 
			
		||||
            case "docker":
 | 
			
		||||
                return getDockerUpgradeInstructions(tbVersion, currentEdgeVersion);
 | 
			
		||||
            case "ubuntu":
 | 
			
		||||
            case "centos":
 | 
			
		||||
                return getLinuxUpgradeInstructions(tbVersion, currentEdgeVersion, upgradeMethod.toLowerCase());
 | 
			
		||||
            default:
 | 
			
		||||
                throw new IllegalArgumentException("Unsupported upgrade method for Edge: " + upgradeMethod);
 | 
			
		||||
        }
 | 
			
		||||
        return switch (upgradeMethod.toLowerCase()) {
 | 
			
		||||
            case "docker" -> getDockerUpgradeInstructions(tbVersion, currentEdgeVersion);
 | 
			
		||||
            case "ubuntu", "centos" ->
 | 
			
		||||
                    getLinuxUpgradeInstructions(tbVersion, currentEdgeVersion, upgradeMethod.toLowerCase());
 | 
			
		||||
            default -> throw new IllegalArgumentException("Unsupported upgrade method for Edge: " + upgradeMethod);
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@ -167,28 +156,12 @@ public class DefaultEdgeUpgradeInstructionsService implements EdgeUpgradeInstruc
 | 
			
		||||
        return new EdgeInstructions(result.toString());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String getTagVersion(String version) {
 | 
			
		||||
        return version.endsWith(".0") ? version.substring(0, version.length() - 2) : version;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String convertEdgeVersionToDocsFormat(String edgeVersion) {
 | 
			
		||||
        return edgeVersion.replace("_", ".").substring(2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String readFile(Path file) {
 | 
			
		||||
        try {
 | 
			
		||||
            return Files.readString(file);
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            log.warn("Failed to read file: {}", file, e);
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Path resolveFile(String subDir, String... subDirs) {
 | 
			
		||||
        return getEdgeInstallInstructionsDir().resolve(Paths.get(subDir, subDirs));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Path getEdgeInstallInstructionsDir() {
 | 
			
		||||
        return Paths.get(installScripts.getDataDir(), InstallScripts.JSON_DIR, EDGE_DIR, INSTRUCTIONS_DIR, UPGRADE_DIR);
 | 
			
		||||
    @Override
 | 
			
		||||
    protected String getBaseDirName() {
 | 
			
		||||
        return UPGRADE_DIR;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user