Commit a7d5392f3729148a2463d099a99efbecec305c1d
Merge branch 'develop/3.0' of https://github.com/thingsboard/thingsboard into map/3.0
Showing
95 changed files
with
1379 additions
and
1382 deletions
Too many changes to show.
To preserve performance only 95 of 168 files are displayed.
... | ... | @@ -111,6 +111,10 @@ |
111 | 111 | <groupId>org.slf4j</groupId> |
112 | 112 | <artifactId>slf4j-log4j12</artifactId> |
113 | 113 | </exclusion> |
114 | + <exclusion> | |
115 | + <groupId>org.hibernate</groupId> | |
116 | + <artifactId>hibernate-validator</artifactId> | |
117 | + </exclusion> | |
114 | 118 | </exclusions> |
115 | 119 | <scope>test</scope> |
116 | 120 | </dependency> |
... | ... | @@ -241,6 +245,12 @@ |
241 | 245 | <groupId>org.springframework.boot</groupId> |
242 | 246 | <artifactId>spring-boot-starter-test</artifactId> |
243 | 247 | <scope>test</scope> |
248 | + <exclusions> | |
249 | + <exclusion> | |
250 | + <groupId>com.vaadin.external.google</groupId> | |
251 | + <artifactId>android-json</artifactId> | |
252 | + </exclusion> | |
253 | + </exclusions> | |
244 | 254 | </dependency> |
245 | 255 | <dependency> |
246 | 256 | <groupId>org.springframework.security</groupId> | ... | ... |
... | ... | @@ -164,25 +164,24 @@ BEGIN |
164 | 164 | END; |
165 | 165 | $$; |
166 | 166 | |
167 | --- call insert_into_ts_kv(); | |
167 | +CREATE OR REPLACE FUNCTION to_uuid(IN entity_id varchar, OUT uuid_id uuid) AS | |
168 | +$$ | |
169 | +BEGIN | |
170 | + uuid_id := substring(entity_id, 8, 8) || '-' || substring(entity_id, 4, 4) || '-1' || substring(entity_id, 1, 3) || | |
171 | + '-' || substring(entity_id, 16, 4) || '-' || substring(entity_id, 20, 12); | |
172 | +END; | |
173 | +$$ LANGUAGE plpgsql; | |
168 | 174 | |
169 | -CREATE OR REPLACE PROCEDURE insert_into_ts_kv() LANGUAGE plpgsql AS $$ | |
170 | -DECLARE | |
171 | - insert_size CONSTANT integer := 10000; | |
172 | - insert_counter integer DEFAULT 0; | |
173 | - insert_record RECORD; | |
174 | - insert_cursor CURSOR FOR SELECT CONCAT(entity_id_uuid_first_part, '-', entity_id_uuid_second_part, '-1', entity_id_uuid_third_part, '-', entity_id_uuid_fourth_part, '-', entity_id_uuid_fifth_part)::uuid AS entity_id, | |
175 | +CREATE OR REPLACE PROCEDURE insert_into_ts_kv(IN path_to_file varchar) LANGUAGE plpgsql AS $$ | |
176 | +BEGIN | |
177 | + EXECUTE format ('COPY (SELECT to_uuid(entity_id) AS entity_id, | |
175 | 178 | ts_kv_records.key AS key, |
176 | 179 | ts_kv_records.ts AS ts, |
177 | 180 | ts_kv_records.bool_v AS bool_v, |
178 | 181 | ts_kv_records.str_v AS str_v, |
179 | 182 | ts_kv_records.long_v AS long_v, |
180 | 183 | ts_kv_records.dbl_v AS dbl_v |
181 | - FROM (SELECT SUBSTRING(entity_id, 8, 8) AS entity_id_uuid_first_part, | |
182 | - SUBSTRING(entity_id, 4, 4) AS entity_id_uuid_second_part, | |
183 | - SUBSTRING(entity_id, 1, 3) AS entity_id_uuid_third_part, | |
184 | - SUBSTRING(entity_id, 16, 4) AS entity_id_uuid_fourth_part, | |
185 | - SUBSTRING(entity_id, 20) AS entity_id_uuid_fifth_part, | |
184 | + FROM (SELECT entity_id AS entity_id, | |
186 | 185 | key_id AS key, |
187 | 186 | ts, |
188 | 187 | bool_v, |
... | ... | @@ -190,46 +189,23 @@ DECLARE |
190 | 189 | long_v, |
191 | 190 | dbl_v |
192 | 191 | FROM ts_kv_old |
193 | - INNER JOIN ts_kv_dictionary ON (ts_kv_old.key = ts_kv_dictionary.key)) AS ts_kv_records; | |
194 | -BEGIN | |
195 | - OPEN insert_cursor; | |
196 | - LOOP | |
197 | - insert_counter := insert_counter + 1; | |
198 | - FETCH insert_cursor INTO insert_record; | |
199 | - IF NOT FOUND THEN | |
200 | - RAISE NOTICE '% records have been inserted into the partitioned ts_kv!',insert_counter - 1; | |
201 | - EXIT; | |
202 | - END IF; | |
203 | - INSERT INTO ts_kv(entity_id, key, ts, bool_v, str_v, long_v, dbl_v) | |
204 | - VALUES (insert_record.entity_id, insert_record.key, insert_record.ts, insert_record.bool_v, insert_record.str_v, | |
205 | - insert_record.long_v, insert_record.dbl_v); | |
206 | - IF MOD(insert_counter, insert_size) = 0 THEN | |
207 | - RAISE NOTICE '% records have been inserted into the partitioned ts_kv!',insert_counter; | |
208 | - END IF; | |
209 | - END LOOP; | |
210 | - CLOSE insert_cursor; | |
211 | -END; | |
192 | + INNER JOIN ts_kv_dictionary ON (ts_kv_old.key = ts_kv_dictionary.key)) AS ts_kv_records) TO %L;', path_to_file); | |
193 | + EXECUTE format ('COPY ts_kv FROM %L', path_to_file); | |
194 | +END | |
212 | 195 | $$; |
213 | 196 | |
214 | 197 | -- call insert_into_ts_kv_latest(); |
215 | 198 | |
216 | -CREATE OR REPLACE PROCEDURE insert_into_ts_kv_latest() LANGUAGE plpgsql AS $$ | |
217 | -DECLARE | |
218 | - insert_size CONSTANT integer := 10000; | |
219 | - insert_counter integer DEFAULT 0; | |
220 | - insert_record RECORD; | |
221 | - insert_cursor CURSOR FOR SELECT CONCAT(entity_id_uuid_first_part, '-', entity_id_uuid_second_part, '-1', entity_id_uuid_third_part, '-', entity_id_uuid_fourth_part, '-', entity_id_uuid_fifth_part)::uuid AS entity_id, | |
199 | +CREATE OR REPLACE PROCEDURE insert_into_ts_kv_latest(IN path_to_file varchar) LANGUAGE plpgsql AS $$ | |
200 | +BEGIN | |
201 | + EXECUTE format ('COPY (SELECT to_uuid(entity_id) AS entity_id, | |
222 | 202 | ts_kv_latest_records.key AS key, |
223 | 203 | ts_kv_latest_records.ts AS ts, |
224 | 204 | ts_kv_latest_records.bool_v AS bool_v, |
225 | 205 | ts_kv_latest_records.str_v AS str_v, |
226 | 206 | ts_kv_latest_records.long_v AS long_v, |
227 | 207 | ts_kv_latest_records.dbl_v AS dbl_v |
228 | - FROM (SELECT SUBSTRING(entity_id, 8, 8) AS entity_id_uuid_first_part, | |
229 | - SUBSTRING(entity_id, 4, 4) AS entity_id_uuid_second_part, | |
230 | - SUBSTRING(entity_id, 1, 3) AS entity_id_uuid_third_part, | |
231 | - SUBSTRING(entity_id, 16, 4) AS entity_id_uuid_fourth_part, | |
232 | - SUBSTRING(entity_id, 20) AS entity_id_uuid_fifth_part, | |
208 | + FROM (SELECT entity_id AS entity_id, | |
233 | 209 | key_id AS key, |
234 | 210 | ts, |
235 | 211 | bool_v, |
... | ... | @@ -237,24 +213,8 @@ DECLARE |
237 | 213 | long_v, |
238 | 214 | dbl_v |
239 | 215 | FROM ts_kv_latest_old |
240 | - INNER JOIN ts_kv_dictionary ON (ts_kv_latest_old.key = ts_kv_dictionary.key)) AS ts_kv_latest_records; | |
241 | -BEGIN | |
242 | - OPEN insert_cursor; | |
243 | - LOOP | |
244 | - insert_counter := insert_counter + 1; | |
245 | - FETCH insert_cursor INTO insert_record; | |
246 | - IF NOT FOUND THEN | |
247 | - RAISE NOTICE '% records have been inserted into the ts_kv_latest!',insert_counter - 1; | |
248 | - EXIT; | |
249 | - END IF; | |
250 | - INSERT INTO ts_kv_latest(entity_id, key, ts, bool_v, str_v, long_v, dbl_v) | |
251 | - VALUES (insert_record.entity_id, insert_record.key, insert_record.ts, insert_record.bool_v, insert_record.str_v, | |
252 | - insert_record.long_v, insert_record.dbl_v); | |
253 | - IF MOD(insert_counter, insert_size) = 0 THEN | |
254 | - RAISE NOTICE '% records have been inserted into the ts_kv_latest!',insert_counter; | |
255 | - END IF; | |
256 | - END LOOP; | |
257 | - CLOSE insert_cursor; | |
216 | + INNER JOIN ts_kv_dictionary ON (ts_kv_latest_old.key = ts_kv_dictionary.key)) AS ts_kv_latest_records) TO %L;', path_to_file); | |
217 | + EXECUTE format ('COPY ts_kv_latest FROM %L', path_to_file); | |
258 | 218 | END; |
259 | 219 | $$; |
260 | 220 | ... | ... |
... | ... | @@ -96,51 +96,36 @@ BEGIN |
96 | 96 | END; |
97 | 97 | $$; |
98 | 98 | |
99 | --- call insert_into_ts_kv(); | |
99 | +CREATE OR REPLACE FUNCTION to_uuid(IN entity_id varchar, OUT uuid_id uuid) AS | |
100 | +$$ | |
101 | +BEGIN | |
102 | + uuid_id := substring(entity_id, 8, 8) || '-' || substring(entity_id, 4, 4) || '-1' || substring(entity_id, 1, 3) || | |
103 | + '-' || substring(entity_id, 16, 4) || '-' || substring(entity_id, 20, 12); | |
104 | +END; | |
105 | +$$ LANGUAGE plpgsql; | |
100 | 106 | |
101 | -CREATE OR REPLACE PROCEDURE insert_into_ts_kv() LANGUAGE plpgsql AS $$ | |
107 | +-- call insert_into_ts_kv(); | |
102 | 108 | |
103 | -DECLARE | |
104 | - insert_size CONSTANT integer := 10000; | |
105 | - insert_counter integer DEFAULT 0; | |
106 | - insert_record RECORD; | |
107 | - insert_cursor CURSOR FOR SELECT CONCAT(entity_id_uuid_first_part, '-', entity_id_uuid_second_part, '-1', entity_id_uuid_third_part, '-', entity_id_uuid_fourth_part, '-', entity_id_uuid_fifth_part)::uuid AS entity_id, | |
108 | - new_ts_kv_records.key AS key, | |
109 | - new_ts_kv_records.ts AS ts, | |
110 | - new_ts_kv_records.bool_v AS bool_v, | |
111 | - new_ts_kv_records.str_v AS str_v, | |
112 | - new_ts_kv_records.long_v AS long_v, | |
113 | - new_ts_kv_records.dbl_v AS dbl_v | |
114 | - FROM (SELECT SUBSTRING(entity_id, 8, 8) AS entity_id_uuid_first_part, | |
115 | - SUBSTRING(entity_id, 4, 4) AS entity_id_uuid_second_part, | |
116 | - SUBSTRING(entity_id, 1, 3) AS entity_id_uuid_third_part, | |
117 | - SUBSTRING(entity_id, 16, 4) AS entity_id_uuid_fourth_part, | |
118 | - SUBSTRING(entity_id, 20) AS entity_id_uuid_fifth_part, | |
119 | - key_id AS key, | |
120 | - ts, | |
121 | - bool_v, | |
122 | - str_v, | |
123 | - long_v, | |
124 | - dbl_v | |
125 | - FROM tenant_ts_kv_old | |
126 | - INNER JOIN ts_kv_dictionary ON (tenant_ts_kv_old.key = ts_kv_dictionary.key)) AS new_ts_kv_records; | |
109 | +CREATE OR REPLACE PROCEDURE insert_into_ts_kv(IN path_to_file varchar) LANGUAGE plpgsql AS $$ | |
127 | 110 | BEGIN |
128 | - OPEN insert_cursor; | |
129 | - LOOP | |
130 | - insert_counter := insert_counter + 1; | |
131 | - FETCH insert_cursor INTO insert_record; | |
132 | - IF NOT FOUND THEN | |
133 | - RAISE NOTICE '% records have been inserted into the new ts_kv table!',insert_counter - 1; | |
134 | - EXIT; | |
135 | - END IF; | |
136 | - INSERT INTO ts_kv(entity_id, key, ts, bool_v, str_v, long_v, dbl_v) | |
137 | - VALUES (insert_record.entity_id, insert_record.key, insert_record.ts, insert_record.bool_v, insert_record.str_v, | |
138 | - insert_record.long_v, insert_record.dbl_v); | |
139 | - IF MOD(insert_counter, insert_size) = 0 THEN | |
140 | - RAISE NOTICE '% records have been inserted into the new ts_kv table!',insert_counter; | |
141 | - END IF; | |
142 | - END LOOP; | |
143 | - CLOSE insert_cursor; | |
111 | + | |
112 | + EXECUTE format ('COPY (SELECT to_uuid(entity_id) AS entity_id, | |
113 | + new_ts_kv_records.key AS key, | |
114 | + new_ts_kv_records.ts AS ts, | |
115 | + new_ts_kv_records.bool_v AS bool_v, | |
116 | + new_ts_kv_records.str_v AS str_v, | |
117 | + new_ts_kv_records.long_v AS long_v, | |
118 | + new_ts_kv_records.dbl_v AS dbl_v | |
119 | + FROM (SELECT entity_id AS entity_id, | |
120 | + key_id AS key, | |
121 | + ts, | |
122 | + bool_v, | |
123 | + str_v, | |
124 | + long_v, | |
125 | + dbl_v | |
126 | + FROM tenant_ts_kv_old | |
127 | + INNER JOIN ts_kv_dictionary ON (tenant_ts_kv_old.key = ts_kv_dictionary.key)) AS new_ts_kv_records) TO %L;', path_to_file); | |
128 | + EXECUTE format ('COPY ts_kv FROM %L', path_to_file); | |
144 | 129 | END; |
145 | 130 | $$; |
146 | 131 | ... | ... |
... | ... | @@ -16,7 +16,6 @@ |
16 | 16 | package org.thingsboard.server.actors.ruleChain; |
17 | 17 | |
18 | 18 | import akka.actor.ActorRef; |
19 | -import com.datastax.driver.core.ResultSetFuture; | |
20 | 19 | import com.fasterxml.jackson.core.JsonProcessingException; |
21 | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
22 | 21 | import io.netty.channel.EventLoopGroup; |
... | ... | @@ -53,6 +52,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService; |
53 | 52 | import org.thingsboard.server.dao.device.DeviceService; |
54 | 53 | import org.thingsboard.server.dao.entityview.EntityViewService; |
55 | 54 | import org.thingsboard.server.dao.nosql.CassandraStatementTask; |
55 | +import org.thingsboard.server.dao.nosql.TbResultSetFuture; | |
56 | 56 | import org.thingsboard.server.dao.relation.RelationService; |
57 | 57 | import org.thingsboard.server.dao.rule.RuleChainService; |
58 | 58 | import org.thingsboard.server.dao.tenant.TenantService; |
... | ... | @@ -405,7 +405,7 @@ class DefaultTbContext implements TbContext { |
405 | 405 | } |
406 | 406 | |
407 | 407 | @Override |
408 | - public ResultSetFuture submitCassandraTask(CassandraStatementTask task) { | |
408 | + public TbResultSetFuture submitCassandraTask(CassandraStatementTask task) { | |
409 | 409 | return mainCtx.getCassandraBufferedRateExecutor().submit(task); |
410 | 410 | } |
411 | 411 | ... | ... |
... | ... | @@ -15,7 +15,6 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.controller; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
19 | 18 | import com.fasterxml.jackson.core.type.TypeReference; |
20 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
21 | 20 | import com.fasterxml.jackson.databind.ObjectMapper; | ... | ... |
... | ... | @@ -34,6 +34,9 @@ public abstract class AbstractSqlTsDatabaseUpgradeService { |
34 | 34 | protected static final String CALL_REGEX = "call "; |
35 | 35 | protected static final String DROP_TABLE = "DROP TABLE "; |
36 | 36 | protected static final String DROP_PROCEDURE_IF_EXISTS = "DROP PROCEDURE IF EXISTS "; |
37 | + protected static final String TS_KV_SQL = "ts_kv.sql"; | |
38 | + protected static final String PATH_TO_USERS_PUBLIC_FOLDER = "C:\\Users\\Public"; | |
39 | + protected static final String THINGSBOARD_WINDOWS_UPGRADE_DIR = "THINGSBOARD_WINDOWS_UPGRADE_DIR"; | |
37 | 40 | |
38 | 41 | @Value("${spring.datasource.url}") |
39 | 42 | protected String dbUrl; | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.install; |
17 | 17 | |
18 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
18 | +import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException; | |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | 20 | import org.springframework.context.annotation.Profile; |
21 | 21 | import org.springframework.stereotype.Service; | ... | ... |
... | ... | @@ -16,12 +16,17 @@ |
16 | 16 | package org.thingsboard.server.service.install; |
17 | 17 | |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | +import org.apache.commons.lang3.StringUtils; | |
20 | +import org.apache.commons.lang3.SystemUtils; | |
19 | 21 | import org.springframework.beans.factory.annotation.Value; |
20 | 22 | import org.springframework.context.annotation.Profile; |
21 | 23 | import org.springframework.stereotype.Service; |
22 | 24 | import org.thingsboard.server.dao.util.PsqlDao; |
23 | 25 | import org.thingsboard.server.dao.util.SqlTsDao; |
24 | 26 | |
27 | +import java.io.File; | |
28 | +import java.io.IOException; | |
29 | +import java.nio.file.Files; | |
25 | 30 | import java.nio.file.Path; |
26 | 31 | import java.nio.file.Paths; |
27 | 32 | import java.sql.Connection; |
... | ... | @@ -37,6 +42,7 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe |
37 | 42 | @Value("${sql.postgres.ts_key_value_partitioning:MONTHS}") |
38 | 43 | private String partitionType; |
39 | 44 | |
45 | + private static final String TS_KV_LATEST_SQL = "ts_kv_latest.sql"; | |
40 | 46 | private static final String LOAD_FUNCTIONS_SQL = "schema_update_psql_ts.sql"; |
41 | 47 | private static final String LOAD_TTL_FUNCTIONS_SQL = "schema_update_ttl.sql"; |
42 | 48 | private static final String LOAD_DROP_PARTITIONS_FUNCTIONS_SQL = "schema_update_psql_drop_partitions.sql"; |
... | ... | @@ -49,15 +55,13 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe |
49 | 55 | private static final String CREATE_PARTITIONS = "create_partitions(IN partition_type varchar)"; |
50 | 56 | private static final String CREATE_TS_KV_DICTIONARY_TABLE = "create_ts_kv_dictionary_table()"; |
51 | 57 | private static final String INSERT_INTO_DICTIONARY = "insert_into_dictionary()"; |
52 | - private static final String INSERT_INTO_TS_KV = "insert_into_ts_kv()"; | |
53 | - private static final String INSERT_INTO_TS_KV_LATEST = "insert_into_ts_kv_latest()"; | |
58 | + private static final String INSERT_INTO_TS_KV = "insert_into_ts_kv(IN path_to_file varchar)"; | |
59 | + private static final String INSERT_INTO_TS_KV_LATEST = "insert_into_ts_kv_latest(IN path_to_file varchar)"; | |
54 | 60 | |
55 | 61 | private static final String CALL_CREATE_PARTITION_TS_KV_TABLE = CALL_REGEX + CREATE_PARTITION_TS_KV_TABLE; |
56 | 62 | private static final String CALL_CREATE_NEW_TS_KV_LATEST_TABLE = CALL_REGEX + CREATE_NEW_TS_KV_LATEST_TABLE; |
57 | 63 | private static final String CALL_CREATE_TS_KV_DICTIONARY_TABLE = CALL_REGEX + CREATE_TS_KV_DICTIONARY_TABLE; |
58 | 64 | private static final String CALL_INSERT_INTO_DICTIONARY = CALL_REGEX + INSERT_INTO_DICTIONARY; |
59 | - private static final String CALL_INSERT_INTO_TS_KV = CALL_REGEX + INSERT_INTO_TS_KV; | |
60 | - private static final String CALL_INSERT_INTO_TS_KV_LATEST = CALL_REGEX + INSERT_INTO_TS_KV_LATEST; | |
61 | 65 | |
62 | 66 | private static final String DROP_TABLE_TS_KV_OLD = DROP_TABLE + TS_KV_OLD; |
63 | 67 | private static final String DROP_TABLE_TS_KV_LATEST_OLD = DROP_TABLE + TS_KV_LATEST_OLD; |
... | ... | @@ -94,9 +98,58 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe |
94 | 98 | } |
95 | 99 | executeQuery(conn, CALL_CREATE_TS_KV_DICTIONARY_TABLE); |
96 | 100 | executeQuery(conn, CALL_INSERT_INTO_DICTIONARY); |
97 | - executeQuery(conn, CALL_INSERT_INTO_TS_KV); | |
98 | - executeQuery(conn, CALL_CREATE_NEW_TS_KV_LATEST_TABLE); | |
99 | - executeQuery(conn, CALL_INSERT_INTO_TS_KV_LATEST); | |
101 | + | |
102 | + Path pathToTempTsKvFile; | |
103 | + Path pathToTempTsKvLatestFile; | |
104 | + if (SystemUtils.IS_OS_WINDOWS) { | |
105 | + log.info("Lookup for environment variable: {} ...", THINGSBOARD_WINDOWS_UPGRADE_DIR); | |
106 | + Path pathToDir; | |
107 | + String thingsboardWindowsUpgradeDir = System.getenv("THINGSBOARD_WINDOWS_UPGRADE_DIR"); | |
108 | + if (StringUtils.isNotEmpty(thingsboardWindowsUpgradeDir)) { | |
109 | + log.info("Environment variable: {} was found!", THINGSBOARD_WINDOWS_UPGRADE_DIR); | |
110 | + pathToDir = Paths.get(thingsboardWindowsUpgradeDir); | |
111 | + } else { | |
112 | + log.info("Failed to lookup environment variable: {}", THINGSBOARD_WINDOWS_UPGRADE_DIR); | |
113 | + pathToDir = Paths.get(PATH_TO_USERS_PUBLIC_FOLDER); | |
114 | + } | |
115 | + log.info("Directory: {} will be used for creation temporary upgrade files!", pathToDir); | |
116 | + try { | |
117 | + Path tsKvFile = Files.createTempFile(pathToDir, "ts_kv", ".sql"); | |
118 | + Path tsKvLatestFile = Files.createTempFile(pathToDir, "ts_kv_latest", ".sql"); | |
119 | + pathToTempTsKvFile = tsKvFile.toAbsolutePath(); | |
120 | + pathToTempTsKvLatestFile = tsKvLatestFile.toAbsolutePath(); | |
121 | + executeQuery(conn, "call insert_into_ts_kv('" + pathToTempTsKvFile + "')"); | |
122 | + executeQuery(conn, CALL_CREATE_NEW_TS_KV_LATEST_TABLE); | |
123 | + executeQuery(conn, "call insert_into_ts_kv_latest('" + pathToTempTsKvLatestFile + "');"); | |
124 | + } catch (IOException | SecurityException e) { | |
125 | + throw new RuntimeException("Failed to create time-series upgrade files due to: " + e); | |
126 | + } | |
127 | + } else { | |
128 | + Path tempDirPath = Files.createTempDirectory("ts_kv"); | |
129 | + File tempDirAsFile = tempDirPath.toFile(); | |
130 | + boolean writable = tempDirAsFile.setWritable(true, false); | |
131 | + boolean readable = tempDirAsFile.setReadable(true, false); | |
132 | + boolean executable = tempDirAsFile.setExecutable(true, false); | |
133 | + if (writable && readable && executable) { | |
134 | + pathToTempTsKvFile = tempDirPath.resolve(TS_KV_SQL).toAbsolutePath(); | |
135 | + pathToTempTsKvLatestFile = tempDirPath.resolve(TS_KV_LATEST_SQL).toAbsolutePath(); | |
136 | + executeQuery(conn, "call insert_into_ts_kv('" + pathToTempTsKvFile + "')"); | |
137 | + executeQuery(conn, CALL_CREATE_NEW_TS_KV_LATEST_TABLE); | |
138 | + executeQuery(conn, "call insert_into_ts_kv_latest('" + pathToTempTsKvLatestFile + "');"); | |
139 | + } else { | |
140 | + throw new RuntimeException("Failed to grant write permissions for the: " + tempDirPath + "folder!"); | |
141 | + } | |
142 | + } | |
143 | + if (pathToTempTsKvFile.toFile().exists() && pathToTempTsKvLatestFile.toFile().exists()) { | |
144 | + boolean deleteTsKvFile = pathToTempTsKvFile.toFile().delete(); | |
145 | + if (deleteTsKvFile) { | |
146 | + log.info("Successfully deleted the temp file for ts_kv table upgrade!"); | |
147 | + } | |
148 | + boolean deleteTsKvLatestFile = pathToTempTsKvLatestFile.toFile().delete(); | |
149 | + if (deleteTsKvLatestFile) { | |
150 | + log.info("Successfully deleted the temp file for ts_kv_latest table upgrade!"); | |
151 | + } | |
152 | + } | |
100 | 153 | |
101 | 154 | executeQuery(conn, DROP_TABLE_TS_KV_OLD); |
102 | 155 | executeQuery(conn, DROP_TABLE_TS_KV_LATEST_OLD); | ... | ... |
... | ... | @@ -16,6 +16,8 @@ |
16 | 16 | package org.thingsboard.server.service.install; |
17 | 17 | |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | +import org.apache.commons.lang3.StringUtils; | |
20 | +import org.apache.commons.lang3.SystemUtils; | |
19 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
20 | 22 | import org.springframework.beans.factory.annotation.Value; |
21 | 23 | import org.springframework.context.annotation.Profile; |
... | ... | @@ -23,6 +25,9 @@ import org.springframework.stereotype.Service; |
23 | 25 | import org.thingsboard.server.dao.util.PsqlDao; |
24 | 26 | import org.thingsboard.server.dao.util.TimescaleDBTsDao; |
25 | 27 | |
28 | +import java.io.File; | |
29 | +import java.io.IOException; | |
30 | +import java.nio.file.Files; | |
26 | 31 | import java.nio.file.Path; |
27 | 32 | import java.nio.file.Paths; |
28 | 33 | import java.sql.Connection; |
... | ... | @@ -47,14 +52,13 @@ public class TimescaleTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgr |
47 | 52 | private static final String CREATE_NEW_TS_KV_TABLE = "create_new_ts_kv_table()"; |
48 | 53 | private static final String CREATE_TS_KV_DICTIONARY_TABLE = "create_ts_kv_dictionary_table()"; |
49 | 54 | private static final String INSERT_INTO_DICTIONARY = "insert_into_dictionary()"; |
50 | - private static final String INSERT_INTO_TS_KV = "insert_into_ts_kv()"; | |
55 | + private static final String INSERT_INTO_TS_KV = "insert_into_ts_kv(IN path_to_file varchar)"; | |
51 | 56 | private static final String INSERT_INTO_TS_KV_LATEST = "insert_into_ts_kv_latest()"; |
52 | 57 | |
53 | 58 | private static final String CALL_CREATE_TS_KV_LATEST_TABLE = CALL_REGEX + CREATE_TS_KV_LATEST_TABLE; |
54 | 59 | private static final String CALL_CREATE_NEW_TENANT_TS_KV_TABLE = CALL_REGEX + CREATE_NEW_TS_KV_TABLE; |
55 | 60 | private static final String CALL_CREATE_TS_KV_DICTIONARY_TABLE = CALL_REGEX + CREATE_TS_KV_DICTIONARY_TABLE; |
56 | 61 | private static final String CALL_INSERT_INTO_DICTIONARY = CALL_REGEX + INSERT_INTO_DICTIONARY; |
57 | - private static final String CALL_INSERT_INTO_TS_KV = CALL_REGEX + INSERT_INTO_TS_KV; | |
58 | 62 | private static final String CALL_INSERT_INTO_TS_KV_LATEST = CALL_REGEX + INSERT_INTO_TS_KV_LATEST; |
59 | 63 | |
60 | 64 | private static final String DROP_OLD_TENANT_TS_KV_TABLE = DROP_TABLE + TENANT_TS_KV_OLD_TABLE; |
... | ... | @@ -63,7 +67,7 @@ public class TimescaleTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgr |
63 | 67 | private static final String DROP_PROCEDURE_CREATE_TENANT_TS_KV_TABLE_COPY = DROP_PROCEDURE_IF_EXISTS + CREATE_NEW_TS_KV_TABLE; |
64 | 68 | private static final String DROP_PROCEDURE_CREATE_TS_KV_DICTIONARY_TABLE = DROP_PROCEDURE_IF_EXISTS + CREATE_TS_KV_DICTIONARY_TABLE; |
65 | 69 | private static final String DROP_PROCEDURE_INSERT_INTO_DICTIONARY = DROP_PROCEDURE_IF_EXISTS + INSERT_INTO_DICTIONARY; |
66 | - private static final String DROP_PROCEDURE_INSERT_INTO_TENANT_TS_KV = DROP_PROCEDURE_IF_EXISTS + INSERT_INTO_TS_KV; | |
70 | + private static final String DROP_PROCEDURE_INSERT_INTO_TS_KV = DROP_PROCEDURE_IF_EXISTS + INSERT_INTO_TS_KV; | |
67 | 71 | private static final String DROP_PROCEDURE_INSERT_INTO_TS_KV_LATEST = DROP_PROCEDURE_IF_EXISTS + INSERT_INTO_TS_KV_LATEST; |
68 | 72 | |
69 | 73 | @Autowired |
... | ... | @@ -91,7 +95,49 @@ public class TimescaleTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgr |
91 | 95 | |
92 | 96 | executeQuery(conn, CALL_CREATE_TS_KV_DICTIONARY_TABLE); |
93 | 97 | executeQuery(conn, CALL_INSERT_INTO_DICTIONARY); |
94 | - executeQuery(conn, CALL_INSERT_INTO_TS_KV); | |
98 | + | |
99 | + Path pathToTempTsKvFile; | |
100 | + if (SystemUtils.IS_OS_WINDOWS) { | |
101 | + Path pathToDir; | |
102 | + log.info("Lookup for environment variable: {} ...", THINGSBOARD_WINDOWS_UPGRADE_DIR); | |
103 | + String thingsboardWindowsUpgradeDir = System.getenv(THINGSBOARD_WINDOWS_UPGRADE_DIR); | |
104 | + if (StringUtils.isNotEmpty(thingsboardWindowsUpgradeDir)) { | |
105 | + log.info("Environment variable: {} was found!", THINGSBOARD_WINDOWS_UPGRADE_DIR); | |
106 | + pathToDir = Paths.get(thingsboardWindowsUpgradeDir); | |
107 | + } else { | |
108 | + log.info("Failed to lookup environment variable: {}", THINGSBOARD_WINDOWS_UPGRADE_DIR); | |
109 | + pathToDir = Paths.get(PATH_TO_USERS_PUBLIC_FOLDER); | |
110 | + } | |
111 | + log.info("Directory: {} will be used for creation temporary upgrade file!", pathToDir); | |
112 | + try { | |
113 | + Path tsKvFile = Files.createTempFile(pathToDir, "ts_kv", ".sql"); | |
114 | + pathToTempTsKvFile = tsKvFile.toAbsolutePath(); | |
115 | + executeQuery(conn, "call insert_into_ts_kv('" + pathToTempTsKvFile + "')"); | |
116 | + pathToTempTsKvFile.toFile().deleteOnExit(); | |
117 | + } catch (IOException | SecurityException e) { | |
118 | + throw new RuntimeException("Failed to create time-series upgrade files due to: " + e); | |
119 | + } | |
120 | + } else { | |
121 | + Path tempDirPath = Files.createTempDirectory("ts_kv"); | |
122 | + File tempDirAsFile = tempDirPath.toFile(); | |
123 | + boolean writable = tempDirAsFile.setWritable(true, false); | |
124 | + boolean readable = tempDirAsFile.setReadable(true, false); | |
125 | + boolean executable = tempDirAsFile.setExecutable(true, false); | |
126 | + if (writable && readable && executable) { | |
127 | + pathToTempTsKvFile = tempDirPath.resolve(TS_KV_SQL).toAbsolutePath(); | |
128 | + executeQuery(conn, "call insert_into_ts_kv('" + pathToTempTsKvFile + "')"); | |
129 | + } else { | |
130 | + throw new RuntimeException("Failed to grant write permissions for the: " + tempDirPath + "folder!"); | |
131 | + } | |
132 | + } | |
133 | + | |
134 | + if (pathToTempTsKvFile.toFile().exists()) { | |
135 | + boolean deleteTsKvFile = pathToTempTsKvFile.toFile().delete(); | |
136 | + if (deleteTsKvFile) { | |
137 | + log.info("Successfully deleted the temp file for ts_kv table upgrade!"); | |
138 | + } | |
139 | + } | |
140 | + | |
95 | 141 | executeQuery(conn, CALL_INSERT_INTO_TS_KV_LATEST); |
96 | 142 | |
97 | 143 | executeQuery(conn, DROP_OLD_TENANT_TS_KV_TABLE); |
... | ... | @@ -100,7 +146,7 @@ public class TimescaleTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgr |
100 | 146 | executeQuery(conn, DROP_PROCEDURE_CREATE_TENANT_TS_KV_TABLE_COPY); |
101 | 147 | executeQuery(conn, DROP_PROCEDURE_CREATE_TS_KV_DICTIONARY_TABLE); |
102 | 148 | executeQuery(conn, DROP_PROCEDURE_INSERT_INTO_DICTIONARY); |
103 | - executeQuery(conn, DROP_PROCEDURE_INSERT_INTO_TENANT_TS_KV); | |
149 | + executeQuery(conn, DROP_PROCEDURE_INSERT_INTO_TS_KV); | |
104 | 150 | executeQuery(conn, DROP_PROCEDURE_INSERT_INTO_TS_KV_LATEST); |
105 | 151 | |
106 | 152 | executeQuery(conn, "ALTER TABLE ts_kv ADD COLUMN IF NOT EXISTS json_v json;"); | ... | ... |
... | ... | @@ -15,25 +15,27 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.install.cql; |
17 | 17 | |
18 | -import com.datastax.driver.core.BoundStatement; | |
19 | -import com.datastax.driver.core.DataType; | |
20 | -import com.datastax.driver.core.KeyspaceMetadata; | |
21 | -import com.datastax.driver.core.PreparedStatement; | |
22 | -import com.datastax.driver.core.ResultSet; | |
23 | -import com.datastax.driver.core.Row; | |
24 | -import com.datastax.driver.core.Session; | |
25 | -import com.datastax.driver.core.SimpleStatement; | |
26 | -import com.datastax.driver.core.Statement; | |
27 | -import com.datastax.driver.core.TableMetadata; | |
18 | +import com.datastax.oss.driver.api.core.cql.BoundStatementBuilder; | |
19 | +import com.datastax.oss.driver.api.core.cql.PreparedStatement; | |
20 | +import com.datastax.oss.driver.api.core.cql.ResultSet; | |
21 | +import com.datastax.oss.driver.api.core.cql.Row; | |
22 | +import com.datastax.oss.driver.api.core.cql.SimpleStatement; | |
23 | +import com.datastax.oss.driver.api.core.cql.Statement; | |
24 | +import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata; | |
25 | +import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; | |
26 | +import com.datastax.oss.driver.api.core.type.DataType; | |
27 | +import com.datastax.oss.protocol.internal.ProtocolConstants; | |
28 | 28 | import org.apache.commons.csv.CSVFormat; |
29 | 29 | import org.apache.commons.csv.CSVParser; |
30 | 30 | import org.apache.commons.csv.CSVPrinter; |
31 | 31 | import org.apache.commons.csv.CSVRecord; |
32 | +import org.thingsboard.server.dao.cassandra.guava.GuavaSession; | |
32 | 33 | |
33 | 34 | import java.io.IOException; |
34 | 35 | import java.nio.file.Files; |
35 | 36 | import java.nio.file.Path; |
36 | 37 | import java.nio.file.StandardCopyOption; |
38 | +import java.time.Instant; | |
37 | 39 | import java.util.ArrayList; |
38 | 40 | import java.util.Date; |
39 | 41 | import java.util.Iterator; |
... | ... | @@ -44,12 +46,12 @@ import static org.thingsboard.server.service.install.DatabaseHelper.CSV_DUMP_FOR |
44 | 46 | |
45 | 47 | public class CassandraDbHelper { |
46 | 48 | |
47 | - public static Path dumpCfIfExists(KeyspaceMetadata ks, Session session, String cfName, | |
49 | + public static Path dumpCfIfExists(KeyspaceMetadata ks, GuavaSession session, String cfName, | |
48 | 50 | String[] columns, String[] defaultValues, String dumpPrefix) throws Exception { |
49 | 51 | return dumpCfIfExists(ks, session, cfName, columns, defaultValues, dumpPrefix, false); |
50 | 52 | } |
51 | 53 | |
52 | - public static Path dumpCfIfExists(KeyspaceMetadata ks, Session session, String cfName, | |
54 | + public static Path dumpCfIfExists(KeyspaceMetadata ks, GuavaSession session, String cfName, | |
53 | 55 | String[] columns, String[] defaultValues, String dumpPrefix, boolean printHeader) throws Exception { |
54 | 56 | if (ks.getTable(cfName) != null) { |
55 | 57 | Path dumpFile = Files.createTempFile(dumpPrefix, null); |
... | ... | @@ -59,8 +61,8 @@ public class CassandraDbHelper { |
59 | 61 | csvFormat = csvFormat.withHeader(columns); |
60 | 62 | } |
61 | 63 | try (CSVPrinter csvPrinter = new CSVPrinter(Files.newBufferedWriter(dumpFile), csvFormat)) { |
62 | - Statement stmt = new SimpleStatement("SELECT * FROM " + cfName); | |
63 | - stmt.setFetchSize(1000); | |
64 | + Statement stmt = SimpleStatement.newInstance("SELECT * FROM " + cfName); | |
65 | + stmt.setPageSize(1000); | |
64 | 66 | ResultSet rs = session.execute(stmt); |
65 | 67 | Iterator<Row> iter = rs.iterator(); |
66 | 68 | while (iter.hasNext()) { |
... | ... | @@ -95,12 +97,12 @@ public class CassandraDbHelper { |
95 | 97 | Files.move(tmp, targetDumpFile, StandardCopyOption.REPLACE_EXISTING); |
96 | 98 | } |
97 | 99 | |
98 | - public static void loadCf(KeyspaceMetadata ks, Session session, String cfName, String[] columns, Path sourceFile) throws Exception { | |
100 | + public static void loadCf(KeyspaceMetadata ks, GuavaSession session, String cfName, String[] columns, Path sourceFile) throws Exception { | |
99 | 101 | loadCf(ks, session, cfName, columns, sourceFile, false); |
100 | 102 | } |
101 | 103 | |
102 | - public static void loadCf(KeyspaceMetadata ks, Session session, String cfName, String[] columns, Path sourceFile, boolean parseHeader) throws Exception { | |
103 | - TableMetadata tableMetadata = ks.getTable(cfName); | |
104 | + public static void loadCf(KeyspaceMetadata ks, GuavaSession session, String cfName, String[] columns, Path sourceFile, boolean parseHeader) throws Exception { | |
105 | + TableMetadata tableMetadata = ks.getTable(cfName).get(); | |
104 | 106 | PreparedStatement prepared = session.prepare(createInsertStatement(cfName, columns)); |
105 | 107 | CSVFormat csvFormat = CSV_DUMP_FORMAT; |
106 | 108 | if (parseHeader) { |
... | ... | @@ -110,11 +112,11 @@ public class CassandraDbHelper { |
110 | 112 | } |
111 | 113 | try (CSVParser csvParser = new CSVParser(Files.newBufferedReader(sourceFile), csvFormat)) { |
112 | 114 | csvParser.forEach(record -> { |
113 | - BoundStatement boundStatement = prepared.bind(); | |
115 | + BoundStatementBuilder boundStatementBuilder = new BoundStatementBuilder(prepared.bind()); | |
114 | 116 | for (String column : columns) { |
115 | - setColumnValue(tableMetadata, column, record, boundStatement); | |
117 | + setColumnValue(tableMetadata, column, record, boundStatementBuilder); | |
116 | 118 | } |
117 | - session.execute(boundStatement); | |
119 | + session.execute(boundStatementBuilder.build()); | |
118 | 120 | }); |
119 | 121 | } |
120 | 122 | } |
... | ... | @@ -136,27 +138,27 @@ public class CassandraDbHelper { |
136 | 138 | } |
137 | 139 | |
138 | 140 | private static String getColumnValue(String column, String defaultValue, Row row) { |
139 | - int index = row.getColumnDefinitions().getIndexOf(column); | |
141 | + int index = row.getColumnDefinitions().firstIndexOf(column); | |
140 | 142 | if (index > -1) { |
141 | 143 | String str; |
142 | - DataType type = row.getColumnDefinitions().getType(index); | |
144 | + DataType type = row.getColumnDefinitions().get(index).getType(); | |
143 | 145 | try { |
144 | 146 | if (row.isNull(index)) { |
145 | 147 | return null; |
146 | - } else if (type == DataType.cdouble()) { | |
148 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.DOUBLE) { | |
147 | 149 | str = new Double(row.getDouble(index)).toString(); |
148 | - } else if (type == DataType.cint()) { | |
150 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.INT) { | |
149 | 151 | str = new Integer(row.getInt(index)).toString(); |
150 | - } else if (type == DataType.bigint()) { | |
152 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.BIGINT) { | |
151 | 153 | str = new Long(row.getLong(index)).toString(); |
152 | - } else if (type == DataType.uuid()) { | |
153 | - str = row.getUUID(index).toString(); | |
154 | - } else if (type == DataType.timeuuid()) { | |
155 | - str = row.getUUID(index).toString(); | |
156 | - } else if (type == DataType.cfloat()) { | |
154 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.UUID) { | |
155 | + str = row.getUuid(index).toString(); | |
156 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMEUUID) { | |
157 | + str = row.getUuid(index).toString(); | |
158 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.FLOAT) { | |
157 | 159 | str = new Float(row.getFloat(index)).toString(); |
158 | - } else if (type == DataType.timestamp()) { | |
159 | - str = ""+row.getTimestamp(index).getTime(); | |
160 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMESTAMP) { | |
161 | + str = ""+row.getInstant(index).toEpochMilli(); | |
160 | 162 | } else { |
161 | 163 | str = row.getString(index); |
162 | 164 | } |
... | ... | @@ -186,27 +188,27 @@ public class CassandraDbHelper { |
186 | 188 | } |
187 | 189 | |
188 | 190 | private static void setColumnValue(TableMetadata tableMetadata, String column, |
189 | - CSVRecord record, BoundStatement boundStatement) { | |
191 | + CSVRecord record, BoundStatementBuilder boundStatementBuilder) { | |
190 | 192 | String value = record.get(column); |
191 | - DataType type = tableMetadata.getColumn(column).getType(); | |
193 | + DataType type = tableMetadata.getColumn(column).get().getType(); | |
192 | 194 | if (value == null) { |
193 | - boundStatement.setToNull(column); | |
194 | - } else if (type == DataType.cdouble()) { | |
195 | - boundStatement.setDouble(column, Double.valueOf(value)); | |
196 | - } else if (type == DataType.cint()) { | |
197 | - boundStatement.setInt(column, Integer.valueOf(value)); | |
198 | - } else if (type == DataType.bigint()) { | |
199 | - boundStatement.setLong(column, Long.valueOf(value)); | |
200 | - } else if (type == DataType.uuid()) { | |
201 | - boundStatement.setUUID(column, UUID.fromString(value)); | |
202 | - } else if (type == DataType.timeuuid()) { | |
203 | - boundStatement.setUUID(column, UUID.fromString(value)); | |
204 | - } else if (type == DataType.cfloat()) { | |
205 | - boundStatement.setFloat(column, Float.valueOf(value)); | |
206 | - } else if (type == DataType.timestamp()) { | |
207 | - boundStatement.setTimestamp(column, new Date(Long.valueOf(value))); | |
195 | + boundStatementBuilder.setToNull(column); | |
196 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.DOUBLE) { | |
197 | + boundStatementBuilder.setDouble(column, Double.valueOf(value)); | |
198 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.INT) { | |
199 | + boundStatementBuilder.setInt(column, Integer.valueOf(value)); | |
200 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.BIGINT) { | |
201 | + boundStatementBuilder.setLong(column, Long.valueOf(value)); | |
202 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.UUID) { | |
203 | + boundStatementBuilder.setUuid(column, UUID.fromString(value)); | |
204 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMEUUID) { | |
205 | + boundStatementBuilder.setUuid(column, UUID.fromString(value)); | |
206 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.FLOAT) { | |
207 | + boundStatementBuilder.setFloat(column, Float.valueOf(value)); | |
208 | + } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMESTAMP) { | |
209 | + boundStatementBuilder.setInstant(column, Instant.ofEpochMilli(Long.valueOf(value))); | |
208 | 210 | } else { |
209 | - boundStatement.setString(column, value); | |
211 | + boundStatementBuilder.setString(column, value); | |
210 | 212 | } |
211 | 213 | } |
212 | 214 | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.install.migrate; |
17 | 17 | |
18 | -import com.datastax.driver.core.Row; | |
18 | +import com.datastax.oss.driver.api.core.cql.Row; | |
19 | 19 | import lombok.Data; |
20 | 20 | import org.thingsboard.server.common.data.UUIDConverter; |
21 | 21 | |
... | ... | @@ -105,7 +105,7 @@ public class CassandraToSqlColumn { |
105 | 105 | } else { |
106 | 106 | switch (this.type) { |
107 | 107 | case ID: |
108 | - return UUIDConverter.fromTimeUUID(row.getUUID(index)); | |
108 | + return UUIDConverter.fromTimeUUID(row.getUuid(index)); | |
109 | 109 | case DOUBLE: |
110 | 110 | return Double.toString(row.getDouble(index)); |
111 | 111 | case INTEGER: |
... | ... | @@ -115,7 +115,7 @@ public class CassandraToSqlColumn { |
115 | 115 | case BIGINT: |
116 | 116 | return Long.toString(row.getLong(index)); |
117 | 117 | case BOOLEAN: |
118 | - return Boolean.toString(row.getBool(index)); | |
118 | + return Boolean.toString(row.getBoolean(index)); | |
119 | 119 | case STRING: |
120 | 120 | case JSON: |
121 | 121 | case ENUM_TO_INT: | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.install.migrate; |
17 | 17 | |
18 | -import com.datastax.driver.core.Row; | |
18 | +import com.datastax.oss.driver.api.core.cql.Row; | |
19 | 19 | |
20 | 20 | import java.util.UUID; |
21 | 21 | |
... | ... | @@ -29,7 +29,7 @@ public class CassandraToSqlEventTsColumn extends CassandraToSqlColumn { |
29 | 29 | |
30 | 30 | @Override |
31 | 31 | public String getColumnValue(Row row) { |
32 | - UUID id = row.getUUID(getIndex()); | |
32 | + UUID id = row.getUuid(getIndex()); | |
33 | 33 | long ts = getTs(id); |
34 | 34 | return ts + ""; |
35 | 35 | } |
... | ... | @@ -37,4 +37,4 @@ public class CassandraToSqlEventTsColumn extends CassandraToSqlColumn { |
37 | 37 | private long getTs(UUID uuid) { |
38 | 38 | return (uuid.timestamp() - EPOCH_DIFF) / 10000; |
39 | 39 | } |
40 | -} | |
\ No newline at end of file | ||
40 | +} | ... | ... |
... | ... | @@ -15,20 +15,17 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.install.migrate; |
17 | 17 | |
18 | -import com.datastax.driver.core.ResultSet; | |
19 | -import com.datastax.driver.core.Row; | |
20 | -import com.datastax.driver.core.Session; | |
21 | -import com.datastax.driver.core.SimpleStatement; | |
22 | -import com.datastax.driver.core.Statement; | |
18 | +import com.datastax.oss.driver.api.core.cql.ResultSet; | |
19 | +import com.datastax.oss.driver.api.core.cql.Row; | |
20 | +import com.datastax.oss.driver.api.core.cql.SimpleStatement; | |
21 | +import com.datastax.oss.driver.api.core.cql.Statement; | |
23 | 22 | import lombok.Data; |
24 | 23 | import lombok.extern.slf4j.Slf4j; |
25 | -import org.hibernate.exception.ConstraintViolationException; | |
26 | 24 | import org.hibernate.internal.util.JdbcExceptionHelper; |
27 | 25 | import org.postgresql.util.PSQLException; |
28 | 26 | import org.thingsboard.server.common.data.UUIDConverter; |
29 | -import org.thingsboard.server.dao.exception.DataValidationException; | |
27 | +import org.thingsboard.server.dao.cassandra.guava.GuavaSession; | |
30 | 28 | |
31 | -import java.sql.BatchUpdateException; | |
32 | 29 | import java.sql.Connection; |
33 | 30 | import java.sql.DatabaseMetaData; |
34 | 31 | import java.sql.PreparedStatement; |
... | ... | @@ -38,7 +35,6 @@ import java.util.Arrays; |
38 | 35 | import java.util.Iterator; |
39 | 36 | import java.util.List; |
40 | 37 | import java.util.Optional; |
41 | -import java.util.stream.Collectors; | |
42 | 38 | |
43 | 39 | @Data |
44 | 40 | @Slf4j |
... | ... | @@ -78,7 +74,7 @@ public class CassandraToSqlTable { |
78 | 74 | } |
79 | 75 | } |
80 | 76 | |
81 | - public void migrateToSql(Session session, Connection conn) throws SQLException { | |
77 | + public void migrateToSql(GuavaSession session, Connection conn) throws SQLException { | |
82 | 78 | log.info("[{}] Migrating data from cassandra '{}' Column Family to '{}' SQL table...", this.sqlTableName, this.cassandraCf, this.sqlTableName); |
83 | 79 | DatabaseMetaData metadata = conn.getMetaData(); |
84 | 80 | java.sql.ResultSet resultSet = metadata.getColumns(null, null, this.sqlTableName, null); |
... | ... | @@ -92,7 +88,7 @@ public class CassandraToSqlTable { |
92 | 88 | } |
93 | 89 | this.sqlInsertStatement = createSqlInsertStatement(conn); |
94 | 90 | Statement cassandraSelectStatement = createCassandraSelectStatement(); |
95 | - cassandraSelectStatement.setFetchSize(100); | |
91 | + cassandraSelectStatement.setPageSize(100); | |
96 | 92 | ResultSet rs = session.execute(cassandraSelectStatement); |
97 | 93 | Iterator<Row> iter = rs.iterator(); |
98 | 94 | int rowCounter = 0; |
... | ... | @@ -281,7 +277,7 @@ public class CassandraToSqlTable { |
281 | 277 | } |
282 | 278 | selectStatementBuilder.deleteCharAt(selectStatementBuilder.length() - 1); |
283 | 279 | selectStatementBuilder.append(" FROM ").append(cassandraCf); |
284 | - return new SimpleStatement(selectStatementBuilder.toString()); | |
280 | + return SimpleStatement.newInstance(selectStatementBuilder.toString()); | |
285 | 281 | } |
286 | 282 | |
287 | 283 | private PreparedStatement createSqlInsertStatement(Connection conn) throws SQLException { | ... | ... |
... | ... | @@ -176,9 +176,9 @@ cassandra: |
176 | 176 | # Enable/disable secure connection |
177 | 177 | ssl: "${CASSANDRA_USE_SSL:false}" |
178 | 178 | # Enable/disable JMX |
179 | - jmx: "${CASSANDRA_USE_JMX:true}" | |
179 | + jmx: "${CASSANDRA_USE_JMX:false}" | |
180 | 180 | # Enable/disable metrics collection. |
181 | - metrics: "${CASSANDRA_DISABLE_METRICS:true}" | |
181 | + metrics: "${CASSANDRA_USE_METRICS:false}" | |
182 | 182 | # NONE SNAPPY LZ4 |
183 | 183 | compression: "${CASSANDRA_COMPRESSION:none}" |
184 | 184 | # Specify cassandra cluster initialization timeout in milliseconds (if no hosts available during startup) |
... | ... | @@ -258,11 +258,11 @@ sql: |
258 | 258 | ttl: |
259 | 259 | ts: |
260 | 260 | enabled: "${SQL_TTL_TS_ENABLED:true}" |
261 | - execution_interval_ms: "${SQL_TTL_TS_EXECUTION_INTERVAL:86400000}" # Number of miliseconds. The current value corresponds to one day | |
261 | + execution_interval_ms: "${SQL_TTL_TS_EXECUTION_INTERVAL:86400000}" # Number of milliseconds. The current value corresponds to one day | |
262 | 262 | ts_key_value_ttl: "${SQL_TTL_TS_TS_KEY_VALUE_TTL:0}" # Number of seconds |
263 | 263 | events: |
264 | 264 | enabled: "${SQL_TTL_EVENTS_ENABLED:true}" |
265 | - execution_interval_ms: "${SQL_TTL_EVENTS_EXECUTION_INTERVAL:86400000}" # Number of miliseconds. The current value corresponds to one day | |
265 | + execution_interval_ms: "${SQL_TTL_EVENTS_EXECUTION_INTERVAL:86400000}" # Number of milliseconds. The current value corresponds to one day | |
266 | 266 | events_ttl: "${SQL_TTL_EVENTS_EVENTS_TTL:0}" # Number of seconds |
267 | 267 | debug_events_ttl: "${SQL_TTL_EVENTS_DEBUG_EVENTS_TTL:604800}" # Number of seconds. The current value corresponds to one week |
268 | 268 | |
... | ... | @@ -583,6 +583,9 @@ queue: |
583 | 583 | linger.ms: "${TB_KAFKA_LINGER_MS:1}" |
584 | 584 | buffer.memory: "${TB_BUFFER_MEMORY:33554432}" |
585 | 585 | replication_factor: "${TB_QUEUE_KAFKA_REPLICATION_FACTOR:1}" |
586 | + max_poll_records: "${TB_QUEUE_KAFKA_MAX_POLL_RECORDS:8192}" | |
587 | + max_partition_fetch_bytes: "${TB_QUEUE_KAFKA_MAX_PARTITION_FETCH_BYTES:16777216}" | |
588 | + fetch_max_bytes: "${TB_QUEUE_KAFKA_FETCH_MAX_BYTES:134217728}" | |
586 | 589 | topic-properties: |
587 | 590 | rule-engine: "${TB_QUEUE_KAFKA_RE_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000}" |
588 | 591 | core: "${TB_QUEUE_KAFKA_CORE_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000}" | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.controller; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.core.type.TypeReference; |
20 | 20 | import org.apache.commons.lang3.RandomStringUtils; |
21 | 21 | import org.junit.After; |
... | ... | @@ -206,7 +206,7 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest { |
206 | 206 | asset.setType("default"); |
207 | 207 | Asset savedAsset = doPost("/api/asset", asset, Asset.class); |
208 | 208 | |
209 | - doPost("/api/customer/" + UUIDs.timeBased().toString() | |
209 | + doPost("/api/customer/" + Uuids.timeBased().toString() | |
210 | 210 | + "/asset/" + savedAsset.getId().getId().toString()) |
211 | 211 | .andExpect(status().isNotFound()); |
212 | 212 | } | ... | ... |
... | ... | @@ -24,7 +24,7 @@ import java.util.ArrayList; |
24 | 24 | import java.util.Collections; |
25 | 25 | import java.util.List; |
26 | 26 | |
27 | -import com.datastax.driver.core.utils.UUIDs; | |
27 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
28 | 28 | import org.apache.commons.lang3.RandomStringUtils; |
29 | 29 | import org.thingsboard.server.common.data.*; |
30 | 30 | import org.thingsboard.server.common.data.id.CustomerId; |
... | ... | @@ -158,7 +158,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest |
158 | 158 | dashboard.setTitle("My dashboard"); |
159 | 159 | Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); |
160 | 160 | |
161 | - doPost("/api/customer/" + UUIDs.timeBased().toString() | |
161 | + doPost("/api/customer/" + Uuids.timeBased().toString() | |
162 | 162 | + "/dashboard/" + savedDashboard.getId().getId().toString()) |
163 | 163 | .andExpect(status().isNotFound()); |
164 | 164 | } | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import java.util.ArrayList; |
23 | 23 | import java.util.Collections; |
24 | 24 | import java.util.List; |
25 | 25 | |
26 | -import com.datastax.driver.core.utils.UUIDs; | |
26 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
27 | 27 | import org.apache.commons.lang3.RandomStringUtils; |
28 | 28 | import org.thingsboard.server.common.data.*; |
29 | 29 | import org.thingsboard.server.common.data.id.CustomerId; |
... | ... | @@ -215,7 +215,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
215 | 215 | device.setType("default"); |
216 | 216 | Device savedDevice = doPost("/api/device", device, Device.class); |
217 | 217 | |
218 | - doPost("/api/customer/" + UUIDs.timeBased().toString() | |
218 | + doPost("/api/customer/" + Uuids.timeBased().toString() | |
219 | 219 | + "/device/" + savedDevice.getId().getId().toString()) |
220 | 220 | .andExpect(status().isNotFound()); |
221 | 221 | } |
... | ... | @@ -333,7 +333,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
333 | 333 | Device savedDevice = doPost("/api/device", device, Device.class); |
334 | 334 | DeviceCredentials deviceCredentials = |
335 | 335 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); |
336 | - DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(UUIDs.timeBased())); | |
336 | + DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(Uuids.timeBased())); | |
337 | 337 | newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime()); |
338 | 338 | newDeviceCredentials.setDeviceId(deviceCredentials.getDeviceId()); |
339 | 339 | newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType()); |
... | ... | @@ -351,7 +351,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
351 | 351 | Device savedDevice = doPost("/api/device", device, Device.class); |
352 | 352 | DeviceCredentials deviceCredentials = |
353 | 353 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); |
354 | - deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased())); | |
354 | + deviceCredentials.setDeviceId(new DeviceId(Uuids.timeBased())); | |
355 | 355 | doPost("/api/device/credentials", deviceCredentials) |
356 | 356 | .andExpect(status().isNotFound()); |
357 | 357 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.controller; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.core.type.TypeReference; |
20 | 20 | import lombok.extern.slf4j.Slf4j; |
21 | 21 | import org.apache.commons.lang3.RandomStringUtils; |
... | ... | @@ -176,7 +176,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
176 | 176 | @Test |
177 | 177 | public void testAssignEntityViewToNonExistentCustomer() throws Exception { |
178 | 178 | EntityView savedView = getNewSavedEntityView("Test entity view"); |
179 | - doPost("/api/customer/" + UUIDs.timeBased().toString() + "/device/" + savedView.getId().getId().toString()) | |
179 | + doPost("/api/customer/" + Uuids.timeBased().toString() + "/device/" + savedView.getId().getId().toString()) | |
180 | 180 | .andExpect(status().isNotFound()); |
181 | 181 | } |
182 | 182 | ... | ... |
... | ... | @@ -34,7 +34,7 @@ public class MqttNoSqlTestSuite { |
34 | 34 | @ClassRule |
35 | 35 | public static CustomSqlUnit sqlUnit = new CustomSqlUnit( |
36 | 36 | Arrays.asList("sql/schema-entities-hsql.sql", "sql/system-data.sql"), |
37 | - "sql/drop-all-tables.sql", | |
37 | + "sql/hsql/drop-all-tables.sql", | |
38 | 38 | "nosql-test.properties"); |
39 | 39 | |
40 | 40 | @ClassRule | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.mqtt.rpc; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import io.netty.handler.codec.mqtt.MqttQoS; |
20 | 20 | import lombok.extern.slf4j.Slf4j; |
21 | 21 | import org.apache.commons.lang3.StringUtils; |
... | ... | @@ -143,7 +143,7 @@ public abstract class AbstractMqttServerSideRpcIntegrationTest extends AbstractC |
143 | 143 | @Test |
144 | 144 | public void testServerMqttOneWayRpcDeviceDoesNotExist() throws Exception { |
145 | 145 | String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"25\",\"value\": 1}}"; |
146 | - String nonExistentDeviceId = UUIDs.timeBased().toString(); | |
146 | + String nonExistentDeviceId = Uuids.timeBased().toString(); | |
147 | 147 | |
148 | 148 | String result = doPostAsync("/api/plugins/rpc/oneway/" + nonExistentDeviceId, setGpioRequest, String.class, |
149 | 149 | status().isNotFound()); |
... | ... | @@ -200,7 +200,7 @@ public abstract class AbstractMqttServerSideRpcIntegrationTest extends AbstractC |
200 | 200 | @Test |
201 | 201 | public void testServerMqttTwoWayRpcDeviceDoesNotExist() throws Exception { |
202 | 202 | String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"28\",\"value\": 1}}"; |
203 | - String nonExistentDeviceId = UUIDs.timeBased().toString(); | |
203 | + String nonExistentDeviceId = Uuids.timeBased().toString(); | |
204 | 204 | |
205 | 205 | String result = doPostAsync("/api/plugins/rpc/twoway/" + nonExistentDeviceId, setGpioRequest, String.class, |
206 | 206 | status().isNotFound()); | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.cluster.routing; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | 20 | import org.junit.Assert; |
21 | 21 | import org.junit.Before; |
... | ... | @@ -101,7 +101,7 @@ public class HashPartitionServiceTest { |
101 | 101 | public void testDispersionOnMillionDevices() { |
102 | 102 | List<DeviceId> devices = new ArrayList<>(); |
103 | 103 | for (int i = 0; i < ITERATIONS; i++) { |
104 | - devices.add(new DeviceId(UUIDs.timeBased())); | |
104 | + devices.add(new DeviceId(Uuids.timeBased())); | |
105 | 105 | } |
106 | 106 | testDevicesDispersion(devices); |
107 | 107 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.script; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.google.common.collect.Sets; |
20 | 20 | import org.junit.After; |
21 | 21 | import org.junit.Before; |
... | ... | @@ -41,7 +41,7 @@ public class RuleNodeJsScriptEngineTest { |
41 | 41 | private ScriptEngine scriptEngine; |
42 | 42 | private TestNashornJsInvokeService jsSandboxService; |
43 | 43 | |
44 | - private EntityId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); | |
44 | + private EntityId ruleNodeId = new RuleNodeId(Uuids.timeBased()); | |
45 | 45 | |
46 | 46 | @Before |
47 | 47 | public void beforeTest() throws Exception { |
... | ... | @@ -247,4 +247,4 @@ public class RuleNodeJsScriptEngineTest { |
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
250 | -} | |
\ No newline at end of file | ||
250 | +} | ... | ... |
... | ... | @@ -78,18 +78,13 @@ |
78 | 78 | <scope>provided</scope> |
79 | 79 | </dependency> |
80 | 80 | <dependency> |
81 | - <groupId>com.datastax.cassandra</groupId> | |
82 | - <artifactId>cassandra-driver-core</artifactId> | |
81 | + <groupId>com.datastax.oss</groupId> | |
82 | + <artifactId>java-driver-core</artifactId> | |
83 | 83 | <scope>provided</scope> |
84 | 84 | </dependency> |
85 | 85 | <dependency> |
86 | - <groupId>com.datastax.cassandra</groupId> | |
87 | - <artifactId>cassandra-driver-mapping</artifactId> | |
88 | - <scope>provided</scope> | |
89 | - </dependency> | |
90 | - <dependency> | |
91 | - <groupId>com.datastax.cassandra</groupId> | |
92 | - <artifactId>cassandra-driver-extras</artifactId> | |
86 | + <groupId>io.dropwizard.metrics</groupId> | |
87 | + <artifactId>metrics-jmx</artifactId> | |
93 | 88 | <scope>provided</scope> |
94 | 89 | </dependency> |
95 | 90 | <dependency> | ... | ... |
... | ... | @@ -16,117 +16,50 @@ |
16 | 16 | package org.thingsboard.server.dao.cassandra; |
17 | 17 | |
18 | 18 | |
19 | -import com.datastax.driver.core.Cluster; | |
20 | -import com.datastax.driver.core.ConsistencyLevel; | |
21 | -import com.datastax.driver.core.HostDistance; | |
22 | -import com.datastax.driver.core.PoolingOptions; | |
23 | -import com.datastax.driver.core.ProtocolOptions.Compression; | |
24 | -import com.datastax.driver.core.Session; | |
25 | -import com.datastax.driver.mapping.DefaultPropertyMapper; | |
26 | -import com.datastax.driver.mapping.Mapper; | |
27 | -import com.datastax.driver.mapping.MappingConfiguration; | |
28 | -import com.datastax.driver.mapping.MappingManager; | |
29 | -import com.datastax.driver.mapping.PropertyAccessStrategy; | |
19 | +import com.codahale.metrics.MetricRegistry; | |
20 | +import com.codahale.metrics.jmx.JmxReporter; | |
21 | +import com.datastax.oss.driver.api.core.ConsistencyLevel; | |
30 | 22 | import lombok.extern.slf4j.Slf4j; |
31 | -import org.apache.commons.lang3.StringUtils; | |
32 | 23 | import org.springframework.beans.factory.annotation.Autowired; |
33 | 24 | import org.springframework.beans.factory.annotation.Value; |
34 | 25 | import org.springframework.core.env.Environment; |
26 | +import org.thingsboard.server.dao.cassandra.guava.GuavaSession; | |
27 | +import org.thingsboard.server.dao.cassandra.guava.GuavaSessionBuilder; | |
28 | +import org.thingsboard.server.dao.cassandra.guava.GuavaSessionUtils; | |
35 | 29 | |
36 | 30 | import javax.annotation.PreDestroy; |
37 | -import java.net.InetSocketAddress; | |
38 | -import java.util.ArrayList; | |
39 | -import java.util.Collections; | |
40 | -import java.util.List; | |
41 | 31 | |
42 | 32 | @Slf4j |
43 | 33 | public abstract class AbstractCassandraCluster { |
44 | 34 | |
45 | - private static final String COMMA = ","; | |
46 | - private static final String COLON = ":"; | |
47 | - | |
48 | - @Value("${cassandra.cluster_name}") | |
49 | - private String clusterName; | |
50 | - @Value("${cassandra.url}") | |
51 | - private String url; | |
52 | - @Value("${cassandra.compression}") | |
53 | - private String compression; | |
54 | - @Value("${cassandra.ssl}") | |
55 | - private Boolean ssl; | |
56 | 35 | @Value("${cassandra.jmx}") |
57 | 36 | private Boolean jmx; |
58 | 37 | @Value("${cassandra.metrics}") |
59 | 38 | private Boolean metrics; |
60 | - @Value("${cassandra.credentials}") | |
61 | - private Boolean credentials; | |
62 | - @Value("${cassandra.username}") | |
63 | - private String username; | |
64 | - @Value("${cassandra.password}") | |
65 | - private String password; | |
66 | - @Value("${cassandra.init_timeout_ms}") | |
67 | - private long initTimeout; | |
68 | - @Value("${cassandra.init_retry_interval_ms}") | |
69 | - private long initRetryInterval; | |
70 | - @Value("${cassandra.max_requests_per_connection_local:32768}") | |
71 | - private int max_requests_local; | |
72 | - @Value("${cassandra.max_requests_per_connection_remote:32768}") | |
73 | - private int max_requests_remote; | |
74 | 39 | |
75 | 40 | @Autowired |
76 | - private CassandraSocketOptions socketOpts; | |
77 | - | |
78 | - @Autowired | |
79 | - private CassandraQueryOptions queryOpts; | |
41 | + private CassandraDriverOptions driverOptions; | |
80 | 42 | |
81 | 43 | @Autowired |
82 | 44 | private Environment environment; |
83 | 45 | |
84 | - private Cluster cluster; | |
85 | - private Cluster.Builder clusterBuilder; | |
46 | + private GuavaSessionBuilder sessionBuilder; | |
86 | 47 | |
87 | - private Session session; | |
48 | + private GuavaSession session; | |
88 | 49 | |
89 | - private MappingManager mappingManager; | |
90 | - | |
91 | - public <T> Mapper<T> getMapper(Class<T> clazz) { | |
92 | - return mappingManager.mapper(clazz); | |
93 | - } | |
50 | + private JmxReporter reporter; | |
94 | 51 | |
95 | 52 | private String keyspaceName; |
96 | 53 | |
97 | 54 | protected void init(String keyspaceName) { |
98 | 55 | this.keyspaceName = keyspaceName; |
99 | - this.clusterBuilder = Cluster.builder() | |
100 | - .addContactPointsWithPorts(getContactPoints(url)) | |
101 | - .withClusterName(clusterName) | |
102 | - .withSocketOptions(socketOpts.getOpts()) | |
103 | - .withPoolingOptions(new PoolingOptions() | |
104 | - .setMaxRequestsPerConnection(HostDistance.LOCAL, max_requests_local) | |
105 | - .setMaxRequestsPerConnection(HostDistance.REMOTE, max_requests_remote)); | |
106 | - this.clusterBuilder.withQueryOptions(queryOpts.getOpts()); | |
107 | - this.clusterBuilder.withCompression(StringUtils.isEmpty(compression) ? Compression.NONE : Compression.valueOf(compression.toUpperCase())); | |
108 | - if (ssl) { | |
109 | - this.clusterBuilder.withSSL(); | |
110 | - } | |
111 | - if (!jmx) { | |
112 | - this.clusterBuilder.withoutJMXReporting(); | |
113 | - } | |
114 | - if (!metrics) { | |
115 | - this.clusterBuilder.withoutMetrics(); | |
116 | - } | |
117 | - if (credentials) { | |
118 | - this.clusterBuilder.withCredentials(username, password); | |
119 | - } | |
56 | + this.sessionBuilder = GuavaSessionUtils.builder().withConfigLoader(this.driverOptions.getLoader()); | |
120 | 57 | if (!isInstall()) { |
121 | 58 | initSession(); |
122 | 59 | } |
123 | 60 | } |
124 | 61 | |
125 | - public Cluster getCluster() { | |
126 | - return cluster; | |
127 | - } | |
128 | - | |
129 | - public Session getSession() { | |
62 | + public GuavaSession getSession() { | |
130 | 63 | if (!isInstall()) { |
131 | 64 | return session; |
132 | 65 | } else { |
... | ... | @@ -146,64 +79,40 @@ public abstract class AbstractCassandraCluster { |
146 | 79 | } |
147 | 80 | |
148 | 81 | private void initSession() { |
149 | - long endTime = System.currentTimeMillis() + initTimeout; | |
150 | - while (System.currentTimeMillis() < endTime) { | |
151 | - try { | |
152 | - cluster = clusterBuilder.build(); | |
153 | - cluster.init(); | |
154 | - if (this.keyspaceName != null) { | |
155 | - session = cluster.connect(keyspaceName); | |
156 | - } else { | |
157 | - session = cluster.connect(); | |
158 | - } | |
159 | -// For Cassandra Driver version 3.5.0 | |
160 | - DefaultPropertyMapper propertyMapper = new DefaultPropertyMapper(); | |
161 | - propertyMapper.setPropertyAccessStrategy(PropertyAccessStrategy.FIELDS); | |
162 | - MappingConfiguration configuration = MappingConfiguration.builder().withPropertyMapper(propertyMapper).build(); | |
163 | - mappingManager = new MappingManager(session, configuration); | |
164 | -// For Cassandra Driver version 3.0.0 | |
165 | -// mappingManager = new MappingManager(session); | |
166 | - break; | |
167 | - } catch (Exception e) { | |
168 | - log.warn("Failed to initialize cassandra cluster due to {}. Will retry in {} ms", e.getMessage(), initRetryInterval); | |
169 | - try { | |
170 | - Thread.sleep(initRetryInterval); | |
171 | - } catch (InterruptedException ie) { | |
172 | - log.warn("Failed to wait until retry", ie); | |
173 | - Thread.currentThread().interrupt(); | |
174 | - } | |
175 | - } | |
82 | + if (this.keyspaceName != null) { | |
83 | + this.sessionBuilder.withKeyspace(this.keyspaceName); | |
84 | + } | |
85 | + this.sessionBuilder.withLocalDatacenter("datacenter1"); | |
86 | + session = sessionBuilder.build(); | |
87 | + if (this.metrics && this.jmx) { | |
88 | + MetricRegistry registry = | |
89 | + session.getMetrics().orElseThrow( | |
90 | + () -> new IllegalStateException("Metrics are disabled")) | |
91 | + .getRegistry(); | |
92 | + this.reporter = | |
93 | + JmxReporter.forRegistry(registry) | |
94 | + .inDomain("com.datastax.oss.driver") | |
95 | + .build(); | |
96 | + this.reporter.start(); | |
176 | 97 | } |
177 | 98 | } |
178 | 99 | |
179 | 100 | @PreDestroy |
180 | 101 | public void close() { |
181 | - if (cluster != null) { | |
182 | - cluster.close(); | |
102 | + if (reporter != null) { | |
103 | + reporter.stop(); | |
183 | 104 | } |
184 | - } | |
185 | - | |
186 | - private List<InetSocketAddress> getContactPoints(String url) { | |
187 | - List<InetSocketAddress> result; | |
188 | - if (StringUtils.isBlank(url)) { | |
189 | - result = Collections.emptyList(); | |
190 | - } else { | |
191 | - result = new ArrayList<>(); | |
192 | - for (String hostPort : url.split(COMMA)) { | |
193 | - String host = hostPort.split(COLON)[0]; | |
194 | - Integer port = Integer.valueOf(hostPort.split(COLON)[1]); | |
195 | - result.add(new InetSocketAddress(host, port)); | |
196 | - } | |
105 | + if (session != null) { | |
106 | + session.close(); | |
197 | 107 | } |
198 | - return result; | |
199 | 108 | } |
200 | 109 | |
201 | 110 | public ConsistencyLevel getDefaultReadConsistencyLevel() { |
202 | - return queryOpts.getDefaultReadConsistencyLevel(); | |
111 | + return driverOptions.getDefaultReadConsistencyLevel(); | |
203 | 112 | } |
204 | 113 | |
205 | 114 | public ConsistencyLevel getDefaultWriteConsistencyLevel() { |
206 | - return queryOpts.getDefaultWriteConsistencyLevel(); | |
115 | + return driverOptions.getDefaultWriteConsistencyLevel(); | |
207 | 116 | } |
208 | 117 | |
209 | 118 | } | ... | ... |
common/dao-api/src/main/java/org/thingsboard/server/dao/cassandra/CassandraDriverOptions.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2020 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.cassandra; | |
17 | + | |
18 | +import com.datastax.oss.driver.api.core.ConsistencyLevel; | |
19 | +import com.datastax.oss.driver.api.core.DefaultConsistencyLevel; | |
20 | +import com.datastax.oss.driver.api.core.config.DefaultDriverOption; | |
21 | +import com.datastax.oss.driver.api.core.config.DriverConfigLoader; | |
22 | +import com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder; | |
23 | +import com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric; | |
24 | +import com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric; | |
25 | +import lombok.Data; | |
26 | +import org.apache.commons.lang3.StringUtils; | |
27 | +import org.springframework.beans.factory.annotation.Value; | |
28 | +import org.springframework.context.annotation.Configuration; | |
29 | +import org.springframework.stereotype.Component; | |
30 | +import org.thingsboard.server.dao.util.NoSqlAnyDao; | |
31 | + | |
32 | +import javax.annotation.PostConstruct; | |
33 | +import java.time.Duration; | |
34 | +import java.util.ArrayList; | |
35 | +import java.util.Arrays; | |
36 | +import java.util.Collections; | |
37 | +import java.util.List; | |
38 | + | |
39 | +@Component | |
40 | +@Configuration | |
41 | +@Data | |
42 | +@NoSqlAnyDao | |
43 | +public class CassandraDriverOptions { | |
44 | + | |
45 | + private static final String COMMA = ","; | |
46 | + | |
47 | + @Value("${cassandra.cluster_name}") | |
48 | + private String clusterName; | |
49 | + @Value("${cassandra.url}") | |
50 | + private String url; | |
51 | + | |
52 | + @Value("${cassandra.socket.connect_timeout}") | |
53 | + private int connectTimeoutMillis; | |
54 | + @Value("${cassandra.socket.read_timeout}") | |
55 | + private int readTimeoutMillis; | |
56 | + @Value("${cassandra.socket.keep_alive}") | |
57 | + private Boolean keepAlive; | |
58 | + @Value("${cassandra.socket.reuse_address}") | |
59 | + private Boolean reuseAddress; | |
60 | + @Value("${cassandra.socket.so_linger}") | |
61 | + private Integer soLinger; | |
62 | + @Value("${cassandra.socket.tcp_no_delay}") | |
63 | + private Boolean tcpNoDelay; | |
64 | + @Value("${cassandra.socket.receive_buffer_size}") | |
65 | + private Integer receiveBufferSize; | |
66 | + @Value("${cassandra.socket.send_buffer_size}") | |
67 | + private Integer sendBufferSize; | |
68 | + | |
69 | + @Value("${cassandra.max_requests_per_connection_local:32768}") | |
70 | + private int max_requests_local; | |
71 | + @Value("${cassandra.max_requests_per_connection_remote:32768}") | |
72 | + private int max_requests_remote; | |
73 | + | |
74 | + @Value("${cassandra.query.default_fetch_size}") | |
75 | + private Integer defaultFetchSize; | |
76 | + @Value("${cassandra.query.read_consistency_level}") | |
77 | + private String readConsistencyLevel; | |
78 | + @Value("${cassandra.query.write_consistency_level}") | |
79 | + private String writeConsistencyLevel; | |
80 | + | |
81 | + @Value("${cassandra.compression}") | |
82 | + private String compression; | |
83 | + @Value("${cassandra.ssl}") | |
84 | + private Boolean ssl; | |
85 | + @Value("${cassandra.metrics}") | |
86 | + private Boolean metrics; | |
87 | + | |
88 | + @Value("${cassandra.credentials}") | |
89 | + private Boolean credentials; | |
90 | + @Value("${cassandra.username}") | |
91 | + private String username; | |
92 | + @Value("${cassandra.password}") | |
93 | + private String password; | |
94 | + | |
95 | + @Value("${cassandra.init_timeout_ms}") | |
96 | + private long initTimeout; | |
97 | + @Value("${cassandra.init_retry_interval_ms}") | |
98 | + private long initRetryInterval; | |
99 | + | |
100 | + private DriverConfigLoader loader; | |
101 | + | |
102 | + private ConsistencyLevel defaultReadConsistencyLevel; | |
103 | + private ConsistencyLevel defaultWriteConsistencyLevel; | |
104 | + | |
105 | + @PostConstruct | |
106 | + public void initLoader() { | |
107 | + ProgrammaticDriverConfigLoaderBuilder driverConfigBuilder = | |
108 | + DriverConfigLoader.programmaticBuilder(); | |
109 | + | |
110 | + driverConfigBuilder | |
111 | + .withStringList(DefaultDriverOption.CONTACT_POINTS, getContactPoints(url)) | |
112 | + .withString(DefaultDriverOption.SESSION_NAME, clusterName); | |
113 | + | |
114 | + this.initSocketOptions(driverConfigBuilder); | |
115 | + this.initPoolingOptions(driverConfigBuilder); | |
116 | + this.initQueryOptions(driverConfigBuilder); | |
117 | + | |
118 | + driverConfigBuilder.withString(DefaultDriverOption.PROTOCOL_COMPRESSION, | |
119 | + StringUtils.isEmpty(this.compression) ? "none" : this.compression.toLowerCase()); | |
120 | + | |
121 | + if (this.ssl) { | |
122 | + driverConfigBuilder.withString(DefaultDriverOption.SSL_ENGINE_FACTORY_CLASS, | |
123 | + "DefaultSslEngineFactory"); | |
124 | + } | |
125 | + | |
126 | + if (this.metrics) { | |
127 | + driverConfigBuilder.withStringList(DefaultDriverOption.METRICS_SESSION_ENABLED, | |
128 | + Arrays.asList(DefaultSessionMetric.CONNECTED_NODES.getPath(), | |
129 | + DefaultSessionMetric.CQL_REQUESTS.getPath())); | |
130 | + driverConfigBuilder.withStringList(DefaultDriverOption.METRICS_NODE_ENABLED, | |
131 | + Arrays.asList(DefaultNodeMetric.OPEN_CONNECTIONS.getPath(), | |
132 | + DefaultNodeMetric.IN_FLIGHT.getPath())); | |
133 | + } | |
134 | + | |
135 | + if (this.credentials) { | |
136 | + driverConfigBuilder.withString(DefaultDriverOption.AUTH_PROVIDER_CLASS, | |
137 | + "PlainTextAuthProvider"); | |
138 | + driverConfigBuilder.withString(DefaultDriverOption.AUTH_PROVIDER_USER_NAME, | |
139 | + this.username); | |
140 | + driverConfigBuilder.withString(DefaultDriverOption.AUTH_PROVIDER_PASSWORD, | |
141 | + this.password); | |
142 | + } | |
143 | + | |
144 | + driverConfigBuilder.withBoolean(DefaultDriverOption.RECONNECT_ON_INIT, | |
145 | + true); | |
146 | + driverConfigBuilder.withString(DefaultDriverOption.RECONNECTION_POLICY_CLASS, | |
147 | + "ExponentialReconnectionPolicy"); | |
148 | + driverConfigBuilder.withDuration(DefaultDriverOption.RECONNECTION_BASE_DELAY, | |
149 | + Duration.ofMillis(this.initRetryInterval)); | |
150 | + driverConfigBuilder.withDuration(DefaultDriverOption.RECONNECTION_MAX_DELAY, | |
151 | + Duration.ofMillis(this.initTimeout)); | |
152 | + | |
153 | + this.loader = driverConfigBuilder.build(); | |
154 | + } | |
155 | + | |
156 | + protected ConsistencyLevel getDefaultReadConsistencyLevel() { | |
157 | + if (defaultReadConsistencyLevel == null) { | |
158 | + if (readConsistencyLevel != null) { | |
159 | + defaultReadConsistencyLevel = DefaultConsistencyLevel.valueOf(readConsistencyLevel.toUpperCase()); | |
160 | + } else { | |
161 | + defaultReadConsistencyLevel = DefaultConsistencyLevel.ONE; | |
162 | + } | |
163 | + } | |
164 | + return defaultReadConsistencyLevel; | |
165 | + } | |
166 | + | |
167 | + protected ConsistencyLevel getDefaultWriteConsistencyLevel() { | |
168 | + if (defaultWriteConsistencyLevel == null) { | |
169 | + if (writeConsistencyLevel != null) { | |
170 | + defaultWriteConsistencyLevel = DefaultConsistencyLevel.valueOf(writeConsistencyLevel.toUpperCase()); | |
171 | + } else { | |
172 | + defaultWriteConsistencyLevel = DefaultConsistencyLevel.ONE; | |
173 | + } | |
174 | + } | |
175 | + return defaultWriteConsistencyLevel; | |
176 | + } | |
177 | + | |
178 | + private void initSocketOptions(ProgrammaticDriverConfigLoaderBuilder driverConfigBuilder) { | |
179 | + driverConfigBuilder.withDuration(DefaultDriverOption.CONNECTION_CONNECT_TIMEOUT, | |
180 | + Duration.ofMillis(this.connectTimeoutMillis)); | |
181 | + driverConfigBuilder.withDuration(DefaultDriverOption.REQUEST_TIMEOUT, | |
182 | + Duration.ofMillis(this.readTimeoutMillis)); | |
183 | + if (this.keepAlive != null) { | |
184 | + driverConfigBuilder.withBoolean(DefaultDriverOption.SOCKET_KEEP_ALIVE, | |
185 | + this.keepAlive); | |
186 | + } | |
187 | + if (this.reuseAddress != null) { | |
188 | + driverConfigBuilder.withBoolean(DefaultDriverOption.SOCKET_REUSE_ADDRESS, | |
189 | + this.reuseAddress); | |
190 | + } | |
191 | + if (this.soLinger != null) { | |
192 | + driverConfigBuilder.withInt(DefaultDriverOption.SOCKET_LINGER_INTERVAL, | |
193 | + this.soLinger); | |
194 | + } | |
195 | + if (this.tcpNoDelay != null) { | |
196 | + driverConfigBuilder.withBoolean(DefaultDriverOption.SOCKET_TCP_NODELAY, | |
197 | + this.tcpNoDelay); | |
198 | + } | |
199 | + if (this.receiveBufferSize != null) { | |
200 | + driverConfigBuilder.withInt(DefaultDriverOption.SOCKET_RECEIVE_BUFFER_SIZE, | |
201 | + this.receiveBufferSize); | |
202 | + } | |
203 | + if (this.sendBufferSize != null) { | |
204 | + driverConfigBuilder.withInt(DefaultDriverOption.SOCKET_SEND_BUFFER_SIZE, | |
205 | + this.sendBufferSize); | |
206 | + } | |
207 | + } | |
208 | + | |
209 | + private void initPoolingOptions(ProgrammaticDriverConfigLoaderBuilder driverConfigBuilder) { | |
210 | + driverConfigBuilder.withInt(DefaultDriverOption.CONNECTION_MAX_REQUESTS, | |
211 | + this.max_requests_local); | |
212 | + } | |
213 | + | |
214 | + private void initQueryOptions(ProgrammaticDriverConfigLoaderBuilder driverConfigBuilder) { | |
215 | + driverConfigBuilder.withInt(DefaultDriverOption.REQUEST_PAGE_SIZE, | |
216 | + this.defaultFetchSize); | |
217 | + } | |
218 | + | |
219 | + private List<String> getContactPoints(String url) { | |
220 | + List<String> result; | |
221 | + if (StringUtils.isBlank(url)) { | |
222 | + result = Collections.emptyList(); | |
223 | + } else { | |
224 | + result = new ArrayList<>(); | |
225 | + for (String hostPort : url.split(COMMA)) { | |
226 | + result.add(hostPort); | |
227 | + } | |
228 | + } | |
229 | + return result; | |
230 | + } | |
231 | + | |
232 | +} | ... | ... |
common/dao-api/src/main/java/org/thingsboard/server/dao/cassandra/CassandraQueryOptions.java
deleted
100644 → 0
1 | -/** | |
2 | - * Copyright © 2016-2020 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.cassandra; | |
17 | - | |
18 | -import com.datastax.driver.core.ConsistencyLevel; | |
19 | -import com.datastax.driver.core.QueryOptions; | |
20 | -import lombok.Data; | |
21 | -import org.springframework.beans.factory.annotation.Value; | |
22 | -import org.springframework.context.annotation.Configuration; | |
23 | -import org.springframework.stereotype.Component; | |
24 | -import org.thingsboard.server.dao.util.NoSqlAnyDao; | |
25 | - | |
26 | -import javax.annotation.PostConstruct; | |
27 | - | |
28 | -@Component | |
29 | -@Configuration | |
30 | -@Data | |
31 | -@NoSqlAnyDao | |
32 | -public class CassandraQueryOptions { | |
33 | - | |
34 | - @Value("${cassandra.query.default_fetch_size}") | |
35 | - private Integer defaultFetchSize; | |
36 | - @Value("${cassandra.query.read_consistency_level}") | |
37 | - private String readConsistencyLevel; | |
38 | - @Value("${cassandra.query.write_consistency_level}") | |
39 | - private String writeConsistencyLevel; | |
40 | - | |
41 | - private QueryOptions opts; | |
42 | - | |
43 | - private ConsistencyLevel defaultReadConsistencyLevel; | |
44 | - private ConsistencyLevel defaultWriteConsistencyLevel; | |
45 | - | |
46 | - @PostConstruct | |
47 | - public void initOpts(){ | |
48 | - opts = new QueryOptions(); | |
49 | - opts.setFetchSize(defaultFetchSize); | |
50 | - } | |
51 | - | |
52 | - protected ConsistencyLevel getDefaultReadConsistencyLevel() { | |
53 | - if (defaultReadConsistencyLevel == null) { | |
54 | - if (readConsistencyLevel != null) { | |
55 | - defaultReadConsistencyLevel = ConsistencyLevel.valueOf(readConsistencyLevel.toUpperCase()); | |
56 | - } else { | |
57 | - defaultReadConsistencyLevel = ConsistencyLevel.ONE; | |
58 | - } | |
59 | - } | |
60 | - return defaultReadConsistencyLevel; | |
61 | - } | |
62 | - | |
63 | - protected ConsistencyLevel getDefaultWriteConsistencyLevel() { | |
64 | - if (defaultWriteConsistencyLevel == null) { | |
65 | - if (writeConsistencyLevel != null) { | |
66 | - defaultWriteConsistencyLevel = ConsistencyLevel.valueOf(writeConsistencyLevel.toUpperCase()); | |
67 | - } else { | |
68 | - defaultWriteConsistencyLevel = ConsistencyLevel.ONE; | |
69 | - } | |
70 | - } | |
71 | - return defaultWriteConsistencyLevel; | |
72 | - } | |
73 | -} |
common/dao-api/src/main/java/org/thingsboard/server/dao/cassandra/CassandraSocketOptions.java
deleted
100644 → 0
1 | -/** | |
2 | - * Copyright © 2016-2020 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.cassandra; | |
17 | - | |
18 | -import com.datastax.driver.core.SocketOptions; | |
19 | -import lombok.Data; | |
20 | -import org.springframework.beans.factory.annotation.Value; | |
21 | -import org.springframework.context.annotation.Configuration; | |
22 | -import org.springframework.stereotype.Component; | |
23 | -import org.thingsboard.server.dao.util.NoSqlAnyDao; | |
24 | - | |
25 | -import javax.annotation.PostConstruct; | |
26 | - | |
27 | -@Component | |
28 | -@Configuration | |
29 | -@Data | |
30 | -@NoSqlAnyDao | |
31 | -public class CassandraSocketOptions { | |
32 | - | |
33 | - @Value("${cassandra.socket.connect_timeout}") | |
34 | - private int connectTimeoutMillis; | |
35 | - @Value("${cassandra.socket.read_timeout}") | |
36 | - private int readTimeoutMillis; | |
37 | - @Value("${cassandra.socket.keep_alive}") | |
38 | - private Boolean keepAlive; | |
39 | - @Value("${cassandra.socket.reuse_address}") | |
40 | - private Boolean reuseAddress; | |
41 | - @Value("${cassandra.socket.so_linger}") | |
42 | - private Integer soLinger; | |
43 | - @Value("${cassandra.socket.tcp_no_delay}") | |
44 | - private Boolean tcpNoDelay; | |
45 | - @Value("${cassandra.socket.receive_buffer_size}") | |
46 | - private Integer receiveBufferSize; | |
47 | - @Value("${cassandra.socket.send_buffer_size}") | |
48 | - private Integer sendBufferSize; | |
49 | - | |
50 | - private SocketOptions opts; | |
51 | - | |
52 | - @PostConstruct | |
53 | - public void initOpts() { | |
54 | - opts = new SocketOptions(); | |
55 | - opts.setConnectTimeoutMillis(connectTimeoutMillis); | |
56 | - opts.setReadTimeoutMillis(readTimeoutMillis); | |
57 | - if (keepAlive != null) { | |
58 | - opts.setKeepAlive(keepAlive); | |
59 | - } | |
60 | - if (reuseAddress != null) { | |
61 | - opts.setReuseAddress(reuseAddress); | |
62 | - } | |
63 | - if (soLinger != null) { | |
64 | - opts.setSoLinger(soLinger); | |
65 | - } | |
66 | - if (tcpNoDelay != null) { | |
67 | - opts.setTcpNoDelay(tcpNoDelay); | |
68 | - } | |
69 | - if (receiveBufferSize != null) { | |
70 | - opts.setReceiveBufferSize(receiveBufferSize); | |
71 | - } | |
72 | - if (sendBufferSize != null) { | |
73 | - opts.setSendBufferSize(sendBufferSize); | |
74 | - } | |
75 | - } | |
76 | -} |
common/dao-api/src/main/java/org/thingsboard/server/dao/cassandra/guava/DefaultGuavaSession.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/type/JsonCodec.java
... | ... | @@ -13,15 +13,14 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.model.type; | |
16 | +package org.thingsboard.server.dao.cassandra.guava; | |
17 | 17 | |
18 | -import com.datastax.driver.extras.codecs.json.JacksonJsonCodec; | |
19 | -import com.fasterxml.jackson.databind.JsonNode; | |
18 | +import com.datastax.oss.driver.api.core.session.Session; | |
19 | +import com.datastax.oss.driver.internal.core.session.SessionWrapper; | |
20 | 20 | |
21 | -public class JsonCodec extends JacksonJsonCodec<JsonNode> { | |
21 | +public class DefaultGuavaSession extends SessionWrapper implements GuavaSession { | |
22 | 22 | |
23 | - public JsonCodec() { | |
24 | - super(JsonNode.class); | |
23 | + public DefaultGuavaSession(Session delegate) { | |
24 | + super(delegate); | |
25 | 25 | } |
26 | - | |
27 | 26 | } | ... | ... |
common/dao-api/src/main/java/org/thingsboard/server/dao/cassandra/guava/GuavaDriverContext.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2020 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.cassandra.guava; | |
17 | + | |
18 | +import com.datastax.oss.driver.api.core.config.DriverConfigLoader; | |
19 | +import com.datastax.oss.driver.api.core.cql.PrepareRequest; | |
20 | +import com.datastax.oss.driver.api.core.cql.Statement; | |
21 | +import com.datastax.oss.driver.api.core.metadata.Node; | |
22 | +import com.datastax.oss.driver.api.core.metadata.NodeStateListener; | |
23 | +import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener; | |
24 | +import com.datastax.oss.driver.api.core.session.ProgrammaticArguments; | |
25 | +import com.datastax.oss.driver.api.core.tracker.RequestTracker; | |
26 | +import com.datastax.oss.driver.api.core.type.codec.TypeCodec; | |
27 | +import com.datastax.oss.driver.internal.core.context.DefaultDriverContext; | |
28 | +import com.datastax.oss.driver.internal.core.cql.CqlPrepareAsyncProcessor; | |
29 | +import com.datastax.oss.driver.internal.core.cql.CqlPrepareSyncProcessor; | |
30 | +import com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor; | |
31 | +import com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor; | |
32 | +import com.datastax.oss.driver.internal.core.session.RequestProcessorRegistry; | |
33 | +import java.util.List; | |
34 | +import java.util.Map; | |
35 | +import java.util.function.Predicate; | |
36 | + | |
37 | +/** | |
38 | + * A Custom {@link DefaultDriverContext} that overrides {@link #getRequestProcessorRegistry()} to | |
39 | + * return a {@link RequestProcessorRegistry} that includes processors for returning guava futures. | |
40 | + */ | |
41 | +public class GuavaDriverContext extends DefaultDriverContext { | |
42 | + | |
43 | + public GuavaDriverContext( | |
44 | + DriverConfigLoader configLoader, | |
45 | + List<TypeCodec<?>> typeCodecs, | |
46 | + NodeStateListener nodeStateListener, | |
47 | + SchemaChangeListener schemaChangeListener, | |
48 | + RequestTracker requestTracker, | |
49 | + Map<String, String> localDatacenters, | |
50 | + Map<String, Predicate<Node>> nodeFilters, | |
51 | + ClassLoader classLoader) { | |
52 | + super( | |
53 | + configLoader, | |
54 | + ProgrammaticArguments.builder() | |
55 | + .addTypeCodecs(typeCodecs.toArray(new TypeCodec<?>[0])) | |
56 | + .withNodeStateListener(nodeStateListener) | |
57 | + .withSchemaChangeListener(schemaChangeListener) | |
58 | + .withRequestTracker(requestTracker) | |
59 | + .withLocalDatacenters(localDatacenters) | |
60 | + .withNodeFilters(nodeFilters) | |
61 | + .withClassLoader(classLoader) | |
62 | + .build()); | |
63 | + } | |
64 | + | |
65 | + @Override | |
66 | + public RequestProcessorRegistry buildRequestProcessorRegistry() { | |
67 | + // Register the typical request processors, except instead of the normal async processors, | |
68 | + // use GuavaRequestAsyncProcessor to return ListenableFutures in async methods. | |
69 | + | |
70 | + CqlRequestAsyncProcessor cqlRequestAsyncProcessor = new CqlRequestAsyncProcessor(); | |
71 | + CqlPrepareAsyncProcessor cqlPrepareAsyncProcessor = new CqlPrepareAsyncProcessor(); | |
72 | + CqlRequestSyncProcessor cqlRequestSyncProcessor = | |
73 | + new CqlRequestSyncProcessor(cqlRequestAsyncProcessor); | |
74 | + | |
75 | + return new RequestProcessorRegistry( | |
76 | + getSessionName(), | |
77 | + cqlRequestSyncProcessor, | |
78 | + new CqlPrepareSyncProcessor(cqlPrepareAsyncProcessor), | |
79 | + new GuavaRequestAsyncProcessor<>( | |
80 | + cqlRequestAsyncProcessor, Statement.class, GuavaSession.ASYNC), | |
81 | + new GuavaRequestAsyncProcessor<>( | |
82 | + cqlPrepareAsyncProcessor, PrepareRequest.class, GuavaSession.ASYNC_PREPARED)); | |
83 | + } | |
84 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2020 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.cassandra.guava; | |
17 | + | |
18 | +import com.datastax.oss.driver.api.core.session.Request; | |
19 | +import com.datastax.oss.driver.api.core.type.reflect.GenericType; | |
20 | +import com.datastax.oss.driver.internal.core.context.InternalDriverContext; | |
21 | +import com.datastax.oss.driver.internal.core.session.DefaultSession; | |
22 | +import com.datastax.oss.driver.internal.core.session.RequestProcessor; | |
23 | +import com.google.common.util.concurrent.Futures; | |
24 | +import com.google.common.util.concurrent.ListenableFuture; | |
25 | +import com.google.common.util.concurrent.SettableFuture; | |
26 | +import java.util.concurrent.CompletionStage; | |
27 | + | |
28 | +/** | |
29 | + * Wraps a {@link RequestProcessor} that returns {@link CompletionStage}s and converts them to a | |
30 | + * {@link ListenableFuture}s. | |
31 | + * | |
32 | + * @param <T> The type of request | |
33 | + * @param <U> The type of responses enclosed in the future response. | |
34 | + */ | |
35 | +public class GuavaRequestAsyncProcessor<T extends Request, U> | |
36 | + implements RequestProcessor<T, ListenableFuture<U>> { | |
37 | + | |
38 | + private final RequestProcessor<T, CompletionStage<U>> subProcessor; | |
39 | + | |
40 | + private final GenericType resultType; | |
41 | + | |
42 | + private final Class<?> requestClass; | |
43 | + | |
44 | + GuavaRequestAsyncProcessor( | |
45 | + RequestProcessor<T, CompletionStage<U>> subProcessor, | |
46 | + Class<?> requestClass, | |
47 | + GenericType resultType) { | |
48 | + this.subProcessor = subProcessor; | |
49 | + this.requestClass = requestClass; | |
50 | + this.resultType = resultType; | |
51 | + } | |
52 | + | |
53 | + @Override | |
54 | + public boolean canProcess(Request request, GenericType resultType) { | |
55 | + return requestClass.isInstance(request) && resultType.equals(this.resultType); | |
56 | + } | |
57 | + | |
58 | + @Override | |
59 | + public ListenableFuture<U> process( | |
60 | + T request, DefaultSession session, InternalDriverContext context, String sessionLogPrefix) { | |
61 | + SettableFuture<U> future = SettableFuture.create(); | |
62 | + subProcessor | |
63 | + .process(request, session, context, sessionLogPrefix) | |
64 | + .whenComplete( | |
65 | + (r, ex) -> { | |
66 | + if (ex != null) { | |
67 | + future.setException(ex); | |
68 | + } else { | |
69 | + future.set(r); | |
70 | + } | |
71 | + }); | |
72 | + return future; | |
73 | + } | |
74 | + | |
75 | + @Override | |
76 | + public ListenableFuture<U> newFailure(RuntimeException error) { | |
77 | + return Futures.immediateFailedFuture(error); | |
78 | + } | |
79 | +} | ... | ... |
common/dao-api/src/main/java/org/thingsboard/server/dao/cassandra/guava/GuavaSession.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/type/ComponentLifecycleStateCodec.java
... | ... | @@ -13,15 +13,39 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.model.type; | |
16 | +package org.thingsboard.server.dao.cassandra.guava; | |
17 | 17 | |
18 | -import com.datastax.driver.extras.codecs.enums.EnumNameCodec; | |
19 | -import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | |
18 | +import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | |
19 | +import com.datastax.oss.driver.api.core.cql.PreparedStatement; | |
20 | +import com.datastax.oss.driver.api.core.cql.SimpleStatement; | |
21 | +import com.datastax.oss.driver.api.core.cql.Statement; | |
22 | +import com.datastax.oss.driver.api.core.cql.SyncCqlSession; | |
23 | +import com.datastax.oss.driver.api.core.session.Session; | |
24 | +import com.datastax.oss.driver.api.core.type.reflect.GenericType; | |
25 | +import com.datastax.oss.driver.internal.core.cql.DefaultPrepareRequest; | |
26 | +import com.google.common.util.concurrent.ListenableFuture; | |
20 | 27 | |
21 | -public class ComponentLifecycleStateCodec extends EnumNameCodec<ComponentLifecycleState> { | |
28 | +public interface GuavaSession extends Session, SyncCqlSession { | |
22 | 29 | |
23 | - public ComponentLifecycleStateCodec() { | |
24 | - super(ComponentLifecycleState.class); | |
30 | + GenericType<ListenableFuture<AsyncResultSet>> ASYNC = | |
31 | + new GenericType<ListenableFuture<AsyncResultSet>>() {}; | |
32 | + | |
33 | + GenericType<ListenableFuture<PreparedStatement>> ASYNC_PREPARED = | |
34 | + new GenericType<ListenableFuture<PreparedStatement>>() {}; | |
35 | + | |
36 | + default ListenableFuture<AsyncResultSet> executeAsync(Statement<?> statement) { | |
37 | + return this.execute(statement, ASYNC); | |
38 | + } | |
39 | + | |
40 | + default ListenableFuture<AsyncResultSet> executeAsync(String statement) { | |
41 | + return this.executeAsync(SimpleStatement.newInstance(statement)); | |
25 | 42 | } |
26 | 43 | |
44 | + default ListenableFuture<PreparedStatement> prepareAsync(SimpleStatement statement) { | |
45 | + return this.execute(new DefaultPrepareRequest(statement), ASYNC_PREPARED); | |
46 | + } | |
47 | + | |
48 | + default ListenableFuture<PreparedStatement> prepareAsync(String statement) { | |
49 | + return this.prepareAsync(SimpleStatement.newInstance(statement)); | |
50 | + } | |
27 | 51 | } | ... | ... |
common/dao-api/src/main/java/org/thingsboard/server/dao/cassandra/guava/GuavaSessionBuilder.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2020 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.cassandra.guava; | |
17 | + | |
18 | +import com.datastax.oss.driver.api.core.CqlSession; | |
19 | +import com.datastax.oss.driver.api.core.config.DriverConfigLoader; | |
20 | +import com.datastax.oss.driver.api.core.context.DriverContext; | |
21 | +import com.datastax.oss.driver.api.core.metadata.Node; | |
22 | +import com.datastax.oss.driver.api.core.metadata.NodeStateListener; | |
23 | +import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener; | |
24 | +import com.datastax.oss.driver.api.core.session.SessionBuilder; | |
25 | +import com.datastax.oss.driver.api.core.tracker.RequestTracker; | |
26 | +import com.datastax.oss.driver.api.core.type.codec.TypeCodec; | |
27 | +import edu.umd.cs.findbugs.annotations.NonNull; | |
28 | +import java.util.List; | |
29 | +import java.util.Map; | |
30 | +import java.util.function.Predicate; | |
31 | + | |
32 | +public class GuavaSessionBuilder extends SessionBuilder<GuavaSessionBuilder, GuavaSession> { | |
33 | + | |
34 | + @Override | |
35 | + protected DriverContext buildContext( | |
36 | + DriverConfigLoader configLoader, | |
37 | + List<TypeCodec<?>> typeCodecs, | |
38 | + NodeStateListener nodeStateListener, | |
39 | + SchemaChangeListener schemaChangeListener, | |
40 | + RequestTracker requestTracker, | |
41 | + Map<String, String> localDatacenters, | |
42 | + Map<String, Predicate<Node>> nodeFilters, | |
43 | + ClassLoader classLoader) { | |
44 | + return new GuavaDriverContext( | |
45 | + configLoader, | |
46 | + typeCodecs, | |
47 | + nodeStateListener, | |
48 | + schemaChangeListener, | |
49 | + requestTracker, | |
50 | + localDatacenters, | |
51 | + nodeFilters, | |
52 | + classLoader); | |
53 | + } | |
54 | + | |
55 | + @Override | |
56 | + protected GuavaSession wrap(@NonNull CqlSession defaultSession) { | |
57 | + return new DefaultGuavaSession(defaultSession); | |
58 | + } | |
59 | +} | ... | ... |
common/dao-api/src/main/java/org/thingsboard/server/dao/cassandra/guava/GuavaSessionUtils.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/type/EntityTypeCodec.java
... | ... | @@ -13,15 +13,10 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.model.type; | |
16 | +package org.thingsboard.server.dao.cassandra.guava; | |
17 | 17 | |
18 | -import com.datastax.driver.extras.codecs.enums.EnumNameCodec; | |
19 | -import org.thingsboard.server.common.data.EntityType; | |
20 | - | |
21 | -public class EntityTypeCodec extends EnumNameCodec<EntityType> { | |
22 | - | |
23 | - public EntityTypeCodec() { | |
24 | - super(EntityType.class); | |
18 | +public class GuavaSessionUtils { | |
19 | + public static GuavaSessionBuilder builder() { | |
20 | + return new GuavaSessionBuilder(); | |
25 | 21 | } |
26 | - | |
27 | 22 | } | ... | ... |
... | ... | @@ -15,12 +15,17 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.nosql; |
17 | 17 | |
18 | -import com.datastax.driver.core.Session; | |
19 | -import com.datastax.driver.core.Statement; | |
18 | +import com.datastax.oss.driver.api.core.cql.Statement; | |
19 | +import com.google.common.util.concurrent.Futures; | |
20 | +import com.google.common.util.concurrent.ListenableFuture; | |
21 | +import com.google.common.util.concurrent.MoreExecutors; | |
20 | 22 | import lombok.Data; |
21 | 23 | import org.thingsboard.server.common.data.id.TenantId; |
24 | +import org.thingsboard.server.dao.cassandra.guava.GuavaSession; | |
22 | 25 | import org.thingsboard.server.dao.util.AsyncTask; |
23 | 26 | |
27 | +import java.util.function.Function; | |
28 | + | |
24 | 29 | /** |
25 | 30 | * Created by ashvayka on 24.10.18. |
26 | 31 | */ |
... | ... | @@ -28,7 +33,14 @@ import org.thingsboard.server.dao.util.AsyncTask; |
28 | 33 | public class CassandraStatementTask implements AsyncTask { |
29 | 34 | |
30 | 35 | private final TenantId tenantId; |
31 | - private final Session session; | |
36 | + private final GuavaSession session; | |
32 | 37 | private final Statement statement; |
33 | 38 | |
39 | + public ListenableFuture<TbResultSet> executeAsync(Function<Statement, TbResultSetFuture> executeAsyncFunction) { | |
40 | + return Futures.transform(session.executeAsync(statement), | |
41 | + result -> new TbResultSet(statement, result, executeAsyncFunction), | |
42 | + MoreExecutors.directExecutor() | |
43 | + ); | |
44 | + } | |
45 | + | |
34 | 46 | } | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2020 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.nosql; | |
17 | + | |
18 | +import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | |
19 | +import com.datastax.oss.driver.api.core.cql.ColumnDefinitions; | |
20 | +import com.datastax.oss.driver.api.core.cql.ExecutionInfo; | |
21 | +import com.datastax.oss.driver.api.core.cql.Row; | |
22 | +import com.datastax.oss.driver.api.core.cql.Statement; | |
23 | +import com.google.common.collect.Lists; | |
24 | +import com.google.common.util.concurrent.FutureCallback; | |
25 | +import com.google.common.util.concurrent.Futures; | |
26 | +import com.google.common.util.concurrent.ListenableFuture; | |
27 | +import com.google.common.util.concurrent.MoreExecutors; | |
28 | +import com.google.common.util.concurrent.SettableFuture; | |
29 | +import edu.umd.cs.findbugs.annotations.NonNull; | |
30 | +import org.checkerframework.checker.nullness.qual.Nullable; | |
31 | + | |
32 | +import java.nio.ByteBuffer; | |
33 | +import java.util.ArrayList; | |
34 | +import java.util.List; | |
35 | +import java.util.concurrent.CompletionStage; | |
36 | +import java.util.concurrent.Executor; | |
37 | +import java.util.function.Function; | |
38 | + | |
39 | +public class TbResultSet implements AsyncResultSet { | |
40 | + | |
41 | + private final Statement originalStatement; | |
42 | + private final AsyncResultSet delegate; | |
43 | + private final Function<Statement, TbResultSetFuture> executeAsyncFunction; | |
44 | + | |
45 | + public TbResultSet(Statement originalStatement, AsyncResultSet delegate, | |
46 | + Function<Statement, TbResultSetFuture> executeAsyncFunction) { | |
47 | + this.originalStatement = originalStatement; | |
48 | + this.delegate = delegate; | |
49 | + this.executeAsyncFunction = executeAsyncFunction; | |
50 | + } | |
51 | + | |
52 | + @NonNull | |
53 | + @Override | |
54 | + public ColumnDefinitions getColumnDefinitions() { | |
55 | + return delegate.getColumnDefinitions(); | |
56 | + } | |
57 | + | |
58 | + @NonNull | |
59 | + @Override | |
60 | + public ExecutionInfo getExecutionInfo() { | |
61 | + return delegate.getExecutionInfo(); | |
62 | + } | |
63 | + | |
64 | + @Override | |
65 | + public int remaining() { | |
66 | + return delegate.remaining(); | |
67 | + } | |
68 | + | |
69 | + @NonNull | |
70 | + @Override | |
71 | + public Iterable<Row> currentPage() { | |
72 | + return delegate.currentPage(); | |
73 | + } | |
74 | + | |
75 | + @Override | |
76 | + public boolean hasMorePages() { | |
77 | + return delegate.hasMorePages(); | |
78 | + } | |
79 | + | |
80 | + @NonNull | |
81 | + @Override | |
82 | + public CompletionStage<AsyncResultSet> fetchNextPage() throws IllegalStateException { | |
83 | + return delegate.fetchNextPage(); | |
84 | + } | |
85 | + | |
86 | + @Override | |
87 | + public boolean wasApplied() { | |
88 | + return delegate.wasApplied(); | |
89 | + } | |
90 | + | |
91 | + public ListenableFuture<List<Row>> allRows(Executor executor) { | |
92 | + List<Row> allRows = new ArrayList<>(); | |
93 | + SettableFuture<List<Row>> resultFuture = SettableFuture.create(); | |
94 | + this.processRows(originalStatement, delegate, allRows, resultFuture, executor); | |
95 | + return resultFuture; | |
96 | + } | |
97 | + | |
98 | + private void processRows(Statement statement, | |
99 | + AsyncResultSet resultSet, | |
100 | + List<Row> allRows, | |
101 | + SettableFuture<List<Row>> resultFuture, | |
102 | + Executor executor) { | |
103 | + allRows.addAll(loadRows(resultSet)); | |
104 | + if (resultSet.hasMorePages()) { | |
105 | + ByteBuffer nextPagingState = resultSet.getExecutionInfo().getPagingState(); | |
106 | + Statement<?> nextStatement = statement.setPagingState(nextPagingState); | |
107 | + TbResultSetFuture resultSetFuture = executeAsyncFunction.apply(nextStatement); | |
108 | + Futures.addCallback(resultSetFuture, | |
109 | + new FutureCallback<TbResultSet>() { | |
110 | + @Override | |
111 | + public void onSuccess(@Nullable TbResultSet result) { | |
112 | + processRows(nextStatement, result, | |
113 | + allRows, resultFuture, executor); | |
114 | + } | |
115 | + | |
116 | + @Override | |
117 | + public void onFailure(Throwable t) { | |
118 | + resultFuture.setException(t); | |
119 | + } | |
120 | + }, executor != null ? executor : MoreExecutors.directExecutor() | |
121 | + ); | |
122 | + } else { | |
123 | + resultFuture.set(allRows); | |
124 | + } | |
125 | + } | |
126 | + | |
127 | + List<Row> loadRows(AsyncResultSet resultSet) { | |
128 | + return Lists.newArrayList(resultSet.currentPage()); | |
129 | + } | |
130 | + | |
131 | +} | ... | ... |
common/dao-api/src/main/java/org/thingsboard/server/dao/nosql/TbResultSetFuture.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/nosql/TbResultSetFuture.java
... | ... | @@ -15,8 +15,8 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.nosql; |
17 | 17 | |
18 | -import com.datastax.driver.core.ResultSet; | |
19 | -import com.datastax.driver.core.ResultSetFuture; | |
18 | +import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | |
19 | +import com.google.common.util.concurrent.ListenableFuture; | |
20 | 20 | import com.google.common.util.concurrent.SettableFuture; |
21 | 21 | |
22 | 22 | import java.util.concurrent.ExecutionException; |
... | ... | @@ -27,21 +27,19 @@ import java.util.concurrent.TimeoutException; |
27 | 27 | /** |
28 | 28 | * Created by ashvayka on 24.10.18. |
29 | 29 | */ |
30 | -public class TbResultSetFuture implements ResultSetFuture { | |
30 | +public class TbResultSetFuture implements ListenableFuture<TbResultSet> { | |
31 | 31 | |
32 | - private final SettableFuture<ResultSet> mainFuture; | |
32 | + private final SettableFuture<TbResultSet> mainFuture; | |
33 | 33 | |
34 | - public TbResultSetFuture(SettableFuture<ResultSet> mainFuture) { | |
34 | + public TbResultSetFuture(SettableFuture<TbResultSet> mainFuture) { | |
35 | 35 | this.mainFuture = mainFuture; |
36 | 36 | } |
37 | 37 | |
38 | - @Override | |
39 | - public ResultSet getUninterruptibly() { | |
38 | + public TbResultSet getUninterruptibly() { | |
40 | 39 | return getSafe(); |
41 | 40 | } |
42 | 41 | |
43 | - @Override | |
44 | - public ResultSet getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException { | |
42 | + public TbResultSet getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException { | |
45 | 43 | return getSafe(timeout, unit); |
46 | 44 | } |
47 | 45 | |
... | ... | @@ -61,12 +59,12 @@ public class TbResultSetFuture implements ResultSetFuture { |
61 | 59 | } |
62 | 60 | |
63 | 61 | @Override |
64 | - public ResultSet get() throws InterruptedException, ExecutionException { | |
62 | + public TbResultSet get() throws InterruptedException, ExecutionException { | |
65 | 63 | return mainFuture.get(); |
66 | 64 | } |
67 | 65 | |
68 | 66 | @Override |
69 | - public ResultSet get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { | |
67 | + public TbResultSet get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { | |
70 | 68 | return mainFuture.get(timeout, unit); |
71 | 69 | } |
72 | 70 | |
... | ... | @@ -75,7 +73,7 @@ public class TbResultSetFuture implements ResultSetFuture { |
75 | 73 | mainFuture.addListener(listener, executor); |
76 | 74 | } |
77 | 75 | |
78 | - private ResultSet getSafe() { | |
76 | + private TbResultSet getSafe() { | |
79 | 77 | try { |
80 | 78 | return mainFuture.get(); |
81 | 79 | } catch (InterruptedException | ExecutionException e) { |
... | ... | @@ -83,7 +81,7 @@ public class TbResultSetFuture implements ResultSetFuture { |
83 | 81 | } |
84 | 82 | } |
85 | 83 | |
86 | - private ResultSet getSafe(long timeout, TimeUnit unit) throws TimeoutException { | |
84 | + private TbResultSet getSafe(long timeout, TimeUnit unit) throws TimeoutException { | |
87 | 85 | try { |
88 | 86 | return mainFuture.get(timeout, unit); |
89 | 87 | } catch (InterruptedException | ExecutionException e) { | ... | ... |
... | ... | @@ -67,8 +67,8 @@ |
67 | 67 | <scope>test</scope> |
68 | 68 | </dependency> |
69 | 69 | <dependency> |
70 | - <groupId>com.datastax.cassandra</groupId> | |
71 | - <artifactId>cassandra-driver-core</artifactId> | |
70 | + <groupId>com.datastax.oss</groupId> | |
71 | + <artifactId>java-driver-core</artifactId> | |
72 | 72 | <scope>test</scope> |
73 | 73 | </dependency> |
74 | 74 | </dependencies> | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.junit.Assert; |
20 | 20 | import org.junit.Test; |
21 | 21 | import org.junit.runner.RunWith; |
... | ... | @@ -61,8 +61,8 @@ public class UUIDConverterTest { |
61 | 61 | before = tmp; |
62 | 62 | } |
63 | 63 | |
64 | - String beforeStr = UUIDConverter.fromTimeUUID(UUIDs.startOf(before)); | |
65 | - String afterStr = UUIDConverter.fromTimeUUID(UUIDs.startOf(after)); | |
64 | + String beforeStr = UUIDConverter.fromTimeUUID(Uuids.startOf(before)); | |
65 | + String afterStr = UUIDConverter.fromTimeUUID(Uuids.startOf(after)); | |
66 | 66 | |
67 | 67 | if (afterStr.compareTo(beforeStr) < 0) { |
68 | 68 | System.out.println("Before: " + before + " | " + beforeStr); | ... | ... |
... | ... | @@ -54,6 +54,9 @@ public class TbKafkaConsumerTemplate<T extends TbQueueMsg> extends AbstractTbQue |
54 | 54 | if (groupId != null) { |
55 | 55 | props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId); |
56 | 56 | } |
57 | + props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, settings.getMaxPollRecords()); | |
58 | + props.put(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, settings.getMaxPartitionFetchBytes()); | |
59 | + props.put(ConsumerConfig.FETCH_MAX_BYTES_CONFIG, settings.getFetchMaxBytes()); | |
57 | 60 | props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, autoCommit); |
58 | 61 | props.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, autoCommitIntervalMs); |
59 | 62 | props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer"); | ... | ... |
... | ... | @@ -55,6 +55,18 @@ public class TbKafkaSettings { |
55 | 55 | @Getter |
56 | 56 | private short replicationFactor; |
57 | 57 | |
58 | + @Value("${queue.kafka.max_poll_records:8192}") | |
59 | + @Getter | |
60 | + private int maxPollRecords; | |
61 | + | |
62 | + @Value("${queue.kafka.max_partition_fetch_bytes:16777216}") | |
63 | + @Getter | |
64 | + private int maxPartitionFetchBytes; | |
65 | + | |
66 | + @Value("${queue.kafka.fetch_max_bytes:134217728}") | |
67 | + @Getter | |
68 | + private int fetchMaxBytes; | |
69 | + | |
58 | 70 | @Value("${kafka.other:#{null}}") |
59 | 71 | private List<TbKafkaProperty> other; |
60 | 72 | ... | ... |
... | ... | @@ -391,6 +391,7 @@ public class JsonConverter { |
391 | 391 | break; |
392 | 392 | case JSON_V: |
393 | 393 | result.add(de.getKv().getKey(), JSON_PARSER.parse(de.getKv().getJsonV())); |
394 | + break; | |
394 | 395 | default: |
395 | 396 | throw new IllegalArgumentException("Unsupported data type: " + de.getKv().getType()); |
396 | 397 | } | ... | ... |
... | ... | @@ -120,18 +120,18 @@ |
120 | 120 | <groupId>org.springframework.security</groupId> |
121 | 121 | <artifactId>spring-security-oauth2-client</artifactId> |
122 | 122 | </dependency> |
123 | - <dependency> | |
124 | - <groupId>com.datastax.cassandra</groupId> | |
125 | - <artifactId>cassandra-driver-core</artifactId> | |
126 | - </dependency> | |
127 | - <dependency> | |
128 | - <groupId>com.datastax.cassandra</groupId> | |
129 | - <artifactId>cassandra-driver-mapping</artifactId> | |
130 | - </dependency> | |
131 | - <dependency> | |
132 | - <groupId>com.datastax.cassandra</groupId> | |
133 | - <artifactId>cassandra-driver-extras</artifactId> | |
134 | - </dependency> | |
123 | + <dependency> | |
124 | + <groupId>com.datastax.oss</groupId> | |
125 | + <artifactId>java-driver-core</artifactId> | |
126 | + </dependency> | |
127 | + <dependency> | |
128 | + <groupId>com.datastax.oss</groupId> | |
129 | + <artifactId>java-driver-query-builder</artifactId> | |
130 | + </dependency> | |
131 | + <dependency> | |
132 | + <groupId>io.dropwizard.metrics</groupId> | |
133 | + <artifactId>metrics-jmx</artifactId> | |
134 | + </dependency> | |
135 | 135 | <dependency> |
136 | 136 | <groupId>io.takari.junit</groupId> |
137 | 137 | <artifactId>takari-cpsuite</artifactId> |
... | ... | @@ -149,6 +149,10 @@ |
149 | 149 | <groupId>org.slf4j</groupId> |
150 | 150 | <artifactId>slf4j-log4j12</artifactId> |
151 | 151 | </exclusion> |
152 | + <exclusion> | |
153 | + <groupId>org.hibernate</groupId> | |
154 | + <artifactId>hibernate-validator</artifactId> | |
155 | + </exclusion> | |
152 | 156 | </exclusions> |
153 | 157 | <scope>test</scope> |
154 | 158 | </dependency> | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.springframework.data.domain.Page; |
20 | 20 | import org.springframework.data.domain.PageRequest; |
21 | 21 | import org.springframework.data.domain.Pageable; |
... | ... | @@ -49,7 +49,7 @@ public abstract class DaoUtil { |
49 | 49 | |
50 | 50 | public static String startTimeToId(Long startTime) { |
51 | 51 | if (startTime != null) { |
52 | - UUID startOf = UUIDs.startOf(startTime); | |
52 | + UUID startOf = Uuids.startOf(startTime); | |
53 | 53 | return UUIDConverter.fromTimeUUID(startOf); |
54 | 54 | } else { |
55 | 55 | return null; |
... | ... | @@ -58,7 +58,7 @@ public abstract class DaoUtil { |
58 | 58 | |
59 | 59 | public static String endTimeToId(Long endTime) { |
60 | 60 | if (endTime != null) { |
61 | - UUID endOf = UUIDs.endOf(endTime); | |
61 | + UUID endOf = Uuids.endOf(endTime); | |
62 | 62 | return UUIDConverter.fromTimeUUID(endOf); |
63 | 63 | } else { |
64 | 64 | return null; | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.audit; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
21 | 21 | import com.fasterxml.jackson.databind.node.ArrayNode; |
... | ... | @@ -296,7 +296,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
296 | 296 | ActionStatus actionStatus, |
297 | 297 | String actionFailureDetails) { |
298 | 298 | AuditLog result = new AuditLog(); |
299 | - result.setId(new AuditLogId(UUIDs.timeBased())); | |
299 | + result.setId(new AuditLogId(Uuids.timeBased())); | |
300 | 300 | result.setTenantId(tenantId); |
301 | 301 | result.setEntityId(entityId); |
302 | 302 | result.setEntityName(entityName); | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/EntitySubtypeEntity.java
deleted
100644 → 0
1 | -/** | |
2 | - * Copyright © 2016-2020 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.model; | |
17 | - | |
18 | -import com.datastax.driver.mapping.annotations.Column; | |
19 | -import com.datastax.driver.mapping.annotations.PartitionKey; | |
20 | -import com.datastax.driver.mapping.annotations.Table; | |
21 | -import org.thingsboard.server.common.data.EntitySubtype; | |
22 | -import org.thingsboard.server.common.data.EntityType; | |
23 | -import org.thingsboard.server.common.data.id.TenantId; | |
24 | -import org.thingsboard.server.dao.model.type.EntityTypeCodec; | |
25 | - | |
26 | -import java.util.UUID; | |
27 | - | |
28 | -import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_COLUMN_FAMILY_NAME; | |
29 | -import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY; | |
30 | -import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_TENANT_ID_PROPERTY; | |
31 | -import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_TYPE_PROPERTY; | |
32 | - | |
33 | -@Table(name = ENTITY_SUBTYPE_COLUMN_FAMILY_NAME) | |
34 | -public class EntitySubtypeEntity { | |
35 | - | |
36 | - @PartitionKey(value = 0) | |
37 | - @Column(name = ENTITY_SUBTYPE_TENANT_ID_PROPERTY) | |
38 | - private UUID tenantId; | |
39 | - | |
40 | - @PartitionKey(value = 1) | |
41 | - @Column(name = ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, codec = EntityTypeCodec.class) | |
42 | - private EntityType entityType; | |
43 | - | |
44 | - @PartitionKey(value = 2) | |
45 | - @Column(name = ENTITY_SUBTYPE_TYPE_PROPERTY) | |
46 | - private String type; | |
47 | - | |
48 | - public EntitySubtypeEntity() { | |
49 | - super(); | |
50 | - } | |
51 | - | |
52 | - public EntitySubtypeEntity(EntitySubtype entitySubtype) { | |
53 | - this.tenantId = entitySubtype.getTenantId().getId(); | |
54 | - this.entityType = entitySubtype.getEntityType(); | |
55 | - this.type = entitySubtype.getType(); | |
56 | - } | |
57 | - | |
58 | - public UUID getTenantId() { | |
59 | - return tenantId; | |
60 | - } | |
61 | - | |
62 | - public void setTenantId(UUID tenantId) { | |
63 | - this.tenantId = tenantId; | |
64 | - } | |
65 | - | |
66 | - public EntityType getEntityType() { | |
67 | - return entityType; | |
68 | - } | |
69 | - | |
70 | - public void setEntityType(EntityType entityType) { | |
71 | - this.entityType = entityType; | |
72 | - } | |
73 | - | |
74 | - public String getType() { | |
75 | - return type; | |
76 | - } | |
77 | - | |
78 | - public void setType(String type) { | |
79 | - this.type = type; | |
80 | - } | |
81 | - | |
82 | - | |
83 | - @Override | |
84 | - public boolean equals(Object o) { | |
85 | - if (this == o) return true; | |
86 | - if (o == null || getClass() != o.getClass()) return false; | |
87 | - | |
88 | - EntitySubtypeEntity that = (EntitySubtypeEntity) o; | |
89 | - | |
90 | - if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) return false; | |
91 | - if (entityType != that.entityType) return false; | |
92 | - return type != null ? type.equals(that.type) : that.type == null; | |
93 | - | |
94 | - } | |
95 | - | |
96 | - @Override | |
97 | - public int hashCode() { | |
98 | - int result = tenantId != null ? tenantId.hashCode() : 0; | |
99 | - result = 31 * result + (entityType != null ? entityType.hashCode() : 0); | |
100 | - result = 31 * result + (type != null ? type.hashCode() : 0); | |
101 | - return result; | |
102 | - } | |
103 | - | |
104 | - @Override | |
105 | - public String toString() { | |
106 | - final StringBuilder sb = new StringBuilder("EntitySubtypeEntity{"); | |
107 | - sb.append("tenantId=").append(tenantId); | |
108 | - sb.append(", entityType=").append(entityType); | |
109 | - sb.append(", type='").append(type).append('\''); | |
110 | - sb.append('}'); | |
111 | - return sb.toString(); | |
112 | - } | |
113 | - | |
114 | - public EntitySubtype toEntitySubtype() { | |
115 | - EntitySubtype entitySubtype = new EntitySubtype(); | |
116 | - entitySubtype.setTenantId(new TenantId(tenantId)); | |
117 | - entitySubtype.setEntityType(entityType); | |
118 | - entitySubtype.setType(type); | |
119 | - return entitySubtype; | |
120 | - } | |
121 | -} |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.apache.commons.lang3.ArrayUtils; |
20 | 20 | import org.thingsboard.server.common.data.UUIDConverter; |
21 | 21 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -28,7 +28,7 @@ public class ModelConstants { |
28 | 28 | private ModelConstants() { |
29 | 29 | } |
30 | 30 | |
31 | - public static final UUID NULL_UUID = UUIDs.startOf(0); | |
31 | + public static final UUID NULL_UUID = Uuids.startOf(0); | |
32 | 32 | public static final String NULL_UUID_STR = UUIDConverter.fromTimeUUID(NULL_UUID); |
33 | 33 | public static final TenantId SYSTEM_TENANT = new TenantId(ModelConstants.NULL_UUID); |
34 | 34 | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -154,7 +154,7 @@ public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity |
154 | 154 | |
155 | 155 | protected Alarm toAlarm() { |
156 | 156 | Alarm alarm = new Alarm(new AlarmId(UUIDConverter.fromString(id))); |
157 | - alarm.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id))); | |
157 | + alarm.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id))); | |
158 | 158 | if (tenantId != null) { |
159 | 159 | alarm.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); |
160 | 160 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -116,7 +116,7 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity |
116 | 116 | |
117 | 117 | protected Asset toAsset() { |
118 | 118 | Asset asset = new Asset(new AssetId(UUIDConverter.fromString(id))); |
119 | - asset.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id))); | |
119 | + asset.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id))); | |
120 | 120 | if (tenantId != null) { |
121 | 121 | asset.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); |
122 | 122 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -104,7 +104,7 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti |
104 | 104 | |
105 | 105 | protected Device toDevice() { |
106 | 106 | Device device = new Device(new DeviceId(getUuid())); |
107 | - device.setCreatedTime(UUIDs.unixTimestamp(getUuid())); | |
107 | + device.setCreatedTime(Uuids.unixTimestamp(getUuid())); | |
108 | 108 | if (tenantId != null) { |
109 | 109 | device.setTenantId(new TenantId(toUUID(tenantId))); |
110 | 110 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
21 | 21 | import lombok.Data; |
... | ... | @@ -147,7 +147,7 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas |
147 | 147 | |
148 | 148 | protected EntityView toEntityView() { |
149 | 149 | EntityView entityView = new EntityView(new EntityViewId(getUuid())); |
150 | - entityView.setCreatedTime(UUIDs.unixTimestamp(getUuid())); | |
150 | + entityView.setCreatedTime(Uuids.unixTimestamp(getUuid())); | |
151 | 151 | |
152 | 152 | if (entityId != null) { |
153 | 153 | entityView.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), toUUID(entityId).toString())); | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -65,10 +65,10 @@ public final class AdminSettingsEntity extends BaseSqlEntity<AdminSettings> impl |
65 | 65 | @Override |
66 | 66 | public AdminSettings toData() { |
67 | 67 | AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(UUIDConverter.fromString(id))); |
68 | - adminSettings.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id))); | |
68 | + adminSettings.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id))); | |
69 | 69 | adminSettings.setKey(key); |
70 | 70 | adminSettings.setJsonValue(jsonValue); |
71 | 71 | return adminSettings; |
72 | 72 | } |
73 | 73 | |
74 | -} | |
\ No newline at end of file | ||
74 | +} | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -129,7 +129,7 @@ public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntit |
129 | 129 | @Override |
130 | 130 | public AuditLog toData() { |
131 | 131 | AuditLog auditLog = new AuditLog(new AuditLogId(this.getUuid())); |
132 | - auditLog.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
132 | + auditLog.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
133 | 133 | if (tenantId != null) { |
134 | 134 | auditLog.setTenantId(new TenantId(toUUID(tenantId))); |
135 | 135 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -112,7 +112,7 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea |
112 | 112 | @Override |
113 | 113 | public Customer toData() { |
114 | 114 | Customer customer = new Customer(new CustomerId(this.getUuid())); |
115 | - customer.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
115 | + customer.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
116 | 116 | customer.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); |
117 | 117 | customer.setTitle(title); |
118 | 118 | customer.setCountry(country); |
... | ... | @@ -126,4 +126,4 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea |
126 | 126 | customer.setAdditionalInfo(additionalInfo); |
127 | 127 | return customer; |
128 | 128 | } |
129 | -} | |
\ No newline at end of file | ||
129 | +} | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.core.JsonProcessingException; |
20 | 20 | import com.fasterxml.jackson.databind.JavaType; |
21 | 21 | import com.fasterxml.jackson.databind.JsonNode; |
... | ... | @@ -104,7 +104,7 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S |
104 | 104 | @Override |
105 | 105 | public Dashboard toData() { |
106 | 106 | Dashboard dashboard = new Dashboard(new DashboardId(this.getUuid())); |
107 | - dashboard.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
107 | + dashboard.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
108 | 108 | if (tenantId != null) { |
109 | 109 | dashboard.setTenantId(new TenantId(toUUID(tenantId))); |
110 | 110 | } |
... | ... | @@ -119,4 +119,4 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S |
119 | 119 | dashboard.setConfiguration(configuration); |
120 | 120 | return dashboard; |
121 | 121 | } |
122 | -} | |
\ No newline at end of file | ||
122 | +} | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.core.JsonProcessingException; |
20 | 20 | import com.fasterxml.jackson.databind.JavaType; |
21 | 21 | import com.fasterxml.jackson.databind.ObjectMapper; |
... | ... | @@ -98,7 +98,7 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements |
98 | 98 | @Override |
99 | 99 | public DashboardInfo toData() { |
100 | 100 | DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(this.getUuid())); |
101 | - dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
101 | + dashboardInfo.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
102 | 102 | if (tenantId != null) { |
103 | 103 | dashboardInfo.setTenantId(new TenantId(toUUID(tenantId))); |
104 | 104 | } |
... | ... | @@ -113,4 +113,4 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements |
113 | 113 | return dashboardInfo; |
114 | 114 | } |
115 | 115 | |
116 | -} | |
\ No newline at end of file | ||
116 | +} | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import lombok.Data; |
20 | 20 | import lombok.EqualsAndHashCode; |
21 | 21 | import org.thingsboard.server.common.data.id.DeviceCredentialsId; |
... | ... | @@ -70,7 +70,7 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia |
70 | 70 | @Override |
71 | 71 | public DeviceCredentials toData() { |
72 | 72 | DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(this.getUuid())); |
73 | - deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
73 | + deviceCredentials.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
74 | 74 | if (deviceId != null) { |
75 | 75 | deviceCredentials.setDeviceId(new DeviceId(toUUID(deviceId))); |
76 | 76 | } |
... | ... | @@ -80,4 +80,4 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia |
80 | 80 | return deviceCredentials; |
81 | 81 | } |
82 | 82 | |
83 | -} | |
\ No newline at end of file | ||
83 | +} | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -103,7 +103,7 @@ public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Eve |
103 | 103 | @Override |
104 | 104 | public Event toData() { |
105 | 105 | Event event = new Event(new EventId(this.getUuid())); |
106 | - event.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
106 | + event.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
107 | 107 | event.setTenantId(new TenantId(toUUID(tenantId))); |
108 | 108 | event.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, toUUID(entityId))); |
109 | 109 | event.setBody(body); | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -101,7 +101,7 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT |
101 | 101 | @Override |
102 | 102 | public RuleChain toData() { |
103 | 103 | RuleChain ruleChain = new RuleChain(new RuleChainId(this.getUuid())); |
104 | - ruleChain.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
104 | + ruleChain.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
105 | 105 | ruleChain.setTenantId(new TenantId(toUUID(tenantId))); |
106 | 106 | ruleChain.setName(name); |
107 | 107 | if (firstRuleNodeId != null) { | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -95,7 +95,7 @@ public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTex |
95 | 95 | @Override |
96 | 96 | public RuleNode toData() { |
97 | 97 | RuleNode ruleNode = new RuleNode(new RuleNodeId(this.getUuid())); |
98 | - ruleNode.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
98 | + ruleNode.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
99 | 99 | if (ruleChainId != null) { |
100 | 100 | ruleNode.setRuleChainId(new RuleChainId(toUUID(ruleChainId))); |
101 | 101 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -122,7 +122,7 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT |
122 | 122 | @Override |
123 | 123 | public Tenant toData() { |
124 | 124 | Tenant tenant = new Tenant(new TenantId(this.getUuid())); |
125 | - tenant.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
125 | + tenant.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
126 | 126 | tenant.setTitle(title); |
127 | 127 | tenant.setRegion(region); |
128 | 128 | tenant.setCountry(country); |
... | ... | @@ -140,4 +140,4 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT |
140 | 140 | } |
141 | 141 | |
142 | 142 | |
143 | -} | |
\ No newline at end of file | ||
143 | +} | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import lombok.Data; |
20 | 20 | import lombok.EqualsAndHashCode; |
21 | 21 | import org.thingsboard.server.common.data.id.UserCredentialsId; |
... | ... | @@ -70,7 +70,7 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> |
70 | 70 | @Override |
71 | 71 | public UserCredentials toData() { |
72 | 72 | UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(this.getUuid())); |
73 | - userCredentials.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
73 | + userCredentials.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
74 | 74 | if (userId != null) { |
75 | 75 | userCredentials.setUserId(new UserId(toUUID(userId))); |
76 | 76 | } |
... | ... | @@ -81,4 +81,4 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> |
81 | 81 | return userCredentials; |
82 | 82 | } |
83 | 83 | |
84 | -} | |
\ No newline at end of file | ||
84 | +} | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -109,7 +109,7 @@ public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity< |
109 | 109 | @Override |
110 | 110 | public User toData() { |
111 | 111 | User user = new User(new UserId(this.getUuid())); |
112 | - user.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
112 | + user.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
113 | 113 | user.setAuthority(authority); |
114 | 114 | if (tenantId != null) { |
115 | 115 | user.setTenantId(new TenantId(fromString(tenantId))); | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
... | ... | @@ -76,7 +76,7 @@ public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implement |
76 | 76 | @Override |
77 | 77 | public WidgetType toData() { |
78 | 78 | WidgetType widgetType = new WidgetType(new WidgetTypeId(this.getUuid())); |
79 | - widgetType.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); | |
79 | + widgetType.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | |
80 | 80 | if (tenantId != null) { |
81 | 81 | widgetType.setTenantId(new TenantId(toUUID(tenantId))); |
82 | 82 | } | ... | ... |
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | 18 | |
19 | -import com.datastax.driver.core.utils.UUIDs; | |
19 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
20 | 20 | import lombok.Data; |
21 | 21 | import lombok.EqualsAndHashCode; |
22 | 22 | import org.thingsboard.server.common.data.UUIDConverter; |
... | ... | @@ -77,7 +77,7 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> impl |
77 | 77 | @Override |
78 | 78 | public WidgetsBundle toData() { |
79 | 79 | WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(UUIDConverter.fromString(id))); |
80 | - widgetsBundle.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id))); | |
80 | + widgetsBundle.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id))); | |
81 | 81 | if (tenantId != null) { |
82 | 82 | widgetsBundle.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); |
83 | 83 | } | ... | ... |
1 | -/** | |
2 | - * Copyright © 2016-2020 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.model.wrapper; | |
17 | - | |
18 | - | |
19 | -import com.datastax.driver.core.ResultSet; | |
20 | - | |
21 | -public class EntityResultSet<T> { | |
22 | - | |
23 | - private ResultSet resultSet; | |
24 | - private T entity; | |
25 | - | |
26 | - public EntityResultSet(ResultSet resultSet, T entity) { | |
27 | - this.resultSet = resultSet; | |
28 | - this.entity = entity; | |
29 | - } | |
30 | - | |
31 | - public T getEntity() { | |
32 | - return entity; | |
33 | - } | |
34 | - | |
35 | - public boolean wasApplied() { | |
36 | - return resultSet.wasApplied(); | |
37 | - } | |
38 | -} |
... | ... | @@ -15,9 +15,11 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.nosql; |
17 | 17 | |
18 | -import com.datastax.driver.core.ResultSet; | |
19 | -import com.datastax.driver.core.ResultSetFuture; | |
18 | +import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | |
19 | +import com.datastax.oss.driver.api.core.cql.Row; | |
20 | 20 | import com.google.common.base.Function; |
21 | +import com.google.common.collect.Lists; | |
22 | +import com.google.common.util.concurrent.AsyncFunction; | |
21 | 23 | import com.google.common.util.concurrent.Futures; |
22 | 24 | import com.google.common.util.concurrent.ListenableFuture; |
23 | 25 | import org.thingsboard.common.util.ThingsBoardThreadFactory; |
... | ... | @@ -25,8 +27,11 @@ import org.thingsboard.common.util.ThingsBoardThreadFactory; |
25 | 27 | import javax.annotation.Nullable; |
26 | 28 | import javax.annotation.PostConstruct; |
27 | 29 | import javax.annotation.PreDestroy; |
30 | +import java.util.ArrayList; | |
31 | +import java.util.List; | |
28 | 32 | import java.util.concurrent.ExecutorService; |
29 | 33 | import java.util.concurrent.Executors; |
34 | +import java.util.stream.Collectors; | |
30 | 35 | |
31 | 36 | /** |
32 | 37 | * Created by ashvayka on 21.02.17. |
... | ... | @@ -47,13 +52,28 @@ public abstract class CassandraAbstractAsyncDao extends CassandraAbstractDao { |
47 | 52 | } |
48 | 53 | } |
49 | 54 | |
50 | - protected <T> ListenableFuture<T> getFuture(ResultSetFuture future, java.util.function.Function<ResultSet, T> transformer) { | |
51 | - return Futures.transform(future, new Function<ResultSet, T>() { | |
55 | + protected <T> ListenableFuture<T> getFuture(TbResultSetFuture future, java.util.function.Function<TbResultSet, T> transformer) { | |
56 | + return Futures.transform(future, new Function<TbResultSet, T>() { | |
52 | 57 | @Nullable |
53 | 58 | @Override |
54 | - public T apply(@Nullable ResultSet input) { | |
59 | + public T apply(@Nullable TbResultSet input) { | |
55 | 60 | return transformer.apply(input); |
56 | 61 | } |
57 | 62 | }, readResultsProcessingExecutor); |
58 | 63 | } |
64 | + | |
65 | + protected <T> ListenableFuture<T> getFutureAsync(TbResultSetFuture future, com.google.common.util.concurrent.AsyncFunction<TbResultSet, T> transformer) { | |
66 | + return Futures.transformAsync(future, new AsyncFunction<TbResultSet, T>() { | |
67 | + @Nullable | |
68 | + @Override | |
69 | + public ListenableFuture<T> apply(@Nullable TbResultSet input) { | |
70 | + try { | |
71 | + return transformer.apply(input); | |
72 | + } catch (Exception e) { | |
73 | + return Futures.immediateFailedFuture(e); | |
74 | + } | |
75 | + } | |
76 | + }, readResultsProcessingExecutor); | |
77 | + } | |
78 | + | |
59 | 79 | } | ... | ... |
... | ... | @@ -15,16 +15,17 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.nosql; |
17 | 17 | |
18 | -import com.datastax.driver.core.*; | |
19 | -import com.datastax.driver.core.exceptions.CodecNotFoundException; | |
18 | +import com.datastax.oss.driver.api.core.ConsistencyLevel; | |
19 | +import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | |
20 | +import com.datastax.oss.driver.api.core.cql.BoundStatement; | |
21 | +import com.datastax.oss.driver.api.core.cql.PreparedStatement; | |
22 | +import com.datastax.oss.driver.api.core.cql.Statement; | |
20 | 23 | import lombok.extern.slf4j.Slf4j; |
21 | 24 | import org.springframework.beans.factory.annotation.Autowired; |
22 | 25 | import org.springframework.beans.factory.annotation.Qualifier; |
23 | 26 | import org.thingsboard.server.common.data.id.TenantId; |
24 | 27 | import org.thingsboard.server.dao.cassandra.CassandraCluster; |
25 | -import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec; | |
26 | -import org.thingsboard.server.dao.model.type.EntityTypeCodec; | |
27 | -import org.thingsboard.server.dao.model.type.JsonCodec; | |
28 | +import org.thingsboard.server.dao.cassandra.guava.GuavaSession; | |
28 | 29 | |
29 | 30 | import java.util.concurrent.ConcurrentHashMap; |
30 | 31 | import java.util.concurrent.ConcurrentMap; |
... | ... | @@ -41,20 +42,16 @@ public abstract class CassandraAbstractDao { |
41 | 42 | @Autowired |
42 | 43 | private CassandraBufferedRateExecutor rateLimiter; |
43 | 44 | |
44 | - private Session session; | |
45 | + private GuavaSession session; | |
45 | 46 | |
46 | 47 | private ConsistencyLevel defaultReadLevel; |
47 | 48 | private ConsistencyLevel defaultWriteLevel; |
48 | 49 | |
49 | - private Session getSession() { | |
50 | + private GuavaSession getSession() { | |
50 | 51 | if (session == null) { |
51 | 52 | session = cluster.getSession(); |
52 | 53 | defaultReadLevel = cluster.getDefaultReadConsistencyLevel(); |
53 | 54 | defaultWriteLevel = cluster.getDefaultWriteConsistencyLevel(); |
54 | - CodecRegistry registry = session.getCluster().getConfiguration().getCodecRegistry(); | |
55 | - registerCodecIfNotFound(registry, new JsonCodec()); | |
56 | - registerCodecIfNotFound(registry, new ComponentLifecycleStateCodec()); | |
57 | - registerCodecIfNotFound(registry, new EntityTypeCodec()); | |
58 | 55 | } |
59 | 56 | return session; |
60 | 57 | } |
... | ... | @@ -63,38 +60,30 @@ public abstract class CassandraAbstractDao { |
63 | 60 | return preparedStatementMap.computeIfAbsent(query, i -> getSession().prepare(i)); |
64 | 61 | } |
65 | 62 | |
66 | - private void registerCodecIfNotFound(CodecRegistry registry, TypeCodec<?> codec) { | |
67 | - try { | |
68 | - registry.codecFor(codec.getCqlType(), codec.getJavaType()); | |
69 | - } catch (CodecNotFoundException e) { | |
70 | - registry.register(codec); | |
71 | - } | |
72 | - } | |
73 | - | |
74 | - protected ResultSet executeRead(TenantId tenantId, Statement statement) { | |
63 | + protected AsyncResultSet executeRead(TenantId tenantId, Statement statement) { | |
75 | 64 | return execute(tenantId, statement, defaultReadLevel); |
76 | 65 | } |
77 | 66 | |
78 | - protected ResultSet executeWrite(TenantId tenantId, Statement statement) { | |
67 | + protected AsyncResultSet executeWrite(TenantId tenantId, Statement statement) { | |
79 | 68 | return execute(tenantId, statement, defaultWriteLevel); |
80 | 69 | } |
81 | 70 | |
82 | - protected ResultSetFuture executeAsyncRead(TenantId tenantId, Statement statement) { | |
71 | + protected TbResultSetFuture executeAsyncRead(TenantId tenantId, Statement statement) { | |
83 | 72 | return executeAsync(tenantId, statement, defaultReadLevel); |
84 | 73 | } |
85 | 74 | |
86 | - protected ResultSetFuture executeAsyncWrite(TenantId tenantId, Statement statement) { | |
75 | + protected TbResultSetFuture executeAsyncWrite(TenantId tenantId, Statement statement) { | |
87 | 76 | return executeAsync(tenantId, statement, defaultWriteLevel); |
88 | 77 | } |
89 | 78 | |
90 | - private ResultSet execute(TenantId tenantId, Statement statement, ConsistencyLevel level) { | |
79 | + private AsyncResultSet execute(TenantId tenantId, Statement statement, ConsistencyLevel level) { | |
91 | 80 | if (log.isDebugEnabled()) { |
92 | 81 | log.debug("Execute cassandra statement {}", statementToString(statement)); |
93 | 82 | } |
94 | 83 | return executeAsync(tenantId, statement, level).getUninterruptibly(); |
95 | 84 | } |
96 | 85 | |
97 | - private ResultSetFuture executeAsync(TenantId tenantId, Statement statement, ConsistencyLevel level) { | |
86 | + private TbResultSetFuture executeAsync(TenantId tenantId, Statement statement, ConsistencyLevel level) { | |
98 | 87 | if (log.isDebugEnabled()) { |
99 | 88 | log.debug("Execute cassandra async statement {}", statementToString(statement)); |
100 | 89 | } |
... | ... | @@ -106,9 +95,9 @@ public abstract class CassandraAbstractDao { |
106 | 95 | |
107 | 96 | private static String statementToString(Statement statement) { |
108 | 97 | if (statement instanceof BoundStatement) { |
109 | - return ((BoundStatement) statement).preparedStatement().getQueryString(); | |
98 | + return ((BoundStatement) statement).getPreparedStatement().getQuery(); | |
110 | 99 | } else { |
111 | 100 | return statement.toString(); |
112 | 101 | } |
113 | 102 | } |
114 | -} | |
\ No newline at end of file | ||
103 | +} | ... | ... |
... | ... | @@ -15,8 +15,8 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.nosql; |
17 | 17 | |
18 | -import com.datastax.driver.core.ResultSet; | |
19 | -import com.datastax.driver.core.ResultSetFuture; | |
18 | +import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | |
19 | +import com.google.common.util.concurrent.ListenableFuture; | |
20 | 20 | import com.google.common.util.concurrent.SettableFuture; |
21 | 21 | import lombok.extern.slf4j.Slf4j; |
22 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -39,7 +39,7 @@ import java.util.Map; |
39 | 39 | @Component |
40 | 40 | @Slf4j |
41 | 41 | @NoSqlAnyDao |
42 | -public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor<CassandraStatementTask, ResultSetFuture, ResultSet> { | |
42 | +public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor<CassandraStatementTask, TbResultSetFuture, TbResultSet> { | |
43 | 43 | |
44 | 44 | @Autowired |
45 | 45 | private EntityService entityService; |
... | ... | @@ -107,19 +107,22 @@ public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor< |
107 | 107 | } |
108 | 108 | |
109 | 109 | @Override |
110 | - protected SettableFuture<ResultSet> create() { | |
110 | + protected SettableFuture<TbResultSet> create() { | |
111 | 111 | return SettableFuture.create(); |
112 | 112 | } |
113 | 113 | |
114 | 114 | @Override |
115 | - protected ResultSetFuture wrap(CassandraStatementTask task, SettableFuture<ResultSet> future) { | |
115 | + protected TbResultSetFuture wrap(CassandraStatementTask task, SettableFuture<TbResultSet> future) { | |
116 | 116 | return new TbResultSetFuture(future); |
117 | 117 | } |
118 | 118 | |
119 | 119 | @Override |
120 | - protected ResultSetFuture execute(AsyncTaskContext<CassandraStatementTask, ResultSet> taskCtx) { | |
120 | + protected ListenableFuture<TbResultSet> execute(AsyncTaskContext<CassandraStatementTask, TbResultSet> taskCtx) { | |
121 | 121 | CassandraStatementTask task = taskCtx.getTask(); |
122 | - return task.getSession().executeAsync(task.getStatement()); | |
122 | + return task.executeAsync( | |
123 | + statement -> | |
124 | + this.submit(new CassandraStatementTask(task.getTenantId(), task.getSession(), statement)) | |
125 | + ); | |
123 | 126 | } |
124 | 127 | |
125 | 128 | } | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/nosql/RateLimitedResultSetFuture.java
deleted
100644 → 0
1 | -/** | |
2 | - * Copyright © 2016-2020 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.nosql; | |
17 | - | |
18 | -import com.datastax.driver.core.ResultSet; | |
19 | -import com.datastax.driver.core.ResultSetFuture; | |
20 | -import com.datastax.driver.core.Session; | |
21 | -import com.datastax.driver.core.Statement; | |
22 | -import com.google.common.util.concurrent.FutureCallback; | |
23 | -import com.google.common.util.concurrent.Futures; | |
24 | -import com.google.common.util.concurrent.ListenableFuture; | |
25 | -import com.google.common.util.concurrent.MoreExecutors; | |
26 | -import com.google.common.util.concurrent.Uninterruptibles; | |
27 | -import org.thingsboard.server.dao.exception.BufferLimitException; | |
28 | -import org.thingsboard.server.dao.util.AsyncRateLimiter; | |
29 | - | |
30 | -import javax.annotation.Nullable; | |
31 | -import java.util.concurrent.CancellationException; | |
32 | -import java.util.concurrent.ExecutionException; | |
33 | -import java.util.concurrent.Executor; | |
34 | -import java.util.concurrent.TimeUnit; | |
35 | -import java.util.concurrent.TimeoutException; | |
36 | - | |
37 | -public class RateLimitedResultSetFuture implements ResultSetFuture { | |
38 | - | |
39 | - private final ListenableFuture<ResultSetFuture> originalFuture; | |
40 | - private final ListenableFuture<Void> rateLimitFuture; | |
41 | - | |
42 | - public RateLimitedResultSetFuture(Session session, AsyncRateLimiter rateLimiter, Statement statement) { | |
43 | - this.rateLimitFuture = Futures.catchingAsync(rateLimiter.acquireAsync(), Throwable.class, t -> { | |
44 | - if (!(t instanceof BufferLimitException)) { | |
45 | - rateLimiter.release(); | |
46 | - } | |
47 | - return Futures.immediateFailedFuture(t); | |
48 | - }, MoreExecutors.directExecutor()); | |
49 | - this.originalFuture = Futures.transform(rateLimitFuture, | |
50 | - i -> executeAsyncWithRelease(rateLimiter, session, statement), MoreExecutors.directExecutor()); | |
51 | - | |
52 | - } | |
53 | - | |
54 | - @Override | |
55 | - public ResultSet getUninterruptibly() { | |
56 | - return safeGet().getUninterruptibly(); | |
57 | - } | |
58 | - | |
59 | - @Override | |
60 | - public ResultSet getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException { | |
61 | - long rateLimitStart = System.nanoTime(); | |
62 | - ResultSetFuture resultSetFuture = null; | |
63 | - try { | |
64 | - resultSetFuture = originalFuture.get(timeout, unit); | |
65 | - } catch (InterruptedException | ExecutionException e) { | |
66 | - throw new IllegalStateException(e); | |
67 | - } | |
68 | - long rateLimitDurationNano = System.nanoTime() - rateLimitStart; | |
69 | - long innerTimeoutNano = unit.toNanos(timeout) - rateLimitDurationNano; | |
70 | - if (innerTimeoutNano > 0) { | |
71 | - return resultSetFuture.getUninterruptibly(innerTimeoutNano, TimeUnit.NANOSECONDS); | |
72 | - } | |
73 | - throw new TimeoutException("Timeout waiting for task."); | |
74 | - } | |
75 | - | |
76 | - @Override | |
77 | - public boolean cancel(boolean mayInterruptIfRunning) { | |
78 | - if (originalFuture.isDone()) { | |
79 | - return safeGet().cancel(mayInterruptIfRunning); | |
80 | - } else { | |
81 | - return originalFuture.cancel(mayInterruptIfRunning); | |
82 | - } | |
83 | - } | |
84 | - | |
85 | - @Override | |
86 | - public boolean isCancelled() { | |
87 | - if (originalFuture.isDone()) { | |
88 | - return safeGet().isCancelled(); | |
89 | - } | |
90 | - | |
91 | - return originalFuture.isCancelled(); | |
92 | - } | |
93 | - | |
94 | - @Override | |
95 | - public boolean isDone() { | |
96 | - return originalFuture.isDone() && safeGet().isDone(); | |
97 | - } | |
98 | - | |
99 | - @Override | |
100 | - public ResultSet get() throws InterruptedException, ExecutionException { | |
101 | - return safeGet().get(); | |
102 | - } | |
103 | - | |
104 | - @Override | |
105 | - public ResultSet get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { | |
106 | - long rateLimitStart = System.nanoTime(); | |
107 | - ResultSetFuture resultSetFuture = originalFuture.get(timeout, unit); | |
108 | - long rateLimitDurationNano = System.nanoTime() - rateLimitStart; | |
109 | - long innerTimeoutNano = unit.toNanos(timeout) - rateLimitDurationNano; | |
110 | - if (innerTimeoutNano > 0) { | |
111 | - return resultSetFuture.get(innerTimeoutNano, TimeUnit.NANOSECONDS); | |
112 | - } | |
113 | - throw new TimeoutException("Timeout waiting for task."); | |
114 | - } | |
115 | - | |
116 | - @Override | |
117 | - public void addListener(Runnable listener, Executor executor) { | |
118 | - originalFuture.addListener(() -> { | |
119 | - try { | |
120 | - ResultSetFuture resultSetFuture = Uninterruptibles.getUninterruptibly(originalFuture); | |
121 | - resultSetFuture.addListener(listener, executor); | |
122 | - } catch (CancellationException | ExecutionException e) { | |
123 | - Futures.immediateFailedFuture(e).addListener(listener, executor); | |
124 | - } | |
125 | - }, executor); | |
126 | - } | |
127 | - | |
128 | - private ResultSetFuture safeGet() { | |
129 | - try { | |
130 | - return originalFuture.get(); | |
131 | - } catch (InterruptedException | ExecutionException e) { | |
132 | - throw new IllegalStateException(e); | |
133 | - } | |
134 | - } | |
135 | - | |
136 | - private ResultSetFuture executeAsyncWithRelease(AsyncRateLimiter rateLimiter, Session session, Statement statement) { | |
137 | - try { | |
138 | - ResultSetFuture resultSetFuture = session.executeAsync(statement); | |
139 | - Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() { | |
140 | - @Override | |
141 | - public void onSuccess(@Nullable ResultSet result) { | |
142 | - rateLimiter.release(); | |
143 | - } | |
144 | - | |
145 | - @Override | |
146 | - public void onFailure(Throwable t) { | |
147 | - rateLimiter.release(); | |
148 | - } | |
149 | - }, MoreExecutors.directExecutor()); | |
150 | - return resultSetFuture; | |
151 | - } catch (RuntimeException re) { | |
152 | - rateLimiter.release(); | |
153 | - throw re; | |
154 | - } | |
155 | - } | |
156 | -} |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.google.common.collect.Lists; |
20 | 20 | import com.google.common.util.concurrent.ListenableFuture; |
21 | 21 | import lombok.extern.slf4j.Slf4j; |
... | ... | @@ -59,7 +59,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> |
59 | 59 | setSearchText(entity); |
60 | 60 | log.debug("Saving entity {}", entity); |
61 | 61 | if (entity.getUuid() == null) { |
62 | - entity.setUuid(UUIDs.timeBased()); | |
62 | + entity.setUuid(Uuids.timeBased()); | |
63 | 63 | } |
64 | 64 | entity = getCrudRepository().save(entity); |
65 | 65 | return DaoUtil.getData(entity); | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.sql; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.springframework.data.jpa.domain.Specification; |
20 | 20 | import org.thingsboard.server.common.data.UUIDConverter; |
21 | 21 | import org.thingsboard.server.common.data.page.TimePageLink; |
... | ... | @@ -40,12 +40,12 @@ public abstract class JpaAbstractSearchTimeDao<E extends BaseEntity<D>, D> exten |
40 | 40 | public Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { |
41 | 41 | List<Predicate> predicates = new ArrayList<>(); |
42 | 42 | if (pageLink.getStartTime() != null) { |
43 | - UUID startOf = UUIDs.startOf(pageLink.getStartTime()); | |
43 | + UUID startOf = Uuids.startOf(pageLink.getStartTime()); | |
44 | 44 | Predicate lowerBound = criteriaBuilder.greaterThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(startOf)); |
45 | 45 | predicates.add(lowerBound); |
46 | 46 | } |
47 | 47 | if (pageLink.getEndTime() != null) { |
48 | - UUID endOf = UUIDs.endOf(pageLink.getEndTime()); | |
48 | + UUID endOf = Uuids.endOf(pageLink.getEndTime()); | |
49 | 49 | Predicate upperBound = criteriaBuilder.lessThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(endOf)); |
50 | 50 | predicates.add(upperBound); |
51 | 51 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.sql.component; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | 20 | import org.springframework.data.repository.CrudRepository; |
21 | 21 | import org.springframework.stereotype.Component; |
... | ... | @@ -64,7 +64,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp |
64 | 64 | @Override |
65 | 65 | public Optional<ComponentDescriptor> saveIfNotExist(TenantId tenantId, ComponentDescriptor component) { |
66 | 66 | if (component.getId() == null) { |
67 | - component.setId(new ComponentDescriptorId(UUIDs.timeBased())); | |
67 | + component.setId(new ComponentDescriptorId(Uuids.timeBased())); | |
68 | 68 | } |
69 | 69 | if (!componentDescriptorRepository.existsById(UUIDConverter.fromTimeUUID(component.getId().getId()))) { |
70 | 70 | ComponentDescriptorEntity componentDescriptorEntity = new ComponentDescriptorEntity(component); | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.sql.event; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.google.common.util.concurrent.ListenableFuture; |
20 | 20 | import lombok.extern.slf4j.Slf4j; |
21 | 21 | import org.apache.commons.lang3.StringUtils; |
... | ... | @@ -75,7 +75,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event |
75 | 75 | public Event save(TenantId tenantId, Event event) { |
76 | 76 | log.debug("Save event [{}] ", event); |
77 | 77 | if (event.getId() == null) { |
78 | - event.setId(new EventId(UUIDs.timeBased())); | |
78 | + event.setId(new EventId(Uuids.timeBased())); | |
79 | 79 | } |
80 | 80 | if (StringUtils.isEmpty(event.getUid())) { |
81 | 81 | event.setUid(event.getId().toString()); |
... | ... | @@ -87,7 +87,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event |
87 | 87 | public ListenableFuture<Event> saveAsync(Event event) { |
88 | 88 | log.debug("Save event [{}] ", event); |
89 | 89 | if (event.getId() == null) { |
90 | - event.setId(new EventId(UUIDs.timeBased())); | |
90 | + event.setId(new EventId(Uuids.timeBased())); | |
91 | 91 | } |
92 | 92 | if (StringUtils.isEmpty(event.getUid())) { |
93 | 93 | event.setUid(event.getId().toString()); |
... | ... | @@ -152,7 +152,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event |
152 | 152 | entity.setTenantId(UUIDConverter.fromTimeUUID(systemTenantId)); |
153 | 153 | } |
154 | 154 | if (entity.getUuid() == null) { |
155 | - entity.setUuid(UUIDs.timeBased()); | |
155 | + entity.setUuid(Uuids.timeBased()); | |
156 | 156 | } |
157 | 157 | if (StringUtils.isEmpty(entity.getEventUid())) { |
158 | 158 | entity.setEventUid(entity.getUuid().toString()); | ... | ... |
... | ... | @@ -15,8 +15,10 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.timeseries; |
17 | 17 | |
18 | -import com.datastax.driver.core.ResultSet; | |
19 | -import com.datastax.driver.core.Row; | |
18 | +import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | |
19 | +import com.datastax.oss.driver.api.core.cql.Row; | |
20 | +import com.google.common.util.concurrent.Futures; | |
21 | +import com.google.common.util.concurrent.ListenableFuture; | |
20 | 22 | import lombok.extern.slf4j.Slf4j; |
21 | 23 | import org.thingsboard.server.common.data.kv.Aggregation; |
22 | 24 | import org.thingsboard.server.common.data.kv.BasicTsKvEntry; |
... | ... | @@ -27,16 +29,19 @@ import org.thingsboard.server.common.data.kv.JsonDataEntry; |
27 | 29 | import org.thingsboard.server.common.data.kv.LongDataEntry; |
28 | 30 | import org.thingsboard.server.common.data.kv.StringDataEntry; |
29 | 31 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
32 | +import org.thingsboard.server.dao.nosql.TbResultSet; | |
30 | 33 | |
31 | 34 | import javax.annotation.Nullable; |
32 | 35 | import java.util.List; |
33 | 36 | import java.util.Optional; |
37 | +import java.util.concurrent.Executor; | |
38 | +import java.util.stream.Collectors; | |
34 | 39 | |
35 | 40 | /** |
36 | 41 | * Created by ashvayka on 20.02.17. |
37 | 42 | */ |
38 | 43 | @Slf4j |
39 | -public class AggregatePartitionsFunction implements com.google.common.base.Function<List<ResultSet>, Optional<TsKvEntry>> { | |
44 | +public class AggregatePartitionsFunction implements com.google.common.util.concurrent.AsyncFunction<List<TbResultSet>, Optional<TsKvEntry>> { | |
40 | 45 | |
41 | 46 | private static final int LONG_CNT_POS = 0; |
42 | 47 | private static final int DOUBLE_CNT_POS = 1; |
... | ... | @@ -52,33 +57,39 @@ public class AggregatePartitionsFunction implements com.google.common.base.Funct |
52 | 57 | private final Aggregation aggregation; |
53 | 58 | private final String key; |
54 | 59 | private final long ts; |
60 | + private final Executor executor; | |
55 | 61 | |
56 | - public AggregatePartitionsFunction(Aggregation aggregation, String key, long ts) { | |
62 | + public AggregatePartitionsFunction(Aggregation aggregation, String key, long ts, Executor executor) { | |
57 | 63 | this.aggregation = aggregation; |
58 | 64 | this.key = key; |
59 | 65 | this.ts = ts; |
66 | + this.executor = executor; | |
60 | 67 | } |
61 | 68 | |
62 | 69 | @Override |
63 | - public Optional<TsKvEntry> apply(@Nullable List<ResultSet> rsList) { | |
64 | - try { | |
65 | - log.trace("[{}][{}][{}] Going to aggregate data", key, ts, aggregation); | |
66 | - if (rsList == null || rsList.isEmpty()) { | |
67 | - return Optional.empty(); | |
68 | - } | |
69 | - | |
70 | - AggregationResult aggResult = new AggregationResult(); | |
71 | - | |
72 | - for (ResultSet rs : rsList) { | |
73 | - for (Row row : rs.all()) { | |
74 | - processResultSetRow(row, aggResult); | |
70 | + public ListenableFuture<Optional<TsKvEntry>> apply(@Nullable List<TbResultSet> rsList) { | |
71 | + log.trace("[{}][{}][{}] Going to aggregate data", key, ts, aggregation); | |
72 | + if (rsList == null || rsList.isEmpty()) { | |
73 | + return Futures.immediateFuture(Optional.empty()); | |
74 | + } | |
75 | + return Futures.transform( | |
76 | + Futures.allAsList( | |
77 | + rsList.stream().map(rs -> rs.allRows(this.executor)) | |
78 | + .collect(Collectors.toList())), | |
79 | + rowsList -> { | |
80 | + try { | |
81 | + AggregationResult aggResult = new AggregationResult(); | |
82 | + for (List<Row> rs : rowsList) { | |
83 | + for (Row row : rs) { | |
84 | + processResultSetRow(row, aggResult); | |
85 | + } | |
75 | 86 | } |
87 | + return processAggregationResult(aggResult); | |
88 | + } catch (Exception e) { | |
89 | + log.error("[{}][{}][{}] Failed to aggregate data", key, ts, aggregation, e); | |
90 | + return Optional.empty(); | |
76 | 91 | } |
77 | - return processAggregationResult(aggResult); | |
78 | - } catch (Exception e) { | |
79 | - log.error("[{}][{}][{}] Failed to aggregate data", key, ts, aggregation, e); | |
80 | - return Optional.empty(); | |
81 | - } | |
92 | + }, this.executor); | |
82 | 93 | } |
83 | 94 | |
84 | 95 | private void processResultSetRow(Row row, AggregationResult aggResult) { |
... | ... | @@ -181,7 +192,7 @@ public class AggregatePartitionsFunction implements com.google.common.base.Funct |
181 | 192 | |
182 | 193 | private Boolean getBooleanValue(Row row) { |
183 | 194 | if (aggregation == Aggregation.MIN || aggregation == Aggregation.MAX) { |
184 | - return row.getBool(BOOL_POS); | |
195 | + return row.getBoolean(BOOL_POS); | |
185 | 196 | } else { |
186 | 197 | return null; //NOSONAR, null is used for further comparison |
187 | 198 | } | ... | ... |
... | ... | @@ -15,14 +15,14 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.timeseries; |
17 | 17 | |
18 | -import com.datastax.driver.core.BoundStatement; | |
19 | -import com.datastax.driver.core.PreparedStatement; | |
20 | -import com.datastax.driver.core.ResultSet; | |
21 | -import com.datastax.driver.core.ResultSetFuture; | |
22 | -import com.datastax.driver.core.Row; | |
23 | -import com.datastax.driver.core.Statement; | |
24 | -import com.datastax.driver.core.querybuilder.QueryBuilder; | |
25 | -import com.datastax.driver.core.querybuilder.Select; | |
18 | +import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | |
19 | +import com.datastax.oss.driver.api.core.cql.BoundStatement; | |
20 | +import com.datastax.oss.driver.api.core.cql.BoundStatementBuilder; | |
21 | +import com.datastax.oss.driver.api.core.cql.PreparedStatement; | |
22 | +import com.datastax.oss.driver.api.core.cql.Row; | |
23 | +import com.datastax.oss.driver.api.core.cql.Statement; | |
24 | +import com.datastax.oss.driver.api.querybuilder.QueryBuilder; | |
25 | +import com.datastax.oss.driver.api.querybuilder.select.Select; | |
26 | 26 | import com.google.common.base.Function; |
27 | 27 | import com.google.common.util.concurrent.AsyncFunction; |
28 | 28 | import com.google.common.util.concurrent.FutureCallback; |
... | ... | @@ -52,6 +52,8 @@ import org.thingsboard.server.common.data.kv.StringDataEntry; |
52 | 52 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
53 | 53 | import org.thingsboard.server.dao.model.ModelConstants; |
54 | 54 | import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao; |
55 | +import org.thingsboard.server.dao.nosql.TbResultSet; | |
56 | +import org.thingsboard.server.dao.nosql.TbResultSetFuture; | |
55 | 57 | import org.thingsboard.server.dao.util.NoSqlTsDao; |
56 | 58 | |
57 | 59 | import javax.annotation.Nullable; |
... | ... | @@ -69,7 +71,7 @@ import java.util.Optional; |
69 | 71 | import java.util.concurrent.ExecutionException; |
70 | 72 | import java.util.stream.Collectors; |
71 | 73 | |
72 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
74 | +import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; | |
73 | 75 | |
74 | 76 | /** |
75 | 77 | * @author Andrew Shvayka |
... | ... | @@ -189,8 +191,8 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
189 | 191 | if (isFixedPartitioning()) { //no need to fetch partitions from DB |
190 | 192 | return Futures.immediateFuture(FIXED_PARTITION); |
191 | 193 | } |
192 | - ResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition); | |
193 | - return Futures.transform(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor); | |
194 | + TbResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition); | |
195 | + return Futures.transformAsync(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor); | |
194 | 196 | } |
195 | 197 | |
196 | 198 | private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(TenantId tenantId, EntityId entityId, ReadTsKvQuery query) { |
... | ... | @@ -225,20 +227,41 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
225 | 227 | resultFuture.set(cursor.getData()); |
226 | 228 | } else { |
227 | 229 | PreparedStatement proto = getFetchStmt(Aggregation.NONE, cursor.getOrderBy()); |
228 | - BoundStatement stmt = proto.bind(); | |
229 | - stmt.setString(0, cursor.getEntityType()); | |
230 | - stmt.setUUID(1, cursor.getEntityId()); | |
231 | - stmt.setString(2, cursor.getKey()); | |
232 | - stmt.setLong(3, cursor.getNextPartition()); | |
233 | - stmt.setLong(4, cursor.getStartTs()); | |
234 | - stmt.setLong(5, cursor.getEndTs()); | |
235 | - stmt.setInt(6, cursor.getCurrentLimit()); | |
236 | - | |
237 | - Futures.addCallback(executeAsyncRead(tenantId, stmt), new FutureCallback<ResultSet>() { | |
230 | + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind()); | |
231 | + | |
232 | + stmtBuilder.setString(0, cursor.getEntityType()); | |
233 | + stmtBuilder.setUuid(1, cursor.getEntityId()); | |
234 | + stmtBuilder.setString(2, cursor.getKey()); | |
235 | + stmtBuilder.setLong(3, cursor.getNextPartition()); | |
236 | + stmtBuilder.setLong(4, cursor.getStartTs()); | |
237 | + stmtBuilder.setLong(5, cursor.getEndTs()); | |
238 | + stmtBuilder.setInt(6, cursor.getCurrentLimit()); | |
239 | + | |
240 | + BoundStatement stmt = stmtBuilder.build(); | |
241 | + | |
242 | + Futures.addCallback(executeAsyncRead(tenantId, stmt), new FutureCallback<TbResultSet>() { | |
238 | 243 | @Override |
239 | - public void onSuccess(@Nullable ResultSet result) { | |
240 | - cursor.addData(convertResultToTsKvEntryList(result == null ? Collections.emptyList() : result.all())); | |
241 | - findAllAsyncSequentiallyWithLimit(tenantId, cursor, resultFuture); | |
244 | + public void onSuccess(@Nullable TbResultSet result) { | |
245 | + if (result == null) { | |
246 | + cursor.addData(convertResultToTsKvEntryList(Collections.emptyList())); | |
247 | + findAllAsyncSequentiallyWithLimit(tenantId, cursor, resultFuture); | |
248 | + } else { | |
249 | + Futures.addCallback(result.allRows(readResultsProcessingExecutor), new FutureCallback<List<Row>>() { | |
250 | + | |
251 | + @Override | |
252 | + public void onSuccess(@Nullable List<Row> result) { | |
253 | + cursor.addData(convertResultToTsKvEntryList(result == null ? Collections.emptyList() : result)); | |
254 | + findAllAsyncSequentiallyWithLimit(tenantId, cursor, resultFuture); | |
255 | + } | |
256 | + | |
257 | + @Override | |
258 | + public void onFailure(Throwable t) { | |
259 | + log.error("[{}][{}] Failed to fetch data for query {}-{}", stmt, t); | |
260 | + } | |
261 | + }, readResultsProcessingExecutor); | |
262 | + | |
263 | + | |
264 | + } | |
242 | 265 | } |
243 | 266 | |
244 | 267 | @Override |
... | ... | @@ -256,31 +279,35 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
256 | 279 | final long endTs = query.getEndTs(); |
257 | 280 | final long ts = startTs + (endTs - startTs) / 2; |
258 | 281 | ListenableFuture<List<Long>> partitionsListFuture = getPartitionsFuture(tenantId, query, entityId, minPartition, maxPartition); |
259 | - ListenableFuture<List<ResultSet>> aggregationChunks = Futures.transformAsync(partitionsListFuture, | |
282 | + ListenableFuture<List<TbResultSet>> aggregationChunks = Futures.transformAsync(partitionsListFuture, | |
260 | 283 | getFetchChunksAsyncFunction(tenantId, entityId, key, aggregation, startTs, endTs), readResultsProcessingExecutor); |
261 | 284 | |
262 | - return Futures.transform(aggregationChunks, new AggregatePartitionsFunction(aggregation, key, ts), readResultsProcessingExecutor); | |
285 | + return Futures.transformAsync(aggregationChunks, new AggregatePartitionsFunction(aggregation, key, ts, readResultsProcessingExecutor), readResultsProcessingExecutor); | |
263 | 286 | } |
264 | 287 | |
265 | - private Function<ResultSet, List<Long>> getPartitionsArrayFunction() { | |
266 | - return rows -> rows.all().stream() | |
267 | - .map(row -> row.getLong(ModelConstants.PARTITION_COLUMN)).collect(Collectors.toList()); | |
288 | + private AsyncFunction<TbResultSet, List<Long>> getPartitionsArrayFunction() { | |
289 | + return rs -> | |
290 | + Futures.transform(rs.allRows(readResultsProcessingExecutor), rows -> | |
291 | + rows.stream() | |
292 | + .map(row -> row.getLong(ModelConstants.PARTITION_COLUMN)).collect(Collectors.toList()), | |
293 | + readResultsProcessingExecutor); | |
268 | 294 | } |
269 | 295 | |
270 | - private AsyncFunction<List<Long>, List<ResultSet>> getFetchChunksAsyncFunction(TenantId tenantId, EntityId entityId, String key, Aggregation aggregation, long startTs, long endTs) { | |
296 | + private AsyncFunction<List<Long>, List<TbResultSet>> getFetchChunksAsyncFunction(TenantId tenantId, EntityId entityId, String key, Aggregation aggregation, long startTs, long endTs) { | |
271 | 297 | return partitions -> { |
272 | 298 | try { |
273 | 299 | PreparedStatement proto = getFetchStmt(aggregation, DESC_ORDER); |
274 | - List<ResultSetFuture> futures = new ArrayList<>(partitions.size()); | |
300 | + List<TbResultSetFuture> futures = new ArrayList<>(partitions.size()); | |
275 | 301 | for (Long partition : partitions) { |
276 | 302 | log.trace("Fetching data for partition [{}] for entityType {} and entityId {}", partition, entityId.getEntityType(), entityId.getId()); |
277 | - BoundStatement stmt = proto.bind(); | |
278 | - stmt.setString(0, entityId.getEntityType().name()); | |
279 | - stmt.setUUID(1, entityId.getId()); | |
280 | - stmt.setString(2, key); | |
281 | - stmt.setLong(3, partition); | |
282 | - stmt.setLong(4, startTs); | |
283 | - stmt.setLong(5, endTs); | |
303 | + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind()); | |
304 | + stmtBuilder.setString(0, entityId.getEntityType().name()); | |
305 | + stmtBuilder.setUuid(1, entityId.getId()); | |
306 | + stmtBuilder.setString(2, key); | |
307 | + stmtBuilder.setLong(3, partition); | |
308 | + stmtBuilder.setLong(4, startTs); | |
309 | + stmtBuilder.setLong(5, endTs); | |
310 | + BoundStatement stmt = stmtBuilder.build(); | |
284 | 311 | log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId()); |
285 | 312 | futures.add(executeAsyncRead(tenantId, stmt)); |
286 | 313 | } |
... | ... | @@ -294,21 +321,23 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
294 | 321 | |
295 | 322 | @Override |
296 | 323 | public ListenableFuture<TsKvEntry> findLatest(TenantId tenantId, EntityId entityId, String key) { |
297 | - BoundStatement stmt = getFindLatestStmt().bind(); | |
298 | - stmt.setString(0, entityId.getEntityType().name()); | |
299 | - stmt.setUUID(1, entityId.getId()); | |
300 | - stmt.setString(2, key); | |
324 | + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(getFindLatestStmt().bind()); | |
325 | + stmtBuilder.setString(0, entityId.getEntityType().name()); | |
326 | + stmtBuilder.setUuid(1, entityId.getId()); | |
327 | + stmtBuilder.setString(2, key); | |
328 | + BoundStatement stmt = stmtBuilder.build(); | |
301 | 329 | log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId()); |
302 | 330 | return getFuture(executeAsyncRead(tenantId, stmt), rs -> convertResultToTsKvEntry(key, rs.one())); |
303 | 331 | } |
304 | 332 | |
305 | 333 | @Override |
306 | 334 | public ListenableFuture<List<TsKvEntry>> findAllLatest(TenantId tenantId, EntityId entityId) { |
307 | - BoundStatement stmt = getFindAllLatestStmt().bind(); | |
308 | - stmt.setString(0, entityId.getEntityType().name()); | |
309 | - stmt.setUUID(1, entityId.getId()); | |
335 | + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(getFindAllLatestStmt().bind()); | |
336 | + stmtBuilder.setString(0, entityId.getEntityType().name()); | |
337 | + stmtBuilder.setUuid(1, entityId.getId()); | |
338 | + BoundStatement stmt = stmtBuilder.build(); | |
310 | 339 | log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId()); |
311 | - return getFuture(executeAsyncRead(tenantId, stmt), rs -> convertResultToTsKvEntryList(rs.all())); | |
340 | + return getFutureAsync(executeAsyncRead(tenantId, stmt), rs -> convertAsyncResultSetToTsKvEntryList(rs)); | |
312 | 341 | } |
313 | 342 | |
314 | 343 | @Override |
... | ... | @@ -320,16 +349,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
320 | 349 | if (setNullValuesEnabled) { |
321 | 350 | processSetNullValues(tenantId, entityId, tsKvEntry, ttl, futures, partition, type); |
322 | 351 | } |
323 | - BoundStatement stmt = (ttl == 0 ? getSaveStmt(type) : getSaveTtlStmt(type)).bind(); | |
324 | - stmt.setString(0, entityId.getEntityType().name()) | |
325 | - .setUUID(1, entityId.getId()) | |
352 | + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder((ttl == 0 ? getSaveStmt(type) : getSaveTtlStmt(type)).bind()); | |
353 | + stmtBuilder.setString(0, entityId.getEntityType().name()) | |
354 | + .setUuid(1, entityId.getId()) | |
326 | 355 | .setString(2, tsKvEntry.getKey()) |
327 | 356 | .setLong(3, partition) |
328 | 357 | .setLong(4, tsKvEntry.getTs()); |
329 | - addValue(tsKvEntry, stmt, 5); | |
358 | + addValue(tsKvEntry, stmtBuilder, 5); | |
330 | 359 | if (ttl > 0) { |
331 | - stmt.setInt(6, (int) ttl); | |
360 | + stmtBuilder.setInt(6, (int) ttl); | |
332 | 361 | } |
362 | + BoundStatement stmt = stmtBuilder.build(); | |
333 | 363 | futures.add(getFuture(executeAsyncWrite(tenantId, stmt), rs -> null)); |
334 | 364 | return Futures.transform(Futures.allAsList(futures), result -> null, MoreExecutors.directExecutor()); |
335 | 365 | } |
... | ... | @@ -370,16 +400,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
370 | 400 | } |
371 | 401 | |
372 | 402 | private ListenableFuture<Void> saveNull(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry, long ttl, long partition, DataType type) { |
373 | - BoundStatement stmt = (ttl == 0 ? getSaveStmt(type) : getSaveTtlStmt(type)).bind(); | |
374 | - stmt.setString(0, entityId.getEntityType().name()) | |
375 | - .setUUID(1, entityId.getId()) | |
403 | + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder((ttl == 0 ? getSaveStmt(type) : getSaveTtlStmt(type)).bind()); | |
404 | + stmtBuilder.setString(0, entityId.getEntityType().name()) | |
405 | + .setUuid(1, entityId.getId()) | |
376 | 406 | .setString(2, tsKvEntry.getKey()) |
377 | 407 | .setLong(3, partition) |
378 | 408 | .setLong(4, tsKvEntry.getTs()); |
379 | - stmt.setToNull(getColumnName(type)); | |
409 | + stmtBuilder.setToNull(getColumnName(type)); | |
380 | 410 | if (ttl > 0) { |
381 | - stmt.setInt(6, (int) ttl); | |
411 | + stmtBuilder.setInt(6, (int) ttl); | |
382 | 412 | } |
413 | + BoundStatement stmt = stmtBuilder.build(); | |
383 | 414 | return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null); |
384 | 415 | } |
385 | 416 | |
... | ... | @@ -391,14 +422,15 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
391 | 422 | ttl = computeTtl(ttl); |
392 | 423 | long partition = toPartitionTs(tsKvEntryTs); |
393 | 424 | log.debug("Saving partition {} for the entity [{}-{}] and key {}", partition, entityId.getEntityType(), entityId.getId(), key); |
394 | - BoundStatement stmt = (ttl == 0 ? getPartitionInsertStmt() : getPartitionInsertTtlStmt()).bind(); | |
395 | - stmt = stmt.setString(0, entityId.getEntityType().name()) | |
396 | - .setUUID(1, entityId.getId()) | |
425 | + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder((ttl == 0 ? getPartitionInsertStmt() : getPartitionInsertTtlStmt()).bind()); | |
426 | + stmtBuilder.setString(0, entityId.getEntityType().name()) | |
427 | + .setUuid(1, entityId.getId()) | |
397 | 428 | .setLong(2, partition) |
398 | 429 | .setString(3, key); |
399 | 430 | if (ttl > 0) { |
400 | - stmt.setInt(4, (int) ttl); | |
431 | + stmtBuilder.setInt(4, (int) ttl); | |
401 | 432 | } |
433 | + BoundStatement stmt = stmtBuilder.build(); | |
402 | 434 | return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null); |
403 | 435 | } |
404 | 436 | |
... | ... | @@ -415,9 +447,9 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
415 | 447 | |
416 | 448 | @Override |
417 | 449 | public ListenableFuture<Void> saveLatest(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry) { |
418 | - BoundStatement stmt = getLatestStmt().bind() | |
419 | - .setString(0, entityId.getEntityType().name()) | |
420 | - .setUUID(1, entityId.getId()) | |
450 | + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(getLatestStmt().bind()); | |
451 | + stmtBuilder.setString(0, entityId.getEntityType().name()) | |
452 | + .setUuid(1, entityId.getId()) | |
421 | 453 | .setString(2, tsKvEntry.getKey()) |
422 | 454 | .setLong(3, tsKvEntry.getTs()) |
423 | 455 | .set(4, tsKvEntry.getBooleanValue().orElse(null), Boolean.class) |
... | ... | @@ -426,10 +458,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
426 | 458 | .set(7, tsKvEntry.getDoubleValue().orElse(null), Double.class); |
427 | 459 | Optional<String> jsonV = tsKvEntry.getJsonValue(); |
428 | 460 | if (jsonV.isPresent()) { |
429 | - stmt.setString(8, tsKvEntry.getJsonValue().get()); | |
461 | + stmtBuilder.setString(8, tsKvEntry.getJsonValue().get()); | |
430 | 462 | } else { |
431 | - stmt.setToNull(8); | |
463 | + stmtBuilder.setToNull(8); | |
432 | 464 | } |
465 | + BoundStatement stmt = stmtBuilder.build(); | |
433 | 466 | |
434 | 467 | return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null); |
435 | 468 | } |
... | ... | @@ -439,10 +472,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
439 | 472 | long minPartition = toPartitionTs(query.getStartTs()); |
440 | 473 | long maxPartition = toPartitionTs(query.getEndTs()); |
441 | 474 | |
442 | - ResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition); | |
475 | + TbResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition); | |
443 | 476 | |
444 | 477 | final SimpleListenableFuture<Void> resultFuture = new SimpleListenableFuture<>(); |
445 | - final ListenableFuture<List<Long>> partitionsListFuture = Futures.transform(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor); | |
478 | + final ListenableFuture<List<Long>> partitionsListFuture = Futures.transformAsync(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor); | |
446 | 479 | |
447 | 480 | Futures.addCallback(partitionsListFuture, new FutureCallback<List<Long>>() { |
448 | 481 | @Override |
... | ... | @@ -464,17 +497,19 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
464 | 497 | resultFuture.set(null); |
465 | 498 | } else { |
466 | 499 | PreparedStatement proto = getDeleteStmt(); |
467 | - BoundStatement stmt = proto.bind(); | |
468 | - stmt.setString(0, cursor.getEntityType()); | |
469 | - stmt.setUUID(1, cursor.getEntityId()); | |
470 | - stmt.setString(2, cursor.getKey()); | |
471 | - stmt.setLong(3, cursor.getNextPartition()); | |
472 | - stmt.setLong(4, cursor.getStartTs()); | |
473 | - stmt.setLong(5, cursor.getEndTs()); | |
474 | - | |
475 | - Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<ResultSet>() { | |
500 | + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind()); | |
501 | + stmtBuilder.setString(0, cursor.getEntityType()); | |
502 | + stmtBuilder.setUuid(1, cursor.getEntityId()); | |
503 | + stmtBuilder.setString(2, cursor.getKey()); | |
504 | + stmtBuilder.setLong(3, cursor.getNextPartition()); | |
505 | + stmtBuilder.setLong(4, cursor.getStartTs()); | |
506 | + stmtBuilder.setLong(5, cursor.getEndTs()); | |
507 | + | |
508 | + BoundStatement stmt = stmtBuilder.build(); | |
509 | + | |
510 | + Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<AsyncResultSet>() { | |
476 | 511 | @Override |
477 | - public void onSuccess(@Nullable ResultSet result) { | |
512 | + public void onSuccess(@Nullable AsyncResultSet result) { | |
478 | 513 | deleteAsync(tenantId, cursor, resultFuture); |
479 | 514 | } |
480 | 515 | |
... | ... | @@ -568,10 +603,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
568 | 603 | } |
569 | 604 | |
570 | 605 | private ListenableFuture<Void> deleteLatest(TenantId tenantId, EntityId entityId, String key) { |
571 | - Statement delete = QueryBuilder.delete().all().from(ModelConstants.TS_KV_LATEST_CF) | |
572 | - .where(eq(ModelConstants.ENTITY_TYPE_COLUMN, entityId.getEntityType())) | |
573 | - .and(eq(ModelConstants.ENTITY_ID_COLUMN, entityId.getId())) | |
574 | - .and(eq(ModelConstants.KEY_COLUMN, key)); | |
606 | + Statement delete = QueryBuilder.deleteFrom(ModelConstants.TS_KV_LATEST_CF) | |
607 | + .whereColumn(ModelConstants.ENTITY_TYPE_COLUMN).isEqualTo(literal(entityId.getEntityType().name())) | |
608 | + .whereColumn(ModelConstants.ENTITY_ID_COLUMN).isEqualTo(literal(entityId.getId())) | |
609 | + .whereColumn(ModelConstants.KEY_COLUMN).isEqualTo(literal(key)).build(); | |
575 | 610 | log.debug("Remove request: {}", delete.toString()); |
576 | 611 | return getFuture(executeAsyncWrite(tenantId, delete), rs -> null); |
577 | 612 | } |
... | ... | @@ -583,10 +618,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
583 | 618 | if (minPartition == maxPartition) { |
584 | 619 | return Futures.immediateFuture(null); |
585 | 620 | } else { |
586 | - ResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition); | |
621 | + TbResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition); | |
587 | 622 | |
588 | 623 | final SimpleListenableFuture<Void> resultFuture = new SimpleListenableFuture<>(); |
589 | - final ListenableFuture<List<Long>> partitionsListFuture = Futures.transform(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor); | |
624 | + final ListenableFuture<List<Long>> partitionsListFuture = Futures.transformAsync(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor); | |
590 | 625 | |
591 | 626 | Futures.addCallback(partitionsListFuture, new FutureCallback<List<Long>>() { |
592 | 627 | @Override |
... | ... | @@ -617,15 +652,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
617 | 652 | resultFuture.set(null); |
618 | 653 | } else { |
619 | 654 | PreparedStatement proto = getDeletePartitionStmt(); |
620 | - BoundStatement stmt = proto.bind(); | |
621 | - stmt.setString(0, cursor.getEntityType()); | |
622 | - stmt.setUUID(1, cursor.getEntityId()); | |
623 | - stmt.setLong(2, cursor.getNextPartition()); | |
624 | - stmt.setString(3, cursor.getKey()); | |
655 | + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind()); | |
656 | + stmtBuilder.setString(0, cursor.getEntityType()); | |
657 | + stmtBuilder.setUuid(1, cursor.getEntityId()); | |
658 | + stmtBuilder.setLong(2, cursor.getNextPartition()); | |
659 | + stmtBuilder.setString(3, cursor.getKey()); | |
625 | 660 | |
626 | - Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<ResultSet>() { | |
661 | + BoundStatement stmt = stmtBuilder.build(); | |
662 | + | |
663 | + Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<AsyncResultSet>() { | |
627 | 664 | @Override |
628 | - public void onSuccess(@Nullable ResultSet result) { | |
665 | + public void onSuccess(@Nullable AsyncResultSet result) { | |
629 | 666 | deletePartitionAsync(tenantId, cursor, resultFuture); |
630 | 667 | } |
631 | 668 | |
... | ... | @@ -648,6 +685,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
648 | 685 | return deletePartitionStmt; |
649 | 686 | } |
650 | 687 | |
688 | + private ListenableFuture<List<TsKvEntry>> convertAsyncResultSetToTsKvEntryList(TbResultSet rs) { | |
689 | + return Futures.transform(rs.allRows(readResultsProcessingExecutor), | |
690 | + rows -> this.convertResultToTsKvEntryList(rows), readResultsProcessingExecutor); | |
691 | + } | |
692 | + | |
651 | 693 | private List<TsKvEntry> convertResultToTsKvEntryList(List<Row> rows) { |
652 | 694 | List<TsKvEntry> entries = new ArrayList<>(rows.size()); |
653 | 695 | if (!rows.isEmpty()) { |
... | ... | @@ -706,12 +748,14 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
706 | 748 | * Select existing partitions from the table |
707 | 749 | * <code>{@link ModelConstants#TS_KV_PARTITIONS_CF}</code> for the given entity |
708 | 750 | */ |
709 | - private ResultSetFuture fetchPartitions(TenantId tenantId, EntityId entityId, String key, long minPartition, long maxPartition) { | |
710 | - Select.Where select = QueryBuilder.select(ModelConstants.PARTITION_COLUMN).from(ModelConstants.TS_KV_PARTITIONS_CF).where(eq(ModelConstants.ENTITY_TYPE_COLUMN, entityId.getEntityType().name())) | |
711 | - .and(eq(ModelConstants.ENTITY_ID_COLUMN, entityId.getId())).and(eq(ModelConstants.KEY_COLUMN, key)); | |
712 | - select.and(QueryBuilder.gte(ModelConstants.PARTITION_COLUMN, minPartition)); | |
713 | - select.and(QueryBuilder.lte(ModelConstants.PARTITION_COLUMN, maxPartition)); | |
714 | - return executeAsyncRead(tenantId, select); | |
751 | + private TbResultSetFuture fetchPartitions(TenantId tenantId, EntityId entityId, String key, long minPartition, long maxPartition) { | |
752 | + Select select = QueryBuilder.selectFrom(ModelConstants.TS_KV_PARTITIONS_CF).column(ModelConstants.PARTITION_COLUMN) | |
753 | + .whereColumn(ModelConstants.ENTITY_TYPE_COLUMN).isEqualTo(literal(entityId.getEntityType().name())) | |
754 | + .whereColumn(ModelConstants.ENTITY_ID_COLUMN).isEqualTo(literal(entityId.getId())) | |
755 | + .whereColumn(ModelConstants.KEY_COLUMN).isEqualTo(literal(key)) | |
756 | + .whereColumn(ModelConstants.PARTITION_COLUMN).isGreaterThanOrEqualTo(literal(minPartition)) | |
757 | + .whereColumn(ModelConstants.PARTITION_COLUMN).isLessThanOrEqualTo(literal(maxPartition)); | |
758 | + return executeAsyncRead(tenantId, select.build()); | |
715 | 759 | } |
716 | 760 | |
717 | 761 | private PreparedStatement getSaveStmt(DataType dataType) { |
... | ... | @@ -882,11 +926,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem |
882 | 926 | } |
883 | 927 | } |
884 | 928 | |
885 | - private static void addValue(KvEntry kvEntry, BoundStatement stmt, int column) { | |
929 | + private static void addValue(KvEntry kvEntry, BoundStatementBuilder stmt, int column) { | |
886 | 930 | switch (kvEntry.getDataType()) { |
887 | 931 | case BOOLEAN: |
888 | 932 | Optional<Boolean> booleanValue = kvEntry.getBooleanValue(); |
889 | - booleanValue.ifPresent(b -> stmt.setBool(column, b)); | |
933 | + booleanValue.ifPresent(b -> stmt.setBoolean(column, b)); | |
890 | 934 | break; |
891 | 935 | case STRING: |
892 | 936 | Optional<String> stringValue = kvEntry.getStrValue(); | ... | ... |
... | ... | @@ -15,7 +15,14 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.util; |
17 | 17 | |
18 | -import com.datastax.driver.core.*; | |
18 | +import com.datastax.oss.driver.api.core.ProtocolVersion; | |
19 | +import com.datastax.oss.driver.api.core.cql.BoundStatement; | |
20 | +import com.datastax.oss.driver.api.core.cql.ColumnDefinition; | |
21 | +import com.datastax.oss.driver.api.core.cql.ColumnDefinitions; | |
22 | +import com.datastax.oss.driver.api.core.cql.PreparedStatement; | |
23 | +import com.datastax.oss.driver.api.core.type.DataType; | |
24 | +import com.datastax.oss.driver.api.core.type.codec.TypeCodec; | |
25 | +import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; | |
19 | 26 | import com.google.common.util.concurrent.FutureCallback; |
20 | 27 | import com.google.common.util.concurrent.Futures; |
21 | 28 | import com.google.common.util.concurrent.ListenableFuture; |
... | ... | @@ -212,7 +219,7 @@ public abstract class AbstractBufferedRateExecutor<T extends AsyncTask, F extend |
212 | 219 | CassandraStatementTask cassStmtTask = (CassandraStatementTask) taskCtx.getTask(); |
213 | 220 | if (cassStmtTask.getStatement() instanceof BoundStatement) { |
214 | 221 | BoundStatement stmt = (BoundStatement) cassStmtTask.getStatement(); |
215 | - String query = stmt.preparedStatement().getQueryString(); | |
222 | + String query = stmt.getPreparedStatement().getQuery(); | |
216 | 223 | try { |
217 | 224 | query = toStringWithValues(stmt, ProtocolVersion.V5); |
218 | 225 | } catch (Exception e) { |
... | ... | @@ -225,16 +232,16 @@ public abstract class AbstractBufferedRateExecutor<T extends AsyncTask, F extend |
225 | 232 | } |
226 | 233 | |
227 | 234 | private static String toStringWithValues(BoundStatement boundStatement, ProtocolVersion protocolVersion) { |
228 | - CodecRegistry codecRegistry = boundStatement.preparedStatement().getCodecRegistry(); | |
229 | - PreparedStatement preparedStatement = boundStatement.preparedStatement(); | |
230 | - String query = preparedStatement.getQueryString(); | |
231 | - ColumnDefinitions defs = preparedStatement.getVariables(); | |
235 | + CodecRegistry codecRegistry = boundStatement.codecRegistry(); | |
236 | + PreparedStatement preparedStatement = boundStatement.getPreparedStatement(); | |
237 | + String query = preparedStatement.getQuery(); | |
238 | + ColumnDefinitions defs = preparedStatement.getVariableDefinitions(); | |
232 | 239 | int index = 0; |
233 | - for (ColumnDefinitions.Definition def : defs) { | |
240 | + for (ColumnDefinition def : defs) { | |
234 | 241 | DataType type = def.getType(); |
235 | 242 | TypeCodec<Object> codec = codecRegistry.codecFor(type); |
236 | 243 | if (boundStatement.getBytesUnsafe(index) != null) { |
237 | - Object value = codec.deserialize(boundStatement.getBytesUnsafe(index), protocolVersion); | |
244 | + Object value = codec.decode(boundStatement.getBytesUnsafe(index), protocolVersion); | |
238 | 245 | String replacement = Matcher.quoteReplacement(codec.format(value)); |
239 | 246 | query = query.replaceFirst("\\?", replacement); |
240 | 247 | } | ... | ... |
... | ... | @@ -15,8 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao; |
17 | 17 | |
18 | -import com.datastax.driver.core.Cluster; | |
19 | -import com.datastax.driver.core.Session; | |
18 | +import com.datastax.oss.driver.api.core.CqlSession; | |
20 | 19 | import org.cassandraunit.BaseCassandraUnit; |
21 | 20 | import org.cassandraunit.CQLDataLoader; |
22 | 21 | import org.cassandraunit.dataset.CQLDataSet; |
... | ... | @@ -27,8 +26,7 @@ import java.util.List; |
27 | 26 | public class CustomCassandraCQLUnit extends BaseCassandraUnit { |
28 | 27 | protected List<CQLDataSet> dataSets; |
29 | 28 | |
30 | - public Session session; | |
31 | - public Cluster cluster; | |
29 | + public CqlSession session; | |
32 | 30 | |
33 | 31 | public CustomCassandraCQLUnit(List<CQLDataSet> dataSets) { |
34 | 32 | this.dataSets = dataSets; |
... | ... | @@ -65,11 +63,7 @@ public class CustomCassandraCQLUnit extends BaseCassandraUnit { |
65 | 63 | |
66 | 64 | @Override |
67 | 65 | protected void load() { |
68 | - String hostIp = EmbeddedCassandraServerHelper.getHost(); | |
69 | - int port = EmbeddedCassandraServerHelper.getNativeTransportPort(); | |
70 | - cluster = new Cluster.Builder().addContactPoints(hostIp).withPort(port).withSocketOptions(getSocketOptions()) | |
71 | - .build(); | |
72 | - session = cluster.connect(); | |
66 | + session = EmbeddedCassandraServerHelper.getSession(); | |
73 | 67 | CQLDataLoader dataLoader = new CQLDataLoader(session); |
74 | 68 | dataSets.forEach(dataLoader::load); |
75 | 69 | session = dataLoader.getSession(); |
... | ... | @@ -79,20 +73,16 @@ public class CustomCassandraCQLUnit extends BaseCassandraUnit { |
79 | 73 | @Override |
80 | 74 | protected void after() { |
81 | 75 | super.after(); |
82 | - try (Cluster c = cluster; Session s = session) { | |
76 | + try (CqlSession s = session) { | |
83 | 77 | session = null; |
84 | - cluster = null; | |
85 | 78 | } |
86 | 79 | System.setSecurityManager(null); |
87 | 80 | } |
88 | 81 | |
89 | 82 | // Getters for those who do not like to directly access fields |
90 | 83 | |
91 | - public Session getSession() { | |
84 | + public CqlSession getSession() { | |
92 | 85 | return session; |
93 | 86 | } |
94 | 87 | |
95 | - public Cluster getCluster() { | |
96 | - return cluster; | |
97 | - } | |
98 | 88 | } | ... | ... |
... | ... | @@ -32,7 +32,7 @@ public class NoSqlDaoServiceTestSuite { |
32 | 32 | @ClassRule |
33 | 33 | public static CustomSqlUnit sqlUnit = new CustomSqlUnit( |
34 | 34 | Arrays.asList("sql/schema-entities-hsql.sql", "sql/schema-entities-idx.sql", "sql/system-data.sql", "sql/system-test.sql"), |
35 | - "sql/drop-all-tables.sql", | |
35 | + "sql/hsql/drop-all-tables.sql", | |
36 | 36 | "nosql-test.properties" |
37 | 37 | ); |
38 | 38 | ... | ... |
dao/src/test/java/org/thingsboard/server/dao/nosql/RateLimitedResultSetFutureTest.java
deleted
100644 → 0
1 | -/** | |
2 | - * Copyright © 2016-2020 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.nosql; | |
17 | - | |
18 | -import com.datastax.driver.core.ProtocolVersion; | |
19 | -import com.datastax.driver.core.ResultSet; | |
20 | -import com.datastax.driver.core.ResultSetFuture; | |
21 | -import com.datastax.driver.core.Row; | |
22 | -import com.datastax.driver.core.Session; | |
23 | -import com.datastax.driver.core.Statement; | |
24 | -import com.datastax.driver.core.exceptions.UnsupportedFeatureException; | |
25 | -import com.google.common.util.concurrent.Futures; | |
26 | -import com.google.common.util.concurrent.ListenableFuture; | |
27 | -import com.google.common.util.concurrent.MoreExecutors; | |
28 | -import org.junit.Test; | |
29 | -import org.junit.runner.RunWith; | |
30 | -import org.mockito.Mock; | |
31 | -import org.mockito.Mockito; | |
32 | -import org.mockito.runners.MockitoJUnitRunner; | |
33 | -import org.mockito.stubbing.Answer; | |
34 | -import org.thingsboard.server.dao.exception.BufferLimitException; | |
35 | -import org.thingsboard.server.dao.util.AsyncRateLimiter; | |
36 | - | |
37 | -import java.util.concurrent.CountDownLatch; | |
38 | -import java.util.concurrent.ExecutionException; | |
39 | -import java.util.concurrent.Executors; | |
40 | -import java.util.concurrent.TimeoutException; | |
41 | - | |
42 | -import static org.junit.Assert.assertSame; | |
43 | -import static org.junit.Assert.assertTrue; | |
44 | -import static org.junit.Assert.fail; | |
45 | -import static org.mockito.Mockito.times; | |
46 | -import static org.mockito.Mockito.verify; | |
47 | -import static org.mockito.Mockito.verifyNoMoreInteractions; | |
48 | -import static org.mockito.Mockito.when; | |
49 | - | |
50 | -@RunWith(MockitoJUnitRunner.class) | |
51 | -public class RateLimitedResultSetFutureTest { | |
52 | - | |
53 | - private RateLimitedResultSetFuture resultSetFuture; | |
54 | - | |
55 | - @Mock | |
56 | - private AsyncRateLimiter rateLimiter; | |
57 | - @Mock | |
58 | - private Session session; | |
59 | - @Mock | |
60 | - private Statement statement; | |
61 | - @Mock | |
62 | - private ResultSetFuture realFuture; | |
63 | - @Mock | |
64 | - private ResultSet rows; | |
65 | - @Mock | |
66 | - private Row row; | |
67 | - | |
68 | - @Test | |
69 | - public void doNotReleasePermissionIfRateLimitFutureFailed() throws InterruptedException { | |
70 | - when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFailedFuture(new BufferLimitException())); | |
71 | - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement); | |
72 | - Thread.sleep(1000L); | |
73 | - verify(rateLimiter).acquireAsync(); | |
74 | - try { | |
75 | - assertTrue(resultSetFuture.isDone()); | |
76 | - fail(); | |
77 | - } catch (Exception e) { | |
78 | - assertTrue(e instanceof IllegalStateException); | |
79 | - Throwable actualCause = e.getCause(); | |
80 | - assertTrue(actualCause instanceof ExecutionException); | |
81 | - } | |
82 | - verifyNoMoreInteractions(session, rateLimiter, statement); | |
83 | - | |
84 | - } | |
85 | - | |
86 | - @Test | |
87 | - public void getUninterruptiblyDelegateToCassandra() throws InterruptedException, ExecutionException { | |
88 | - when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFuture(null)); | |
89 | - when(session.executeAsync(statement)).thenReturn(realFuture); | |
90 | - Mockito.doAnswer((Answer<Void>) invocation -> { | |
91 | - Object[] args = invocation.getArguments(); | |
92 | - Runnable task = (Runnable) args[0]; | |
93 | - task.run(); | |
94 | - return null; | |
95 | - }).when(realFuture).addListener(Mockito.any(), Mockito.any()); | |
96 | - | |
97 | - when(realFuture.getUninterruptibly()).thenReturn(rows); | |
98 | - | |
99 | - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement); | |
100 | - ResultSet actual = resultSetFuture.getUninterruptibly(); | |
101 | - assertSame(rows, actual); | |
102 | - verify(rateLimiter, times(1)).acquireAsync(); | |
103 | - verify(rateLimiter, times(1)).release(); | |
104 | - } | |
105 | - | |
106 | - @Test | |
107 | - public void addListenerAllowsFutureTransformation() throws InterruptedException, ExecutionException { | |
108 | - when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFuture(null)); | |
109 | - when(session.executeAsync(statement)).thenReturn(realFuture); | |
110 | - Mockito.doAnswer((Answer<Void>) invocation -> { | |
111 | - Object[] args = invocation.getArguments(); | |
112 | - Runnable task = (Runnable) args[0]; | |
113 | - task.run(); | |
114 | - return null; | |
115 | - }).when(realFuture).addListener(Mockito.any(), Mockito.any()); | |
116 | - | |
117 | - when(realFuture.get()).thenReturn(rows); | |
118 | - when(rows.one()).thenReturn(row); | |
119 | - | |
120 | - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement); | |
121 | - | |
122 | - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor()); | |
123 | - Row actualRow = transform.get(); | |
124 | - | |
125 | - assertSame(row, actualRow); | |
126 | - verify(rateLimiter, times(1)).acquireAsync(); | |
127 | - verify(rateLimiter, times(1)).release(); | |
128 | - } | |
129 | - | |
130 | - @Test | |
131 | - public void immidiateCassandraExceptionReturnsPermit() throws InterruptedException, ExecutionException { | |
132 | - when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFuture(null)); | |
133 | - when(session.executeAsync(statement)).thenThrow(new UnsupportedFeatureException(ProtocolVersion.V3, "hjg")); | |
134 | - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement); | |
135 | - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor()); | |
136 | - try { | |
137 | - transform.get(); | |
138 | - fail(); | |
139 | - } catch (Exception e) { | |
140 | - assertTrue(e instanceof ExecutionException); | |
141 | - } | |
142 | - verify(rateLimiter, times(1)).acquireAsync(); | |
143 | - verify(rateLimiter, times(1)).release(); | |
144 | - } | |
145 | - | |
146 | - @Test | |
147 | - public void queryTimeoutReturnsPermit() throws InterruptedException, ExecutionException { | |
148 | - when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFuture(null)); | |
149 | - when(session.executeAsync(statement)).thenReturn(realFuture); | |
150 | - Mockito.doAnswer((Answer<Void>) invocation -> { | |
151 | - Object[] args = invocation.getArguments(); | |
152 | - Runnable task = (Runnable) args[0]; | |
153 | - task.run(); | |
154 | - return null; | |
155 | - }).when(realFuture).addListener(Mockito.any(), Mockito.any()); | |
156 | - | |
157 | - when(realFuture.get()).thenThrow(new ExecutionException("Fail", new TimeoutException("timeout"))); | |
158 | - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement); | |
159 | - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor()); | |
160 | - try { | |
161 | - transform.get(); | |
162 | - fail(); | |
163 | - } catch (Exception e) { | |
164 | - assertTrue(e instanceof ExecutionException); | |
165 | - } | |
166 | - verify(rateLimiter, times(1)).acquireAsync(); | |
167 | - verify(rateLimiter, times(1)).release(); | |
168 | - } | |
169 | - | |
170 | - @Test | |
171 | - public void expiredQueryReturnPermit() throws InterruptedException, ExecutionException { | |
172 | - CountDownLatch latch = new CountDownLatch(1); | |
173 | - ListenableFuture<Void> future = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1)).submit(() -> { | |
174 | - latch.await(); | |
175 | - return null; | |
176 | - }); | |
177 | - when(rateLimiter.acquireAsync()).thenReturn(future); | |
178 | - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement); | |
179 | - | |
180 | - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor()); | |
181 | -// TimeUnit.MILLISECONDS.sleep(200); | |
182 | - future.cancel(false); | |
183 | - latch.countDown(); | |
184 | - | |
185 | - try { | |
186 | - transform.get(); | |
187 | - fail(); | |
188 | - } catch (Exception e) { | |
189 | - assertTrue(e instanceof ExecutionException); | |
190 | - } | |
191 | - verify(rateLimiter, times(1)).acquireAsync(); | |
192 | - verify(rateLimiter, times(1)).release(); | |
193 | - } | |
194 | - | |
195 | -} | |
\ No newline at end of file |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
21 | 21 | import org.junit.runner.RunWith; |
... | ... | @@ -134,7 +134,7 @@ public abstract class AbstractServiceTest { |
134 | 134 | |
135 | 135 | protected Event generateEvent(TenantId tenantId, EntityId entityId, String eventType, String eventUid) throws IOException { |
136 | 136 | if (tenantId == null) { |
137 | - tenantId = new TenantId(UUIDs.timeBased()); | |
137 | + tenantId = new TenantId(Uuids.timeBased()); | |
138 | 138 | } |
139 | 139 | Event event = new Event(); |
140 | 140 | event.setTenantId(tenantId); | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.junit.After; |
20 | 20 | import org.junit.Assert; |
21 | 21 | import org.junit.Before; |
... | ... | @@ -59,8 +59,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { |
59 | 59 | |
60 | 60 | @Test |
61 | 61 | public void testSaveAndFetchAlarm() throws ExecutionException, InterruptedException { |
62 | - AssetId parentId = new AssetId(UUIDs.timeBased()); | |
63 | - AssetId childId = new AssetId(UUIDs.timeBased()); | |
62 | + AssetId parentId = new AssetId(Uuids.timeBased()); | |
63 | + AssetId childId = new AssetId(Uuids.timeBased()); | |
64 | 64 | |
65 | 65 | EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); |
66 | 66 | |
... | ... | @@ -96,8 +96,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { |
96 | 96 | |
97 | 97 | @Test |
98 | 98 | public void testFindAlarm() throws ExecutionException, InterruptedException { |
99 | - AssetId parentId = new AssetId(UUIDs.timeBased()); | |
100 | - AssetId childId = new AssetId(UUIDs.timeBased()); | |
99 | + AssetId parentId = new AssetId(Uuids.timeBased()); | |
100 | + AssetId childId = new AssetId(Uuids.timeBased()); | |
101 | 101 | |
102 | 102 | EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); |
103 | 103 | |
... | ... | @@ -197,8 +197,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { |
197 | 197 | |
198 | 198 | @Test |
199 | 199 | public void testDeleteAlarm() throws ExecutionException, InterruptedException { |
200 | - AssetId parentId = new AssetId(UUIDs.timeBased()); | |
201 | - AssetId childId = new AssetId(UUIDs.timeBased()); | |
200 | + AssetId parentId = new AssetId(Uuids.timeBased()); | |
201 | + AssetId childId = new AssetId(Uuids.timeBased()); | |
202 | 202 | |
203 | 203 | EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); |
204 | 204 | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.apache.commons.lang3.RandomStringUtils; |
20 | 20 | import org.junit.After; |
21 | 21 | import org.junit.Assert; |
... | ... | @@ -104,7 +104,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest { |
104 | 104 | Asset asset = new Asset(); |
105 | 105 | asset.setName("My asset"); |
106 | 106 | asset.setType("default"); |
107 | - asset.setTenantId(new TenantId(UUIDs.timeBased())); | |
107 | + asset.setTenantId(new TenantId(Uuids.timeBased())); | |
108 | 108 | assetService.saveAsset(asset); |
109 | 109 | } |
110 | 110 | |
... | ... | @@ -116,7 +116,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest { |
116 | 116 | asset.setTenantId(tenantId); |
117 | 117 | asset = assetService.saveAsset(asset); |
118 | 118 | try { |
119 | - assetService.assignAssetToCustomer(tenantId, asset.getId(), new CustomerId(UUIDs.timeBased())); | |
119 | + assetService.assignAssetToCustomer(tenantId, asset.getId(), new CustomerId(Uuids.timeBased())); | |
120 | 120 | } finally { |
121 | 121 | assetService.deleteAsset(tenantId, asset.getId()); |
122 | 122 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.apache.commons.lang3.RandomStringUtils; |
20 | 20 | import org.junit.After; |
21 | 21 | import org.junit.Assert; |
... | ... | @@ -105,7 +105,7 @@ public abstract class BaseCustomerServiceTest extends AbstractServiceTest { |
105 | 105 | public void testSaveCustomerWithInvalidTenant() { |
106 | 106 | Customer customer = new Customer(); |
107 | 107 | customer.setTitle("My customer"); |
108 | - customer.setTenantId(new TenantId(UUIDs.timeBased())); | |
108 | + customer.setTenantId(new TenantId(Uuids.timeBased())); | |
109 | 109 | customerService.saveCustomer(customer); |
110 | 110 | } |
111 | 111 | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.apache.commons.lang3.RandomStringUtils; |
20 | 20 | import org.junit.After; |
21 | 21 | import org.junit.Assert; |
... | ... | @@ -98,7 +98,7 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest { |
98 | 98 | public void testSaveDashboardWithInvalidTenant() { |
99 | 99 | Dashboard dashboard = new Dashboard(); |
100 | 100 | dashboard.setTitle("My dashboard"); |
101 | - dashboard.setTenantId(new TenantId(UUIDs.timeBased())); | |
101 | + dashboard.setTenantId(new TenantId(Uuids.timeBased())); | |
102 | 102 | dashboardService.saveDashboard(dashboard); |
103 | 103 | } |
104 | 104 | |
... | ... | @@ -109,7 +109,7 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest { |
109 | 109 | dashboard.setTenantId(tenantId); |
110 | 110 | dashboard = dashboardService.saveDashboard(dashboard); |
111 | 111 | try { |
112 | - dashboardService.assignDashboardToCustomer(tenantId, dashboard.getId(), new CustomerId(UUIDs.timeBased())); | |
112 | + dashboardService.assignDashboardToCustomer(tenantId, dashboard.getId(), new CustomerId(Uuids.timeBased())); | |
113 | 113 | } finally { |
114 | 114 | dashboardService.deleteDashboard(tenantId, dashboard.getId()); |
115 | 115 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.junit.After; |
20 | 20 | import org.junit.Assert; |
21 | 21 | import org.junit.Before; |
... | ... | @@ -109,7 +109,7 @@ public abstract class BaseDeviceCredentialsServiceTest extends AbstractServiceTe |
109 | 109 | device.setTenantId(tenantId); |
110 | 110 | device = deviceService.saveDevice(device); |
111 | 111 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId()); |
112 | - DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(UUIDs.timeBased())); | |
112 | + DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(Uuids.timeBased())); | |
113 | 113 | newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime()); |
114 | 114 | newDeviceCredentials.setDeviceId(deviceCredentials.getDeviceId()); |
115 | 115 | newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType()); |
... | ... | @@ -129,7 +129,7 @@ public abstract class BaseDeviceCredentialsServiceTest extends AbstractServiceTe |
129 | 129 | device.setTenantId(tenantId); |
130 | 130 | device = deviceService.saveDevice(device); |
131 | 131 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId()); |
132 | - deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased())); | |
132 | + deviceCredentials.setDeviceId(new DeviceId(Uuids.timeBased())); | |
133 | 133 | try { |
134 | 134 | deviceCredentialsService.updateDeviceCredentials(tenantId, deviceCredentials); |
135 | 135 | } finally { | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.apache.commons.lang3.RandomStringUtils; |
20 | 20 | import org.junit.After; |
21 | 21 | import org.junit.Assert; |
... | ... | @@ -110,7 +110,7 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest { |
110 | 110 | Device device = new Device(); |
111 | 111 | device.setName("My device"); |
112 | 112 | device.setType("default"); |
113 | - device.setTenantId(new TenantId(UUIDs.timeBased())); | |
113 | + device.setTenantId(new TenantId(Uuids.timeBased())); | |
114 | 114 | deviceService.saveDevice(device); |
115 | 115 | } |
116 | 116 | |
... | ... | @@ -122,7 +122,7 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest { |
122 | 122 | device.setTenantId(tenantId); |
123 | 123 | device = deviceService.saveDevice(device); |
124 | 124 | try { |
125 | - deviceService.assignDeviceToCustomer(tenantId, device.getId(), new CustomerId(UUIDs.timeBased())); | |
125 | + deviceService.assignDeviceToCustomer(tenantId, device.getId(), new CustomerId(Uuids.timeBased())); | |
126 | 126 | } finally { |
127 | 127 | deviceService.deleteDevice(tenantId, device.getId()); |
128 | 128 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.junit.After; |
20 | 20 | import org.junit.Assert; |
21 | 21 | import org.junit.Before; |
... | ... | @@ -47,8 +47,8 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
47 | 47 | |
48 | 48 | @Test |
49 | 49 | public void testSaveRelation() throws ExecutionException, InterruptedException { |
50 | - AssetId parentId = new AssetId(UUIDs.timeBased()); | |
51 | - AssetId childId = new AssetId(UUIDs.timeBased()); | |
50 | + AssetId parentId = new AssetId(Uuids.timeBased()); | |
51 | + AssetId childId = new AssetId(Uuids.timeBased()); | |
52 | 52 | |
53 | 53 | EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); |
54 | 54 | |
... | ... | @@ -65,9 +65,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
65 | 65 | |
66 | 66 | @Test |
67 | 67 | public void testDeleteRelation() throws ExecutionException, InterruptedException { |
68 | - AssetId parentId = new AssetId(UUIDs.timeBased()); | |
69 | - AssetId childId = new AssetId(UUIDs.timeBased()); | |
70 | - AssetId subChildId = new AssetId(UUIDs.timeBased()); | |
68 | + AssetId parentId = new AssetId(Uuids.timeBased()); | |
69 | + AssetId childId = new AssetId(Uuids.timeBased()); | |
70 | + AssetId subChildId = new AssetId(Uuids.timeBased()); | |
71 | 71 | |
72 | 72 | EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); |
73 | 73 | EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE); |
... | ... | @@ -86,9 +86,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
86 | 86 | |
87 | 87 | @Test |
88 | 88 | public void testDeleteEntityRelations() throws ExecutionException, InterruptedException { |
89 | - AssetId parentId = new AssetId(UUIDs.timeBased()); | |
90 | - AssetId childId = new AssetId(UUIDs.timeBased()); | |
91 | - AssetId subChildId = new AssetId(UUIDs.timeBased()); | |
89 | + AssetId parentId = new AssetId(Uuids.timeBased()); | |
90 | + AssetId childId = new AssetId(Uuids.timeBased()); | |
91 | + AssetId subChildId = new AssetId(Uuids.timeBased()); | |
92 | 92 | |
93 | 93 | EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); |
94 | 94 | EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE); |
... | ... | @@ -105,10 +105,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
105 | 105 | |
106 | 106 | @Test |
107 | 107 | public void testFindFrom() throws ExecutionException, InterruptedException { |
108 | - AssetId parentA = new AssetId(UUIDs.timeBased()); | |
109 | - AssetId parentB = new AssetId(UUIDs.timeBased()); | |
110 | - AssetId childA = new AssetId(UUIDs.timeBased()); | |
111 | - AssetId childB = new AssetId(UUIDs.timeBased()); | |
108 | + AssetId parentA = new AssetId(Uuids.timeBased()); | |
109 | + AssetId parentB = new AssetId(Uuids.timeBased()); | |
110 | + AssetId childA = new AssetId(Uuids.timeBased()); | |
111 | + AssetId childB = new AssetId(Uuids.timeBased()); | |
112 | 112 | |
113 | 113 | EntityRelation relationA1 = new EntityRelation(parentA, childA, EntityRelation.CONTAINS_TYPE); |
114 | 114 | EntityRelation relationA2 = new EntityRelation(parentA, childB, EntityRelation.CONTAINS_TYPE); |
... | ... | @@ -157,10 +157,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
157 | 157 | |
158 | 158 | @Test |
159 | 159 | public void testFindTo() throws ExecutionException, InterruptedException { |
160 | - AssetId parentA = new AssetId(UUIDs.timeBased()); | |
161 | - AssetId parentB = new AssetId(UUIDs.timeBased()); | |
162 | - AssetId childA = new AssetId(UUIDs.timeBased()); | |
163 | - AssetId childB = new AssetId(UUIDs.timeBased()); | |
160 | + AssetId parentA = new AssetId(Uuids.timeBased()); | |
161 | + AssetId parentB = new AssetId(Uuids.timeBased()); | |
162 | + AssetId childA = new AssetId(Uuids.timeBased()); | |
163 | + AssetId childB = new AssetId(Uuids.timeBased()); | |
164 | 164 | |
165 | 165 | EntityRelation relationA1 = new EntityRelation(parentA, childA, EntityRelation.CONTAINS_TYPE); |
166 | 166 | EntityRelation relationA2 = new EntityRelation(parentA, childB, EntityRelation.CONTAINS_TYPE); |
... | ... | @@ -207,9 +207,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
207 | 207 | @Test |
208 | 208 | public void testCyclicRecursiveRelation() throws ExecutionException, InterruptedException { |
209 | 209 | // A -> B -> C -> A |
210 | - AssetId assetA = new AssetId(UUIDs.timeBased()); | |
211 | - AssetId assetB = new AssetId(UUIDs.timeBased()); | |
212 | - AssetId assetC = new AssetId(UUIDs.timeBased()); | |
210 | + AssetId assetA = new AssetId(Uuids.timeBased()); | |
211 | + AssetId assetB = new AssetId(Uuids.timeBased()); | |
212 | + AssetId assetC = new AssetId(Uuids.timeBased()); | |
213 | 213 | |
214 | 214 | EntityRelation relationA = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE); |
215 | 215 | EntityRelation relationB = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE); |
... | ... | @@ -239,10 +239,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
239 | 239 | @Test |
240 | 240 | public void testRecursiveRelation() throws ExecutionException, InterruptedException { |
241 | 241 | // A -> B -> [C,D] |
242 | - AssetId assetA = new AssetId(UUIDs.timeBased()); | |
243 | - AssetId assetB = new AssetId(UUIDs.timeBased()); | |
244 | - AssetId assetC = new AssetId(UUIDs.timeBased()); | |
245 | - DeviceId deviceD = new DeviceId(UUIDs.timeBased()); | |
242 | + AssetId assetA = new AssetId(Uuids.timeBased()); | |
243 | + AssetId assetB = new AssetId(Uuids.timeBased()); | |
244 | + AssetId assetC = new AssetId(Uuids.timeBased()); | |
245 | + DeviceId deviceD = new DeviceId(Uuids.timeBased()); | |
246 | 246 | |
247 | 247 | EntityRelation relationAB = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE); |
248 | 248 | EntityRelation relationBC = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE); |
... | ... | @@ -272,7 +272,7 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
272 | 272 | @Test(expected = DataValidationException.class) |
273 | 273 | public void testSaveRelationWithEmptyFrom() throws ExecutionException, InterruptedException { |
274 | 274 | EntityRelation relation = new EntityRelation(); |
275 | - relation.setTo(new AssetId(UUIDs.timeBased())); | |
275 | + relation.setTo(new AssetId(Uuids.timeBased())); | |
276 | 276 | relation.setType(EntityRelation.CONTAINS_TYPE); |
277 | 277 | Assert.assertTrue(saveRelation(relation)); |
278 | 278 | } |
... | ... | @@ -280,7 +280,7 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
280 | 280 | @Test(expected = DataValidationException.class) |
281 | 281 | public void testSaveRelationWithEmptyTo() throws ExecutionException, InterruptedException { |
282 | 282 | EntityRelation relation = new EntityRelation(); |
283 | - relation.setFrom(new AssetId(UUIDs.timeBased())); | |
283 | + relation.setFrom(new AssetId(Uuids.timeBased())); | |
284 | 284 | relation.setType(EntityRelation.CONTAINS_TYPE); |
285 | 285 | Assert.assertTrue(saveRelation(relation)); |
286 | 286 | } |
... | ... | @@ -288,8 +288,8 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
288 | 288 | @Test(expected = DataValidationException.class) |
289 | 289 | public void testSaveRelationWithEmptyType() throws ExecutionException, InterruptedException { |
290 | 290 | EntityRelation relation = new EntityRelation(); |
291 | - relation.setFrom(new AssetId(UUIDs.timeBased())); | |
292 | - relation.setTo(new AssetId(UUIDs.timeBased())); | |
291 | + relation.setFrom(new AssetId(Uuids.timeBased())); | |
292 | + relation.setTo(new AssetId(Uuids.timeBased())); | |
293 | 293 | Assert.assertTrue(saveRelation(relation)); |
294 | 294 | } |
295 | 295 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | 20 | import org.apache.commons.lang3.RandomStringUtils; |
21 | 21 | import org.junit.After; |
... | ... | @@ -94,7 +94,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { |
94 | 94 | public void testSaveRuleChainWithInvalidTenant() { |
95 | 95 | RuleChain ruleChain = new RuleChain(); |
96 | 96 | ruleChain.setName("My RuleChain"); |
97 | - ruleChain.setTenantId(new TenantId(UUIDs.timeBased())); | |
97 | + ruleChain.setTenantId(new TenantId(Uuids.timeBased())); | |
98 | 98 | ruleChainService.saveRuleChain(ruleChain); |
99 | 99 | } |
100 | 100 | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
21 | 21 | import org.junit.After; |
... | ... | @@ -141,7 +141,7 @@ public abstract class BaseWidgetTypeServiceTest extends AbstractServiceTest { |
141 | 141 | WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle); |
142 | 142 | |
143 | 143 | WidgetType widgetType = new WidgetType(); |
144 | - widgetType.setTenantId(new TenantId(UUIDs.timeBased())); | |
144 | + widgetType.setTenantId(new TenantId(Uuids.timeBased())); | |
145 | 145 | widgetType.setBundleAlias(savedWidgetsBundle.getAlias()); |
146 | 146 | widgetType.setName("Widget Type"); |
147 | 147 | widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class)); | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.junit.After; |
20 | 20 | import org.junit.Assert; |
21 | 21 | import org.junit.Before; |
... | ... | @@ -88,7 +88,7 @@ public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest { |
88 | 88 | public void testSaveWidgetsBundleWithInvalidTenant() { |
89 | 89 | WidgetsBundle widgetsBundle = new WidgetsBundle(); |
90 | 90 | widgetsBundle.setTitle("My widgets bundle"); |
91 | - widgetsBundle.setTenantId(new TenantId(UUIDs.timeBased())); | |
91 | + widgetsBundle.setTenantId(new TenantId(Uuids.timeBased())); | |
92 | 92 | widgetsBundleService.saveWidgetsBundle(widgetsBundle); |
93 | 93 | } |
94 | 94 | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service.attributes; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.junit.Assert; |
20 | 20 | import org.junit.Before; |
21 | 21 | import org.junit.Test; |
... | ... | @@ -47,7 +47,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest { |
47 | 47 | |
48 | 48 | @Test |
49 | 49 | public void saveAndFetch() throws Exception { |
50 | - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | |
50 | + DeviceId deviceId = new DeviceId(Uuids.timeBased()); | |
51 | 51 | KvEntry attrValue = new StringDataEntry("attribute1", "value1"); |
52 | 52 | AttributeKvEntry attr = new BaseAttributeKvEntry(attrValue, 42L); |
53 | 53 | attributesService.save(SYSTEM_TENANT_ID, deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attr)).get(); |
... | ... | @@ -58,7 +58,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest { |
58 | 58 | |
59 | 59 | @Test |
60 | 60 | public void saveMultipleTypeAndFetch() throws Exception { |
61 | - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | |
61 | + DeviceId deviceId = new DeviceId(Uuids.timeBased()); | |
62 | 62 | KvEntry attrOldValue = new StringDataEntry("attribute1", "value1"); |
63 | 63 | AttributeKvEntry attrOld = new BaseAttributeKvEntry(attrOldValue, 42L); |
64 | 64 | |
... | ... | @@ -78,7 +78,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest { |
78 | 78 | |
79 | 79 | @Test |
80 | 80 | public void findAll() throws Exception { |
81 | - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | |
81 | + DeviceId deviceId = new DeviceId(Uuids.timeBased()); | |
82 | 82 | |
83 | 83 | KvEntry attrAOldValue = new StringDataEntry("A", "value1"); |
84 | 84 | AttributeKvEntry attrAOld = new BaseAttributeKvEntry(attrAOldValue, 42L); | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service.event; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import org.junit.Assert; |
20 | 20 | import org.junit.Test; |
21 | 21 | import org.thingsboard.server.common.data.DataConstants; |
... | ... | @@ -40,8 +40,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest { |
40 | 40 | |
41 | 41 | @Test |
42 | 42 | public void saveEvent() throws Exception { |
43 | - DeviceId devId = new DeviceId(UUIDs.timeBased()); | |
44 | - Event event = generateEvent(null, devId, "ALARM", UUIDs.timeBased().toString()); | |
43 | + DeviceId devId = new DeviceId(Uuids.timeBased()); | |
44 | + Event event = generateEvent(null, devId, "ALARM", Uuids.timeBased().toString()); | |
45 | 45 | Event saved = eventService.save(event); |
46 | 46 | Optional<Event> loaded = eventService.findEvent(event.getTenantId(), event.getEntityId(), event.getType(), event.getUid()); |
47 | 47 | Assert.assertTrue(loaded.isPresent()); |
... | ... | @@ -51,8 +51,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest { |
51 | 51 | |
52 | 52 | @Test |
53 | 53 | public void saveEventIfNotExists() throws Exception { |
54 | - DeviceId devId = new DeviceId(UUIDs.timeBased()); | |
55 | - Event event = generateEvent(null, devId, "ALARM", UUIDs.timeBased().toString()); | |
54 | + DeviceId devId = new DeviceId(Uuids.timeBased()); | |
55 | + Event event = generateEvent(null, devId, "ALARM", Uuids.timeBased().toString()); | |
56 | 56 | Optional<Event> saved = eventService.saveIfNotExists(event); |
57 | 57 | Assert.assertTrue(saved.isPresent()); |
58 | 58 | saved = eventService.saveIfNotExists(event); |
... | ... | @@ -67,8 +67,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest { |
67 | 67 | long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC); |
68 | 68 | long timeAfterEndTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC); |
69 | 69 | |
70 | - CustomerId customerId = new CustomerId(UUIDs.timeBased()); | |
71 | - TenantId tenantId = new TenantId(UUIDs.timeBased()); | |
70 | + CustomerId customerId = new CustomerId(Uuids.timeBased()); | |
71 | + TenantId tenantId = new TenantId(Uuids.timeBased()); | |
72 | 72 | saveEventWithProvidedTime(timeBeforeStartTime, customerId, tenantId); |
73 | 73 | Event savedEvent = saveEventWithProvidedTime(eventTime, customerId, tenantId); |
74 | 74 | Event savedEvent2 = saveEventWithProvidedTime(eventTime+1, customerId, tenantId); |
... | ... | @@ -102,8 +102,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest { |
102 | 102 | long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC); |
103 | 103 | long timeAfterEndTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC); |
104 | 104 | |
105 | - CustomerId customerId = new CustomerId(UUIDs.timeBased()); | |
106 | - TenantId tenantId = new TenantId(UUIDs.timeBased()); | |
105 | + CustomerId customerId = new CustomerId(Uuids.timeBased()); | |
106 | + TenantId tenantId = new TenantId(Uuids.timeBased()); | |
107 | 107 | saveEventWithProvidedTime(timeBeforeStartTime, customerId, tenantId); |
108 | 108 | Event savedEvent = saveEventWithProvidedTime(eventTime, customerId, tenantId); |
109 | 109 | Event savedEvent2 = saveEventWithProvidedTime(eventTime+1, customerId, tenantId); |
... | ... | @@ -131,7 +131,7 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest { |
131 | 131 | |
132 | 132 | private Event saveEventWithProvidedTime(long time, EntityId entityId, TenantId tenantId) throws IOException { |
133 | 133 | Event event = generateEvent(tenantId, entityId, DataConstants.STATS, null); |
134 | - event.setId(new EventId(UUIDs.startOf(time))); | |
134 | + event.setId(new EventId(Uuids.startOf(time))); | |
135 | 135 | return eventService.save(event); |
136 | 136 | } |
137 | -} | |
\ No newline at end of file | ||
137 | +} | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service.timeseries; |
17 | 17 | |
18 | -import com.datastax.driver.core.utils.UUIDs; | |
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | 20 | import org.junit.*; |
21 | 21 | import org.thingsboard.server.common.data.EntityView; |
... | ... | @@ -84,7 +84,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { |
84 | 84 | |
85 | 85 | @Test |
86 | 86 | public void testFindAllLatest() throws Exception { |
87 | - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | |
87 | + DeviceId deviceId = new DeviceId(Uuids.timeBased()); | |
88 | 88 | |
89 | 89 | saveEntries(deviceId, TS - 2); |
90 | 90 | saveEntries(deviceId, TS - 1); |
... | ... | @@ -132,7 +132,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { |
132 | 132 | |
133 | 133 | @Test |
134 | 134 | public void testFindLatest() throws Exception { |
135 | - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | |
135 | + DeviceId deviceId = new DeviceId(Uuids.timeBased()); | |
136 | 136 | |
137 | 137 | saveEntries(deviceId, TS - 2); |
138 | 138 | saveEntries(deviceId, TS - 1); |
... | ... | @@ -151,7 +151,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { |
151 | 151 | |
152 | 152 | @Test |
153 | 153 | public void testFindByQueryAscOrder() throws Exception { |
154 | - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | |
154 | + DeviceId deviceId = new DeviceId(Uuids.timeBased()); | |
155 | 155 | |
156 | 156 | saveEntries(deviceId, TS - 2); |
157 | 157 | saveEntries(deviceId, TS - 1); |
... | ... | @@ -177,7 +177,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { |
177 | 177 | |
178 | 178 | @Test |
179 | 179 | public void testFindByQueryDescOrder() throws Exception { |
180 | - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | |
180 | + DeviceId deviceId = new DeviceId(Uuids.timeBased()); | |
181 | 181 | |
182 | 182 | saveEntries(deviceId, TS - 2); |
183 | 183 | saveEntries(deviceId, TS - 1); |
... | ... | @@ -203,7 +203,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { |
203 | 203 | |
204 | 204 | @Test |
205 | 205 | public void testDeleteDeviceTsDataWithOverwritingLatest() throws Exception { |
206 | - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | |
206 | + DeviceId deviceId = new DeviceId(Uuids.timeBased()); | |
207 | 207 | |
208 | 208 | saveEntries(deviceId, 10000); |
209 | 209 | saveEntries(deviceId, 20000); |
... | ... | @@ -223,7 +223,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { |
223 | 223 | |
224 | 224 | @Test |
225 | 225 | public void testFindDeviceTsData() throws Exception { |
226 | - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | |
226 | + DeviceId deviceId = new DeviceId(Uuids.timeBased()); | |
227 | 227 | List<TsKvEntry> entries = new ArrayList<>(); |
228 | 228 | |
229 | 229 | entries.add(save(deviceId, 5000, 100)); |
... | ... | @@ -374,7 +374,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { |
374 | 374 | |
375 | 375 | @Test |
376 | 376 | public void testFindDeviceLongAndDoubleTsData() throws Exception { |
377 | - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | |
377 | + DeviceId deviceId = new DeviceId(Uuids.timeBased()); | |
378 | 378 | List<TsKvEntry> entries = new ArrayList<>(); |
379 | 379 | |
380 | 380 | entries.add(save(deviceId, 5000, 100)); | ... | ... |