Commit 9071f58e70e5b24655a3945deb6d410cd2571dae

Authored by Volodymyr Babak
2 parents 48bae4b2 5c6df92e

Merge remote-tracking branch 'origin/master' into feature/entity-view

Showing 44 changed files with 406 additions and 119 deletions
@@ -24,9 +24,10 @@ import org.springframework.context.annotation.Profile; @@ -24,9 +24,10 @@ import org.springframework.context.annotation.Profile;
24 import org.springframework.stereotype.Service; 24 import org.springframework.stereotype.Service;
25 import org.thingsboard.server.service.component.ComponentDiscoveryService; 25 import org.thingsboard.server.service.component.ComponentDiscoveryService;
26 import org.thingsboard.server.service.install.DataUpdateService; 26 import org.thingsboard.server.service.install.DataUpdateService;
27 -import org.thingsboard.server.service.install.DatabaseSchemaService;  
28 import org.thingsboard.server.service.install.DatabaseUpgradeService; 27 import org.thingsboard.server.service.install.DatabaseUpgradeService;
  28 +import org.thingsboard.server.service.install.EntityDatabaseSchemaService;
29 import org.thingsboard.server.service.install.SystemDataLoaderService; 29 import org.thingsboard.server.service.install.SystemDataLoaderService;
  30 +import org.thingsboard.server.service.install.TsDatabaseSchemaService;
