Showing
14 changed files
with
125 additions
and
38 deletions
... | ... | @@ -161,15 +161,15 @@ public class RuleChainController extends BaseController { |
161 | 161 | TenantId tenantId = getCurrentUser().getTenantId(); |
162 | 162 | RuleChain previousRootRuleChain = ruleChainService.getRootTenantRuleChain(tenantId); |
163 | 163 | if (ruleChainService.setRootRuleChain(getTenantId(), ruleChainId)) { |
164 | + if (previousRootRuleChain != null) { | |
165 | + previousRootRuleChain = ruleChainService.findRuleChainById(getTenantId(), previousRootRuleChain.getId()); | |
164 | 166 | |
165 | - previousRootRuleChain = ruleChainService.findRuleChainById(getTenantId(), previousRootRuleChain.getId()); | |
166 | - | |
167 | - tbClusterService.onEntityStateChange(previousRootRuleChain.getTenantId(), previousRootRuleChain.getId(), | |
168 | - ComponentLifecycleEvent.UPDATED); | |
169 | - | |
170 | - logEntityAction(previousRootRuleChain.getId(), previousRootRuleChain, | |
171 | - null, ActionType.UPDATED, null); | |
167 | + tbClusterService.onEntityStateChange(previousRootRuleChain.getTenantId(), previousRootRuleChain.getId(), | |
168 | + ComponentLifecycleEvent.UPDATED); | |
172 | 169 | |
170 | + logEntityAction(previousRootRuleChain.getId(), previousRootRuleChain, | |
171 | + null, ActionType.UPDATED, null); | |
172 | + } | |
173 | 173 | ruleChain = ruleChainService.findRuleChainById(getTenantId(), ruleChainId); |
174 | 174 | |
175 | 175 | tbClusterService.onEntityStateChange(ruleChain.getTenantId(), ruleChain.getId(), | ... | ... |
... | ... | @@ -88,26 +88,33 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC |
88 | 88 | RuleChain ruleChain = ruleChainDao.findById(tenantId, ruleChainId.getId()); |
89 | 89 | if (!ruleChain.isRoot()) { |
90 | 90 | RuleChain previousRootRuleChain = getRootTenantRuleChain(ruleChain.getTenantId()); |
91 | - if (!previousRootRuleChain.getId().equals(ruleChain.getId())) { | |
92 | - try { | |
91 | + try { | |
92 | + if (previousRootRuleChain == null) { | |
93 | + setRootAndSave(tenantId, ruleChain); | |
94 | + return true; | |
95 | + } else if (!previousRootRuleChain.getId().equals(ruleChain.getId())) { | |
93 | 96 | deleteRelation(tenantId, new EntityRelation(previousRootRuleChain.getTenantId(), previousRootRuleChain.getId(), |
94 | 97 | EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN)); |
95 | 98 | previousRootRuleChain.setRoot(false); |
96 | 99 | ruleChainDao.save(tenantId, previousRootRuleChain); |
97 | - createRelation(tenantId, new EntityRelation(ruleChain.getTenantId(), ruleChain.getId(), | |
98 | - EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN)); | |
99 | - ruleChain.setRoot(true); | |
100 | - ruleChainDao.save(tenantId, ruleChain); | |
100 | + setRootAndSave(tenantId, ruleChain); | |
101 | 101 | return true; |
102 | - } catch (ExecutionException | InterruptedException e) { | |
103 | - log.warn("[{}] Failed to set root rule chain, ruleChainId: [{}]", ruleChainId); | |
104 | - throw new RuntimeException(e); | |
105 | 102 | } |
103 | + } catch (ExecutionException | InterruptedException e) { | |
104 | + log.warn("[{}] Failed to set root rule chain, ruleChainId: [{}]", ruleChainId); | |
105 | + throw new RuntimeException(e); | |
106 | 106 | } |
107 | 107 | } |
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | |
111 | + private void setRootAndSave(TenantId tenantId, RuleChain ruleChain) throws ExecutionException, InterruptedException { | |
112 | + createRelation(tenantId, new EntityRelation(ruleChain.getTenantId(), ruleChain.getId(), | |
113 | + EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN)); | |
114 | + ruleChain.setRoot(true); | |
115 | + ruleChainDao.save(tenantId, ruleChain); | |
116 | + } | |
117 | + | |
111 | 118 | @Override |
112 | 119 | public RuleChainMetaData saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData) { |
113 | 120 | Validator.validateId(ruleChainMetaData.getRuleChainId(), "Incorrect rule chain id."); | ... | ... |
... | ... | @@ -58,7 +58,7 @@ In case of any issues you can examine service logs for errors. |
58 | 58 | For example to see ThingsBoard node logs execute the following command: |
59 | 59 | |
60 | 60 | ` |
61 | -$ docker-compose logs -f tb1 | |
61 | +$ docker-compose logs -f tb-core1 tb-rule-engine1 | |
62 | 62 | ` |
63 | 63 | |
64 | 64 | Or use `docker-compose ps` to see the state of all the containers. | ... | ... |
... | ... | @@ -24,14 +24,28 @@ services: |
24 | 24 | - "9042" |
25 | 25 | volumes: |
26 | 26 | - ./tb-node/cassandra:/var/lib/cassandra |
27 | - tb1: | |
27 | + tb-core1: | |
28 | 28 | env_file: |
29 | 29 | - tb-node.cassandra.env |
30 | 30 | depends_on: |
31 | 31 | - kafka |
32 | 32 | - redis |
33 | 33 | - cassandra |
34 | - tb2: | |
34 | + tb-core2: | |
35 | + env_file: | |
36 | + - tb-node.cassandra.env | |
37 | + depends_on: | |
38 | + - kafka | |
39 | + - redis | |
40 | + - cassandra | |
41 | + tb-rule-engine1: | |
42 | + env_file: | |
43 | + - tb-node.cassandra.env | |
44 | + depends_on: | |
45 | + - kafka | |
46 | + - redis | |
47 | + - cassandra | |
48 | + tb-rule-engine2: | |
35 | 49 | env_file: |
36 | 50 | - tb-node.cassandra.env |
37 | 51 | depends_on: | ... | ... |
... | ... | @@ -20,10 +20,16 @@ services: |
20 | 20 | postgres: |
21 | 21 | volumes: |
22 | 22 | - postgres-db-volume:/var/lib/postgresql/data |
23 | - tb1: | |
23 | + tb-core1: | |
24 | 24 | volumes: |
25 | 25 | - tb-log-volume:/var/log/thingsboard |
26 | - tb2: | |
26 | + tb-core2: | |
27 | + volumes: | |
28 | + - tb-log-volume:/var/log/thingsboard | |
29 | + tb-rule-engine1: | |
30 | + volumes: | |
31 | + - tb-log-volume:/var/log/thingsboard | |
32 | + tb-rule-engine2: | |
27 | 33 | volumes: |
28 | 34 | - tb-log-volume:/var/log/thingsboard |
29 | 35 | tb-coap-transport: | ... | ... |
... | ... | @@ -27,14 +27,28 @@ services: |
27 | 27 | POSTGRES_PASSWORD: postgres |
28 | 28 | volumes: |
29 | 29 | - ./tb-node/postgres:/var/lib/postgresql/data |
30 | - tb1: | |
30 | + tb-core1: | |
31 | 31 | env_file: |
32 | 32 | - tb-node.postgres.env |
33 | 33 | depends_on: |
34 | 34 | - kafka |
35 | 35 | - redis |
36 | 36 | - postgres |
37 | - tb2: | |
37 | + tb-core2: | |
38 | + env_file: | |
39 | + - tb-node.postgres.env | |
40 | + depends_on: | |
41 | + - kafka | |
42 | + - redis | |
43 | + - postgres | |
44 | + tb-rule-engine1: | |
45 | + env_file: | |
46 | + - tb-node.postgres.env | |
47 | + depends_on: | |
48 | + - kafka | |
49 | + - redis | |
50 | + - postgres | |
51 | + tb-rule-engine2: | |
38 | 52 | env_file: |
39 | 53 | - tb-node.postgres.env |
40 | 54 | depends_on: | ... | ... |
... | ... | @@ -48,7 +48,7 @@ services: |
48 | 48 | - tb-js-executor.env |
49 | 49 | depends_on: |
50 | 50 | - kafka |
51 | - tb1: | |
51 | + tb-core1: | |
52 | 52 | restart: always |
53 | 53 | image: "${DOCKER_REPO}/${TB_NODE_DOCKER_NAME}:${TB_VERSION}" |
54 | 54 | ports: |
... | ... | @@ -59,7 +59,8 @@ services: |
59 | 59 | max-size: "200m" |
60 | 60 | max-file: "30" |
61 | 61 | environment: |
62 | - TB_SERVICE_ID: tb1 | |
62 | + TB_SERVICE_ID: tb-core1 | |
63 | + TB_SERVICE_TYPE: tb-core | |
63 | 64 | env_file: |
64 | 65 | - tb-node.env |
65 | 66 | volumes: |
... | ... | @@ -69,7 +70,7 @@ services: |
69 | 70 | - kafka |
70 | 71 | - redis |
71 | 72 | - tb-js-executor |
72 | - tb2: | |
73 | + tb-core2: | |
73 | 74 | restart: always |
74 | 75 | image: "${DOCKER_REPO}/${TB_NODE_DOCKER_NAME}:${TB_VERSION}" |
75 | 76 | ports: |
... | ... | @@ -80,7 +81,52 @@ services: |
80 | 81 | max-size: "200m" |
81 | 82 | max-file: "30" |
82 | 83 | environment: |
83 | - TB_SERVICE_ID: tb2 | |
84 | + TB_SERVICE_ID: tb-core2 | |
85 | + TB_SERVICE_TYPE: tb-core | |
86 | + env_file: | |
87 | + - tb-node.env | |
88 | + volumes: | |
89 | + - ./tb-node/conf:/config | |
90 | + - ./tb-node/log:/var/log/thingsboard | |
91 | + depends_on: | |
92 | + - kafka | |
93 | + - redis | |
94 | + - tb-js-executor | |
95 | + tb-rule-engine1: | |
96 | + restart: always | |
97 | + image: "${DOCKER_REPO}/${TB_NODE_DOCKER_NAME}:${TB_VERSION}" | |
98 | + ports: | |
99 | + - "8080" | |
100 | + logging: | |
101 | + driver: "json-file" | |
102 | + options: | |
103 | + max-size: "200m" | |
104 | + max-file: "30" | |
105 | + environment: | |
106 | + TB_SERVICE_ID: tb-rule-engine1 | |
107 | + TB_SERVICE_TYPE: tb-rule-engine | |
108 | + env_file: | |
109 | + - tb-node.env | |
110 | + volumes: | |
111 | + - ./tb-node/conf:/config | |
112 | + - ./tb-node/log:/var/log/thingsboard | |
113 | + depends_on: | |
114 | + - kafka | |
115 | + - redis | |
116 | + - tb-js-executor | |
117 | + tb-rule-engine2: | |
118 | + restart: always | |
119 | + image: "${DOCKER_REPO}/${TB_NODE_DOCKER_NAME}:${TB_VERSION}" | |
120 | + ports: | |
121 | + - "8080" | |
122 | + logging: | |
123 | + driver: "json-file" | |
124 | + options: | |
125 | + max-size: "200m" | |
126 | + max-file: "30" | |
127 | + environment: | |
128 | + TB_SERVICE_ID: tb-rule-engine2 | |
129 | + TB_SERVICE_TYPE: tb-rule-engine | |
84 | 130 | env_file: |
85 | 131 | - tb-node.env |
86 | 132 | volumes: |
... | ... | @@ -195,8 +241,8 @@ services: |
195 | 241 | MQTT_PORT: 1883 |
196 | 242 | FORCE_HTTPS_REDIRECT: "false" |
197 | 243 | links: |
198 | - - tb1 | |
199 | - - tb2 | |
244 | + - tb-core1 | |
245 | + - tb-core2 | |
200 | 246 | - tb-web-ui1 |
201 | 247 | - tb-web-ui2 |
202 | 248 | - tb-mqtt-transport1 | ... | ... |
... | ... | @@ -49,6 +49,6 @@ if [ ! -z "${ADDITIONAL_STARTUP_SERVICES// }" ]; then |
49 | 49 | docker-compose -f docker-compose.yml $ADDITIONAL_COMPOSE_ARGS up -d redis $ADDITIONAL_STARTUP_SERVICES |
50 | 50 | fi |
51 | 51 | |
52 | -docker-compose -f docker-compose.yml $ADDITIONAL_COMPOSE_ARGS run --no-deps --rm -e INSTALL_TB=true -e LOAD_DEMO=${loadDemo} tb1 | |
52 | +docker-compose -f docker-compose.yml $ADDITIONAL_COMPOSE_ARGS run --no-deps --rm -e INSTALL_TB=true -e LOAD_DEMO=${loadDemo} tb-core1 | |
53 | 53 | |
54 | 54 | ... | ... |
... | ... | @@ -44,8 +44,8 @@ ADDITIONAL_COMPOSE_ARGS=$(additionalComposeArgs) || exit $? |
44 | 44 | |
45 | 45 | ADDITIONAL_STARTUP_SERVICES=$(additionalStartupServices) || exit $? |
46 | 46 | |
47 | -docker-compose -f docker-compose.yml $ADDITIONAL_COMPOSE_ARGS pull tb1 | |
47 | +docker-compose -f docker-compose.yml $ADDITIONAL_COMPOSE_ARGS pull tb-core1 | |
48 | 48 | |
49 | 49 | docker-compose -f docker-compose.yml $ADDITIONAL_COMPOSE_ARGS up -d redis $ADDITIONAL_STARTUP_SERVICES |
50 | 50 | |
51 | -docker-compose -f docker-compose.yml $ADDITIONAL_COMPOSE_ARGS run --no-deps --rm -e UPGRADE_TB=true -e FROM_VERSION=${fromVersion} tb1 | |
51 | +docker-compose -f docker-compose.yml $ADDITIONAL_COMPOSE_ARGS run --no-deps --rm -e UPGRADE_TB=true -e FROM_VERSION=${fromVersion} tb-core1 | ... | ... |
... | ... | @@ -111,6 +111,6 @@ backend tb-api-backend |
111 | 111 | balance leastconn |
112 | 112 | option tcp-check |
113 | 113 | option log-health-checks |
114 | - server tbApi1 tb1:8080 check inter 5s resolvers docker_resolver resolve-prefer ipv4 | |
115 | - server tbApi2 tb2:8080 check inter 5s resolvers docker_resolver resolve-prefer ipv4 | |
114 | + server tbApi1 tb-core1:8080 check inter 5s resolvers docker_resolver resolve-prefer ipv4 | |
115 | + server tbApi2 tb-core2:8080 check inter 5s resolvers docker_resolver resolve-prefer ipv4 | |
116 | 116 | http-request set-header X-Forwarded-Port %[dst_port] | ... | ... |
... | ... | @@ -92,7 +92,7 @@ public class ThingsBoardDbInstaller extends ExternalResource { |
92 | 92 | dockerCompose.withCommand("up -d redis postgres"); |
93 | 93 | dockerCompose.invokeCompose(); |
94 | 94 | |
95 | - dockerCompose.withCommand("run --no-deps --rm -e INSTALL_TB=true -e LOAD_DEMO=true tb1"); | |
95 | + dockerCompose.withCommand("run --no-deps --rm -e INSTALL_TB=true -e LOAD_DEMO=true tb-core1"); | |
96 | 96 | dockerCompose.invokeCompose(); |
97 | 97 | |
98 | 98 | } finally { | ... | ... |