Browse Source

Improved edge install instructions text. Fixed testGetEdgeInstallInstructions test

pull/7878/head
Volodymyr Babak 4 years ago
parent
commit
a74971e56b
  1. 50
      application/src/main/data/json/edge/install_instructions/docker/instructions.md
  2. 5
      application/src/main/data/json/edge/install_instructions/docker/localhost_warning.md
  3. 2
      application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallService.java
  4. 15
      application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallInstructions.java
  5. 6
      application/src/test/java/org/thingsboard/server/controller/BaseEdgeControllerTest.java
  6. 88
      application/src/test/resources/edge/install_instructions/docker/expected-install-instructions.md

50
application/src/main/data/json/edge/install_instructions/docker/instructions.md

@ -1,6 +1,6 @@
## Install edge and connect to cloud instructions ## Install ThingsBoard Edge and connect to cloud instructions
Here is the list of commands, that can be used to quickly install and connect edge to the cloud using docker compose. Here is the list of commands, that can be used to quickly install and connect ThingsBoard Edge to the cloud using docker compose.
### Prerequisites ### Prerequisites
@ -8,8 +8,9 @@ Install <a href="https://docs.docker.com/engine/install/" target="_blank"> Docke
### Create data and logs folders ### Create data and logs folders
Run following commands to create directories for storing data and logs. These commands will change directories owner to *thingsboard* docker container user. Run following commands, before starting docker container(s), to create folders for storing data and logs.
**chown** command requires sudo permissions to be able to change owner (command will request password for a sudo access): These commands additionally will change owner of newly created folders to docker container user.
To do this (to change user) **chown** command is used, and this command requires *sudo* permissions (command will request password for a *sudo* access):
```bash ```bash
mkdir -p ~/.mytb-edge-data && sudo chown -R 799:799 ~/.mytb-edge-data mkdir -p ~/.mytb-edge-data && sudo chown -R 799:799 ~/.mytb-edge-data
@ -31,10 +32,7 @@ ${LOCALHOST_WARNING}
Add the following lines to the yml file: Add the following lines to the yml file:
```bash ```bash
version: '3.0'
# Uncomment the following line if you are using docker-compose and not docker compose V2
# version: '2.2'
services: services:
mytbedge: mytbedge:
restart: always restart: always
@ -44,7 +42,7 @@ services:
- "1883:1883" - "1883:1883"
- "5683-5688:5683-5688/udp" - "5683-5688:5683-5688/udp"
environment: environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/tb_edge SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/tb-edge
CLOUD_ROUTING_KEY: ${CLOUD_ROUTING_KEY} CLOUD_ROUTING_KEY: ${CLOUD_ROUTING_KEY}
CLOUD_ROUTING_SECRET: ${CLOUD_ROUTING_SECRET} CLOUD_ROUTING_SECRET: ${CLOUD_ROUTING_SECRET}
CLOUD_RPC_HOST: ${BASE_URL} CLOUD_RPC_HOST: ${BASE_URL}
@ -57,7 +55,7 @@ services:
ports: ports:
- "5432" - "5432"
environment: environment:
POSTGRES_DB: tb_edge POSTGRES_DB: tb-edge
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: postgres
volumes: volumes:
- ~/.mytb-edge-data/db:/var/lib/postgresql/data - ~/.mytb-edge-data/db:/var/lib/postgresql/data
@ -65,8 +63,9 @@ services:
``` ```
#### [Optional] Update bind ports #### [Optional] Update bind ports
If ThingsBoard Edge is going to be running on the same machine where ThingsBoard server (cloud) is running you'll need to update docker compose port mapping. If ThingsBoard Edge is going to be running on the same machine where ThingsBoard server (cloud) is running, you'll need to update docker compose port mapping to avoid port collision between ThingsBoard server and ThingsBoard Edge.
Please update next lines of docker compose:
Please update next lines of `docker-compose.yml` file:
```bash ```bash
ports: ports:
@ -74,28 +73,33 @@ ports:
- "11883:1883" - "11883:1883"
- "15683-15688:5683-5688/udp" - "15683-15688:5683-5688/udp"
``` ```
Please make sure ports above are not used by any other application. Make sure that ports above (18080, 11883, 15683-15688) are not used by any other application.
#### Start ThingsBoard Edge #### Start ThingsBoard Edge
Execute the following commands to pull and up using docker compose V2: Set the terminal in the directory which contains the `docker-compose.yml` file and execute the following commands to up this docker compose directly:
```bash ```bash
docker compose pull docker compose up -d
docker compose up docker compose logs -f mytbedge
{:copy-code} {:copy-code}
``` ```
*NOTE*: If you are using outdated docker-compose (we recommend to use docker compose V2), execute the following commands: ###### NOTE: Docker Compose V2 vs docker-compose (with a hyphen)
ThingsBoard supports Docker Compose V2 (Docker Desktop or Compose plugin) starting from **3.4.2** release, because **docker-compose** as standalone setup is no longer supported by Docker.
We **strongly** recommend to update to Docker Compose V2 and use it.
If you still rely on using Docker Compose as docker-compose (with a hyphen), then please execute the following commands to start ThingsBoard Edge:
```bash ```bash
docker-compose pull docker-compose up -d
docker-compose up docker-compose logs -f mytbedge
{:copy-code}
``` ```
#### Open ThingsBoard Edge UI #### Open ThingsBoard Edge UI
Once started, you will be able to open ThingsBoard Edge UI using the following link http://localhost:8080 Once started, you will be able to open **ThingsBoard Edge UI** using the following link http://localhost:8080.
###### NOTE: Edge HTTP bind port update
Use next **ThingsBoard Edge UI** link **http://localhost:18080** if you updated HTTP 8080 bind port to **18080**.
*NOTE*: If you updated bind ports (optional step) please use updated port instead for Edge UI URL
http://localhost:YOUR_UPDATED_PORT