30 31
31 @Service 32 @Service
32 @Profile("install") 33 @Profile("install")
@@ -43,7 +44,10 @@ public class ThingsboardInstallService { @@ -43,7 +44,10 @@ public class ThingsboardInstallService {
43 private Boolean loadDemo; 44 private Boolean loadDemo;
44 45
45 @Autowired 46 @Autowired
46 - private DatabaseSchemaService databaseSchemaService; 47 + private EntityDatabaseSchemaService entityDatabaseSchemaService;
  48 +
  49 + @Autowired
  50 + private TsDatabaseSchemaService tsDatabaseSchemaService;
47 51
48 @Autowired 52 @Autowired
49 private DatabaseUpgradeService databaseUpgradeService; 53 private DatabaseUpgradeService databaseUpgradeService;
@@ -119,9 +123,13 @@ public class ThingsboardInstallService { @@ -119,9 +123,13 @@ public class ThingsboardInstallService {
119 123
120 log.info("Starting ThingsBoard Installation..."); 124 log.info("Starting ThingsBoard Installation...");
121 125
122 - log.info("Installing DataBase schema..."); 126 + log.info("Installing DataBase schema for entities...");
  127 +
  128 + entityDatabaseSchemaService.createDatabaseSchema();
  129 +
  130 + log.info("Installing DataBase schema for timeseries...");
123 131
124 - databaseSchemaService.createDatabaseSchema(); 132 + tsDatabaseSchemaService.createDatabaseSchema();
125 133
126 log.info("Loading system data..."); 134 log.info("Loading system data...");
127 135
application/src/main/java/org/thingsboard/server/service/install/CassandraAbstractDatabaseSchemaService.java renamed from application/src/main/java/org/thingsboard/server/service/install/CassandraDatabaseSchemaService.java
@@ -17,24 +17,17 @@ package org.thingsboard.server.service.install; @@ -17,24 +17,17 @@ package org.thingsboard.server.service.install;
17 17
18 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
19 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
20 -import org.springframework.context.annotation.Profile;  
21 -import org.springframework.stereotype.Service;  
22 import org.thingsboard.server.dao.cassandra.CassandraInstallCluster; 20 import org.thingsboard.server.dao.cassandra.CassandraInstallCluster;
23 -import org.thingsboard.server.dao.util.NoSqlDao;  
24 import org.thingsboard.server.service.install.cql.CQLStatementsParser; 21 import org.thingsboard.server.service.install.cql.CQLStatementsParser;
25 22
26 import java.nio.file.Path; 23 import java.nio.file.Path;
27 import java.nio.file.Paths; 24 import java.nio.file.Paths;
28 import java.util.List; 25 import java.util.List;
29 26
30 -@Service  
31 -@NoSqlDao  
32 -@Profile("install")  
33 @Slf4j 27 @Slf4j
34 -public class CassandraDatabaseSchemaService implements DatabaseSchemaService { 28 +public abstract class CassandraAbstractDatabaseSchemaService implements DatabaseSchemaService {
35 29
36 private static final String CASSANDRA_DIR = "cassandra"; 30 private static final String CASSANDRA_DIR = "cassandra";
37 - private static final String SCHEMA_CQL = "schema.cql";  
38 31
39 @Autowired 32 @Autowired
40 private CassandraInstallCluster cluster; 33 private CassandraInstallCluster cluster;
@@ -42,10 +35,16 @@ public class CassandraDatabaseSchemaService implements DatabaseSchemaService { @@ -42,10 +35,16 @@ public class CassandraDatabaseSchemaService implements DatabaseSchemaService {
42 @Autowired 35 @Autowired
43 private InstallScripts installScripts; 36 private InstallScripts installScripts;
44 37
  38 + private final String schemaCql;
  39 +
  40 + protected CassandraAbstractDatabaseSchemaService(String schemaCql) {
  41 + this.schemaCql = schemaCql;
  42 + }
  43 +
45 @Override 44 @Override
46 public void createDatabaseSchema() throws Exception { 45 public void createDatabaseSchema() throws Exception {
47 - log.info("Installing Cassandra DataBase schema...");  
48 - Path schemaFile = Paths.get(installScripts.getDataDir(), CASSANDRA_DIR, SCHEMA_CQL); 46 + log.info("Installing Cassandra DataBase schema part: " + schemaCql);
  47 + Path schemaFile = Paths.get(installScripts.getDataDir(), CASSANDRA_DIR, schemaCql);
49 loadCql(schemaFile); 48 loadCql(schemaFile);
50 49
51 } 50 }
  1 +/**
  2 + * Copyright © 2016-2018 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install;
  17 +
  18 +import org.springframework.context.annotation.Profile;
  19 +import org.springframework.stereotype.Service;
  20 +import org.thingsboard.server.dao.util.NoSqlDao;
  21 +
  22 +@Service
  23 +@NoSqlDao
  24 +@Profile("install")
  25 +public class CassandraEntityDatabaseSchemaService extends CassandraAbstractDatabaseSchemaService
  26 + implements EntityDatabaseSchemaService {
  27 + public CassandraEntityDatabaseSchemaService() {
  28 + super("schema-entities.cql");
  29 + }
  30 +}
  1 +/**
  2 + * Copyright © 2016-2018 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install;
  17 +
  18 +import org.springframework.context.annotation.Profile;
  19 +import org.springframework.stereotype.Service;
  20 +import org.thingsboard.server.dao.util.NoSqlTsDao;
  21 +
  22 +@Service
  23 +@NoSqlTsDao
  24 +@Profile("install")
  25 +public class CassandraTsDatabaseSchemaService extends CassandraAbstractDatabaseSchemaService
  26 + implements TsDatabaseSchemaService {
  27 + public CassandraTsDatabaseSchemaService() {
  28 + super("schema-ts.cql");
  29 + }
  30 +}
  1 +/**
  2 + * Copyright © 2016-2018 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install;
  17 +
  18 +public interface EntityDatabaseSchemaService extends DatabaseSchemaService {
  19 +}
application/src/main/java/org/thingsboard/server/service/install/SqlAbstractDatabaseSchemaService.java renamed from application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseSchemaService.java
@@ -18,9 +18,6 @@ package org.thingsboard.server.service.install; @@ -18,9 +18,6 @@ package org.thingsboard.server.service.install;
18 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
19 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.beans.factory.annotation.Value; 20 import org.springframework.beans.factory.annotation.Value;
21 -import org.springframework.context.annotation.Profile;  
22 -import org.springframework.stereotype.Service;  
23 -import org.thingsboard.server.dao.util.SqlDao;  
24 21
25 import java.nio.charset.Charset; 22 import java.nio.charset.Charset;
26 import java.nio.file.Files; 23 import java.nio.file.Files;
@@ -29,14 +26,10 @@ import java.nio.file.Paths; @@ -29,14 +26,10 @@ import java.nio.file.Paths;
29 import java.sql.Connection; 26 import java.sql.Connection;
30 import java.sql.DriverManager; 27 import java.sql.DriverManager;
31 28
32 -@Service  
33 -@Profile("install")  
34 @Slf4j 29 @Slf4j
35 -@SqlDao  
36 -public class SqlDatabaseSchemaService implements DatabaseSchemaService { 30 +public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchemaService {
37 31
38 private static final String SQL_DIR = "sql"; 32 private static final String SQL_DIR = "sql";
39 - private static final String SCHEMA_SQL = "schema.sql";  
40 33
41 @Value("${spring.datasource.url}") 34 @Value("${spring.datasource.url}")
42 private String dbUrl; 35 private String dbUrl;
@@ -50,12 +43,18 @@ public class SqlDatabaseSchemaService implements DatabaseSchemaService { @@ -50,12 +43,18 @@ public class SqlDatabaseSchemaService implements DatabaseSchemaService {
50 @Autowired 43 @Autowired
51 private InstallScripts installScripts; 44 private InstallScripts installScripts;
52 45
  46 + private final String schemaSql;
  47 +
  48 + protected SqlAbstractDatabaseSchemaService(String schemaSql) {
  49 + this.schemaSql = schemaSql;
  50 + }
  51 +
53 @Override 52 @Override
54 public void createDatabaseSchema() throws Exception { 53 public void createDatabaseSchema() throws Exception {
55 54
56 - log.info("Installing SQL DataBase schema..."); 55 + log.info("Installing SQL DataBase schema part: " + schemaSql);
57 56
58 - Path schemaFile = Paths.get(installScripts.getDataDir(), SQL_DIR, SCHEMA_SQL); 57 + Path schemaFile = Paths.get(installScripts.getDataDir(), SQL_DIR, schemaSql);
59 try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) { 58 try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
60 String sql = new String(Files.readAllBytes(schemaFile), Charset.forName("UTF-8")); 59 String sql = new String(Files.readAllBytes(schemaFile), Charset.forName("UTF-8"));
61 conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema 60 conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema
  1 +/**
  2 + * Copyright © 2016-2018 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install;
  17 +
  18 +import org.springframework.context.annotation.Profile;
  19 +import org.springframework.stereotype.Service;
  20 +import org.thingsboard.server.dao.util.SqlDao;
  21 +
  22 +@Service
  23 +@SqlDao
  24 +@Profile("install")
  25 +public class SqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService
  26 + implements EntityDatabaseSchemaService {
  27 + public SqlEntityDatabaseSchemaService() {
  28 + super("schema-entities.sql");
  29 + }
  30 +}
  1 +/**
  2 + * Copyright © 2016-2018 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install;
  17 +
  18 +import org.springframework.context.annotation.Profile;
  19 +import org.springframework.stereotype.Service;
  20 +import org.thingsboard.server.dao.util.SqlTsDao;
  21 +
  22 +@Service
  23 +@SqlTsDao
  24 +@Profile("install")
  25 +public class SqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaService
  26 + implements TsDatabaseSchemaService {
  27 + public SqlTsDatabaseSchemaService() {
  28 + super("schema-ts.sql");
  29 + }
  30 +}
  1 +/**
  2 + * Copyright © 2016-2018 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install;
  17 +
  18 +public interface TsDatabaseSchemaService extends DatabaseSchemaService {
  19 +}
@@ -159,7 +159,11 @@ quota: @@ -159,7 +159,11 @@ quota:
159 intervalMin: 2 159 intervalMin: 2
160 160
161 database: 161 database:
162 - type: "${DATABASE_TYPE:sql}" # cassandra OR sql 162 + entities:
  163 + type: "${DATABASE_TS_TYPE:sql}" # cassandra OR sql
  164 + ts:
  165 + type: "${DATABASE_CASSANDRA_TYPE:sql}" # cassandra OR sql (for hybrid mode, only this value should be cassandra)
  166 +
163 167
164 # Cassandra driver configuration parameters 168 # Cassandra driver configuration parameters
165 cassandra: 169 cassandra:
@@ -206,7 +210,7 @@ cassandra: @@ -206,7 +210,7 @@ cassandra:
206 write_consistency_level: "${CASSANDRA_WRITE_CONSISTENCY_LEVEL:ONE}" 210 write_consistency_level: "${CASSANDRA_WRITE_CONSISTENCY_LEVEL:ONE}"
207 default_fetch_size: "${CASSANDRA_DEFAULT_FETCH_SIZE:2000}" 211 default_fetch_size: "${CASSANDRA_DEFAULT_FETCH_SIZE:2000}"
208 # Specify partitioning size for timestamp key-value storage. Example MINUTES, HOURS, DAYS, MONTHS,INDEFINITE 212 # Specify partitioning size for timestamp key-value storage. Example MINUTES, HOURS, DAYS, MONTHS,INDEFINITE
209 - ts_key_value_partitioning: "${TS_KV_PARTITIONING:MONTHS}" 213 + ts_key_value_partitioning: "${TS_KV_PARTITIONING:INDEFINITE}"
210 ts_key_value_ttl: "${TS_KV_TTL:0}" 214 ts_key_value_ttl: "${TS_KV_TTL:0}"
211 buffer_size: "${CASSANDRA_QUERY_BUFFER_SIZE:200000}" 215 buffer_size: "${CASSANDRA_QUERY_BUFFER_SIZE:200000}"
212 concurrent_limit: "${CASSANDRA_QUERY_CONCURRENT_LIMIT:1000}" 216 concurrent_limit: "${CASSANDRA_QUERY_CONCURRENT_LIMIT:1000}"
@@ -32,7 +32,8 @@ public class ControllerNoSqlTestSuite { @@ -32,7 +32,8 @@ public class ControllerNoSqlTestSuite {
32 public static CustomCassandraCQLUnit cassandraUnit = 32 public static CustomCassandraCQLUnit cassandraUnit =
33 new CustomCassandraCQLUnit( 33 new CustomCassandraCQLUnit(
34 Arrays.asList( 34 Arrays.asList(
35 - new ClassPathCQLDataSet("cassandra/schema.cql", false, false), 35 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  36 + new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
36 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false), 37 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false),
37 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)), 38 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)),
38 "cassandra-test.yaml", 30000l); 39 "cassandra-test.yaml", 30000l);
@@ -30,7 +30,7 @@ public class ControllerSqlTestSuite { @@ -30,7 +30,7 @@ public class ControllerSqlTestSuite {
30 30
31 @ClassRule 31 @ClassRule
32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
33 - Arrays.asList("sql/schema.sql", "sql/system-data.sql"), 33 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),
34 "sql/drop-all-tables.sql", 34 "sql/drop-all-tables.sql",
35 "sql-test.properties"); 35 "sql-test.properties");
36 } 36 }
@@ -32,7 +32,8 @@ public class MqttNoSqlTestSuite { @@ -32,7 +32,8 @@ public class MqttNoSqlTestSuite {
32 public static CustomCassandraCQLUnit cassandraUnit = 32 public static CustomCassandraCQLUnit cassandraUnit =
33 new CustomCassandraCQLUnit( 33 new CustomCassandraCQLUnit(
34 Arrays.asList( 34 Arrays.asList(
35 - new ClassPathCQLDataSet("cassandra/schema.cql", false, false), 35 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  36 + new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
36 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)), 37 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
37 "cassandra-test.yaml", 30000l); 38 "cassandra-test.yaml", 30000l);
38 } 39 }
@@ -15,11 +15,9 @@ @@ -15,11 +15,9 @@
15 */ 15 */
16 package org.thingsboard.server.mqtt; 16 package org.thingsboard.server.mqtt;
17 17
18 -import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;  
19 import org.junit.ClassRule; 18 import org.junit.ClassRule;
20 import org.junit.extensions.cpsuite.ClasspathSuite; 19 import org.junit.extensions.cpsuite.ClasspathSuite;
21 import org.junit.runner.RunWith; 20 import org.junit.runner.RunWith;
22 -import org.thingsboard.server.dao.CustomCassandraCQLUnit;  
23 import org.thingsboard.server.dao.CustomSqlUnit; 21 import org.thingsboard.server.dao.CustomSqlUnit;
24 22
25 import java.util.Arrays; 23 import java.util.Arrays;
@@ -31,7 +29,7 @@ public class MqttSqlTestSuite { @@ -31,7 +29,7 @@ public class MqttSqlTestSuite {
31 29
32 @ClassRule 30 @ClassRule
33 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 31 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
34 - Arrays.asList("sql/schema.sql", "sql/system-data.sql"), 32 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),
35 "sql/drop-all-tables.sql", 33 "sql/drop-all-tables.sql",
36 "sql-test.properties"); 34 "sql-test.properties");
37 } 35 }
@@ -35,7 +35,8 @@ public class RuleEngineNoSqlTestSuite { @@ -35,7 +35,8 @@ public class RuleEngineNoSqlTestSuite {
35 public static CustomCassandraCQLUnit cassandraUnit = 35 public static CustomCassandraCQLUnit cassandraUnit =
36 new CustomCassandraCQLUnit( 36 new CustomCassandraCQLUnit(
37 Arrays.asList( 37 Arrays.asList(
38 - new ClassPathCQLDataSet("cassandra/schema.cql", false, false), 38 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  39 + new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
39 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)), 40 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
40 "cassandra-test.yaml", 30000l); 41 "cassandra-test.yaml", 30000l);
41 42
@@ -30,7 +30,7 @@ public class RuleEngineSqlTestSuite { @@ -30,7 +30,7 @@ public class RuleEngineSqlTestSuite {
30 30
31 @ClassRule 31 @ClassRule
32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
33 - Arrays.asList("sql/schema.sql", "sql/system-data.sql"), 33 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),
34 "sql/drop-all-tables.sql", 34 "sql/drop-all-tables.sql",
35 "sql-test.properties"); 35 "sql-test.properties");
36 } 36 }
@@ -34,7 +34,8 @@ public class SystemNoSqlTestSuite { @@ -34,7 +34,8 @@ public class SystemNoSqlTestSuite {
34 public static CustomCassandraCQLUnit cassandraUnit = 34 public static CustomCassandraCQLUnit cassandraUnit =
35 new CustomCassandraCQLUnit( 35 new CustomCassandraCQLUnit(
36 Arrays.asList( 36 Arrays.asList(
37 - new ClassPathCQLDataSet("cassandra/schema.cql", false, false), 37 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  38 + new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
38 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)), 39 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
39 "cassandra-test.yaml", 30000l); 40 "cassandra-test.yaml", 30000l);
40 } 41 }
@@ -31,7 +31,7 @@ public class SystemSqlTestSuite { @@ -31,7 +31,7 @@ public class SystemSqlTestSuite {
31 31
32 @ClassRule 32 @ClassRule
33 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 33 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
34 - Arrays.asList("sql/schema.sql", "sql/system-data.sql"), 34 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),
35 "sql/drop-all-tables.sql", 35 "sql/drop-all-tables.sql",
36 "sql-test.properties"); 36 "sql-test.properties");
37 37
@@ -17,12 +17,12 @@ package org.thingsboard.server.dao.cassandra; @@ -17,12 +17,12 @@ package org.thingsboard.server.dao.cassandra;
17 17
18 import org.springframework.beans.factory.annotation.Value; 18 import org.springframework.beans.factory.annotation.Value;
19 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
20 -import org.thingsboard.server.dao.util.NoSqlDao; 20 +import org.thingsboard.server.dao.util.NoSqlAnyDao;
21 21
22 import javax.annotation.PostConstruct; 22 import javax.annotation.PostConstruct;
23 23
24 @Component 24 @Component
25 -@NoSqlDao 25 +@NoSqlAnyDao
26 public class CassandraCluster extends AbstractCassandraCluster { 26 public class CassandraCluster extends AbstractCassandraCluster {
27 27
28 @Value("${cassandra.keyspace_name}") 28 @Value("${cassandra.keyspace_name}")
@@ -17,12 +17,12 @@ package org.thingsboard.server.dao.cassandra; @@ -17,12 +17,12 @@ package org.thingsboard.server.dao.cassandra;
17 17
18 import org.springframework.context.annotation.Profile; 18 import org.springframework.context.annotation.Profile;
19 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
20 -import org.thingsboard.server.dao.util.NoSqlDao; 20 +import org.thingsboard.server.dao.util.NoSqlAnyDao;
21 21
22 import javax.annotation.PostConstruct; 22 import javax.annotation.PostConstruct;
23 23
24 @Component 24 @Component
25 -@NoSqlDao 25 +@NoSqlAnyDao
26 @Profile("install") 26 @Profile("install")
27 public class CassandraInstallCluster extends AbstractCassandraCluster { 27 public class CassandraInstallCluster extends AbstractCassandraCluster {
28 28
@@ -21,14 +21,14 @@ import lombok.Data; @@ -21,14 +21,14 @@ import lombok.Data;
21 import org.springframework.beans.factory.annotation.Value; 21 import org.springframework.beans.factory.annotation.Value;
22 import org.springframework.context.annotation.Configuration; 22 import org.springframework.context.annotation.Configuration;
23 import org.springframework.stereotype.Component; 23 import org.springframework.stereotype.Component;
24 -import org.thingsboard.server.dao.util.NoSqlDao; 24 +import org.thingsboard.server.dao.util.NoSqlAnyDao;
25 25
26 import javax.annotation.PostConstruct; 26 import javax.annotation.PostConstruct;
27 27
28 @Component 28 @Component
29 @Configuration 29 @Configuration
30 @Data 30 @Data
31 -@NoSqlDao 31 +@NoSqlAnyDao
32 public class CassandraQueryOptions { 32 public class CassandraQueryOptions {
33 33
34 @Value("${cassandra.query.default_fetch_size}") 34 @Value("${cassandra.query.default_fetch_size}")
@@ -20,14 +20,14 @@ import lombok.Data; @@ -20,14 +20,14 @@ import lombok.Data;
20 import org.springframework.beans.factory.annotation.Value; 20 import org.springframework.beans.factory.annotation.Value;
21 import org.springframework.context.annotation.Configuration; 21 import org.springframework.context.annotation.Configuration;
22 import org.springframework.stereotype.Component; 22 import org.springframework.stereotype.Component;
23 -import org.thingsboard.server.dao.util.NoSqlDao; 23 +import org.thingsboard.server.dao.util.NoSqlAnyDao;
24 24
25 import javax.annotation.PostConstruct; 25 import javax.annotation.PostConstruct;
26 26
27 @Component 27 @Component
28 @Configuration 28 @Configuration
29 @Data 29 @Data
30 -@NoSqlDao 30 +@NoSqlAnyDao
31 public class CassandraSocketOptions { 31 public class CassandraSocketOptions {
32 32
33 @Value("${cassandra.socket.connect_timeout}") 33 @Value("${cassandra.socket.connect_timeout}")
@@ -44,6 +44,7 @@ import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; @@ -44,6 +44,7 @@ import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService;
44 import org.thingsboard.server.dao.timeseries.TimeseriesDao; 44 import org.thingsboard.server.dao.timeseries.TimeseriesDao;
45 import org.thingsboard.server.dao.timeseries.TsInsertExecutorType; 45 import org.thingsboard.server.dao.timeseries.TsInsertExecutorType;
46 import org.thingsboard.server.dao.util.SqlDao; 46 import org.thingsboard.server.dao.util.SqlDao;
  47 +import org.thingsboard.server.dao.util.SqlTsDao;
47 48
48 import javax.annotation.Nullable; 49 import javax.annotation.Nullable;
49 import javax.annotation.PostConstruct; 50 import javax.annotation.PostConstruct;
@@ -60,7 +61,7 @@ import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; @@ -60,7 +61,7 @@ import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
60 61
61 @Component 62 @Component
62 @Slf4j 63 @Slf4j
63 -@SqlDao 64 +@SqlTsDao
64 public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService implements TimeseriesDao { 65 public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService implements TimeseriesDao {
65 66
66 @Value("${sql.ts_inserts_executor_type}") 67 @Value("${sql.ts_inserts_executor_type}")
@@ -49,6 +49,7 @@ import org.thingsboard.server.common.data.kv.TsKvEntry; @@ -49,6 +49,7 @@ import org.thingsboard.server.common.data.kv.TsKvEntry;
49 import org.thingsboard.server.dao.model.ModelConstants; 49 import org.thingsboard.server.dao.model.ModelConstants;
50 import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao; 50 import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao;
51 import org.thingsboard.server.dao.util.NoSqlDao; 51 import org.thingsboard.server.dao.util.NoSqlDao;
  52 +import org.thingsboard.server.dao.util.NoSqlTsDao;
52 53
53 import javax.annotation.Nullable; 54 import javax.annotation.Nullable;
54 import javax.annotation.PostConstruct; 55 import javax.annotation.PostConstruct;
@@ -70,7 +71,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; @@ -70,7 +71,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
70 */ 71 */
71 @Component 72 @Component
72 @Slf4j 73 @Slf4j
73 -@NoSqlDao 74 +@NoSqlTsDao
74 public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implements TimeseriesDao { 75 public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implements TimeseriesDao {
75 76
76 private static final int MIN_AGGREGATION_STEP_MS = 1000; 77 private static final int MIN_AGGREGATION_STEP_MS = 1000;
@@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicInteger; @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicInteger;
34 34
35 @Component 35 @Component
36 @Slf4j 36 @Slf4j
37 -@NoSqlDao 37 +@NoSqlAnyDao
38 public class BufferedRateLimiter implements AsyncRateLimiter { 38 public class BufferedRateLimiter implements AsyncRateLimiter {
39 39
40 private final ListeningExecutorService pool = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10)); 40 private final ListeningExecutorService pool = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
  1 +/**
  2 + * Copyright © 2016-2018 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.util;
  17 +
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
  19 +
  20 +@ConditionalOnExpression("'${database.ts.type}'=='cassandra' || '${database.entities.type}'=='cassandra'")
  21 +public @interface NoSqlAnyDao {
  22 +}
@@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util; @@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util;
17 17
18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
19 19
20 -@ConditionalOnProperty(prefix = "database", value = "type", havingValue = "cassandra") 20 +@ConditionalOnProperty(prefix = "database.entities", value = "type", havingValue = "cassandra")
21 public @interface NoSqlDao { 21 public @interface NoSqlDao {
22 } 22 }
  1 +/**
  2 + * Copyright © 2016-2018 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.util;
  17 +
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  19 +
  20 +@ConditionalOnProperty(prefix = "database.ts", value = "type", havingValue = "cassandra")
  21 +public @interface NoSqlTsDao {
  22 +}
@@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util; @@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util;
17 17
18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
19 19
20 -@ConditionalOnProperty(prefix = "database", value = "type", havingValue = "sql") 20 +@ConditionalOnProperty(prefix = "database.entities", value = "type", havingValue = "sql")
21 public @interface SqlDao { 21 public @interface SqlDao {
22 } 22 }
  1 +/**
  2 + * Copyright © 2016-2018 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.util;
  17 +
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  19 +
  20 +@ConditionalOnProperty(prefix = "database.ts", value = "type", havingValue = "sql")
  21 +public @interface SqlTsDao {
  22 +}
dao/src/main/resources/cassandra/schema-entities.cql renamed from dao/src/main/resources/cassandra/schema.cql
@@ -398,41 +398,6 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.dashboard_by_tenant_and_searc @@ -398,41 +398,6 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.dashboard_by_tenant_and_searc
398 PRIMARY KEY ( tenant_id, search_text, id ) 398 PRIMARY KEY ( tenant_id, search_text, id )
399 WITH CLUSTERING ORDER BY ( search_text ASC, id DESC ); 399 WITH CLUSTERING ORDER BY ( search_text ASC, id DESC );
400 400
401 -CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_cf (  
402 - entity_type text, // (DEVICE, CUSTOMER, TENANT)  
403 - entity_id timeuuid,  
404 - key text,  
405 - partition bigint,  
406 - ts bigint,  
407 - bool_v boolean,  
408 - str_v text,  
409 - long_v bigint,  
410 - dbl_v double,  
411 - PRIMARY KEY (( entity_type, entity_id, key, partition ), ts)  
412 -);  
413 -  
414 -CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_partitions_cf (  
415 - entity_type text, // (DEVICE, CUSTOMER, TENANT)  
416 - entity_id timeuuid,  
417 - key text,  
418 - partition bigint,  
419 - PRIMARY KEY (( entity_type, entity_id, key ), partition)  
420 -) WITH CLUSTERING ORDER BY ( partition ASC )  
421 - AND compaction = { 'class' : 'LeveledCompactionStrategy' };  
422 -  
423 -CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_latest_cf (  
424 - entity_type text, // (DEVICE, CUSTOMER, TENANT)  
425 - entity_id timeuuid,  
426 - key text,  
427 - ts bigint,  
428 - bool_v boolean,  
429 - str_v text,  
430 - long_v bigint,  
431 - dbl_v double,  
432 - PRIMARY KEY (( entity_type, entity_id ), key)  
433 -) WITH compaction = { 'class' : 'LeveledCompactionStrategy' };  
434 -  
435 -  
436 CREATE TABLE IF NOT EXISTS thingsboard.attributes_kv_cf ( 401 CREATE TABLE IF NOT EXISTS thingsboard.attributes_kv_cf (
437 entity_type text, // (DEVICE, CUSTOMER, TENANT) 402 entity_type text, // (DEVICE, CUSTOMER, TENANT)
438 entity_id timeuuid, 403 entity_id timeuuid,
  1 +--
  2 +-- Copyright © 2016-2018 The Thingsboard Authors
  3 +--
  4 +-- Licensed under the Apache License, Version 2.0 (the "License");
  5 +-- you may not use this file except in compliance with the License.
  6 +-- You may obtain a copy of the License at
  7 +--
  8 +-- http://www.apache.org/licenses/LICENSE-2.0
  9 +--
  10 +-- Unless required by applicable law or agreed to in writing, software
  11 +-- distributed under the License is distributed on an "AS IS" BASIS,
  12 +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 +-- See the License for the specific language governing permissions and
  14 +-- limitations under the License.
  15 +--
  16 +
  17 +CREATE KEYSPACE IF NOT EXISTS thingsboard
  18 +WITH replication = {
  19 + 'class' : 'SimpleStrategy',
  20 + 'replication_factor' : 1
  21 +};
  22 +
  23 +CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_cf (
  24 + entity_type text, // (DEVICE, CUSTOMER, TENANT)
  25 + entity_id timeuuid,
  26 + key text,
  27 + partition bigint,
  28 + ts bigint,
  29 + bool_v boolean,
  30 + str_v text,
  31 + long_v bigint,
  32 + dbl_v double,
  33 + PRIMARY KEY (( entity_type, entity_id, key, partition ), ts)
  34 +);
  35 +
  36 +CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_partitions_cf (
  37 + entity_type text, // (DEVICE, CUSTOMER, TENANT)
  38 + entity_id timeuuid,
  39 + key text,
  40 + partition bigint,
  41 + PRIMARY KEY (( entity_type, entity_id, key ), partition)
  42 +) WITH CLUSTERING ORDER BY ( partition ASC )
  43 + AND compaction = { 'class' : 'LeveledCompactionStrategy' };
  44 +
  45 +CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_latest_cf (
  46 + entity_type text, // (DEVICE, CUSTOMER, TENANT)
  47 + entity_id timeuuid,
  48 + key text,
  49 + ts bigint,
  50 + bool_v boolean,
  51 + str_v text,
  52 + long_v bigint,
  53 + dbl_v double,
  54 + PRIMARY KEY (( entity_type, entity_id ), key)
  55 +) WITH compaction = { 'class' : 'LeveledCompactionStrategy' };
dao/src/main/resources/sql/schema-entities.sql renamed from dao/src/main/resources/sql/schema.sql
@@ -179,30 +179,6 @@ CREATE TABLE IF NOT EXISTS tenant ( @@ -179,30 +179,6 @@ CREATE TABLE IF NOT EXISTS tenant (
179 zip varchar(255) 179 zip varchar(255)
180 ); 180 );
181 181
182 -CREATE TABLE IF NOT EXISTS ts_kv (  
183 - entity_type varchar(255) NOT NULL,  
184 - entity_id varchar(31) NOT NULL,  
185 - key varchar(255) NOT NULL,  
186 - ts bigint NOT NULL,  
187 - bool_v boolean,  
188 - str_v varchar(10000000),  
189 - long_v bigint,  
190 - dbl_v double precision,  
191 - CONSTRAINT ts_kv_unq_key UNIQUE (entity_type, entity_id, key, ts)  
192 -);  
193 -  
194 -CREATE TABLE IF NOT EXISTS ts_kv_latest (  
195 - entity_type varchar(255) NOT NULL,  
196 - entity_id varchar(31) NOT NULL,  
197 - key varchar(255) NOT NULL,  
198 - ts bigint NOT NULL,  
199 - bool_v boolean,  
200 - str_v varchar(10000000),  
201 - long_v bigint,  
202 - dbl_v double precision,  
203 - CONSTRAINT ts_kv_latest_unq_key UNIQUE (entity_type, entity_id, key)  
204 -);  
205 -  
206 CREATE TABLE IF NOT EXISTS user_credentials ( 182 CREATE TABLE IF NOT EXISTS user_credentials (
207 id varchar(31) NOT NULL CONSTRAINT user_credentials_pkey PRIMARY KEY, 183 id varchar(31) NOT NULL CONSTRAINT user_credentials_pkey PRIMARY KEY,
208 activate_token varchar(255) UNIQUE, 184 activate_token varchar(255) UNIQUE,
  1 +--
  2 +-- Copyright © 2016-2018 The Thingsboard Authors
  3 +--
  4 +-- Licensed under the Apache License, Version 2.0 (the "License");
  5 +-- you may not use this file except in compliance with the License.
  6 +-- You may obtain a copy of the License at
  7 +--
  8 +-- http://www.apache.org/licenses/LICENSE-2.0
  9 +--
  10 +-- Unless required by applicable law or agreed to in writing, software
  11 +-- distributed under the License is distributed on an "AS IS" BASIS,
  12 +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 +-- See the License for the specific language governing permissions and
  14 +-- limitations under the License.
  15 +--
  16 +
  17 +CREATE TABLE IF NOT EXISTS ts_kv (
  18 + entity_type varchar(255) NOT NULL,
  19 + entity_id varchar(31) NOT NULL,
  20 + key varchar(255) NOT NULL,
  21 + ts bigint NOT NULL,
  22 + bool_v boolean,
  23 + str_v varchar(10000000),
  24 + long_v bigint,
  25 + dbl_v double precision,
  26 + CONSTRAINT ts_kv_unq_key UNIQUE (entity_type, entity_id, key, ts)
  27 +);
  28 +
  29 +CREATE TABLE IF NOT EXISTS ts_kv_latest (
  30 + entity_type varchar(255) NOT NULL,
  31 + entity_id varchar(31) NOT NULL,
  32 + key varchar(255) NOT NULL,
  33 + ts bigint NOT NULL,
  34 + bool_v boolean,
  35 + str_v varchar(10000000),
  36 + long_v bigint,
  37 + dbl_v double precision,
  38 + CONSTRAINT ts_kv_latest_unq_key UNIQUE (entity_type, entity_id, key)
  39 +);
@@ -30,7 +30,7 @@ public class JpaDaoTestSuite { @@ -30,7 +30,7 @@ public class JpaDaoTestSuite {
30 30
31 @ClassRule 31 @ClassRule
32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
33 - Arrays.asList("sql/schema.sql", "sql/system-data.sql"), 33 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),
34 "sql/drop-all-tables.sql", 34 "sql/drop-all-tables.sql",
35 "sql-test.properties" 35 "sql-test.properties"
36 ); 36 );
@@ -34,7 +34,9 @@ public class NoSqlDaoServiceTestSuite { @@ -34,7 +34,9 @@ public class NoSqlDaoServiceTestSuite {
34 @ClassRule 34 @ClassRule
35 public static CustomCassandraCQLUnit cassandraUnit = 35 public static CustomCassandraCQLUnit cassandraUnit =
36 new CustomCassandraCQLUnit( 36 new CustomCassandraCQLUnit(
37 - Arrays.asList(new ClassPathCQLDataSet("cassandra/schema.cql", false, false), 37 + Arrays.asList(
  38 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  39 + new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
38 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false), 40 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false),
39 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)), 41 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)),
40 "cassandra-test.yaml", 30000L); 42 "cassandra-test.yaml", 30000L);
@@ -30,7 +30,7 @@ public class SqlDaoServiceTestSuite { @@ -30,7 +30,7 @@ public class SqlDaoServiceTestSuite {
30 30
31 @ClassRule 31 @ClassRule
32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
33 - Arrays.asList("sql/schema.sql", "sql/system-data.sql", "sql/system-test.sql"), 33 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql", "sql/system-test.sql"),
34 "sql/drop-all-tables.sql", 34 "sql/drop-all-tables.sql",
35 "sql-test.properties" 35 "sql-test.properties"
36 ); 36 );
1 -database.type=cassandra 1 +database.entities.type=cassandra
  2 +database.ts.type=cassandra
2 3
3 cassandra.queue.partitioning=HOURS 4 cassandra.queue.partitioning=HOURS
4 cassandra.queue.ack.ttl=3600 5 cassandra.queue.ack.ttl=3600
1 -database.type=sql 1 +database.ts.type=sql
  2 +database.entities.type=sql
2 3
3 sql.ts_inserts_executor_type=fixed 4 sql.ts_inserts_executor_type=fixed
4 sql.ts_inserts_fixed_thread_pool_size=10 5 sql.ts_inserts_fixed_thread_pool_size=10
@@ -30,7 +30,9 @@ spec: @@ -30,7 +30,9 @@ spec:
30 value: "cassandra-headless" 30 value: "cassandra-headless"
31 - name : CASSANDRA_PORT 31 - name : CASSANDRA_PORT
32 value: "9042" 32 value: "9042"
33 - - name : DATABASE_TYPE 33 + - name : DATABASE_ENTITIES_TYPE
  34 + value: "cassandra"
  35 + - name : DATABASE_TS_TYPE
34 value: "cassandra" 36 value: "cassandra"
35 - name : CASSANDRA_URL 37 - name : CASSANDRA_URL
36 value: "cassandra-headless:9042" 38 value: "cassandra-headless:9042"
@@ -30,7 +30,9 @@ spec: @@ -30,7 +30,9 @@ spec:
30 value: "cassandra-headless" 30 value: "cassandra-headless"
31 - name : CASSANDRA_PORT 31 - name : CASSANDRA_PORT
32 value: "9042" 32 value: "9042"
33 - - name : DATABASE_TYPE 33 + - name : DATABASE_ENTITIES_TYPE
  34 + value: "cassandra"
  35 + - name : DATABASE_TS_TYPE
34 value: "cassandra" 36 value: "cassandra"
35 - name : CASSANDRA_URL 37 - name : CASSANDRA_URL
36 value: "cassandra-headless:9042" 38 value: "cassandra-headless:9042"
@@ -120,7 +120,12 @@ spec: @@ -120,7 +120,12 @@ spec:
120 configMapKeyRef: 120 configMapKeyRef:
121 name: tb-config 121 name: tb-config
122 key: cassandra.url 122 key: cassandra.url
123 - - name: DATABASE_TYPE 123 + - name: DATABASE_ENTITIES_TYPE
  124 + valueFrom:
  125 + configMapKeyRef:
  126 + name: tb-config
  127 + key: database.type
  128 + - name: DATABASE_TS_TYPE
124 valueFrom: 129 valueFrom:
125 configMapKeyRef: 130 configMapKeyRef:
126 name: tb-config 131 name: tb-config
@@ -8,7 +8,8 @@ COAP_BIND_PORT=5683 @@ -8,7 +8,8 @@ COAP_BIND_PORT=5683
8 ZOOKEEPER_URL=zk:2181 8 ZOOKEEPER_URL=zk:2181
9 9
10 # type of database to use: sql[DEFAULT] or cassandra 10 # type of database to use: sql[DEFAULT] or cassandra
11 -DATABASE_TYPE=sql 11 +DATABASE_TS_TYPE=sql
  12 +DATABASE_ENTITIES_TYPE=sql
12 13
13 # cassandra db config 14 # cassandra db config
14 CASSANDRA_URL=cassandra:9042 15 CASSANDRA_URL=cassandra:9042
@@ -23,7 +23,7 @@ printenv | awk -F "=" '{print "export " $1 "='\''" $2 "'\''"}' >> /usr/share/thi @@ -23,7 +23,7 @@ printenv | awk -F "=" '{print "export " $1 "='\''" $2 "'\''"}' >> /usr/share/thi
23 23
24 cat /usr/share/thingsboard/conf/thingsboard.conf 24 cat /usr/share/thingsboard/conf/thingsboard.conf
25 25
26 -if [ "$DATABASE_TYPE" == "cassandra" ]; then 26 +if [ "$DATABASE_ENTITIES_TYPE" == "cassandra" ]; then
27 until nmap $CASSANDRA_HOST -p $CASSANDRA_PORT | grep "$CASSANDRA_PORT/tcp open\|filtered" 27 until nmap $CASSANDRA_HOST -p $CASSANDRA_PORT | grep "$CASSANDRA_PORT/tcp open\|filtered"
28 do 28 do
29 echo "Wait for cassandra db to start..." 29 echo "Wait for cassandra db to start..."
@@ -31,7 +31,7 @@ if [ "$DATABASE_TYPE" == "cassandra" ]; then @@ -31,7 +31,7 @@ if [ "$DATABASE_TYPE" == "cassandra" ]; then
31 done 31 done
32 fi 32 fi
33 33
34 -if [ "$DATABASE_TYPE" == "sql" ]; then 34 +if [ "$DATABASE_ENTITIES_TYPE" == "sql" ]; then
35 if [ "$SPRING_DRIVER_CLASS_NAME" == "org.postgresql.Driver" ]; then 35 if [ "$SPRING_DRIVER_CLASS_NAME" == "org.postgresql.Driver" ]; then
36 until nmap $POSTGRES_HOST -p $POSTGRES_PORT | grep "$POSTGRES_PORT/tcp open" 36 until nmap $POSTGRES_HOST -p $POSTGRES_PORT | grep "$POSTGRES_PORT/tcp open"
37 do 37 do