Merge remote-tracking branch 'origin/develop/1.5' into develop/1.5-queue
This commit is contained in:
commit
7e6a98110e
@ -12,48 +12,8 @@
|
|||||||
"nodes": [
|
"nodes": [
|
||||||
{
|
{
|
||||||
"additionalInfo": {
|
"additionalInfo": {
|
||||||
"layoutX": 639,
|
"layoutX": 824,
|
||||||
"layoutY": 113
|
"layoutY": 156
|
||||||
},
|
|
||||||
"type": "org.thingsboard.rule.engine.filter.TbMsgTypeFilterNode",
|
|
||||||
"name": "PostAttributes",
|
|
||||||
"debugMode": true,
|
|
||||||
"configuration": {
|
|
||||||
"messageTypes": [
|
|
||||||
"POST_ATTRIBUTES_REQUEST"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"additionalInfo": {
|
|
||||||
"layoutX": 638,
|
|
||||||
"layoutY": 206
|
|
||||||
},
|
|
||||||
"type": "org.thingsboard.rule.engine.filter.TbMsgTypeFilterNode",
|
|
||||||
"name": "PostTelemetry",
|
|
||||||
"debugMode": true,
|
|
||||||
"configuration": {
|
|
||||||
"messageTypes": [
|
|
||||||
"POST_TELEMETRY_REQUEST"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"additionalInfo": {
|
|
||||||
"layoutX": 297,
|
|
||||||
"layoutY": 148
|
|
||||||
},
|
|
||||||
"type": "org.thingsboard.rule.engine.action.TbLogNode",
|
|
||||||
"name": "Log",
|
|
||||||
"debugMode": false,
|
|
||||||
"configuration": {
|
|
||||||
"jsScript": "return 'incoming message = ' + msg;"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"additionalInfo": {
|
|
||||||
"layoutX": 905,
|
|
||||||
"layoutY": 203
|
|
||||||
},
|
},
|
||||||
"type": "org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode",
|
"type": "org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode",
|
||||||
"name": "SaveTS",
|
"name": "SaveTS",
|
||||||
@ -64,8 +24,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"additionalInfo": {
|
"additionalInfo": {
|
||||||
"layoutX": 904,
|
"layoutX": 825,
|
||||||
"layoutY": 110
|
"layoutY": 52
|
||||||
},
|
},
|
||||||
"type": "org.thingsboard.rule.engine.telemetry.TbMsgAttributesNode",
|
"type": "org.thingsboard.rule.engine.telemetry.TbMsgAttributesNode",
|
||||||
"name": "save client attributes",
|
"name": "save client attributes",
|
||||||
@ -73,28 +33,64 @@
|
|||||||
"configuration": {
|
"configuration": {
|
||||||
"scope": "CLIENT_SCOPE"
|
"scope": "CLIENT_SCOPE"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"additionalInfo": {
|
||||||
|
"layoutX": 347,
|
||||||
|
"layoutY": 149
|
||||||
|
},
|
||||||
|
"type": "org.thingsboard.rule.engine.filter.TbMsgTypeSwitchNode",
|
||||||
|
"name": "Message Type Switch",
|
||||||
|
"debugMode": false,
|
||||||
|
"configuration": {
|
||||||
|
"version": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"additionalInfo": {
|
||||||
|
"layoutX": 825,
|
||||||
|
"layoutY": 266
|
||||||
|
},
|
||||||
|
"type": "org.thingsboard.rule.engine.action.TbLogNode",
|
||||||
|
"name": "Log RPC",
|
||||||
|
"debugMode": false,
|
||||||
|
"configuration": {
|
||||||
|
"jsScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"additionalInfo": {
|
||||||
|
"layoutX": 825,
|
||||||
|
"layoutY": 379
|
||||||
|
},
|
||||||
|
"type": "org.thingsboard.rule.engine.action.TbLogNode",
|
||||||
|
"name": "Log Other",
|
||||||
|
"debugMode": false,
|
||||||
|
"configuration": {
|
||||||
|
"jsScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"connections": [
|
"connections": [
|
||||||
{
|
|
||||||
"fromIndex": 0,
|
|
||||||
"toIndex": 4,
|
|
||||||
"type": "True"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fromIndex": 1,
|
|
||||||
"toIndex": 3,
|
|
||||||
"type": "True"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fromIndex": 2,
|
"fromIndex": 2,
|
||||||
"toIndex": 0,
|
"toIndex": 4,
|
||||||
"type": "Success"
|
"type": "Other"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fromIndex": 2,
|
"fromIndex": 2,
|
||||||
"toIndex": 1,
|
"toIndex": 1,
|
||||||
"type": "Success"
|
"type": "Post attributes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fromIndex": 2,
|
||||||
|
"toIndex": 0,
|
||||||
|
"type": "Post telemetry"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fromIndex": 2,
|
||||||
|
"toIndex": 3,
|
||||||
|
"type": "RPC Request"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"ruleChainConnections": null
|
"ruleChainConnections": null
|
||||||
|
|||||||
@ -84,6 +84,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.rule_chain_by_tenant_and_sear
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS thingsboard.rule_node (
|
CREATE TABLE IF NOT EXISTS thingsboard.rule_node (
|
||||||
id uuid,
|
id uuid,
|
||||||
|
rule_chain_id uuid,
|
||||||
type text,
|
type text,
|
||||||
name text,
|
name text,
|
||||||
debug_mode boolean,
|
debug_mode boolean,
|
||||||
|
|||||||
@ -28,6 +28,7 @@ CREATE TABLE IF NOT EXISTS rule_chain (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS rule_node (
|
CREATE TABLE IF NOT EXISTS rule_node (
|
||||||
id varchar(31) NOT NULL CONSTRAINT rule_node_pkey PRIMARY KEY,
|
id varchar(31) NOT NULL CONSTRAINT rule_node_pkey PRIMARY KEY,
|
||||||
|
rule_chain_id varchar(31),
|
||||||
additional_info varchar,
|
additional_info varchar,
|
||||||
configuration varchar(10000000),
|
configuration varchar(10000000),
|
||||||
type varchar(255),
|
type varchar(255),
|
||||||
|
|||||||
@ -23,9 +23,7 @@ import org.springframework.context.ApplicationContext;
|
|||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thingsboard.server.service.component.ComponentDiscoveryService;
|
import org.thingsboard.server.service.component.ComponentDiscoveryService;
|
||||||
import org.thingsboard.server.service.install.DatabaseSchemaService;
|
import org.thingsboard.server.service.install.*;
|
||||||
import org.thingsboard.server.service.install.DatabaseUpgradeService;
|
|
||||||
import org.thingsboard.server.service.install.SystemDataLoaderService;
|
|
||||||
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
@ -40,9 +38,6 @@ public class ThingsboardInstallService {
|
|||||||
@Value("${install.upgrade.from_version:1.2.3}")
|
@Value("${install.upgrade.from_version:1.2.3}")
|
||||||
private String upgradeFromVersion;
|
private String upgradeFromVersion;
|
||||||
|
|
||||||
@Value("${install.data_dir}")
|
|
||||||
private String dataDir;
|
|
||||||
|
|
||||||
@Value("${install.load_demo:false}")
|
@Value("${install.load_demo:false}")
|
||||||
private Boolean loadDemo;
|
private Boolean loadDemo;
|
||||||
|
|
||||||
@ -61,6 +56,9 @@ public class ThingsboardInstallService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SystemDataLoaderService systemDataLoaderService;
|
private SystemDataLoaderService systemDataLoaderService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataUpdateService dataUpdateService;
|
||||||
|
|
||||||
public void performInstall() {
|
public void performInstall() {
|
||||||
try {
|
try {
|
||||||
if (isUpgrade) {
|
if (isUpgrade) {
|
||||||
@ -87,6 +85,8 @@ public class ThingsboardInstallService {
|
|||||||
|
|
||||||
databaseUpgradeService.upgradeDatabase("1.4.0");
|
databaseUpgradeService.upgradeDatabase("1.4.0");
|
||||||
|
|
||||||
|
dataUpdateService.updateData("1.4.0");
|
||||||
|
|
||||||
log.info("Updating system data...");
|
log.info("Updating system data...");
|
||||||
|
|
||||||
systemDataLoaderService.deleteSystemWidgetBundle("charts");
|
systemDataLoaderService.deleteSystemWidgetBundle("charts");
|
||||||
@ -113,13 +113,6 @@ public class ThingsboardInstallService {
|
|||||||
|
|
||||||
log.info("Starting ThingsBoard Installation...");
|
log.info("Starting ThingsBoard Installation...");
|
||||||
|
|
||||||
if (this.dataDir == null) {
|
|
||||||
throw new RuntimeException("'install.data_dir' property should specified!");
|
|
||||||
}
|
|
||||||
if (!Paths.get(this.dataDir).toFile().isDirectory()) {
|
|
||||||
throw new RuntimeException("'install.data_dir' property value is not a valid directory!");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("Installing DataBase schema...");
|
log.info("Installing DataBase schema...");
|
||||||
|
|
||||||
databaseSchemaService.createDatabaseSchema();
|
databaseSchemaService.createDatabaseSchema();
|
||||||
|
|||||||
@ -37,17 +37,16 @@ public class CassandraDatabaseSchemaService implements DatabaseSchemaService {
|
|||||||
private static final String CASSANDRA_DIR = "cassandra";
|
private static final String CASSANDRA_DIR = "cassandra";
|
||||||
private static final String SCHEMA_CQL = "schema.cql";
|
private static final String SCHEMA_CQL = "schema.cql";
|
||||||
|
|
||||||
@Value("${install.data_dir}")
|
|
||||||
private String dataDir;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CassandraInstallCluster cluster;
|
private CassandraInstallCluster cluster;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InstallScripts installScripts;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createDatabaseSchema() throws Exception {
|
public void createDatabaseSchema() throws Exception {
|
||||||
log.info("Installing Cassandra DataBase schema...");
|
log.info("Installing Cassandra DataBase schema...");
|
||||||
|
Path schemaFile = Paths.get(installScripts.getDataDir(), CASSANDRA_DIR, SCHEMA_CQL);
|
||||||
Path schemaFile = Paths.get(this.dataDir, CASSANDRA_DIR, SCHEMA_CQL);
|
|
||||||
loadCql(schemaFile);
|
loadCql(schemaFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,9 +43,6 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
|
|||||||
|
|
||||||
private static final String SCHEMA_UPDATE_CQL = "schema_update.cql";
|
private static final String SCHEMA_UPDATE_CQL = "schema_update.cql";
|
||||||
|
|
||||||
@Value("${install.data_dir}")
|
|
||||||
private String dataDir;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CassandraCluster cluster;
|
private CassandraCluster cluster;
|
||||||
|
|
||||||
@ -55,6 +52,9 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DashboardService dashboardService;
|
private DashboardService dashboardService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InstallScripts installScripts;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void upgradeDatabase(String fromVersion) throws Exception {
|
public void upgradeDatabase(String fromVersion) throws Exception {
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
|
|||||||
log.info("Relations dumped.");
|
log.info("Relations dumped.");
|
||||||
|
|
||||||
log.info("Updating schema ...");
|
log.info("Updating schema ...");
|
||||||
Path schemaUpdateFile = Paths.get(this.dataDir, "upgrade", "1.3.0", SCHEMA_UPDATE_CQL);
|
Path schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "1.3.0", SCHEMA_UPDATE_CQL);
|
||||||
loadCql(schemaUpdateFile);
|
loadCql(schemaUpdateFile);
|
||||||
log.info("Schema updated.");
|
log.info("Schema updated.");
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
|
|||||||
|
|
||||||
|
|
||||||
log.info("Updating schema ...");
|
log.info("Updating schema ...");
|
||||||
schemaUpdateFile = Paths.get(this.dataDir, "upgrade", "1.4.0", SCHEMA_UPDATE_CQL);
|
schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "1.4.0", SCHEMA_UPDATE_CQL);
|
||||||
loadCql(schemaUpdateFile);
|
loadCql(schemaUpdateFile);
|
||||||
log.info("Schema updated.");
|
log.info("Schema updated.");
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
|
|||||||
case "1.4.0":
|
case "1.4.0":
|
||||||
|
|
||||||
log.info("Updating schema ...");
|
log.info("Updating schema ...");
|
||||||
schemaUpdateFile = Paths.get(this.dataDir, "upgrade", "1.5.0", SCHEMA_UPDATE_CQL);
|
schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "1.5.0", SCHEMA_UPDATE_CQL);
|
||||||
loadCql(schemaUpdateFile);
|
loadCql(schemaUpdateFile);
|
||||||
log.info("Schema updated.");
|
log.info("Schema updated.");
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2018 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.install;
|
||||||
|
|
||||||
|
public interface DataUpdateService {
|
||||||
|
|
||||||
|
void updateData(String fromVersion) throws Exception;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2018 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.install;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.thingsboard.server.common.data.Tenant;
|
||||||
|
import org.thingsboard.server.common.data.id.IdBased;
|
||||||
|
import org.thingsboard.server.common.data.page.TextPageLink;
|
||||||
|
import org.thingsboard.server.common.data.rule.RuleChain;
|
||||||
|
import org.thingsboard.server.dao.rule.RuleChainService;
|
||||||
|
import org.thingsboard.server.dao.tenant.TenantService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Profile("install")
|
||||||
|
@Slf4j
|
||||||
|
public class DefaultDataUpdateService implements DataUpdateService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TenantService tenantService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RuleChainService ruleChainService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InstallScripts installScripts;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateData(String fromVersion) throws Exception {
|
||||||
|
switch (fromVersion) {
|
||||||
|
case "1.4.0":
|
||||||
|
log.info("Updating data from version 1.4.0 to 1.5.0 ...");
|
||||||
|
tenantsDefaultRuleChainUpdater.updateEntities(null);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unable to update data, unsupported fromVersion: " + fromVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PaginatedUpdater<String, Tenant> tenantsDefaultRuleChainUpdater =
|
||||||
|
new PaginatedUpdater<String, Tenant>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Tenant> findEntities(String region, TextPageLink pageLink) {
|
||||||
|
return tenantService.findTenants(pageLink).getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateEntity(Tenant tenant) {
|
||||||
|
try {
|
||||||
|
RuleChain ruleChain = ruleChainService.getRootTenantRuleChain(tenant.getId());
|
||||||
|
if (ruleChain == null) {
|
||||||
|
installScripts.createDefaultRuleChains(tenant.getId());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Unable to update Tenant", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public abstract class PaginatedUpdater<I, D extends IdBased<?>> {
|
||||||
|
|
||||||
|
private static final int DEFAULT_LIMIT = 100;
|
||||||
|
|
||||||
|
public void updateEntities(I id) {
|
||||||
|
TextPageLink pageLink = new TextPageLink(DEFAULT_LIMIT);
|
||||||
|
boolean hasNext = true;
|
||||||
|
while (hasNext) {
|
||||||
|
List<D> entities = findEntities(id, pageLink);
|
||||||
|
for (D entity : entities) {
|
||||||
|
updateEntity(entity);
|
||||||
|
}
|
||||||
|
hasNext = entities.size() == pageLink.getLimit();
|
||||||
|
if (hasNext) {
|
||||||
|
int index = entities.size() - 1;
|
||||||
|
UUID idOffset = entities.get(index).getUuidId();
|
||||||
|
pageLink.setIdOffset(idOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract List<D> findEntities(I id, TextPageLink pageLink);
|
||||||
|
|
||||||
|
protected abstract void updateEntity(D entity);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -84,6 +84,9 @@ public class InstallScripts {
|
|||||||
|
|
||||||
public String getDataDir() {
|
public String getDataDir() {
|
||||||
if (!StringUtils.isEmpty(dataDir)) {
|
if (!StringUtils.isEmpty(dataDir)) {
|
||||||
|
if (!Paths.get(this.dataDir).toFile().isDirectory()) {
|
||||||
|
throw new RuntimeException("'install.data_dir' property value is not a valid directory!");
|
||||||
|
}
|
||||||
return dataDir;
|
return dataDir;
|
||||||
} else {
|
} else {
|
||||||
String workDir = System.getProperty("user.dir");
|
String workDir = System.getProperty("user.dir");
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
package org.thingsboard.server.service.install;
|
package org.thingsboard.server.service.install;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -38,9 +39,6 @@ public class SqlDatabaseSchemaService implements DatabaseSchemaService {
|
|||||||
private static final String SQL_DIR = "sql";
|
private static final String SQL_DIR = "sql";
|
||||||
private static final String SCHEMA_SQL = "schema.sql";
|
private static final String SCHEMA_SQL = "schema.sql";
|
||||||
|
|
||||||
@Value("${install.data_dir}")
|
|
||||||
private String dataDir;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.url}")
|
@Value("${spring.datasource.url}")
|
||||||
private String dbUrl;
|
private String dbUrl;
|
||||||
|
|
||||||
@ -50,12 +48,15 @@ public class SqlDatabaseSchemaService implements DatabaseSchemaService {
|
|||||||
@Value("${spring.datasource.password}")
|
@Value("${spring.datasource.password}")
|
||||||
private String dbPassword;
|
private String dbPassword;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InstallScripts installScripts;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createDatabaseSchema() throws Exception {
|
public void createDatabaseSchema() throws Exception {
|
||||||
|
|
||||||
log.info("Installing SQL DataBase schema...");
|
log.info("Installing SQL DataBase schema...");
|
||||||
|
|
||||||
Path schemaFile = Paths.get(this.dataDir, SQL_DIR, SCHEMA_SQL);
|
Path schemaFile = Paths.get(installScripts.getDataDir(), SQL_DIR, SCHEMA_SQL);
|
||||||
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
|
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
|
||||||
String sql = new String(Files.readAllBytes(schemaFile), Charset.forName("UTF-8"));
|
String sql = new String(Files.readAllBytes(schemaFile), Charset.forName("UTF-8"));
|
||||||
conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema
|
conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema
|
||||||
|
|||||||
@ -44,9 +44,6 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService {
|
|||||||
|
|
||||||
private static final String SCHEMA_UPDATE_SQL = "schema_update.sql";
|
private static final String SCHEMA_UPDATE_SQL = "schema_update.sql";
|
||||||
|
|
||||||
@Value("${install.data_dir}")
|
|
||||||
private String dataDir;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.url}")
|
@Value("${spring.datasource.url}")
|
||||||
private String dbUrl;
|
private String dbUrl;
|
||||||
|
|
||||||
@ -59,12 +56,15 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DashboardService dashboardService;
|
private DashboardService dashboardService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InstallScripts installScripts;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void upgradeDatabase(String fromVersion) throws Exception {
|
public void upgradeDatabase(String fromVersion) throws Exception {
|
||||||
switch (fromVersion) {
|
switch (fromVersion) {
|
||||||
case "1.3.0":
|
case "1.3.0":
|
||||||
log.info("Updating schema ...");
|
log.info("Updating schema ...");
|
||||||
Path schemaUpdateFile = Paths.get(this.dataDir, "upgrade", "1.3.1", SCHEMA_UPDATE_SQL);
|
Path schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "1.3.1", SCHEMA_UPDATE_SQL);
|
||||||
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
|
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
|
||||||
String sql = new String(Files.readAllBytes(schemaUpdateFile), Charset.forName("UTF-8"));
|
String sql = new String(Files.readAllBytes(schemaUpdateFile), Charset.forName("UTF-8"));
|
||||||
conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
|
conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
|
||||||
@ -82,7 +82,7 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService {
|
|||||||
log.info("Dashboards dumped.");
|
log.info("Dashboards dumped.");
|
||||||
|
|
||||||
log.info("Updating schema ...");
|
log.info("Updating schema ...");
|
||||||
schemaUpdateFile = Paths.get(this.dataDir, "upgrade", "1.4.0", SCHEMA_UPDATE_SQL);
|
schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "1.4.0", SCHEMA_UPDATE_SQL);
|
||||||
String sql = new String(Files.readAllBytes(schemaUpdateFile), Charset.forName("UTF-8"));
|
String sql = new String(Files.readAllBytes(schemaUpdateFile), Charset.forName("UTF-8"));
|
||||||
conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
|
conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
|
||||||
log.info("Schema updated.");
|
log.info("Schema updated.");
|
||||||
@ -100,7 +100,7 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService {
|
|||||||
case "1.4.0":
|
case "1.4.0":
|
||||||
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
|
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
|
||||||
log.info("Updating schema ...");
|
log.info("Updating schema ...");
|
||||||
schemaUpdateFile = Paths.get(this.dataDir, "upgrade", "1.5.0", SCHEMA_UPDATE_SQL);
|
schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "1.5.0", SCHEMA_UPDATE_SQL);
|
||||||
String sql = new String(Files.readAllBytes(schemaUpdateFile), Charset.forName("UTF-8"));
|
String sql = new String(Files.readAllBytes(schemaUpdateFile), Charset.forName("UTF-8"));
|
||||||
conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
|
conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
|
||||||
log.info("Schema updated.");
|
log.info("Schema updated.");
|
||||||
|
|||||||
@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2018 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.rule.engine.api;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.thingsboard.rule.engine.api.NodeConfiguration;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EmptyNodeConfiguration implements NodeConfiguration<EmptyNodeConfiguration> {
|
||||||
|
|
||||||
|
private int version;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EmptyNodeConfiguration defaultConfiguration() {
|
||||||
|
EmptyNodeConfiguration configuration = new EmptyNodeConfiguration();
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -26,7 +26,7 @@ public class TbLogNodeConfiguration implements NodeConfiguration {
|
|||||||
@Override
|
@Override
|
||||||
public TbLogNodeConfiguration defaultConfiguration() {
|
public TbLogNodeConfiguration defaultConfiguration() {
|
||||||
TbLogNodeConfiguration configuration = new TbLogNodeConfiguration();
|
TbLogNodeConfiguration configuration = new TbLogNodeConfiguration();
|
||||||
configuration.setJsScript("return 'incoming message = ' + msg + meta;");
|
configuration.setJsScript("return 'Incoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);");
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,8 +31,7 @@ import org.thingsboard.server.common.msg.TbMsg;
|
|||||||
configClazz = TbMsgTypeFilterNodeConfiguration.class,
|
configClazz = TbMsgTypeFilterNodeConfiguration.class,
|
||||||
relationTypes = {"True", "False"},
|
relationTypes = {"True", "False"},
|
||||||
nodeDescription = "Filter incoming messages by Message Type",
|
nodeDescription = "Filter incoming messages by Message Type",
|
||||||
nodeDetails = "Evaluate incoming Message with configured JS condition. " +
|
nodeDetails = "If incoming MessageType is expected - send Message via <b>Success</b> chain, otherwise <b>Failure</b> chain is used.",
|
||||||
"If incoming MessageType is expected - send Message via <b>Success</b> chain, otherwise <b>Failure</b> chain is used.",
|
|
||||||
uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
|
uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
|
||||||
configDirective = "tbFilterNodeMessageTypeConfig")
|
configDirective = "tbFilterNodeMessageTypeConfig")
|
||||||
public class TbMsgTypeFilterNode implements TbNode {
|
public class TbMsgTypeFilterNode implements TbNode {
|
||||||
|
|||||||
@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2018 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.rule.engine.filter;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.thingsboard.rule.engine.TbNodeUtils;
|
||||||
|
import org.thingsboard.rule.engine.api.*;
|
||||||
|
import org.thingsboard.server.common.data.plugin.ComponentType;
|
||||||
|
import org.thingsboard.server.common.msg.TbMsg;
|
||||||
|
import org.thingsboard.server.common.msg.session.SessionMsgType;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RuleNode(
|
||||||
|
type = ComponentType.FILTER,
|
||||||
|
name = "message type switch",
|
||||||
|
configClazz = EmptyNodeConfiguration.class,
|
||||||
|
relationTypes = {"Post attributes", "Post telemetry", "RPC Request", "Other"},
|
||||||
|
nodeDescription = "Route incoming messages by Message Type",
|
||||||
|
nodeDetails = "Sends messages with message types <b>\"Post attributes\", \"Post telemetry\", \"RPC Request\"</b> via corresponding chain, otherwise <b>Other</b> chain is used.",
|
||||||
|
uiResources = {"static/rulenode/rulenode-core-config.js"},
|
||||||
|
configDirective = "tbNodeEmptyConfig")
|
||||||
|
public class TbMsgTypeSwitchNode implements TbNode {
|
||||||
|
|
||||||
|
EmptyNodeConfiguration config;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
|
||||||
|
this.config = TbNodeUtils.convert(configuration, EmptyNodeConfiguration.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMsg(TbContext ctx, TbMsg msg) throws TbNodeException {
|
||||||
|
String relationType;
|
||||||
|
if (msg.getType().equals(SessionMsgType.POST_ATTRIBUTES_REQUEST.name())) {
|
||||||
|
relationType = "Post attributes";
|
||||||
|
} else if (msg.getType().equals(SessionMsgType.POST_TELEMETRY_REQUEST.name())) {
|
||||||
|
relationType = "Post telemetry";
|
||||||
|
} else if (msg.getType().equals(SessionMsgType.TO_SERVER_RPC_REQUEST.name())) {
|
||||||
|
relationType = "RPC Request";
|
||||||
|
} else {
|
||||||
|
relationType = "Other";
|
||||||
|
}
|
||||||
|
ctx.tellNext(msg, relationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -46,7 +46,9 @@ import java.util.Set;
|
|||||||
name = "save attributes",
|
name = "save attributes",
|
||||||
configClazz = TbMsgAttributesNodeConfiguration.class,
|
configClazz = TbMsgAttributesNodeConfiguration.class,
|
||||||
nodeDescription = "Saves attributes data",
|
nodeDescription = "Saves attributes data",
|
||||||
nodeDetails = "Saves entity attributes based on configurable scope parameter. Expects messages with 'POST_ATTRIBUTES_REQUEST' message type"
|
nodeDetails = "Saves entity attributes based on configurable scope parameter. Expects messages with 'POST_ATTRIBUTES_REQUEST' message type",
|
||||||
|
uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
|
||||||
|
configDirective = "tbActionNodeAttributesConfig"
|
||||||
)
|
)
|
||||||
public class TbMsgAttributesNode implements TbNode {
|
public class TbMsgAttributesNode implements TbNode {
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ import java.util.Map;
|
|||||||
nodeDescription = "Saves timeseries data",
|
nodeDescription = "Saves timeseries data",
|
||||||
nodeDetails = "Saves timeseries telemetry data based on configurable TTL parameter. Expects messages with 'POST_TELEMETRY_REQUEST' message type",
|
nodeDetails = "Saves timeseries telemetry data based on configurable TTL parameter. Expects messages with 'POST_TELEMETRY_REQUEST' message type",
|
||||||
uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
|
uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
|
||||||
configDirective = "tbActionNodeTelemetryConfig"
|
configDirective = "tbActionNodeTimeseriesConfig"
|
||||||
)
|
)
|
||||||
public class TbMsgTimeseriesNode implements TbNode {
|
public class TbMsgTimeseriesNode implements TbNode {
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -316,6 +316,7 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
|
|||||||
delete ruleChainMetaData.ruleChainId;
|
delete ruleChainMetaData.ruleChainId;
|
||||||
for (var i=0;i<ruleChainMetaData.nodes.length;i++) {
|
for (var i=0;i<ruleChainMetaData.nodes.length;i++) {
|
||||||
var node = ruleChainMetaData.nodes[i];
|
var node = ruleChainMetaData.nodes[i];
|
||||||
|
delete node.ruleChainId;
|
||||||
ruleChainMetaData.nodes[i] = prepareExport(node);
|
ruleChainMetaData.nodes[i] = prepareExport(node);
|
||||||
}
|
}
|
||||||
return ruleChainMetaData;
|
return ruleChainMetaData;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user