Commit b7ed7ea039e96e65218eba375a14d36d2091e7f0

Authored by hagaic
1 parent 75b77f09

hybrid db initial commit

... ... @@ -116,7 +116,7 @@ public class ThingsboardInstallService {
116 116
117 117 log.info("Installing DataBase schema...");
118 118
119   - databaseSchemaService.createDatabaseSchema();
  119 + databaseSchemaService.createDatabaseSchema();//TODO
120 120
121 121 log.info("Loading system data...");
122 122
... ...
... ... @@ -20,7 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
20 20 import org.springframework.context.annotation.Profile;
21 21 import org.springframework.stereotype.Service;
22 22 import org.thingsboard.server.dao.cassandra.CassandraInstallCluster;
23   -import org.thingsboard.server.dao.util.NoSqlDao;
  23 +import org.thingsboard.server.dao.util.NoSqlAnyDao;
24 24 import org.thingsboard.server.service.install.cql.CQLStatementsParser;
25 25
26 26 import java.nio.file.Path;
... ... @@ -28,7 +28,7 @@ import java.nio.file.Paths;
28 28 import java.util.List;
29 29
30 30 @Service
31   -@NoSqlDao
  31 +@NoSqlAnyDao
32 32 @Profile("install")
33 33 @Slf4j
34 34 public class CassandraDatabaseSchemaService implements DatabaseSchemaService {
... ...
... ... @@ -23,7 +23,7 @@ import org.springframework.stereotype.Service;
23 23 import org.thingsboard.server.dao.cassandra.CassandraCluster;
24 24 import org.thingsboard.server.dao.cassandra.CassandraInstallCluster;
25 25 import org.thingsboard.server.dao.dashboard.DashboardService;
26   -import org.thingsboard.server.dao.util.NoSqlDao;
  26 +import org.thingsboard.server.dao.util.NoSqlAnyDao;
27 27 import org.thingsboard.server.service.install.cql.CQLStatementsParser;
28 28 import org.thingsboard.server.service.install.cql.CassandraDbHelper;
29 29
... ... @@ -45,7 +45,7 @@ import static org.thingsboard.server.service.install.DatabaseHelper.TENANT_ID;
45 45 import static org.thingsboard.server.service.install.DatabaseHelper.TITLE;
46 46
47 47 @Service
48   -@NoSqlDao
  48 +@NoSqlAnyDao
49 49 @Profile("install")
50 50 @Slf4j
51 51 public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
... ...
... ... @@ -151,6 +151,7 @@ quota:
151 151 # Enable Host API Limits
152 152 enabled: "${QUOTA_TENANT_ENABLED:false}"
153 153 # Array of whitelist tenants
  154 + # Array of whitelist tenants
154 155 whitelist: "${QUOTA_TENANT_WHITELIST:}"
155 156 # Array of blacklist tenants
156 157 blacklist: "${QUOTA_HOST_BLACKLIST:}"
... ... @@ -160,6 +161,10 @@ quota:
160 161
161 162 database:
162 163 type: "${DATABASE_TYPE:sql}" # cassandra OR sql
  164 + entities:
  165 + type: "${DATABASE_TYPE:sql}" # cassandra OR sql
  166 + ts:
  167 + type: "${DATABASE_TYPE:cassandra}" # cassandra OR sql
163 168
164 169 # Cassandra driver configuration parameters
165 170 cassandra:
... ... @@ -206,7 +211,7 @@ cassandra:
206 211 write_consistency_level: "${CASSANDRA_WRITE_CONSISTENCY_LEVEL:ONE}"
207 212 default_fetch_size: "${CASSANDRA_DEFAULT_FETCH_SIZE:2000}"
208 213 # Specify partitioning size for timestamp key-value storage. Example MINUTES, HOURS, DAYS, MONTHS,INDEFINITE
209   - ts_key_value_partitioning: "${TS_KV_PARTITIONING:MONTHS}"
  214 + ts_key_value_partitioning: "${TS_KV_PARTITIONING:INDEFINITE}"
210 215 ts_key_value_ttl: "${TS_KV_TTL:0}"
211 216 buffer_size: "${CASSANDRA_QUERY_BUFFER_SIZE:200000}"
212 217 concurrent_limit: "${CASSANDRA_QUERY_CONCURRENT_LIMIT:1000}"
... ...
... ... @@ -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}")
... ...
... ... @@ -42,6 +42,7 @@ import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService;
42 42 import org.thingsboard.server.dao.timeseries.TimeseriesDao;
43 43 import org.thingsboard.server.dao.timeseries.TsInsertExecutorType;
44 44 import org.thingsboard.server.dao.util.SqlDao;
  45 +import org.thingsboard.server.dao.util.SqlTsDao;
45 46
46 47 import javax.annotation.Nullable;
47 48 import javax.annotation.PostConstruct;
... ... @@ -58,7 +59,7 @@ import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
58 59
59 60 @Component
60 61 @Slf4j
61   -@SqlDao
  62 +@SqlTsDao
62 63 public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService implements TimeseriesDao {
63 64
64 65 @Value("${sql.ts_inserts_executor_type}")
... ...
... ... @@ -47,6 +47,7 @@ import org.thingsboard.server.common.data.kv.TsKvQuery;
47 47 import org.thingsboard.server.dao.model.ModelConstants;
48 48 import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao;
49 49 import org.thingsboard.server.dao.util.NoSqlDao;
  50 +import org.thingsboard.server.dao.util.NoSqlTsDao;
50 51
51 52 import javax.annotation.Nullable;
52 53 import javax.annotation.PostConstruct;
... ... @@ -68,7 +69,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
68 69 */
69 70 @Component
70 71 @Slf4j
71   -@NoSqlDao
  72 +@NoSqlTsDao
72 73 public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implements TimeseriesDao {
73 74
74 75 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.type}'=='cassandra' || '${database.ts.type}'=='cassandra'")
  21 +public @interface NoSqlAnyDao {
  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 +}
... ...
  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 +}
... ...