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 24 import org.springframework.stereotype.Service;
25 25 import org.thingsboard.server.service.component.ComponentDiscoveryService;
26 26 import org.thingsboard.server.service.install.DataUpdateService;
27   -import org.thingsboard.server.service.install.DatabaseSchemaService;
28 27 import org.thingsboard.server.service.install.DatabaseUpgradeService;
  28 +import org.thingsboard.server.service.install.EntityDatabaseSchemaService;
29 29 import org.thingsboard.server.service.install.SystemDataLoaderService;
  30 +import org.thingsboard.server.service.install.TsDatabaseSchemaService;
30 31
31 32 @Service
32 33 @Profile("install")
... ... @@ -43,7 +44,10 @@ public class ThingsboardInstallService {
43 44 private Boolean loadDemo;
44 45
45 46 @Autowired
46   - private DatabaseSchemaService databaseSchemaService;
  47 + private EntityDatabaseSchemaService entityDatabaseSchemaService;
  48 +
  49 + @Autowired
  50 + private TsDatabaseSchemaService tsDatabaseSchemaService;
47 51
48 52 @Autowired
49 53 private DatabaseUpgradeService databaseUpgradeService;
... ... @@ -119,9 +123,13 @@ public class ThingsboardInstallService {
119 123
120 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 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 17
18 18 import lombok.extern.slf4j.Slf4j;
19 19 import org.springframework.beans.factory.annotation.Autowired;
20   -import org.springframework.context.annotation.Profile;
21   -import org.springframework.stereotype.Service;
22 20 import org.thingsboard.server.dao.cassandra.CassandraInstallCluster;
23   -import org.thingsboard.server.dao.util.NoSqlDao;
24 21 import org.thingsboard.server.service.install.cql.CQLStatementsParser;
25 22
26 23 import java.nio.file.Path;
27 24 import java.nio.file.Paths;
28 25 import java.util.List;
29 26
30   -@Service
31   -@NoSqlDao
32   -@Profile("install")
33 27 @Slf4j
34   -public class CassandraDatabaseSchemaService implements DatabaseSchemaService {
  28 +public abstract class CassandraAbstractDatabaseSchemaService implements DatabaseSchemaService {
35 29
36 30 private static final String CASSANDRA_DIR = "cassandra";
37   - private static final String SCHEMA_CQL = "schema.cql";
38 31
39 32 @Autowired
40 33 private CassandraInstallCluster cluster;
... ... @@ -42,10 +35,16 @@ public class CassandraDatabaseSchemaService implements DatabaseSchemaService {
42 35 @Autowired
43 36 private InstallScripts installScripts;
44 37
  38 + private final String schemaCql;
  39 +
  40 + protected CassandraAbstractDatabaseSchemaService(String schemaCql) {
  41 + this.schemaCql = schemaCql;
  42 + }
  43 +
45 44 @Override
46 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 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 18 import lombok.extern.slf4j.Slf4j;
19 19 import org.springframework.beans.factory.annotation.Autowired;
20 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 22 import java.nio.charset.Charset;
26 23 import java.nio.file.Files;
... ... @@ -29,14 +26,10 @@ import java.nio.file.Paths;
29 26 import java.sql.Connection;
30 27 import java.sql.DriverManager;
31 28
32   -@Service
33   -@Profile("install")
34 29 @Slf4j
35   -@SqlDao
36   -public class SqlDatabaseSchemaService implements DatabaseSchemaService {
  30 +public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchemaService {
37 31
38 32 private static final String SQL_DIR = "sql";
39   - private static final String SCHEMA_SQL = "schema.sql";
40 33
41 34 @Value("${spring.datasource.url}")
42 35 private String dbUrl;
... ... @@ -50,12 +43,18 @@ public class SqlDatabaseSchemaService implements DatabaseSchemaService {
50 43 @Autowired
51 44 private InstallScripts installScripts;
52 45
  46 + private final String schemaSql;
  47 +
  48 + protected SqlAbstractDatabaseSchemaService(String schemaSql) {
  49 + this.schemaSql = schemaSql;
  50 + }
  51 +
53 52 @Override
54 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 58 try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
60 59 String sql = new String(Files.readAllBytes(schemaFile), Charset.forName("UTF-8"));
61 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 +}
\ No newline at end of file
... ...
  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 159 intervalMin: 2
160 160
161 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 168 # Cassandra driver configuration parameters
165 169 cassandra:
... ... @@ -206,7 +210,7 @@ cassandra:
206 210 write_consistency_level: "${CASSANDRA_WRITE_CONSISTENCY_LEVEL:ONE}"
207 211 default_fetch_size: "${CASSANDRA_DEFAULT_FETCH_SIZE:2000}"
208 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 214 ts_key_value_ttl: "${TS_KV_TTL:0}"
211 215 buffer_size: "${CASSANDRA_QUERY_BUFFER_SIZE:200000}"
212 216 concurrent_limit: "${CASSANDRA_QUERY_CONCURRENT_LIMIT:1000}"
... ...
... ... @@ -32,7 +32,8 @@ public class ControllerNoSqlTestSuite {
32 32 public static CustomCassandraCQLUnit cassandraUnit =
33 33 new CustomCassandraCQLUnit(
34 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 37 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false),
37 38 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)),
38 39 "cassandra-test.yaml", 30000l);
... ...
... ... @@ -30,7 +30,7 @@ public class ControllerSqlTestSuite {
30 30
31 31 @ClassRule
32 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 34 "sql/drop-all-tables.sql",
35 35 "sql-test.properties");
36 36 }
... ...
... ... @@ -32,7 +32,8 @@ public class MqttNoSqlTestSuite {
32 32 public static CustomCassandraCQLUnit cassandraUnit =
33 33 new CustomCassandraCQLUnit(
34 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 37 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
37 38 "cassandra-test.yaml", 30000l);
38 39 }
... ...
... ... @@ -15,11 +15,9 @@
15 15 */
16 16 package org.thingsboard.server.mqtt;
17 17
18   -import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;
19 18 import org.junit.ClassRule;
20 19 import org.junit.extensions.cpsuite.ClasspathSuite;
21 20 import org.junit.runner.RunWith;
22   -import org.thingsboard.server.dao.CustomCassandraCQLUnit;
23 21 import org.thingsboard.server.dao.CustomSqlUnit;
24 22
25 23 import java.util.Arrays;
... ... @@ -31,7 +29,7 @@ public class MqttSqlTestSuite {
31 29
32 30 @ClassRule
33 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 33 "sql/drop-all-tables.sql",
36 34 "sql-test.properties");
37 35 }
... ...
... ... @@ -35,7 +35,8 @@ public class RuleEngineNoSqlTestSuite {
35 35 public static CustomCassandraCQLUnit cassandraUnit =
36 36 new CustomCassandraCQLUnit(
37 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 40 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
40 41 "cassandra-test.yaml", 30000l);
41 42
... ...
... ... @@ -30,7 +30,7 @@ public class RuleEngineSqlTestSuite {
30 30
31 31 @ClassRule
32 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 34 "sql/drop-all-tables.sql",
35 35 "sql-test.properties");
36 36 }
... ...
... ... @@ -34,7 +34,8 @@ public class SystemNoSqlTestSuite {
34 34 public static CustomCassandraCQLUnit cassandraUnit =
35 35 new CustomCassandraCQLUnit(
36 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 39 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
39 40 "cassandra-test.yaml", 30000l);
40 41 }
... ...
... ... @@ -31,7 +31,7 @@ public class SystemSqlTestSuite {
31 31
32 32 @ClassRule
33 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 35 "sql/drop-all-tables.sql",
36 36 "sql-test.properties");
37 37
... ...
... ... @@ -17,12 +17,12 @@ package org.thingsboard.server.dao.cassandra;
17 17
18 18 import org.springframework.beans.factory.annotation.Value;
19 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 22 import javax.annotation.PostConstruct;
23 23
24 24 @Component
25   -@NoSqlDao
  25 +@NoSqlAnyDao
26 26 public class CassandraCluster extends AbstractCassandraCluster {
27 27
28 28 @Value("${cassandra.keyspace_name}")
... ...
... ... @@ -17,12 +17,12 @@ package org.thingsboard.server.dao.cassandra;
17 17
18 18 import org.springframework.context.annotation.Profile;
19 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 22 import javax.annotation.PostConstruct;
23 23
24 24 @Component
25   -@NoSqlDao
  25 +@NoSqlAnyDao
26 26 @Profile("install")
27 27 public class CassandraInstallCluster extends AbstractCassandraCluster {
28 28
... ...
... ... @@ -21,14 +21,14 @@ import lombok.Data;
21 21 import org.springframework.beans.factory.annotation.Value;
22 22 import org.springframework.context.annotation.Configuration;
23 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 26 import javax.annotation.PostConstruct;
27 27
28 28 @Component
29 29 @Configuration
30 30 @Data
31   -@NoSqlDao
  31 +@NoSqlAnyDao
32 32 public class CassandraQueryOptions {
33 33
34 34 @Value("${cassandra.query.default_fetch_size}")
... ...
... ... @@ -20,14 +20,14 @@ import lombok.Data;
20 20 import org.springframework.beans.factory.annotation.Value;
21 21 import org.springframework.context.annotation.Configuration;
22 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 25 import javax.annotation.PostConstruct;
26 26
27 27 @Component
28 28 @Configuration
29 29 @Data
30   -@NoSqlDao
  30 +@NoSqlAnyDao
31 31 public class CassandraSocketOptions {
32 32
33 33 @Value("${cassandra.socket.connect_timeout}")
... ...
... ... @@ -44,6 +44,7 @@ import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService;
44 44 import org.thingsboard.server.dao.timeseries.TimeseriesDao;
45 45 import org.thingsboard.server.dao.timeseries.TsInsertExecutorType;
46 46 import org.thingsboard.server.dao.util.SqlDao;
  47 +import org.thingsboard.server.dao.util.SqlTsDao;
47 48
48 49 import javax.annotation.Nullable;
49 50 import javax.annotation.PostConstruct;
... ... @@ -60,7 +61,7 @@ import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
60 61
61 62 @Component
62 63 @Slf4j
63   -@SqlDao
  64 +@SqlTsDao
64 65 public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService implements TimeseriesDao {
65 66
66 67 @Value("${sql.ts_inserts_executor_type}")
... ...
... ... @@ -49,6 +49,7 @@ import org.thingsboard.server.common.data.kv.TsKvEntry;
49 49 import org.thingsboard.server.dao.model.ModelConstants;
50 50 import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao;
51 51 import org.thingsboard.server.dao.util.NoSqlDao;
  52 +import org.thingsboard.server.dao.util.NoSqlTsDao;
52 53
53 54 import javax.annotation.Nullable;
54 55 import javax.annotation.PostConstruct;
... ... @@ -70,7 +71,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
70 71 */
71 72 @Component
72 73 @Slf4j
73   -@NoSqlDao
  74 +@NoSqlTsDao
74 75 public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implements TimeseriesDao {
75 76
76 77 private static final int MIN_AGGREGATION_STEP_MS = 1000;
... ...
... ... @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicInteger;
34 34
35 35 @Component
36 36 @Slf4j
37   -@NoSqlDao
  37 +@NoSqlAnyDao
38 38 public class BufferedRateLimiter implements AsyncRateLimiter {
39 39
40 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 17
18 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 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 17
18 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 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 398 PRIMARY KEY ( tenant_id, search_text, id )
399 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 401 CREATE TABLE IF NOT EXISTS thingsboard.attributes_kv_cf (
437 402 entity_type text, // (DEVICE, CUSTOMER, TENANT)
438 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 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 182 CREATE TABLE IF NOT EXISTS user_credentials (
207 183 id varchar(31) NOT NULL CONSTRAINT user_credentials_pkey PRIMARY KEY,
208 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 30
31 31 @ClassRule
32 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 34 "sql/drop-all-tables.sql",
35 35 "sql-test.properties"
36 36 );
... ...
... ... @@ -34,7 +34,9 @@ public class NoSqlDaoServiceTestSuite {
34 34 @ClassRule
35 35 public static CustomCassandraCQLUnit cassandraUnit =
36 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 40 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false),
39 41 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)),
40 42 "cassandra-test.yaml", 30000L);
... ...
... ... @@ -30,7 +30,7 @@ public class SqlDaoServiceTestSuite {
30 30
31 31 @ClassRule
32 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 34 "sql/drop-all-tables.sql",
35 35 "sql-test.properties"
36 36 );
... ...
1   -database.type=cassandra
  1 +database.entities.type=cassandra
  2 +database.ts.type=cassandra
2 3
3 4 cassandra.queue.partitioning=HOURS
4 5 cassandra.queue.ack.ttl=3600
... ...
1   -database.type=sql
  1 +database.ts.type=sql
  2 +database.entities.type=sql
2 3
3 4 sql.ts_inserts_executor_type=fixed
4 5 sql.ts_inserts_fixed_thread_pool_size=10
... ...
... ... @@ -30,7 +30,9 @@ spec:
30 30 value: "cassandra-headless"
31 31 - name : CASSANDRA_PORT
32 32 value: "9042"
33   - - name : DATABASE_TYPE
  33 + - name : DATABASE_ENTITIES_TYPE
  34 + value: "cassandra"
  35 + - name : DATABASE_TS_TYPE
34 36 value: "cassandra"
35 37 - name : CASSANDRA_URL
36 38 value: "cassandra-headless:9042"
... ...
... ... @@ -30,7 +30,9 @@ spec:
30 30 value: "cassandra-headless"
31 31 - name : CASSANDRA_PORT
32 32 value: "9042"
33   - - name : DATABASE_TYPE
  33 + - name : DATABASE_ENTITIES_TYPE
  34 + value: "cassandra"
  35 + - name : DATABASE_TS_TYPE
34 36 value: "cassandra"
35 37 - name : CASSANDRA_URL
36 38 value: "cassandra-headless:9042"
... ...
... ... @@ -120,7 +120,12 @@ spec:
120 120 configMapKeyRef:
121 121 name: tb-config
122 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 129 valueFrom:
125 130 configMapKeyRef:
126 131 name: tb-config
... ...
... ... @@ -8,7 +8,8 @@ COAP_BIND_PORT=5683
8 8 ZOOKEEPER_URL=zk:2181
9 9
10 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 14 # cassandra db config
14 15 CASSANDRA_URL=cassandra:9042
... ...
... ... @@ -23,7 +23,7 @@ printenv | awk -F "=" '{print "export " $1 "='\''" $2 "'\''"}' >> /usr/share/thi
23 23
24 24 cat /usr/share/thingsboard/conf/thingsboard.conf
25 25
26   -if [ "$DATABASE_TYPE" == "cassandra" ]; then
  26 +if [ "$DATABASE_ENTITIES_TYPE" == "cassandra" ]; then
27 27 until nmap $CASSANDRA_HOST -p $CASSANDRA_PORT | grep "$CASSANDRA_PORT/tcp open\|filtered"
28 28 do
29 29 echo "Wait for cassandra db to start..."
... ... @@ -31,7 +31,7 @@ if [ "$DATABASE_TYPE" == "cassandra" ]; then
31 31 done
32 32 fi
33 33
34   -if [ "$DATABASE_TYPE" == "sql" ]; then
  34 +if [ "$DATABASE_ENTITIES_TYPE" == "sql" ]; then
35 35 if [ "$SPRING_DRIVER_CLASS_NAME" == "org.postgresql.Driver" ]; then
36 36 until nmap $POSTGRES_HOST -p $POSTGRES_PORT | grep "$POSTGRES_PORT/tcp open"
37 37 do
... ...