5
application/src/main/data/json/edge/install_instructions/docker/localhost_warning.md

@ -1,4 +1,3 @@
#### WARNING - 'localhost (127.0.0.1)' is not supported ###### WARNING NOTE: 'localhost' is not supported
Please note that your ThingsBoard base URL is **'localhost (127.0.0.1)'** at the moment. Please note that your ThingsBoard base URL is **'localhost'** at the moment. **'localhost'** cannot be used for docker containers - please update **CLOUD_RPC_HOST** environment variable below to the IP address of your machine (*docker **host** machine*). IP address must be **192.168.1.XX** or similar format. In other case - ThingsBoard Edge service, that is running in docker container, will not be able to connect to the cloud.
**'localhost (127.0.0.1)'** cannot be used for docker containers - please update **CLOUD_RPC_HOST** environment variable below to the IP address of your machine (*docker **host** machine*). IP address must be next format **192.168.1.XX** or similar. In other case - Edge service, that is running in docker container, will not be able to connect to the cloud.

2
application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeInstallService.java

@ -40,7 +40,7 @@ public class DefaultEdgeInstallService implements EdgeInstallService {
private static final String EDGE_DIR = "edge"; private static final String EDGE_DIR = "edge";
private static final String EDGE_VERSION = "3.4.2EDGE"; private static final String EDGE_VERSION = "3.4.3EDGE";
private static final String EDGE_INSTALL_INSTRUCTIONS_DIR = "install_instructions"; private static final String EDGE_INSTALL_INSTRUCTIONS_DIR = "install_instructions";

15
application/src/main/java/org/thingsboard/server/service/edge/instructions/EdgeInstallInstructions.java

@ -1,3 +1,18 @@
/**
* Copyright © 2016-2022 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; package org.thingsboard.server.service.edge.instructions;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;

6
application/src/test/java/org/thingsboard/server/controller/BaseEdgeControllerTest.java

@ -886,9 +886,7 @@ public abstract class BaseEdgeControllerTest extends AbstractControllerTest {
Edge edge = constructEdge(tenantId, "Edge for Test Docker Install Instructions", "default", "7390c3a6-69b0-9910-d155-b90aca4b772e", "l7q4zsjplzwhk16geqxy"); Edge edge = constructEdge(tenantId, "Edge for Test Docker Install Instructions", "default", "7390c3a6-69b0-9910-d155-b90aca4b772e", "l7q4zsjplzwhk16geqxy");
Edge savedEdge = doPost("/api/edge", edge, Edge.class); Edge savedEdge = doPost("/api/edge", edge, Edge.class);
String installInstructions = doGet("/api/edge/instructions/" + savedEdge.getId().getId().toString(), String.class); String installInstructions = doGet("/api/edge/instructions/" + savedEdge.getId().getId().toString(), String.class);
URL resource = this.getClass().getClassLoader().getResource("edge/install_instructions/docker/expected-install-instructions.md"); Assert.assertTrue(installInstructions.contains("l7q4zsjplzwhk16geqxy"));
Assert.assertNotNull(resource); Assert.assertTrue(installInstructions.contains("7390c3a6-69b0-9910-d155-b90aca4b772e"));
File file = new File(resource.toURI());
Assert.assertEquals(Files.readString(file.toPath()), installInstructions);
} }
} }

88
application/src/test/resources/edge/install_instructions/docker/expected-install-instructions.md

@ -1,88 +0,0 @@
## Install edge and connect to cloud instructions
### Localhost warning
Localhost cannot be used for docker install - please update baseUrl to the IP address of your machine!
Here is the list of commands, that can be used to quickly install and connect edge to the cloud using docker-compose.
### Prerequisites
Install <a href="https://docs.docker.com/engine/install/" target="_blank"> Docker CE</a> and <a href="https://docs.docker.com/compose/install/" target="_blank"> Docker Compose</a>.
### Create data and logs folders
Run following commands to create a directory for storing data and logs and then change its owner to docker container user, to be able to change user, chown command is used, which requires sudo permissions (command will request password for a sudo access):
```bash
mkdir -p ~/.mytb-edge-data && sudo chown -R 799:799 ~/.mytb-edge-data
mkdir -p ~/.mytb-edge-logs && sudo chown -R 799:799 ~/.mytb-edge-logs
{:copy-code}
```
### Running ThingsBoard Edge as docker service
Create docker compose file for ThingsBoard Edge service:
```bash
nano docker-compose.yml
{:copy-code}
```
Add the following lines to the yml file:
```
version: '2.2'
services:
mytbedge:
restart: always
image: "thingsboard/tb-edge:3.4.1EDGE"
ports:
- "8080:8080"
- "1883:1883"
- "5683-5688:5683-5688/udp"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/tb-edge
CLOUD_ROUTING_KEY: 7390c3a6-69b0-9910-d155-b90aca4b772e
CLOUD_ROUTING_SECRET: l7q4zsjplzwhk16geqxy
CLOUD_RPC_HOST: localhost
volumes:
- ~/.mytb-edge-data:/data
- ~/.mytb-edge-logs:/var/log/tb-edge
postgres:
restart: always
image: "postgres:12"
ports:
- "5432"
environment:
POSTGRES_DB: tb-edge
POSTGRES_PASSWORD: postgres
volumes:
- ~/.mytb-edge-data/db:/var/lib/postgresql/data
{:copy-code}
```
### Ports warning [Optional]
If ThingsBoard Edge is going to be running on the same machine where ThingsBoard server is running you’ll need to update docker compose port mapping.
Please update next lines of docker compose:
ports:
- “18080:8080”
- “11883:1883”
- “15683-15688:5683-5688/udp”
Please make sure ports above are not used by any other application.
Execute the following commands to up this docker compose directly:
```bash
docker-compose pull
docker-compose up
{:copy-code}
```
### Open ThingsBoard Edge UI
Once started, you will be able to open ThingsBoard Edge UI using the following link http://localhost:8080.
If during installation process you have changed edge HTTP_BIND_PORT please use that port instead for Edge UI URL:
http://localhost:HTTP_BIND_PORT
Loading…
Cancel
Save