Commit 76300e400e1e1882c69780eb1d1959071cb8446c

Authored by Igor Kulikov
1 parent b81370b6

Update Cassandra Driver

Showing 109 changed files with 1316 additions and 1481 deletions
@@ -111,6 +111,10 @@ @@ -111,6 +111,10 @@
111 <groupId>org.slf4j</groupId> 111 <groupId>org.slf4j</groupId>
112 <artifactId>slf4j-log4j12</artifactId> 112 <artifactId>slf4j-log4j12</artifactId>
113 </exclusion> 113 </exclusion>
  114 + <exclusion>
  115 + <groupId>org.hibernate</groupId>
  116 + <artifactId>hibernate-validator</artifactId>
  117 + </exclusion>
114 </exclusions> 118 </exclusions>
115 <scope>test</scope> 119 <scope>test</scope>
116 </dependency> 120 </dependency>
@@ -241,6 +245,12 @@ @@ -241,6 +245,12 @@
241 <groupId>org.springframework.boot</groupId> 245 <groupId>org.springframework.boot</groupId>
242 <artifactId>spring-boot-starter-test</artifactId> 246 <artifactId>spring-boot-starter-test</artifactId>
243 <scope>test</scope> 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 </dependency> 254 </dependency>
245 <dependency> 255 <dependency>
246 <groupId>org.springframework.security</groupId> 256 <groupId>org.springframework.security</groupId>
@@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
16 package org.thingsboard.server.actors.ruleChain; 16 package org.thingsboard.server.actors.ruleChain;
17 17
18 import akka.actor.ActorRef; 18 import akka.actor.ActorRef;
19 -import com.datastax.driver.core.ResultSetFuture;  
20 import com.fasterxml.jackson.core.JsonProcessingException; 19 import com.fasterxml.jackson.core.JsonProcessingException;
21 import com.fasterxml.jackson.databind.ObjectMapper; 20 import com.fasterxml.jackson.databind.ObjectMapper;
22 import io.netty.channel.EventLoopGroup; 21 import io.netty.channel.EventLoopGroup;
@@ -53,6 +52,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService; @@ -53,6 +52,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService;
53 import org.thingsboard.server.dao.device.DeviceService; 52 import org.thingsboard.server.dao.device.DeviceService;
54 import org.thingsboard.server.dao.entityview.EntityViewService; 53 import org.thingsboard.server.dao.entityview.EntityViewService;
55 import org.thingsboard.server.dao.nosql.CassandraStatementTask; 54 import org.thingsboard.server.dao.nosql.CassandraStatementTask;
  55 +import org.thingsboard.server.dao.nosql.TbResultSetFuture;
56 import org.thingsboard.server.dao.relation.RelationService; 56 import org.thingsboard.server.dao.relation.RelationService;
57 import org.thingsboard.server.dao.rule.RuleChainService; 57 import org.thingsboard.server.dao.rule.RuleChainService;
58 import org.thingsboard.server.dao.tenant.TenantService; 58 import org.thingsboard.server.dao.tenant.TenantService;
@@ -405,7 +405,7 @@ class DefaultTbContext implements TbContext { @@ -405,7 +405,7 @@ class DefaultTbContext implements TbContext {
405 } 405 }
406 406
407 @Override 407 @Override
408 - public ResultSetFuture submitCassandraTask(CassandraStatementTask task) { 408 + public TbResultSetFuture submitCassandraTask(CassandraStatementTask task) {
409 return mainCtx.getCassandraBufferedRateExecutor().submit(task); 409 return mainCtx.getCassandraBufferedRateExecutor().submit(task);
410 } 410 }
411 411
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.controller; 16 package org.thingsboard.server.controller;
17 17
18 -import com.datastax.driver.core.utils.UUIDs;  
19 import com.fasterxml.jackson.core.type.TypeReference; 18 import com.fasterxml.jackson.core.type.TypeReference;
20 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
21 import com.fasterxml.jackson.databind.ObjectMapper; 20 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.service.install; 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 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
20 import org.springframework.context.annotation.Profile; 20 import org.springframework.context.annotation.Profile;
21 import org.springframework.stereotype.Service; 21 import org.springframework.stereotype.Service;
@@ -15,25 +15,27 @@ @@ -15,25 +15,27 @@
15 */ 15 */
16 package org.thingsboard.server.service.install.cql; 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 import org.apache.commons.csv.CSVFormat; 28 import org.apache.commons.csv.CSVFormat;
29 import org.apache.commons.csv.CSVParser; 29 import org.apache.commons.csv.CSVParser;
30 import org.apache.commons.csv.CSVPrinter; 30 import org.apache.commons.csv.CSVPrinter;
31 import org.apache.commons.csv.CSVRecord; 31 import org.apache.commons.csv.CSVRecord;
  32 +import org.thingsboard.server.dao.cassandra.guava.GuavaSession;
32 33
33 import java.io.IOException; 34 import java.io.IOException;
34 import java.nio.file.Files; 35 import java.nio.file.Files;
35 import java.nio.file.Path; 36 import java.nio.file.Path;
36 import java.nio.file.StandardCopyOption; 37 import java.nio.file.StandardCopyOption;
  38 +import java.time.Instant;
37 import java.util.ArrayList; 39 import java.util.ArrayList;
38 import java.util.Date; 40 import java.util.Date;
39 import java.util.Iterator; 41 import java.util.Iterator;
@@ -44,12 +46,12 @@ import static org.thingsboard.server.service.install.DatabaseHelper.CSV_DUMP_FOR @@ -44,12 +46,12 @@ import static org.thingsboard.server.service.install.DatabaseHelper.CSV_DUMP_FOR
44 46
45 public class CassandraDbHelper { 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 String[] columns, String[] defaultValues, String dumpPrefix) throws Exception { 50 String[] columns, String[] defaultValues, String dumpPrefix) throws Exception {
49 return dumpCfIfExists(ks, session, cfName, columns, defaultValues, dumpPrefix, false); 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 String[] columns, String[] defaultValues, String dumpPrefix, boolean printHeader) throws Exception { 55 String[] columns, String[] defaultValues, String dumpPrefix, boolean printHeader) throws Exception {
54 if (ks.getTable(cfName) != null) { 56 if (ks.getTable(cfName) != null) {
55 Path dumpFile = Files.createTempFile(dumpPrefix, null); 57 Path dumpFile = Files.createTempFile(dumpPrefix, null);
@@ -59,8 +61,8 @@ public class CassandraDbHelper { @@ -59,8 +61,8 @@ public class CassandraDbHelper {
59 csvFormat = csvFormat.withHeader(columns); 61 csvFormat = csvFormat.withHeader(columns);
60 } 62 }
61 try (CSVPrinter csvPrinter = new CSVPrinter(Files.newBufferedWriter(dumpFile), csvFormat)) { 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 ResultSet rs = session.execute(stmt); 66 ResultSet rs = session.execute(stmt);
65 Iterator<Row> iter = rs.iterator(); 67 Iterator<Row> iter = rs.iterator();
66 while (iter.hasNext()) { 68 while (iter.hasNext()) {
@@ -95,12 +97,12 @@ public class CassandraDbHelper { @@ -95,12 +97,12 @@ public class CassandraDbHelper {
95 Files.move(tmp, targetDumpFile, StandardCopyOption.REPLACE_EXISTING); 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 loadCf(ks, session, cfName, columns, sourceFile, false); 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 PreparedStatement prepared = session.prepare(createInsertStatement(cfName, columns)); 106 PreparedStatement prepared = session.prepare(createInsertStatement(cfName, columns));
105 CSVFormat csvFormat = CSV_DUMP_FORMAT; 107 CSVFormat csvFormat = CSV_DUMP_FORMAT;
106 if (parseHeader) { 108 if (parseHeader) {
@@ -110,11 +112,11 @@ public class CassandraDbHelper { @@ -110,11 +112,11 @@ public class CassandraDbHelper {
110 } 112 }
111 try (CSVParser csvParser = new CSVParser(Files.newBufferedReader(sourceFile), csvFormat)) { 113 try (CSVParser csvParser = new CSVParser(Files.newBufferedReader(sourceFile), csvFormat)) {
112 csvParser.forEach(record -> { 114 csvParser.forEach(record -> {
113 - BoundStatement boundStatement = prepared.bind(); 115 + BoundStatementBuilder boundStatementBuilder = new BoundStatementBuilder(prepared.bind());
114 for (String column : columns) { 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,27 +138,27 @@ public class CassandraDbHelper {
136 } 138 }
137 139
138 private static String getColumnValue(String column, String defaultValue, Row row) { 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 if (index > -1) { 142 if (index > -1) {
141 String str; 143 String str;
142 - DataType type = row.getColumnDefinitions().getType(index); 144 + DataType type = row.getColumnDefinitions().get(index).getType();
143 try { 145 try {
144 if (row.isNull(index)) { 146 if (row.isNull(index)) {
145 return null; 147 return null;
146 - } else if (type == DataType.cdouble()) { 148 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.DOUBLE) {
147 str = new Double(row.getDouble(index)).toString(); 149 str = new Double(row.getDouble(index)).toString();
148 - } else if (type == DataType.cint()) { 150 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.INT) {
149 str = new Integer(row.getInt(index)).toString(); 151 str = new Integer(row.getInt(index)).toString();
150 - } else if (type == DataType.bigint()) { 152 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.BIGINT) {
151 str = new Long(row.getLong(index)).toString(); 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 str = new Float(row.getFloat(index)).toString(); 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 } else { 162 } else {
161 str = row.getString(index); 163 str = row.getString(index);
162 } 164 }
@@ -186,27 +188,27 @@ public class CassandraDbHelper { @@ -186,27 +188,27 @@ public class CassandraDbHelper {
186 } 188 }
187 189
188 private static void setColumnValue(TableMetadata tableMetadata, String column, 190 private static void setColumnValue(TableMetadata tableMetadata, String column,
189 - CSVRecord record, BoundStatement boundStatement) { 191 + CSVRecord record, BoundStatementBuilder boundStatementBuilder) {
190 String value = record.get(column); 192 String value = record.get(column);
191 - DataType type = tableMetadata.getColumn(column).getType(); 193 + DataType type = tableMetadata.getColumn(column).get().getType();
192 if (value == null) { 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 } else { 210 } else {
209 - boundStatement.setString(column, value); 211 + boundStatementBuilder.setString(column, value);
210 } 212 }
211 } 213 }
212 214
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.service.install.migrate; 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 import lombok.Data; 19 import lombok.Data;
20 import org.thingsboard.server.common.data.UUIDConverter; 20 import org.thingsboard.server.common.data.UUIDConverter;
21 21
@@ -105,7 +105,7 @@ public class CassandraToSqlColumn { @@ -105,7 +105,7 @@ public class CassandraToSqlColumn {
105 } else { 105 } else {
106 switch (this.type) { 106 switch (this.type) {
107 case ID: 107 case ID:
108 - return UUIDConverter.fromTimeUUID(row.getUUID(index)); 108 + return UUIDConverter.fromTimeUUID(row.getUuid(index));
109 case DOUBLE: 109 case DOUBLE:
110 return Double.toString(row.getDouble(index)); 110 return Double.toString(row.getDouble(index));
111 case INTEGER: 111 case INTEGER:
@@ -115,7 +115,7 @@ public class CassandraToSqlColumn { @@ -115,7 +115,7 @@ public class CassandraToSqlColumn {
115 case BIGINT: 115 case BIGINT:
116 return Long.toString(row.getLong(index)); 116 return Long.toString(row.getLong(index));
117 case BOOLEAN: 117 case BOOLEAN:
118 - return Boolean.toString(row.getBool(index)); 118 + return Boolean.toString(row.getBoolean(index));
119 case STRING: 119 case STRING:
120 case JSON: 120 case JSON:
121 case ENUM_TO_INT: 121 case ENUM_TO_INT:
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.service.install.migrate; 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 import java.util.UUID; 20 import java.util.UUID;
21 21
@@ -29,7 +29,7 @@ public class CassandraToSqlEventTsColumn extends CassandraToSqlColumn { @@ -29,7 +29,7 @@ public class CassandraToSqlEventTsColumn extends CassandraToSqlColumn {
29 29
30 @Override 30 @Override
31 public String getColumnValue(Row row) { 31 public String getColumnValue(Row row) {
32 - UUID id = row.getUUID(getIndex()); 32 + UUID id = row.getUuid(getIndex());
33 long ts = getTs(id); 33 long ts = getTs(id);
34 return ts + ""; 34 return ts + "";
35 } 35 }
@@ -37,4 +37,4 @@ public class CassandraToSqlEventTsColumn extends CassandraToSqlColumn { @@ -37,4 +37,4 @@ public class CassandraToSqlEventTsColumn extends CassandraToSqlColumn {
37 private long getTs(UUID uuid) { 37 private long getTs(UUID uuid) {
38 return (uuid.timestamp() - EPOCH_DIFF) / 10000; 38 return (uuid.timestamp() - EPOCH_DIFF) / 10000;
39 } 39 }
40 -}  
  40 +}
@@ -15,20 +15,17 @@ @@ -15,20 +15,17 @@
15 */ 15 */
16 package org.thingsboard.server.service.install.migrate; 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 import lombok.Data; 22 import lombok.Data;
24 import lombok.extern.slf4j.Slf4j; 23 import lombok.extern.slf4j.Slf4j;
25 -import org.hibernate.exception.ConstraintViolationException;  
26 import org.hibernate.internal.util.JdbcExceptionHelper; 24 import org.hibernate.internal.util.JdbcExceptionHelper;
27 import org.postgresql.util.PSQLException; 25 import org.postgresql.util.PSQLException;
28 import org.thingsboard.server.common.data.UUIDConverter; 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 import java.sql.Connection; 29 import java.sql.Connection;
33 import java.sql.DatabaseMetaData; 30 import java.sql.DatabaseMetaData;
34 import java.sql.PreparedStatement; 31 import java.sql.PreparedStatement;
@@ -38,7 +35,6 @@ import java.util.Arrays; @@ -38,7 +35,6 @@ import java.util.Arrays;
38 import java.util.Iterator; 35 import java.util.Iterator;
39 import java.util.List; 36 import java.util.List;
40 import java.util.Optional; 37 import java.util.Optional;
41 -import java.util.stream.Collectors;  
42 38
43 @Data 39 @Data
44 @Slf4j 40 @Slf4j
@@ -78,7 +74,7 @@ public class CassandraToSqlTable { @@ -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 log.info("[{}] Migrating data from cassandra '{}' Column Family to '{}' SQL table...", this.sqlTableName, this.cassandraCf, this.sqlTableName); 78 log.info("[{}] Migrating data from cassandra '{}' Column Family to '{}' SQL table...", this.sqlTableName, this.cassandraCf, this.sqlTableName);
83 DatabaseMetaData metadata = conn.getMetaData(); 79 DatabaseMetaData metadata = conn.getMetaData();
84 java.sql.ResultSet resultSet = metadata.getColumns(null, null, this.sqlTableName, null); 80 java.sql.ResultSet resultSet = metadata.getColumns(null, null, this.sqlTableName, null);
@@ -92,7 +88,7 @@ public class CassandraToSqlTable { @@ -92,7 +88,7 @@ public class CassandraToSqlTable {
92 } 88 }
93 this.sqlInsertStatement = createSqlInsertStatement(conn); 89 this.sqlInsertStatement = createSqlInsertStatement(conn);
94 Statement cassandraSelectStatement = createCassandraSelectStatement(); 90 Statement cassandraSelectStatement = createCassandraSelectStatement();
95 - cassandraSelectStatement.setFetchSize(100); 91 + cassandraSelectStatement.setPageSize(100);
96 ResultSet rs = session.execute(cassandraSelectStatement); 92 ResultSet rs = session.execute(cassandraSelectStatement);
97 Iterator<Row> iter = rs.iterator(); 93 Iterator<Row> iter = rs.iterator();
98 int rowCounter = 0; 94 int rowCounter = 0;
@@ -281,7 +277,7 @@ public class CassandraToSqlTable { @@ -281,7 +277,7 @@ public class CassandraToSqlTable {
281 } 277 }
282 selectStatementBuilder.deleteCharAt(selectStatementBuilder.length() - 1); 278 selectStatementBuilder.deleteCharAt(selectStatementBuilder.length() - 1);
283 selectStatementBuilder.append(" FROM ").append(cassandraCf); 279 selectStatementBuilder.append(" FROM ").append(cassandraCf);
284 - return new SimpleStatement(selectStatementBuilder.toString()); 280 + return SimpleStatement.newInstance(selectStatementBuilder.toString());
285 } 281 }
286 282
287 private PreparedStatement createSqlInsertStatement(Connection conn) throws SQLException { 283 private PreparedStatement createSqlInsertStatement(Connection conn) throws SQLException {
@@ -178,7 +178,7 @@ cassandra: @@ -178,7 +178,7 @@ cassandra:
178 # Enable/disable JMX 178 # Enable/disable JMX
179 jmx: "${CASSANDRA_USE_JMX:true}" 179 jmx: "${CASSANDRA_USE_JMX:true}"
180 # Enable/disable metrics collection. 180 # Enable/disable metrics collection.
181 - metrics: "${CASSANDRA_DISABLE_METRICS:true}" 181 + metrics: "${CASSANDRA_USE_METRICS:true}"
182 # NONE SNAPPY LZ4 182 # NONE SNAPPY LZ4
183 compression: "${CASSANDRA_COMPRESSION:none}" 183 compression: "${CASSANDRA_COMPRESSION:none}"
184 # Specify cassandra cluster initialization timeout in milliseconds (if no hosts available during startup) 184 # Specify cassandra cluster initialization timeout in milliseconds (if no hosts available during startup)
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.controller; 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 import com.fasterxml.jackson.core.type.TypeReference; 19 import com.fasterxml.jackson.core.type.TypeReference;
20 import org.apache.commons.lang3.RandomStringUtils; 20 import org.apache.commons.lang3.RandomStringUtils;
21 import org.junit.After; 21 import org.junit.After;
@@ -206,7 +206,7 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest { @@ -206,7 +206,7 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
206 asset.setType("default"); 206 asset.setType("default");
207 Asset savedAsset = doPost("/api/asset", asset, Asset.class); 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 + "/asset/" + savedAsset.getId().getId().toString()) 210 + "/asset/" + savedAsset.getId().getId().toString())
211 .andExpect(status().isNotFound()); 211 .andExpect(status().isNotFound());
212 } 212 }
@@ -24,7 +24,7 @@ import java.util.ArrayList; @@ -24,7 +24,7 @@ import java.util.ArrayList;
24 import java.util.Collections; 24 import java.util.Collections;
25 import java.util.List; 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 import org.apache.commons.lang3.RandomStringUtils; 28 import org.apache.commons.lang3.RandomStringUtils;
29 import org.thingsboard.server.common.data.*; 29 import org.thingsboard.server.common.data.*;
30 import org.thingsboard.server.common.data.id.CustomerId; 30 import org.thingsboard.server.common.data.id.CustomerId;
@@ -158,7 +158,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest @@ -158,7 +158,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
158 dashboard.setTitle("My dashboard"); 158 dashboard.setTitle("My dashboard");
159 Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); 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 + "/dashboard/" + savedDashboard.getId().getId().toString()) 162 + "/dashboard/" + savedDashboard.getId().getId().toString())
163 .andExpect(status().isNotFound()); 163 .andExpect(status().isNotFound());
164 } 164 }
@@ -23,7 +23,7 @@ import java.util.ArrayList; @@ -23,7 +23,7 @@ import java.util.ArrayList;
23 import java.util.Collections; 23 import java.util.Collections;
24 import java.util.List; 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 import org.apache.commons.lang3.RandomStringUtils; 27 import org.apache.commons.lang3.RandomStringUtils;
28 import org.thingsboard.server.common.data.*; 28 import org.thingsboard.server.common.data.*;
29 import org.thingsboard.server.common.data.id.CustomerId; 29 import org.thingsboard.server.common.data.id.CustomerId;
@@ -215,7 +215,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { @@ -215,7 +215,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
215 device.setType("default"); 215 device.setType("default");
216 Device savedDevice = doPost("/api/device", device, Device.class); 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 + "/device/" + savedDevice.getId().getId().toString()) 219 + "/device/" + savedDevice.getId().getId().toString())
220 .andExpect(status().isNotFound()); 220 .andExpect(status().isNotFound());
221 } 221 }
@@ -333,7 +333,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { @@ -333,7 +333,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
333 Device savedDevice = doPost("/api/device", device, Device.class); 333 Device savedDevice = doPost("/api/device", device, Device.class);
334 DeviceCredentials deviceCredentials = 334 DeviceCredentials deviceCredentials =
335 doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); 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 newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime()); 337 newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime());
338 newDeviceCredentials.setDeviceId(deviceCredentials.getDeviceId()); 338 newDeviceCredentials.setDeviceId(deviceCredentials.getDeviceId());
339 newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType()); 339 newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType());
@@ -351,7 +351,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { @@ -351,7 +351,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
351 Device savedDevice = doPost("/api/device", device, Device.class); 351 Device savedDevice = doPost("/api/device", device, Device.class);
352 DeviceCredentials deviceCredentials = 352 DeviceCredentials deviceCredentials =
353 doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); 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 doPost("/api/device/credentials", deviceCredentials) 355 doPost("/api/device/credentials", deviceCredentials)
356 .andExpect(status().isNotFound()); 356 .andExpect(status().isNotFound());
357 } 357 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.controller; 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 import com.fasterxml.jackson.core.type.TypeReference; 19 import com.fasterxml.jackson.core.type.TypeReference;
20 import lombok.extern.slf4j.Slf4j; 20 import lombok.extern.slf4j.Slf4j;
21 import org.apache.commons.lang3.RandomStringUtils; 21 import org.apache.commons.lang3.RandomStringUtils;
@@ -176,7 +176,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes @@ -176,7 +176,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
176 @Test 176 @Test
177 public void testAssignEntityViewToNonExistentCustomer() throws Exception { 177 public void testAssignEntityViewToNonExistentCustomer() throws Exception {
178 EntityView savedView = getNewSavedEntityView("Test entity view"); 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 .andExpect(status().isNotFound()); 180 .andExpect(status().isNotFound());
181 } 181 }
182 182
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.mqtt.rpc; 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 import io.netty.handler.codec.mqtt.MqttQoS; 19 import io.netty.handler.codec.mqtt.MqttQoS;
20 import lombok.extern.slf4j.Slf4j; 20 import lombok.extern.slf4j.Slf4j;
21 import org.apache.commons.lang3.StringUtils; 21 import org.apache.commons.lang3.StringUtils;
@@ -143,7 +143,7 @@ public abstract class AbstractMqttServerSideRpcIntegrationTest extends AbstractC @@ -143,7 +143,7 @@ public abstract class AbstractMqttServerSideRpcIntegrationTest extends AbstractC
143 @Test 143 @Test
144 public void testServerMqttOneWayRpcDeviceDoesNotExist() throws Exception { 144 public void testServerMqttOneWayRpcDeviceDoesNotExist() throws Exception {
145 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"25\",\"value\": 1}}"; 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 String result = doPostAsync("/api/plugins/rpc/oneway/" + nonExistentDeviceId, setGpioRequest, String.class, 148 String result = doPostAsync("/api/plugins/rpc/oneway/" + nonExistentDeviceId, setGpioRequest, String.class,
149 status().isNotFound()); 149 status().isNotFound());
@@ -200,7 +200,7 @@ public abstract class AbstractMqttServerSideRpcIntegrationTest extends AbstractC @@ -200,7 +200,7 @@ public abstract class AbstractMqttServerSideRpcIntegrationTest extends AbstractC
200 @Test 200 @Test
201 public void testServerMqttTwoWayRpcDeviceDoesNotExist() throws Exception { 201 public void testServerMqttTwoWayRpcDeviceDoesNotExist() throws Exception {
202 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"28\",\"value\": 1}}"; 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 String result = doPostAsync("/api/plugins/rpc/twoway/" + nonExistentDeviceId, setGpioRequest, String.class, 205 String result = doPostAsync("/api/plugins/rpc/twoway/" + nonExistentDeviceId, setGpioRequest, String.class,
206 status().isNotFound()); 206 status().isNotFound());
@@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
16 package org.thingsboard.server.rules.flow; 16 package org.thingsboard.server.rules.flow;
17 17
18 import akka.actor.ActorRef; 18 import akka.actor.ActorRef;
19 -import com.datastax.driver.core.utils.UUIDs;  
20 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
21 import org.junit.After; 20 import org.junit.After;
22 import org.junit.Assert; 21 import org.junit.Assert;
@@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
16 package org.thingsboard.server.rules.lifecycle; 16 package org.thingsboard.server.rules.lifecycle;
17 17
18 import akka.actor.ActorRef; 18 import akka.actor.ActorRef;
19 -import com.datastax.driver.core.utils.UUIDs;  
20 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
21 import org.junit.After; 20 import org.junit.After;
22 import org.junit.Assert; 21 import org.junit.Assert;
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.service.cluster.routing; 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 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
20 import org.junit.Assert; 20 import org.junit.Assert;
21 import org.junit.Before; 21 import org.junit.Before;
@@ -101,7 +101,7 @@ public class HashPartitionServiceTest { @@ -101,7 +101,7 @@ public class HashPartitionServiceTest {
101 public void testDispersionOnMillionDevices() { 101 public void testDispersionOnMillionDevices() {
102 List<DeviceId> devices = new ArrayList<>(); 102 List<DeviceId> devices = new ArrayList<>();
103 for (int i = 0; i < ITERATIONS; i++) { 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 testDevicesDispersion(devices); 106 testDevicesDispersion(devices);
107 } 107 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.service.script; 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 import com.google.common.collect.Sets; 19 import com.google.common.collect.Sets;
20 import org.junit.After; 20 import org.junit.After;
21 import org.junit.Before; 21 import org.junit.Before;
@@ -41,7 +41,7 @@ public class RuleNodeJsScriptEngineTest { @@ -41,7 +41,7 @@ public class RuleNodeJsScriptEngineTest {
41 private ScriptEngine scriptEngine; 41 private ScriptEngine scriptEngine;
42 private TestNashornJsInvokeService jsSandboxService; 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 @Before 46 @Before
47 public void beforeTest() throws Exception { 47 public void beforeTest() throws Exception {
@@ -247,4 +247,4 @@ public class RuleNodeJsScriptEngineTest { @@ -247,4 +247,4 @@ public class RuleNodeJsScriptEngineTest {
247 } 247 }
248 } 248 }
249 249
250 -}  
  250 +}
@@ -78,18 +78,13 @@ @@ -78,18 +78,13 @@
78 <scope>provided</scope> 78 <scope>provided</scope>
79 </dependency> 79 </dependency>
80 <dependency> 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 <scope>provided</scope> 83 <scope>provided</scope>
84 </dependency> 84 </dependency>
85 <dependency> 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 <scope>provided</scope> 88 <scope>provided</scope>
94 </dependency> 89 </dependency>
95 <dependency> 90 <dependency>
@@ -16,117 +16,50 @@ @@ -16,117 +16,50 @@
16 package org.thingsboard.server.dao.cassandra; 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 import lombok.extern.slf4j.Slf4j; 22 import lombok.extern.slf4j.Slf4j;
31 -import org.apache.commons.lang3.StringUtils;  
32 import org.springframework.beans.factory.annotation.Autowired; 23 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.beans.factory.annotation.Value; 24 import org.springframework.beans.factory.annotation.Value;
34 import org.springframework.core.env.Environment; 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 import javax.annotation.PreDestroy; 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 @Slf4j 32 @Slf4j
43 public abstract class AbstractCassandraCluster { 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 @Value("${cassandra.jmx}") 35 @Value("${cassandra.jmx}")
57 private Boolean jmx; 36 private Boolean jmx;
58 @Value("${cassandra.metrics}") 37 @Value("${cassandra.metrics}")
59 private Boolean metrics; 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 @Autowired 40 @Autowired
76 - private CassandraSocketOptions socketOpts;  
77 -  
78 - @Autowired  
79 - private CassandraQueryOptions queryOpts; 41 + private CassandraDriverOptions driverOptions;
80 42
81 @Autowired 43 @Autowired
82 private Environment environment; 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 private String keyspaceName; 52 private String keyspaceName;
96 53
97 protected void init(String keyspaceName) { 54 protected void init(String keyspaceName) {
98 this.keyspaceName = keyspaceName; 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 if (!isInstall()) { 57 if (!isInstall()) {
121 initSession(); 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 if (!isInstall()) { 63 if (!isInstall()) {
131 return session; 64 return session;
132 } else { 65 } else {
@@ -146,64 +79,40 @@ public abstract class AbstractCassandraCluster { @@ -146,64 +79,40 @@ public abstract class AbstractCassandraCluster {
146 } 79 }
147 80
148 private void initSession() { 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 @PreDestroy 100 @PreDestroy
180 public void close() { 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 public ConsistencyLevel getDefaultReadConsistencyLevel() { 110 public ConsistencyLevel getDefaultReadConsistencyLevel() {
202 - return queryOpts.getDefaultReadConsistencyLevel(); 111 + return driverOptions.getDefaultReadConsistencyLevel();
203 } 112 }
204 113
205 public ConsistencyLevel getDefaultWriteConsistencyLevel() { 114 public ConsistencyLevel getDefaultWriteConsistencyLevel() {
206 - return queryOpts.getDefaultWriteConsistencyLevel(); 115 + return driverOptions.getDefaultWriteConsistencyLevel();
207 } 116 }
208 117
209 } 118 }
  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 +}
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 -}  
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,15 +13,14 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 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 }
  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,15 +13,39 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 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 }
  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,15 +13,10 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 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,10 +15,10 @@ @@ -15,10 +15,10 @@
15 */ 15 */
16 package org.thingsboard.server.dao.nosql; 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;
20 import lombok.Data; 19 import lombok.Data;
21 import org.thingsboard.server.common.data.id.TenantId; 20 import org.thingsboard.server.common.data.id.TenantId;
  21 +import org.thingsboard.server.dao.cassandra.guava.GuavaSession;
22 import org.thingsboard.server.dao.util.AsyncTask; 22 import org.thingsboard.server.dao.util.AsyncTask;
23 23
24 /** 24 /**
@@ -28,7 +28,7 @@ import org.thingsboard.server.dao.util.AsyncTask; @@ -28,7 +28,7 @@ import org.thingsboard.server.dao.util.AsyncTask;
28 public class CassandraStatementTask implements AsyncTask { 28 public class CassandraStatementTask implements AsyncTask {
29 29
30 private final TenantId tenantId; 30 private final TenantId tenantId;
31 - private final Session session; 31 + private final GuavaSession session;
32 private final Statement statement; 32 private final Statement statement;
33 33
34 } 34 }
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,8 +15,8 @@
15 */ 15 */
16 package org.thingsboard.server.dao.nosql; 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 import com.google.common.util.concurrent.SettableFuture; 20 import com.google.common.util.concurrent.SettableFuture;
21 21
22 import java.util.concurrent.ExecutionException; 22 import java.util.concurrent.ExecutionException;
@@ -27,21 +27,19 @@ import java.util.concurrent.TimeoutException; @@ -27,21 +27,19 @@ import java.util.concurrent.TimeoutException;
27 /** 27 /**
28 * Created by ashvayka on 24.10.18. 28 * Created by ashvayka on 24.10.18.
29 */ 29 */
30 -public class TbResultSetFuture implements ResultSetFuture { 30 +public class TbResultSetFuture implements ListenableFuture<AsyncResultSet> {
31 31
32 - private final SettableFuture<ResultSet> mainFuture; 32 + private final SettableFuture<AsyncResultSet> mainFuture;
33 33
34 - public TbResultSetFuture(SettableFuture<ResultSet> mainFuture) { 34 + public TbResultSetFuture(SettableFuture<AsyncResultSet> mainFuture) {
35 this.mainFuture = mainFuture; 35 this.mainFuture = mainFuture;
36 } 36 }
37 37
38 - @Override  
39 - public ResultSet getUninterruptibly() { 38 + public AsyncResultSet getUninterruptibly() {
40 return getSafe(); 39 return getSafe();
41 } 40 }
42 41
43 - @Override  
44 - public ResultSet getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException { 42 + public AsyncResultSet getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException {
45 return getSafe(timeout, unit); 43 return getSafe(timeout, unit);
46 } 44 }
47 45
@@ -61,12 +59,12 @@ public class TbResultSetFuture implements ResultSetFuture { @@ -61,12 +59,12 @@ public class TbResultSetFuture implements ResultSetFuture {
61 } 59 }
62 60
63 @Override 61 @Override
64 - public ResultSet get() throws InterruptedException, ExecutionException { 62 + public AsyncResultSet get() throws InterruptedException, ExecutionException {
65 return mainFuture.get(); 63 return mainFuture.get();
66 } 64 }
67 65
68 @Override 66 @Override
69 - public ResultSet get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { 67 + public AsyncResultSet get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
70 return mainFuture.get(timeout, unit); 68 return mainFuture.get(timeout, unit);
71 } 69 }
72 70
@@ -75,7 +73,7 @@ public class TbResultSetFuture implements ResultSetFuture { @@ -75,7 +73,7 @@ public class TbResultSetFuture implements ResultSetFuture {
75 mainFuture.addListener(listener, executor); 73 mainFuture.addListener(listener, executor);
76 } 74 }
77 75
78 - private ResultSet getSafe() { 76 + private AsyncResultSet getSafe() {
79 try { 77 try {
80 return mainFuture.get(); 78 return mainFuture.get();
81 } catch (InterruptedException | ExecutionException e) { 79 } catch (InterruptedException | ExecutionException e) {
@@ -83,7 +81,7 @@ public class TbResultSetFuture implements ResultSetFuture { @@ -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 AsyncResultSet getSafe(long timeout, TimeUnit unit) throws TimeoutException {
87 try { 85 try {
88 return mainFuture.get(timeout, unit); 86 return mainFuture.get(timeout, unit);
89 } catch (InterruptedException | ExecutionException e) { 87 } catch (InterruptedException | ExecutionException e) {
@@ -67,8 +67,8 @@ @@ -67,8 +67,8 @@
67 <scope>test</scope> 67 <scope>test</scope>
68 </dependency> 68 </dependency>
69 <dependency> 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 <scope>test</scope> 72 <scope>test</scope>
73 </dependency> 73 </dependency>
74 </dependencies> 74 </dependencies>
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.common.data; 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 import org.junit.Assert; 19 import org.junit.Assert;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.junit.runner.RunWith; 21 import org.junit.runner.RunWith;
@@ -61,8 +61,8 @@ public class UUIDConverterTest { @@ -61,8 +61,8 @@ public class UUIDConverterTest {
61 before = tmp; 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 if (afterStr.compareTo(beforeStr) < 0) { 67 if (afterStr.compareTo(beforeStr) < 0) {
68 System.out.println("Before: " + before + " | " + beforeStr); 68 System.out.println("Before: " + before + " | " + beforeStr);
@@ -120,18 +120,18 @@ @@ -120,18 +120,18 @@
120 <groupId>org.springframework.security</groupId> 120 <groupId>org.springframework.security</groupId>
121 <artifactId>spring-security-oauth2-client</artifactId> 121 <artifactId>spring-security-oauth2-client</artifactId>
122 </dependency> 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 <dependency> 135 <dependency>
136 <groupId>io.takari.junit</groupId> 136 <groupId>io.takari.junit</groupId>
137 <artifactId>takari-cpsuite</artifactId> 137 <artifactId>takari-cpsuite</artifactId>
@@ -149,6 +149,10 @@ @@ -149,6 +149,10 @@
149 <groupId>org.slf4j</groupId> 149 <groupId>org.slf4j</groupId>
150 <artifactId>slf4j-log4j12</artifactId> 150 <artifactId>slf4j-log4j12</artifactId>
151 </exclusion> 151 </exclusion>
  152 + <exclusion>
  153 + <groupId>org.hibernate</groupId>
  154 + <artifactId>hibernate-validator</artifactId>
  155 + </exclusion>
152 </exclusions> 156 </exclusions>
153 <scope>test</scope> 157 <scope>test</scope>
154 </dependency> 158 </dependency>
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao; 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 import org.springframework.data.domain.Page; 19 import org.springframework.data.domain.Page;
20 import org.springframework.data.domain.PageRequest; 20 import org.springframework.data.domain.PageRequest;
21 import org.springframework.data.domain.Pageable; 21 import org.springframework.data.domain.Pageable;
@@ -49,7 +49,7 @@ public abstract class DaoUtil { @@ -49,7 +49,7 @@ public abstract class DaoUtil {
49 49
50 public static String startTimeToId(Long startTime) { 50 public static String startTimeToId(Long startTime) {
51 if (startTime != null) { 51 if (startTime != null) {
52 - UUID startOf = UUIDs.startOf(startTime); 52 + UUID startOf = Uuids.startOf(startTime);
53 return UUIDConverter.fromTimeUUID(startOf); 53 return UUIDConverter.fromTimeUUID(startOf);
54 } else { 54 } else {
55 return null; 55 return null;
@@ -58,7 +58,7 @@ public abstract class DaoUtil { @@ -58,7 +58,7 @@ public abstract class DaoUtil {
58 58
59 public static String endTimeToId(Long endTime) { 59 public static String endTimeToId(Long endTime) {
60 if (endTime != null) { 60 if (endTime != null) {
61 - UUID endOf = UUIDs.endOf(endTime); 61 + UUID endOf = Uuids.endOf(endTime);
62 return UUIDConverter.fromTimeUUID(endOf); 62 return UUIDConverter.fromTimeUUID(endOf);
63 } else { 63 } else {
64 return null; 64 return null;
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.audit; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import com.fasterxml.jackson.databind.ObjectMapper; 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import com.fasterxml.jackson.databind.node.ArrayNode; 21 import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -296,7 +296,7 @@ public class AuditLogServiceImpl implements AuditLogService { @@ -296,7 +296,7 @@ public class AuditLogServiceImpl implements AuditLogService {
296 ActionStatus actionStatus, 296 ActionStatus actionStatus,
297 String actionFailureDetails) { 297 String actionFailureDetails) {
298 AuditLog result = new AuditLog(); 298 AuditLog result = new AuditLog();
299 - result.setId(new AuditLogId(UUIDs.timeBased())); 299 + result.setId(new AuditLogId(Uuids.timeBased()));
300 result.setTenantId(tenantId); 300 result.setTenantId(tenantId);
301 result.setEntityId(entityId); 301 result.setEntityId(entityId);
302 result.setEntityName(entityName); 302 result.setEntityName(entityName);
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,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model; 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 import org.apache.commons.lang3.ArrayUtils; 19 import org.apache.commons.lang3.ArrayUtils;
20 import org.thingsboard.server.common.data.UUIDConverter; 20 import org.thingsboard.server.common.data.UUIDConverter;
21 import org.thingsboard.server.common.data.id.TenantId; 21 import org.thingsboard.server.common.data.id.TenantId;
@@ -28,7 +28,7 @@ public class ModelConstants { @@ -28,7 +28,7 @@ public class ModelConstants {
28 private ModelConstants() { 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 public static final String NULL_UUID_STR = UUIDConverter.fromTimeUUID(NULL_UUID); 32 public static final String NULL_UUID_STR = UUIDConverter.fromTimeUUID(NULL_UUID);
33 public static final TenantId SYSTEM_TENANT = new TenantId(ModelConstants.NULL_UUID); 33 public static final TenantId SYSTEM_TENANT = new TenantId(ModelConstants.NULL_UUID);
34 34
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -154,7 +154,7 @@ public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity @@ -154,7 +154,7 @@ public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity
154 154
155 protected Alarm toAlarm() { 155 protected Alarm toAlarm() {
156 Alarm alarm = new Alarm(new AlarmId(UUIDConverter.fromString(id))); 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 if (tenantId != null) { 158 if (tenantId != null) {
159 alarm.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); 159 alarm.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
160 } 160 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -116,7 +116,7 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity @@ -116,7 +116,7 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
116 116
117 protected Asset toAsset() { 117 protected Asset toAsset() {
118 Asset asset = new Asset(new AssetId(UUIDConverter.fromString(id))); 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 if (tenantId != null) { 120 if (tenantId != null) {
121 asset.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); 121 asset.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
122 } 122 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -104,7 +104,7 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti @@ -104,7 +104,7 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti
104 104
105 protected Device toDevice() { 105 protected Device toDevice() {
106 Device device = new Device(new DeviceId(getUuid())); 106 Device device = new Device(new DeviceId(getUuid()));
107 - device.setCreatedTime(UUIDs.unixTimestamp(getUuid())); 107 + device.setCreatedTime(Uuids.unixTimestamp(getUuid()));
108 if (tenantId != null) { 108 if (tenantId != null) {
109 device.setTenantId(new TenantId(toUUID(tenantId))); 109 device.setTenantId(new TenantId(toUUID(tenantId)));
110 } 110 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import com.fasterxml.jackson.databind.ObjectMapper; 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import lombok.Data; 21 import lombok.Data;
@@ -147,7 +147,7 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas @@ -147,7 +147,7 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas
147 147
148 protected EntityView toEntityView() { 148 protected EntityView toEntityView() {
149 EntityView entityView = new EntityView(new EntityViewId(getUuid())); 149 EntityView entityView = new EntityView(new EntityViewId(getUuid()));
150 - entityView.setCreatedTime(UUIDs.unixTimestamp(getUuid())); 150 + entityView.setCreatedTime(Uuids.unixTimestamp(getUuid()));
151 151
152 if (entityId != null) { 152 if (entityId != null) {
153 entityView.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), toUUID(entityId).toString())); 153 entityView.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), toUUID(entityId).toString()));
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -65,10 +65,10 @@ public final class AdminSettingsEntity extends BaseSqlEntity<AdminSettings> impl @@ -65,10 +65,10 @@ public final class AdminSettingsEntity extends BaseSqlEntity<AdminSettings> impl
65 @Override 65 @Override
66 public AdminSettings toData() { 66 public AdminSettings toData() {
67 AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(UUIDConverter.fromString(id))); 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 adminSettings.setKey(key); 69 adminSettings.setKey(key);
70 adminSettings.setJsonValue(jsonValue); 70 adminSettings.setJsonValue(jsonValue);
71 return adminSettings; 71 return adminSettings;
72 } 72 }
73 73
74 -}  
  74 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -129,7 +129,7 @@ public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntit @@ -129,7 +129,7 @@ public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntit
129 @Override 129 @Override
130 public AuditLog toData() { 130 public AuditLog toData() {
131 AuditLog auditLog = new AuditLog(new AuditLogId(this.getUuid())); 131 AuditLog auditLog = new AuditLog(new AuditLogId(this.getUuid()));
132 - auditLog.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 132 + auditLog.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
133 if (tenantId != null) { 133 if (tenantId != null) {
134 auditLog.setTenantId(new TenantId(toUUID(tenantId))); 134 auditLog.setTenantId(new TenantId(toUUID(tenantId)));
135 } 135 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -112,7 +112,7 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea @@ -112,7 +112,7 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea
112 @Override 112 @Override
113 public Customer toData() { 113 public Customer toData() {
114 Customer customer = new Customer(new CustomerId(this.getUuid())); 114 Customer customer = new Customer(new CustomerId(this.getUuid()));
115 - customer.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 115 + customer.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
116 customer.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); 116 customer.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
117 customer.setTitle(title); 117 customer.setTitle(title);
118 customer.setCountry(country); 118 customer.setCountry(country);
@@ -126,4 +126,4 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea @@ -126,4 +126,4 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea
126 customer.setAdditionalInfo(additionalInfo); 126 customer.setAdditionalInfo(additionalInfo);
127 return customer; 127 return customer;
128 } 128 }
129 -}  
  129 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.core.JsonProcessingException; 19 import com.fasterxml.jackson.core.JsonProcessingException;
20 import com.fasterxml.jackson.databind.JavaType; 20 import com.fasterxml.jackson.databind.JavaType;
21 import com.fasterxml.jackson.databind.JsonNode; 21 import com.fasterxml.jackson.databind.JsonNode;
@@ -104,7 +104,7 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S @@ -104,7 +104,7 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
104 @Override 104 @Override
105 public Dashboard toData() { 105 public Dashboard toData() {
106 Dashboard dashboard = new Dashboard(new DashboardId(this.getUuid())); 106 Dashboard dashboard = new Dashboard(new DashboardId(this.getUuid()));
107 - dashboard.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 107 + dashboard.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
108 if (tenantId != null) { 108 if (tenantId != null) {
109 dashboard.setTenantId(new TenantId(toUUID(tenantId))); 109 dashboard.setTenantId(new TenantId(toUUID(tenantId)));
110 } 110 }
@@ -119,4 +119,4 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S @@ -119,4 +119,4 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
119 dashboard.setConfiguration(configuration); 119 dashboard.setConfiguration(configuration);
120 return dashboard; 120 return dashboard;
121 } 121 }
122 -}  
  122 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.core.JsonProcessingException; 19 import com.fasterxml.jackson.core.JsonProcessingException;
20 import com.fasterxml.jackson.databind.JavaType; 20 import com.fasterxml.jackson.databind.JavaType;
21 import com.fasterxml.jackson.databind.ObjectMapper; 21 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -98,7 +98,7 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements @@ -98,7 +98,7 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
98 @Override 98 @Override
99 public DashboardInfo toData() { 99 public DashboardInfo toData() {
100 DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(this.getUuid())); 100 DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(this.getUuid()));
101 - dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 101 + dashboardInfo.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
102 if (tenantId != null) { 102 if (tenantId != null) {
103 dashboardInfo.setTenantId(new TenantId(toUUID(tenantId))); 103 dashboardInfo.setTenantId(new TenantId(toUUID(tenantId)));
104 } 104 }
@@ -113,4 +113,4 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements @@ -113,4 +113,4 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
113 return dashboardInfo; 113 return dashboardInfo;
114 } 114 }
115 115
116 -}  
  116 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import lombok.Data; 19 import lombok.Data;
20 import lombok.EqualsAndHashCode; 20 import lombok.EqualsAndHashCode;
21 import org.thingsboard.server.common.data.id.DeviceCredentialsId; 21 import org.thingsboard.server.common.data.id.DeviceCredentialsId;
@@ -70,7 +70,7 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia @@ -70,7 +70,7 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia
70 @Override 70 @Override
71 public DeviceCredentials toData() { 71 public DeviceCredentials toData() {
72 DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(this.getUuid())); 72 DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(this.getUuid()));
73 - deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 73 + deviceCredentials.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
74 if (deviceId != null) { 74 if (deviceId != null) {
75 deviceCredentials.setDeviceId(new DeviceId(toUUID(deviceId))); 75 deviceCredentials.setDeviceId(new DeviceId(toUUID(deviceId)));
76 } 76 }
@@ -80,4 +80,4 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia @@ -80,4 +80,4 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia
80 return deviceCredentials; 80 return deviceCredentials;
81 } 81 }
82 82
83 -}  
  83 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -103,7 +103,7 @@ public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Eve @@ -103,7 +103,7 @@ public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Eve
103 @Override 103 @Override
104 public Event toData() { 104 public Event toData() {
105 Event event = new Event(new EventId(this.getUuid())); 105 Event event = new Event(new EventId(this.getUuid()));
106 - event.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 106 + event.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
107 event.setTenantId(new TenantId(toUUID(tenantId))); 107 event.setTenantId(new TenantId(toUUID(tenantId)));
108 event.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, toUUID(entityId))); 108 event.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, toUUID(entityId)));
109 event.setBody(body); 109 event.setBody(body);
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -101,7 +101,7 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT @@ -101,7 +101,7 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT
101 @Override 101 @Override
102 public RuleChain toData() { 102 public RuleChain toData() {
103 RuleChain ruleChain = new RuleChain(new RuleChainId(this.getUuid())); 103 RuleChain ruleChain = new RuleChain(new RuleChainId(this.getUuid()));
104 - ruleChain.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 104 + ruleChain.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
105 ruleChain.setTenantId(new TenantId(toUUID(tenantId))); 105 ruleChain.setTenantId(new TenantId(toUUID(tenantId)));
106 ruleChain.setName(name); 106 ruleChain.setName(name);
107 if (firstRuleNodeId != null) { 107 if (firstRuleNodeId != null) {
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -95,7 +95,7 @@ public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTex @@ -95,7 +95,7 @@ public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTex
95 @Override 95 @Override
96 public RuleNode toData() { 96 public RuleNode toData() {
97 RuleNode ruleNode = new RuleNode(new RuleNodeId(this.getUuid())); 97 RuleNode ruleNode = new RuleNode(new RuleNodeId(this.getUuid()));
98 - ruleNode.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 98 + ruleNode.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
99 if (ruleChainId != null) { 99 if (ruleChainId != null) {
100 ruleNode.setRuleChainId(new RuleChainId(toUUID(ruleChainId))); 100 ruleNode.setRuleChainId(new RuleChainId(toUUID(ruleChainId)));
101 } 101 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -122,7 +122,7 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT @@ -122,7 +122,7 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT
122 @Override 122 @Override
123 public Tenant toData() { 123 public Tenant toData() {
124 Tenant tenant = new Tenant(new TenantId(this.getUuid())); 124 Tenant tenant = new Tenant(new TenantId(this.getUuid()));
125 - tenant.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 125 + tenant.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
126 tenant.setTitle(title); 126 tenant.setTitle(title);
127 tenant.setRegion(region); 127 tenant.setRegion(region);
128 tenant.setCountry(country); 128 tenant.setCountry(country);
@@ -140,4 +140,4 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT @@ -140,4 +140,4 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT
140 } 140 }
141 141
142 142
143 -}  
  143 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import lombok.Data; 19 import lombok.Data;
20 import lombok.EqualsAndHashCode; 20 import lombok.EqualsAndHashCode;
21 import org.thingsboard.server.common.data.id.UserCredentialsId; 21 import org.thingsboard.server.common.data.id.UserCredentialsId;
@@ -70,7 +70,7 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> @@ -70,7 +70,7 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials>
70 @Override 70 @Override
71 public UserCredentials toData() { 71 public UserCredentials toData() {
72 UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(this.getUuid())); 72 UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(this.getUuid()));
73 - userCredentials.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 73 + userCredentials.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
74 if (userId != null) { 74 if (userId != null) {
75 userCredentials.setUserId(new UserId(toUUID(userId))); 75 userCredentials.setUserId(new UserId(toUUID(userId)));
76 } 76 }
@@ -81,4 +81,4 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> @@ -81,4 +81,4 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials>
81 return userCredentials; 81 return userCredentials;
82 } 82 }
83 83
84 -}  
  84 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -109,7 +109,7 @@ public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity< @@ -109,7 +109,7 @@ public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity<
109 @Override 109 @Override
110 public User toData() { 110 public User toData() {
111 User user = new User(new UserId(this.getUuid())); 111 User user = new User(new UserId(this.getUuid()));
112 - user.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 112 + user.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
113 user.setAuthority(authority); 113 user.setAuthority(authority);
114 if (tenantId != null) { 114 if (tenantId != null) {
115 user.setTenantId(new TenantId(fromString(tenantId))); 115 user.setTenantId(new TenantId(fromString(tenantId)));
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.model.sql; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
@@ -76,7 +76,7 @@ public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implement @@ -76,7 +76,7 @@ public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implement
76 @Override 76 @Override
77 public WidgetType toData() { 77 public WidgetType toData() {
78 WidgetType widgetType = new WidgetType(new WidgetTypeId(this.getUuid())); 78 WidgetType widgetType = new WidgetType(new WidgetTypeId(this.getUuid()));
79 - widgetType.setCreatedTime(UUIDs.unixTimestamp(this.getUuid())); 79 + widgetType.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
80 if (tenantId != null) { 80 if (tenantId != null) {
81 widgetType.setTenantId(new TenantId(toUUID(tenantId))); 81 widgetType.setTenantId(new TenantId(toUUID(tenantId)));
82 } 82 }
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 package org.thingsboard.server.dao.model.sql; 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 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
22 import org.thingsboard.server.common.data.UUIDConverter; 22 import org.thingsboard.server.common.data.UUIDConverter;
@@ -77,7 +77,7 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> impl @@ -77,7 +77,7 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> impl
77 @Override 77 @Override
78 public WidgetsBundle toData() { 78 public WidgetsBundle toData() {
79 WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(UUIDConverter.fromString(id))); 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 if (tenantId != null) { 81 if (tenantId != null) {
82 widgetsBundle.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); 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,9 +15,11 @@
15 */ 15 */
16 package org.thingsboard.server.dao.nosql; 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 import com.google.common.base.Function; 20 import com.google.common.base.Function;
  21 +import com.google.common.collect.Lists;
  22 +import com.google.common.util.concurrent.AsyncFunction;
21 import com.google.common.util.concurrent.Futures; 23 import com.google.common.util.concurrent.Futures;
22 import com.google.common.util.concurrent.ListenableFuture; 24 import com.google.common.util.concurrent.ListenableFuture;
23 import org.thingsboard.common.util.ThingsBoardThreadFactory; 25 import org.thingsboard.common.util.ThingsBoardThreadFactory;
@@ -25,8 +27,11 @@ import org.thingsboard.common.util.ThingsBoardThreadFactory; @@ -25,8 +27,11 @@ import org.thingsboard.common.util.ThingsBoardThreadFactory;
25 import javax.annotation.Nullable; 27 import javax.annotation.Nullable;
26 import javax.annotation.PostConstruct; 28 import javax.annotation.PostConstruct;
27 import javax.annotation.PreDestroy; 29 import javax.annotation.PreDestroy;
  30 +import java.util.ArrayList;
  31 +import java.util.List;
28 import java.util.concurrent.ExecutorService; 32 import java.util.concurrent.ExecutorService;
29 import java.util.concurrent.Executors; 33 import java.util.concurrent.Executors;
  34 +import java.util.stream.Collectors;
30 35
31 /** 36 /**
32 * Created by ashvayka on 21.02.17. 37 * Created by ashvayka on 21.02.17.
@@ -47,13 +52,32 @@ public abstract class CassandraAbstractAsyncDao extends CassandraAbstractDao { @@ -47,13 +52,32 @@ 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<AsyncResultSet, T> transformer) {
  56 + return Futures.transform(future, new Function<AsyncResultSet, T>() {
52 @Nullable 57 @Nullable
53 @Override 58 @Override
54 - public T apply(@Nullable ResultSet input) { 59 + public T apply(@Nullable AsyncResultSet input) {
55 return transformer.apply(input); 60 return transformer.apply(input);
56 } 61 }
57 }, readResultsProcessingExecutor); 62 }, readResultsProcessingExecutor);
58 } 63 }
  64 +
  65 + protected <T> ListenableFuture<T> getFutureAsync(TbResultSetFuture future, com.google.common.util.concurrent.AsyncFunction<AsyncResultSet, T> transformer) {
  66 + return Futures.transformAsync(future, new AsyncFunction<AsyncResultSet, T>() {
  67 + @Nullable
  68 + @Override
  69 + public ListenableFuture<T> apply(@Nullable AsyncResultSet input) {
  70 + try {
  71 + return transformer.apply(input);
  72 + } catch (Exception e) {
  73 + return Futures.immediateFailedFuture(e);
  74 + }
  75 + }
  76 + }, readResultsProcessingExecutor);
  77 + }
  78 +
  79 + protected ListenableFuture<List<Row>> allRows(AsyncResultSet resultSet) {
  80 + return ResultSetUtils.allRows(resultSet, readResultsProcessingExecutor);
  81 + }
  82 +
59 } 83 }
@@ -15,16 +15,17 @@ @@ -15,16 +15,17 @@
15 */ 15 */
16 package org.thingsboard.server.dao.nosql; 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 import lombok.extern.slf4j.Slf4j; 23 import lombok.extern.slf4j.Slf4j;
21 import org.springframework.beans.factory.annotation.Autowired; 24 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.beans.factory.annotation.Qualifier; 25 import org.springframework.beans.factory.annotation.Qualifier;
23 import org.thingsboard.server.common.data.id.TenantId; 26 import org.thingsboard.server.common.data.id.TenantId;
24 import org.thingsboard.server.dao.cassandra.CassandraCluster; 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 import java.util.concurrent.ConcurrentHashMap; 30 import java.util.concurrent.ConcurrentHashMap;
30 import java.util.concurrent.ConcurrentMap; 31 import java.util.concurrent.ConcurrentMap;
@@ -41,20 +42,16 @@ public abstract class CassandraAbstractDao { @@ -41,20 +42,16 @@ public abstract class CassandraAbstractDao {
41 @Autowired 42 @Autowired
42 private CassandraBufferedRateExecutor rateLimiter; 43 private CassandraBufferedRateExecutor rateLimiter;
43 44
44 - private Session session; 45 + private GuavaSession session;
45 46
46 private ConsistencyLevel defaultReadLevel; 47 private ConsistencyLevel defaultReadLevel;
47 private ConsistencyLevel defaultWriteLevel; 48 private ConsistencyLevel defaultWriteLevel;
48 49
49 - private Session getSession() { 50 + private GuavaSession getSession() {
50 if (session == null) { 51 if (session == null) {
51 session = cluster.getSession(); 52 session = cluster.getSession();
52 defaultReadLevel = cluster.getDefaultReadConsistencyLevel(); 53 defaultReadLevel = cluster.getDefaultReadConsistencyLevel();
53 defaultWriteLevel = cluster.getDefaultWriteConsistencyLevel(); 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 return session; 56 return session;
60 } 57 }
@@ -63,38 +60,30 @@ public abstract class CassandraAbstractDao { @@ -63,38 +60,30 @@ public abstract class CassandraAbstractDao {
63 return preparedStatementMap.computeIfAbsent(query, i -> getSession().prepare(i)); 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 return execute(tenantId, statement, defaultReadLevel); 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 return execute(tenantId, statement, defaultWriteLevel); 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 return executeAsync(tenantId, statement, defaultReadLevel); 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 return executeAsync(tenantId, statement, defaultWriteLevel); 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 if (log.isDebugEnabled()) { 80 if (log.isDebugEnabled()) {
92 log.debug("Execute cassandra statement {}", statementToString(statement)); 81 log.debug("Execute cassandra statement {}", statementToString(statement));
93 } 82 }
94 return executeAsync(tenantId, statement, level).getUninterruptibly(); 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 if (log.isDebugEnabled()) { 87 if (log.isDebugEnabled()) {
99 log.debug("Execute cassandra async statement {}", statementToString(statement)); 88 log.debug("Execute cassandra async statement {}", statementToString(statement));
100 } 89 }
@@ -106,9 +95,9 @@ public abstract class CassandraAbstractDao { @@ -106,9 +95,9 @@ public abstract class CassandraAbstractDao {
106 95
107 private static String statementToString(Statement statement) { 96 private static String statementToString(Statement statement) {
108 if (statement instanceof BoundStatement) { 97 if (statement instanceof BoundStatement) {
109 - return ((BoundStatement) statement).preparedStatement().getQueryString(); 98 + return ((BoundStatement) statement).getPreparedStatement().getQuery();
110 } else { 99 } else {
111 return statement.toString(); 100 return statement.toString();
112 } 101 }
113 } 102 }
114 -}  
  103 +}
@@ -15,8 +15,8 @@ @@ -15,8 +15,8 @@
15 */ 15 */
16 package org.thingsboard.server.dao.nosql; 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 import com.google.common.util.concurrent.SettableFuture; 20 import com.google.common.util.concurrent.SettableFuture;
21 import lombok.extern.slf4j.Slf4j; 21 import lombok.extern.slf4j.Slf4j;
22 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,7 +39,7 @@ import java.util.Map; @@ -39,7 +39,7 @@ import java.util.Map;
39 @Component 39 @Component
40 @Slf4j 40 @Slf4j
41 @NoSqlAnyDao 41 @NoSqlAnyDao
42 -public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor<CassandraStatementTask, ResultSetFuture, ResultSet> { 42 +public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor<CassandraStatementTask, TbResultSetFuture, AsyncResultSet> {
43 43
44 @Autowired 44 @Autowired
45 private EntityService entityService; 45 private EntityService entityService;
@@ -107,17 +107,17 @@ public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor< @@ -107,17 +107,17 @@ public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor<
107 } 107 }
108 108
109 @Override 109 @Override
110 - protected SettableFuture<ResultSet> create() { 110 + protected SettableFuture<AsyncResultSet> create() {
111 return SettableFuture.create(); 111 return SettableFuture.create();
112 } 112 }
113 113
114 @Override 114 @Override
115 - protected ResultSetFuture wrap(CassandraStatementTask task, SettableFuture<ResultSet> future) { 115 + protected TbResultSetFuture wrap(CassandraStatementTask task, SettableFuture<AsyncResultSet> future) {
116 return new TbResultSetFuture(future); 116 return new TbResultSetFuture(future);
117 } 117 }
118 118
119 @Override 119 @Override
120 - protected ResultSetFuture execute(AsyncTaskContext<CassandraStatementTask, ResultSet> taskCtx) { 120 + protected ListenableFuture<AsyncResultSet> execute(AsyncTaskContext<CassandraStatementTask, AsyncResultSet> taskCtx) {
121 CassandraStatementTask task = taskCtx.getTask(); 121 CassandraStatementTask task = taskCtx.getTask();
122 return task.getSession().executeAsync(task.getStatement()); 122 return task.getSession().executeAsync(task.getStatement());
123 } 123 }
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 -}  
  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.Row;
  20 +import com.google.common.collect.Lists;
  21 +import com.google.common.util.concurrent.Futures;
  22 +import com.google.common.util.concurrent.ListenableFuture;
  23 +import com.google.common.util.concurrent.SettableFuture;
  24 +
  25 +import java.util.ArrayList;
  26 +import java.util.List;
  27 +import java.util.concurrent.CompletionStage;
  28 +import java.util.concurrent.Executor;
  29 +import java.util.stream.Collectors;
  30 +
  31 +public class ResultSetUtils {
  32 +
  33 + public static ListenableFuture<List<Row>> allRows(AsyncResultSet resultSet, Executor executor) {
  34 + List<ListenableFuture<AsyncResultSet>> futures = new ArrayList<>();
  35 + futures.add(Futures.immediateFuture(resultSet));
  36 + while (resultSet.hasMorePages()) {
  37 + futures.add(toListenable(resultSet.fetchNextPage()));
  38 + }
  39 + return Futures.transform( Futures.allAsList(futures),
  40 + resultSets -> resultSets.stream()
  41 + .map(rs -> loadRows(rs))
  42 + .flatMap(rows -> rows.stream())
  43 + .collect(Collectors.toList()),
  44 + executor
  45 + );
  46 + }
  47 +
  48 + private static <T> ListenableFuture<T> toListenable(CompletionStage<T> completable) {
  49 + SettableFuture<T> future = SettableFuture.create();
  50 + completable.whenComplete(
  51 + (r, ex) -> {
  52 + if (ex != null) {
  53 + future.setException(ex);
  54 + } else {
  55 + future.set(r);
  56 + }
  57 + }
  58 + );
  59 + return future;
  60 + }
  61 +
  62 + private static List<Row> loadRows(AsyncResultSet resultSet) {
  63 + return Lists.newArrayList(resultSet.currentPage());
  64 + }
  65 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql; 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 import com.google.common.collect.Lists; 19 import com.google.common.collect.Lists;
20 import com.google.common.util.concurrent.ListenableFuture; 20 import com.google.common.util.concurrent.ListenableFuture;
21 import lombok.extern.slf4j.Slf4j; 21 import lombok.extern.slf4j.Slf4j;
@@ -59,7 +59,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> @@ -59,7 +59,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
59 setSearchText(entity); 59 setSearchText(entity);
60 log.debug("Saving entity {}", entity); 60 log.debug("Saving entity {}", entity);
61 if (entity.getUuid() == null) { 61 if (entity.getUuid() == null) {
62 - entity.setUuid(UUIDs.timeBased()); 62 + entity.setUuid(Uuids.timeBased());
63 } 63 }
64 entity = getCrudRepository().save(entity); 64 entity = getCrudRepository().save(entity);
65 return DaoUtil.getData(entity); 65 return DaoUtil.getData(entity);
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql; 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 import org.springframework.data.jpa.domain.Specification; 19 import org.springframework.data.jpa.domain.Specification;
20 import org.thingsboard.server.common.data.UUIDConverter; 20 import org.thingsboard.server.common.data.UUIDConverter;
21 import org.thingsboard.server.common.data.page.TimePageLink; 21 import org.thingsboard.server.common.data.page.TimePageLink;
@@ -40,12 +40,12 @@ public abstract class JpaAbstractSearchTimeDao<E extends BaseEntity<D>, D> exten @@ -40,12 +40,12 @@ public abstract class JpaAbstractSearchTimeDao<E extends BaseEntity<D>, D> exten
40 public Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { 40 public Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
41 List<Predicate> predicates = new ArrayList<>(); 41 List<Predicate> predicates = new ArrayList<>();
42 if (pageLink.getStartTime() != null) { 42 if (pageLink.getStartTime() != null) {
43 - UUID startOf = UUIDs.startOf(pageLink.getStartTime()); 43 + UUID startOf = Uuids.startOf(pageLink.getStartTime());
44 Predicate lowerBound = criteriaBuilder.greaterThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(startOf)); 44 Predicate lowerBound = criteriaBuilder.greaterThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(startOf));
45 predicates.add(lowerBound); 45 predicates.add(lowerBound);
46 } 46 }
47 if (pageLink.getEndTime() != null) { 47 if (pageLink.getEndTime() != null) {
48 - UUID endOf = UUIDs.endOf(pageLink.getEndTime()); 48 + UUID endOf = Uuids.endOf(pageLink.getEndTime());
49 Predicate upperBound = criteriaBuilder.lessThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(endOf)); 49 Predicate upperBound = criteriaBuilder.lessThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(endOf));
50 predicates.add(upperBound); 50 predicates.add(upperBound);
51 } 51 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.component; 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 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.data.repository.CrudRepository; 20 import org.springframework.data.repository.CrudRepository;
21 import org.springframework.stereotype.Component; 21 import org.springframework.stereotype.Component;
@@ -64,7 +64,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp @@ -64,7 +64,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp
64 @Override 64 @Override
65 public Optional<ComponentDescriptor> saveIfNotExist(TenantId tenantId, ComponentDescriptor component) { 65 public Optional<ComponentDescriptor> saveIfNotExist(TenantId tenantId, ComponentDescriptor component) {
66 if (component.getId() == null) { 66 if (component.getId() == null) {
67 - component.setId(new ComponentDescriptorId(UUIDs.timeBased())); 67 + component.setId(new ComponentDescriptorId(Uuids.timeBased()));
68 } 68 }
69 if (!componentDescriptorRepository.existsById(UUIDConverter.fromTimeUUID(component.getId().getId()))) { 69 if (!componentDescriptorRepository.existsById(UUIDConverter.fromTimeUUID(component.getId().getId()))) {
70 ComponentDescriptorEntity componentDescriptorEntity = new ComponentDescriptorEntity(component); 70 ComponentDescriptorEntity componentDescriptorEntity = new ComponentDescriptorEntity(component);
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.event; 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 import com.google.common.util.concurrent.ListenableFuture; 19 import com.google.common.util.concurrent.ListenableFuture;
20 import lombok.extern.slf4j.Slf4j; 20 import lombok.extern.slf4j.Slf4j;
21 import org.apache.commons.lang3.StringUtils; 21 import org.apache.commons.lang3.StringUtils;
@@ -75,7 +75,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event @@ -75,7 +75,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
75 public Event save(TenantId tenantId, Event event) { 75 public Event save(TenantId tenantId, Event event) {
76 log.debug("Save event [{}] ", event); 76 log.debug("Save event [{}] ", event);
77 if (event.getId() == null) { 77 if (event.getId() == null) {
78 - event.setId(new EventId(UUIDs.timeBased())); 78 + event.setId(new EventId(Uuids.timeBased()));
79 } 79 }
80 if (StringUtils.isEmpty(event.getUid())) { 80 if (StringUtils.isEmpty(event.getUid())) {
81 event.setUid(event.getId().toString()); 81 event.setUid(event.getId().toString());
@@ -87,7 +87,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event @@ -87,7 +87,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
87 public ListenableFuture<Event> saveAsync(Event event) { 87 public ListenableFuture<Event> saveAsync(Event event) {
88 log.debug("Save event [{}] ", event); 88 log.debug("Save event [{}] ", event);
89 if (event.getId() == null) { 89 if (event.getId() == null) {
90 - event.setId(new EventId(UUIDs.timeBased())); 90 + event.setId(new EventId(Uuids.timeBased()));
91 } 91 }
92 if (StringUtils.isEmpty(event.getUid())) { 92 if (StringUtils.isEmpty(event.getUid())) {
93 event.setUid(event.getId().toString()); 93 event.setUid(event.getId().toString());
@@ -152,7 +152,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event @@ -152,7 +152,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
152 entity.setTenantId(UUIDConverter.fromTimeUUID(systemTenantId)); 152 entity.setTenantId(UUIDConverter.fromTimeUUID(systemTenantId));
153 } 153 }
154 if (entity.getUuid() == null) { 154 if (entity.getUuid() == null) {
155 - entity.setUuid(UUIDs.timeBased()); 155 + entity.setUuid(Uuids.timeBased());
156 } 156 }
157 if (StringUtils.isEmpty(entity.getEventUid())) { 157 if (StringUtils.isEmpty(entity.getEventUid())) {
158 entity.setEventUid(entity.getUuid().toString()); 158 entity.setEventUid(entity.getUuid().toString());
@@ -15,8 +15,10 @@ @@ -15,8 +15,10 @@
15 */ 15 */
16 package org.thingsboard.server.dao.timeseries; 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 import lombok.extern.slf4j.Slf4j; 22 import lombok.extern.slf4j.Slf4j;
21 import org.thingsboard.server.common.data.kv.Aggregation; 23 import org.thingsboard.server.common.data.kv.Aggregation;
22 import org.thingsboard.server.common.data.kv.BasicTsKvEntry; 24 import org.thingsboard.server.common.data.kv.BasicTsKvEntry;
@@ -27,16 +29,19 @@ import org.thingsboard.server.common.data.kv.JsonDataEntry; @@ -27,16 +29,19 @@ import org.thingsboard.server.common.data.kv.JsonDataEntry;
27 import org.thingsboard.server.common.data.kv.LongDataEntry; 29 import org.thingsboard.server.common.data.kv.LongDataEntry;
28 import org.thingsboard.server.common.data.kv.StringDataEntry; 30 import org.thingsboard.server.common.data.kv.StringDataEntry;
29 import org.thingsboard.server.common.data.kv.TsKvEntry; 31 import org.thingsboard.server.common.data.kv.TsKvEntry;
  32 +import org.thingsboard.server.dao.nosql.ResultSetUtils;
30 33
31 import javax.annotation.Nullable; 34 import javax.annotation.Nullable;
32 import java.util.List; 35 import java.util.List;
33 import java.util.Optional; 36 import java.util.Optional;
  37 +import java.util.concurrent.Executor;
  38 +import java.util.stream.Collectors;
34 39
35 /** 40 /**
36 * Created by ashvayka on 20.02.17. 41 * Created by ashvayka on 20.02.17.
37 */ 42 */
38 @Slf4j 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<AsyncResultSet>, Optional<TsKvEntry>> {
40 45
41 private static final int LONG_CNT_POS = 0; 46 private static final int LONG_CNT_POS = 0;
42 private static final int DOUBLE_CNT_POS = 1; 47 private static final int DOUBLE_CNT_POS = 1;
@@ -52,33 +57,39 @@ public class AggregatePartitionsFunction implements com.google.common.base.Funct @@ -52,33 +57,39 @@ public class AggregatePartitionsFunction implements com.google.common.base.Funct
52 private final Aggregation aggregation; 57 private final Aggregation aggregation;
53 private final String key; 58 private final String key;
54 private final long ts; 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 this.aggregation = aggregation; 63 this.aggregation = aggregation;
58 this.key = key; 64 this.key = key;
59 this.ts = ts; 65 this.ts = ts;
  66 + this.executor = executor;
60 } 67 }
61 68
62 @Override 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<AsyncResultSet> 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 -> ResultSetUtils.allRows(rs, 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 private void processResultSetRow(Row row, AggregationResult aggResult) { 95 private void processResultSetRow(Row row, AggregationResult aggResult) {
@@ -181,7 +192,7 @@ public class AggregatePartitionsFunction implements com.google.common.base.Funct @@ -181,7 +192,7 @@ public class AggregatePartitionsFunction implements com.google.common.base.Funct
181 192
182 private Boolean getBooleanValue(Row row) { 193 private Boolean getBooleanValue(Row row) {
183 if (aggregation == Aggregation.MIN || aggregation == Aggregation.MAX) { 194 if (aggregation == Aggregation.MIN || aggregation == Aggregation.MAX) {
184 - return row.getBool(BOOL_POS); 195 + return row.getBoolean(BOOL_POS);
185 } else { 196 } else {
186 return null; //NOSONAR, null is used for further comparison 197 return null; //NOSONAR, null is used for further comparison
187 } 198 }
@@ -15,14 +15,14 @@ @@ -15,14 +15,14 @@
15 */ 15 */
16 package org.thingsboard.server.dao.timeseries; 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 import com.google.common.base.Function; 26 import com.google.common.base.Function;
27 import com.google.common.util.concurrent.AsyncFunction; 27 import com.google.common.util.concurrent.AsyncFunction;
28 import com.google.common.util.concurrent.FutureCallback; 28 import com.google.common.util.concurrent.FutureCallback;
@@ -52,6 +52,7 @@ import org.thingsboard.server.common.data.kv.StringDataEntry; @@ -52,6 +52,7 @@ import org.thingsboard.server.common.data.kv.StringDataEntry;
52 import org.thingsboard.server.common.data.kv.TsKvEntry; 52 import org.thingsboard.server.common.data.kv.TsKvEntry;
53 import org.thingsboard.server.dao.model.ModelConstants; 53 import org.thingsboard.server.dao.model.ModelConstants;
54 import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao; 54 import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao;
  55 +import org.thingsboard.server.dao.nosql.TbResultSetFuture;
55 import org.thingsboard.server.dao.util.NoSqlTsDao; 56 import org.thingsboard.server.dao.util.NoSqlTsDao;
56 57
57 import javax.annotation.Nullable; 58 import javax.annotation.Nullable;
@@ -69,7 +70,7 @@ import java.util.Optional; @@ -69,7 +70,7 @@ import java.util.Optional;
69 import java.util.concurrent.ExecutionException; 70 import java.util.concurrent.ExecutionException;
70 import java.util.stream.Collectors; 71 import java.util.stream.Collectors;
71 72
72 -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; 73 +import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal;
73 74
74 /** 75 /**
75 * @author Andrew Shvayka 76 * @author Andrew Shvayka
@@ -189,8 +190,8 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -189,8 +190,8 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
189 if (isFixedPartitioning()) { //no need to fetch partitions from DB 190 if (isFixedPartitioning()) { //no need to fetch partitions from DB
190 return Futures.immediateFuture(FIXED_PARTITION); 191 return Futures.immediateFuture(FIXED_PARTITION);
191 } 192 }
192 - ResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition);  
193 - return Futures.transform(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor); 193 + TbResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition);
  194 + return Futures.transformAsync(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor);
194 } 195 }
195 196
196 private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(TenantId tenantId, EntityId entityId, ReadTsKvQuery query) { 197 private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(TenantId tenantId, EntityId entityId, ReadTsKvQuery query) {
@@ -225,20 +226,41 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -225,20 +226,41 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
225 resultFuture.set(cursor.getData()); 226 resultFuture.set(cursor.getData());
226 } else { 227 } else {
227 PreparedStatement proto = getFetchStmt(Aggregation.NONE, cursor.getOrderBy()); 228 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>() { 229 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind());
  230 +
  231 + stmtBuilder.setString(0, cursor.getEntityType());
  232 + stmtBuilder.setUuid(1, cursor.getEntityId());
  233 + stmtBuilder.setString(2, cursor.getKey());
  234 + stmtBuilder.setLong(3, cursor.getNextPartition());
  235 + stmtBuilder.setLong(4, cursor.getStartTs());
  236 + stmtBuilder.setLong(5, cursor.getEndTs());
  237 + stmtBuilder.setInt(6, cursor.getCurrentLimit());
  238 +
  239 + BoundStatement stmt = stmtBuilder.build();
  240 +
  241 + Futures.addCallback(executeAsyncRead(tenantId, stmt), new FutureCallback<AsyncResultSet>() {
238 @Override 242 @Override
239 - public void onSuccess(@Nullable ResultSet result) {  
240 - cursor.addData(convertResultToTsKvEntryList(result == null ? Collections.emptyList() : result.all()));  
241 - findAllAsyncSequentiallyWithLimit(tenantId, cursor, resultFuture); 243 + public void onSuccess(@Nullable AsyncResultSet result) {
  244 + if (result == null) {
  245 + cursor.addData(convertResultToTsKvEntryList(Collections.emptyList()));
  246 + findAllAsyncSequentiallyWithLimit(tenantId, cursor, resultFuture);
  247 + } else {
  248 + Futures.addCallback(allRows(result), new FutureCallback<List<Row>>() {
  249 +
  250 + @Override
  251 + public void onSuccess(@Nullable List<Row> result) {
  252 + cursor.addData(convertResultToTsKvEntryList(result == null ? Collections.emptyList() : result));
  253 + findAllAsyncSequentiallyWithLimit(tenantId, cursor, resultFuture);
  254 + }
  255 +
  256 + @Override
  257 + public void onFailure(Throwable t) {
  258 + log.error("[{}][{}] Failed to fetch data for query {}-{}", stmt, t);
  259 + }
  260 + }, readResultsProcessingExecutor);
  261 +
  262 +
  263 + }
242 } 264 }
243 265
244 @Override 266 @Override
@@ -256,31 +278,35 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -256,31 +278,35 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
256 final long endTs = query.getEndTs(); 278 final long endTs = query.getEndTs();
257 final long ts = startTs + (endTs - startTs) / 2; 279 final long ts = startTs + (endTs - startTs) / 2;
258 ListenableFuture<List<Long>> partitionsListFuture = getPartitionsFuture(tenantId, query, entityId, minPartition, maxPartition); 280 ListenableFuture<List<Long>> partitionsListFuture = getPartitionsFuture(tenantId, query, entityId, minPartition, maxPartition);
259 - ListenableFuture<List<ResultSet>> aggregationChunks = Futures.transformAsync(partitionsListFuture, 281 + ListenableFuture<List<AsyncResultSet>> aggregationChunks = Futures.transformAsync(partitionsListFuture,
260 getFetchChunksAsyncFunction(tenantId, entityId, key, aggregation, startTs, endTs), readResultsProcessingExecutor); 282 getFetchChunksAsyncFunction(tenantId, entityId, key, aggregation, startTs, endTs), readResultsProcessingExecutor);
261 283
262 - return Futures.transform(aggregationChunks, new AggregatePartitionsFunction(aggregation, key, ts), readResultsProcessingExecutor); 284 + return Futures.transformAsync(aggregationChunks, new AggregatePartitionsFunction(aggregation, key, ts, readResultsProcessingExecutor), readResultsProcessingExecutor);
263 } 285 }
264 286
265 - private Function<ResultSet, List<Long>> getPartitionsArrayFunction() {  
266 - return rows -> rows.all().stream()  
267 - .map(row -> row.getLong(ModelConstants.PARTITION_COLUMN)).collect(Collectors.toList()); 287 + private AsyncFunction<AsyncResultSet, List<Long>> getPartitionsArrayFunction() {
  288 + return rs ->
  289 + Futures.transform(allRows(rs), rows ->
  290 + rows.stream()
  291 + .map(row -> row.getLong(ModelConstants.PARTITION_COLUMN)).collect(Collectors.toList()),
  292 + readResultsProcessingExecutor);
268 } 293 }
269 294
270 - private AsyncFunction<List<Long>, List<ResultSet>> getFetchChunksAsyncFunction(TenantId tenantId, EntityId entityId, String key, Aggregation aggregation, long startTs, long endTs) { 295 + private AsyncFunction<List<Long>, List<AsyncResultSet>> getFetchChunksAsyncFunction(TenantId tenantId, EntityId entityId, String key, Aggregation aggregation, long startTs, long endTs) {
271 return partitions -> { 296 return partitions -> {
272 try { 297 try {
273 PreparedStatement proto = getFetchStmt(aggregation, DESC_ORDER); 298 PreparedStatement proto = getFetchStmt(aggregation, DESC_ORDER);
274 - List<ResultSetFuture> futures = new ArrayList<>(partitions.size()); 299 + List<TbResultSetFuture> futures = new ArrayList<>(partitions.size());
275 for (Long partition : partitions) { 300 for (Long partition : partitions) {
276 log.trace("Fetching data for partition [{}] for entityType {} and entityId {}", partition, entityId.getEntityType(), entityId.getId()); 301 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); 302 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind());
  303 + stmtBuilder.setString(0, entityId.getEntityType().name());
  304 + stmtBuilder.setUuid(1, entityId.getId());
  305 + stmtBuilder.setString(2, key);
  306 + stmtBuilder.setLong(3, partition);
  307 + stmtBuilder.setLong(4, startTs);
  308 + stmtBuilder.setLong(5, endTs);
  309 + BoundStatement stmt = stmtBuilder.build();
284 log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId()); 310 log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId());
285 futures.add(executeAsyncRead(tenantId, stmt)); 311 futures.add(executeAsyncRead(tenantId, stmt));
286 } 312 }
@@ -294,21 +320,23 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -294,21 +320,23 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
294 320
295 @Override 321 @Override
296 public ListenableFuture<TsKvEntry> findLatest(TenantId tenantId, EntityId entityId, String key) { 322 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); 323 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(getFindLatestStmt().bind());
  324 + stmtBuilder.setString(0, entityId.getEntityType().name());
  325 + stmtBuilder.setUuid(1, entityId.getId());
  326 + stmtBuilder.setString(2, key);
  327 + BoundStatement stmt = stmtBuilder.build();
301 log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId()); 328 log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId());
302 return getFuture(executeAsyncRead(tenantId, stmt), rs -> convertResultToTsKvEntry(key, rs.one())); 329 return getFuture(executeAsyncRead(tenantId, stmt), rs -> convertResultToTsKvEntry(key, rs.one()));
303 } 330 }
304 331
305 @Override 332 @Override
306 public ListenableFuture<List<TsKvEntry>> findAllLatest(TenantId tenantId, EntityId entityId) { 333 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()); 334 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(getFindAllLatestStmt().bind());
  335 + stmtBuilder.setString(0, entityId.getEntityType().name());
  336 + stmtBuilder.setUuid(1, entityId.getId());
  337 + BoundStatement stmt = stmtBuilder.build();
310 log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId()); 338 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())); 339 + return getFutureAsync(executeAsyncRead(tenantId, stmt), rs -> convertAsyncResultSetToTsKvEntryList(rs));
312 } 340 }
313 341
314 @Override 342 @Override
@@ -320,16 +348,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -320,16 +348,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
320 if (setNullValuesEnabled) { 348 if (setNullValuesEnabled) {
321 processSetNullValues(tenantId, entityId, tsKvEntry, ttl, futures, partition, type); 349 processSetNullValues(tenantId, entityId, tsKvEntry, ttl, futures, partition, type);
322 } 350 }
323 - BoundStatement stmt = (ttl == 0 ? getSaveStmt(type) : getSaveTtlStmt(type)).bind();  
324 - stmt.setString(0, entityId.getEntityType().name())  
325 - .setUUID(1, entityId.getId()) 351 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder((ttl == 0 ? getSaveStmt(type) : getSaveTtlStmt(type)).bind());
  352 + stmtBuilder.setString(0, entityId.getEntityType().name())
  353 + .setUuid(1, entityId.getId())
326 .setString(2, tsKvEntry.getKey()) 354 .setString(2, tsKvEntry.getKey())
327 .setLong(3, partition) 355 .setLong(3, partition)
328 .setLong(4, tsKvEntry.getTs()); 356 .setLong(4, tsKvEntry.getTs());
329 - addValue(tsKvEntry, stmt, 5); 357 + addValue(tsKvEntry, stmtBuilder, 5);
330 if (ttl > 0) { 358 if (ttl > 0) {
331 - stmt.setInt(6, (int) ttl); 359 + stmtBuilder.setInt(6, (int) ttl);
332 } 360 }
  361 + BoundStatement stmt = stmtBuilder.build();
333 futures.add(getFuture(executeAsyncWrite(tenantId, stmt), rs -> null)); 362 futures.add(getFuture(executeAsyncWrite(tenantId, stmt), rs -> null));
334 return Futures.transform(Futures.allAsList(futures), result -> null, MoreExecutors.directExecutor()); 363 return Futures.transform(Futures.allAsList(futures), result -> null, MoreExecutors.directExecutor());
335 } 364 }
@@ -370,16 +399,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -370,16 +399,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
370 } 399 }
371 400
372 private ListenableFuture<Void> saveNull(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry, long ttl, long partition, DataType type) { 401 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()) 402 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder((ttl == 0 ? getSaveStmt(type) : getSaveTtlStmt(type)).bind());
  403 + stmtBuilder.setString(0, entityId.getEntityType().name())
  404 + .setUuid(1, entityId.getId())
376 .setString(2, tsKvEntry.getKey()) 405 .setString(2, tsKvEntry.getKey())
377 .setLong(3, partition) 406 .setLong(3, partition)
378 .setLong(4, tsKvEntry.getTs()); 407 .setLong(4, tsKvEntry.getTs());
379 - stmt.setToNull(getColumnName(type)); 408 + stmtBuilder.setToNull(getColumnName(type));
380 if (ttl > 0) { 409 if (ttl > 0) {
381 - stmt.setInt(6, (int) ttl); 410 + stmtBuilder.setInt(6, (int) ttl);
382 } 411 }
  412 + BoundStatement stmt = stmtBuilder.build();
383 return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null); 413 return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null);
384 } 414 }
385 415
@@ -391,14 +421,15 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -391,14 +421,15 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
391 ttl = computeTtl(ttl); 421 ttl = computeTtl(ttl);
392 long partition = toPartitionTs(tsKvEntryTs); 422 long partition = toPartitionTs(tsKvEntryTs);
393 log.debug("Saving partition {} for the entity [{}-{}] and key {}", partition, entityId.getEntityType(), entityId.getId(), key); 423 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()) 424 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder((ttl == 0 ? getPartitionInsertStmt() : getPartitionInsertTtlStmt()).bind());
  425 + stmtBuilder.setString(0, entityId.getEntityType().name())
  426 + .setUuid(1, entityId.getId())
397 .setLong(2, partition) 427 .setLong(2, partition)
398 .setString(3, key); 428 .setString(3, key);
399 if (ttl > 0) { 429 if (ttl > 0) {
400 - stmt.setInt(4, (int) ttl); 430 + stmtBuilder.setInt(4, (int) ttl);
401 } 431 }
  432 + BoundStatement stmt = stmtBuilder.build();
402 return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null); 433 return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null);
403 } 434 }
404 435
@@ -415,9 +446,9 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -415,9 +446,9 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
415 446
416 @Override 447 @Override
417 public ListenableFuture<Void> saveLatest(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry) { 448 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()) 449 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(getLatestStmt().bind());
  450 + stmtBuilder.setString(0, entityId.getEntityType().name())
  451 + .setUuid(1, entityId.getId())
421 .setString(2, tsKvEntry.getKey()) 452 .setString(2, tsKvEntry.getKey())
422 .setLong(3, tsKvEntry.getTs()) 453 .setLong(3, tsKvEntry.getTs())
423 .set(4, tsKvEntry.getBooleanValue().orElse(null), Boolean.class) 454 .set(4, tsKvEntry.getBooleanValue().orElse(null), Boolean.class)
@@ -426,10 +457,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -426,10 +457,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
426 .set(7, tsKvEntry.getDoubleValue().orElse(null), Double.class); 457 .set(7, tsKvEntry.getDoubleValue().orElse(null), Double.class);
427 Optional<String> jsonV = tsKvEntry.getJsonValue(); 458 Optional<String> jsonV = tsKvEntry.getJsonValue();
428 if (jsonV.isPresent()) { 459 if (jsonV.isPresent()) {
429 - stmt.setString(8, tsKvEntry.getJsonValue().get()); 460 + stmtBuilder.setString(8, tsKvEntry.getJsonValue().get());
430 } else { 461 } else {
431 - stmt.setToNull(8); 462 + stmtBuilder.setToNull(8);
432 } 463 }
  464 + BoundStatement stmt = stmtBuilder.build();
433 465
434 return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null); 466 return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null);
435 } 467 }
@@ -439,10 +471,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -439,10 +471,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
439 long minPartition = toPartitionTs(query.getStartTs()); 471 long minPartition = toPartitionTs(query.getStartTs());
440 long maxPartition = toPartitionTs(query.getEndTs()); 472 long maxPartition = toPartitionTs(query.getEndTs());
441 473
442 - ResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition); 474 + TbResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition);
443 475
444 final SimpleListenableFuture<Void> resultFuture = new SimpleListenableFuture<>(); 476 final SimpleListenableFuture<Void> resultFuture = new SimpleListenableFuture<>();
445 - final ListenableFuture<List<Long>> partitionsListFuture = Futures.transform(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor); 477 + final ListenableFuture<List<Long>> partitionsListFuture = Futures.transformAsync(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor);
446 478
447 Futures.addCallback(partitionsListFuture, new FutureCallback<List<Long>>() { 479 Futures.addCallback(partitionsListFuture, new FutureCallback<List<Long>>() {
448 @Override 480 @Override
@@ -464,17 +496,19 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -464,17 +496,19 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
464 resultFuture.set(null); 496 resultFuture.set(null);
465 } else { 497 } else {
466 PreparedStatement proto = getDeleteStmt(); 498 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>() { 499 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind());
  500 + stmtBuilder.setString(0, cursor.getEntityType());
  501 + stmtBuilder.setUuid(1, cursor.getEntityId());
  502 + stmtBuilder.setString(2, cursor.getKey());
  503 + stmtBuilder.setLong(3, cursor.getNextPartition());
  504 + stmtBuilder.setLong(4, cursor.getStartTs());
  505 + stmtBuilder.setLong(5, cursor.getEndTs());
  506 +
  507 + BoundStatement stmt = stmtBuilder.build();
  508 +
  509 + Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<AsyncResultSet>() {
476 @Override 510 @Override
477 - public void onSuccess(@Nullable ResultSet result) { 511 + public void onSuccess(@Nullable AsyncResultSet result) {
478 deleteAsync(tenantId, cursor, resultFuture); 512 deleteAsync(tenantId, cursor, resultFuture);
479 } 513 }
480 514
@@ -568,10 +602,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -568,10 +602,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
568 } 602 }
569 603
570 private ListenableFuture<Void> deleteLatest(TenantId tenantId, EntityId entityId, String key) { 604 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)); 605 + Statement delete = QueryBuilder.deleteFrom(ModelConstants.TS_KV_LATEST_CF)
  606 + .whereColumn(ModelConstants.ENTITY_TYPE_COLUMN).isEqualTo(literal(entityId.getEntityType().name()))
  607 + .whereColumn(ModelConstants.ENTITY_ID_COLUMN).isEqualTo(literal(entityId.getId()))
  608 + .whereColumn(ModelConstants.KEY_COLUMN).isEqualTo(literal(key)).build();
575 log.debug("Remove request: {}", delete.toString()); 609 log.debug("Remove request: {}", delete.toString());
576 return getFuture(executeAsyncWrite(tenantId, delete), rs -> null); 610 return getFuture(executeAsyncWrite(tenantId, delete), rs -> null);
577 } 611 }
@@ -583,10 +617,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -583,10 +617,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
583 if (minPartition == maxPartition) { 617 if (minPartition == maxPartition) {
584 return Futures.immediateFuture(null); 618 return Futures.immediateFuture(null);
585 } else { 619 } else {
586 - ResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition); 620 + TbResultSetFuture partitionsFuture = fetchPartitions(tenantId, entityId, query.getKey(), minPartition, maxPartition);
587 621
588 final SimpleListenableFuture<Void> resultFuture = new SimpleListenableFuture<>(); 622 final SimpleListenableFuture<Void> resultFuture = new SimpleListenableFuture<>();
589 - final ListenableFuture<List<Long>> partitionsListFuture = Futures.transform(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor); 623 + final ListenableFuture<List<Long>> partitionsListFuture = Futures.transformAsync(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor);
590 624
591 Futures.addCallback(partitionsListFuture, new FutureCallback<List<Long>>() { 625 Futures.addCallback(partitionsListFuture, new FutureCallback<List<Long>>() {
592 @Override 626 @Override
@@ -617,15 +651,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -617,15 +651,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
617 resultFuture.set(null); 651 resultFuture.set(null);
618 } else { 652 } else {
619 PreparedStatement proto = getDeletePartitionStmt(); 653 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()); 654 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind());
  655 + stmtBuilder.setString(0, cursor.getEntityType());
  656 + stmtBuilder.setUuid(1, cursor.getEntityId());
  657 + stmtBuilder.setLong(2, cursor.getNextPartition());
  658 + stmtBuilder.setString(3, cursor.getKey());
625 659
626 - Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<ResultSet>() { 660 + BoundStatement stmt = stmtBuilder.build();
  661 +
  662 + Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<AsyncResultSet>() {
627 @Override 663 @Override
628 - public void onSuccess(@Nullable ResultSet result) { 664 + public void onSuccess(@Nullable AsyncResultSet result) {
629 deletePartitionAsync(tenantId, cursor, resultFuture); 665 deletePartitionAsync(tenantId, cursor, resultFuture);
630 } 666 }
631 667
@@ -648,6 +684,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -648,6 +684,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
648 return deletePartitionStmt; 684 return deletePartitionStmt;
649 } 685 }
650 686
  687 + private ListenableFuture<List<TsKvEntry>> convertAsyncResultSetToTsKvEntryList(AsyncResultSet rs) {
  688 + return Futures.transform(this.allRows(rs),
  689 + rows -> this.convertResultToTsKvEntryList(rows), readResultsProcessingExecutor);
  690 + }
  691 +
651 private List<TsKvEntry> convertResultToTsKvEntryList(List<Row> rows) { 692 private List<TsKvEntry> convertResultToTsKvEntryList(List<Row> rows) {
652 List<TsKvEntry> entries = new ArrayList<>(rows.size()); 693 List<TsKvEntry> entries = new ArrayList<>(rows.size());
653 if (!rows.isEmpty()) { 694 if (!rows.isEmpty()) {
@@ -706,12 +747,14 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -706,12 +747,14 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
706 * Select existing partitions from the table 747 * Select existing partitions from the table
707 * <code>{@link ModelConstants#TS_KV_PARTITIONS_CF}</code> for the given entity 748 * <code>{@link ModelConstants#TS_KV_PARTITIONS_CF}</code> for the given entity
708 */ 749 */
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); 750 + private TbResultSetFuture fetchPartitions(TenantId tenantId, EntityId entityId, String key, long minPartition, long maxPartition) {
  751 + Select select = QueryBuilder.selectFrom(ModelConstants.TS_KV_PARTITIONS_CF).column(ModelConstants.PARTITION_COLUMN)
  752 + .whereColumn(ModelConstants.ENTITY_TYPE_COLUMN).isEqualTo(literal(entityId.getEntityType().name()))
  753 + .whereColumn(ModelConstants.ENTITY_ID_COLUMN).isEqualTo(literal(entityId.getId()))
  754 + .whereColumn(ModelConstants.KEY_COLUMN).isEqualTo(literal(key))
  755 + .whereColumn(ModelConstants.PARTITION_COLUMN).isGreaterThanOrEqualTo(literal(minPartition))
  756 + .whereColumn(ModelConstants.PARTITION_COLUMN).isLessThanOrEqualTo(literal(maxPartition));
  757 + return executeAsyncRead(tenantId, select.build());
715 } 758 }
716 759
717 private PreparedStatement getSaveStmt(DataType dataType) { 760 private PreparedStatement getSaveStmt(DataType dataType) {
@@ -882,11 +925,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem @@ -882,11 +925,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
882 } 925 }
883 } 926 }
884 927
885 - private static void addValue(KvEntry kvEntry, BoundStatement stmt, int column) { 928 + private static void addValue(KvEntry kvEntry, BoundStatementBuilder stmt, int column) {
886 switch (kvEntry.getDataType()) { 929 switch (kvEntry.getDataType()) {
887 case BOOLEAN: 930 case BOOLEAN:
888 Optional<Boolean> booleanValue = kvEntry.getBooleanValue(); 931 Optional<Boolean> booleanValue = kvEntry.getBooleanValue();
889 - booleanValue.ifPresent(b -> stmt.setBool(column, b)); 932 + booleanValue.ifPresent(b -> stmt.setBoolean(column, b));
890 break; 933 break;
891 case STRING: 934 case STRING:
892 Optional<String> stringValue = kvEntry.getStrValue(); 935 Optional<String> stringValue = kvEntry.getStrValue();
@@ -15,7 +15,14 @@ @@ -15,7 +15,14 @@
15 */ 15 */
16 package org.thingsboard.server.dao.util; 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 import com.google.common.util.concurrent.FutureCallback; 26 import com.google.common.util.concurrent.FutureCallback;
20 import com.google.common.util.concurrent.Futures; 27 import com.google.common.util.concurrent.Futures;
21 import com.google.common.util.concurrent.ListenableFuture; 28 import com.google.common.util.concurrent.ListenableFuture;
@@ -212,7 +219,7 @@ public abstract class AbstractBufferedRateExecutor<T extends AsyncTask, F extend @@ -212,7 +219,7 @@ public abstract class AbstractBufferedRateExecutor<T extends AsyncTask, F extend
212 CassandraStatementTask cassStmtTask = (CassandraStatementTask) taskCtx.getTask(); 219 CassandraStatementTask cassStmtTask = (CassandraStatementTask) taskCtx.getTask();
213 if (cassStmtTask.getStatement() instanceof BoundStatement) { 220 if (cassStmtTask.getStatement() instanceof BoundStatement) {
214 BoundStatement stmt = (BoundStatement) cassStmtTask.getStatement(); 221 BoundStatement stmt = (BoundStatement) cassStmtTask.getStatement();
215 - String query = stmt.preparedStatement().getQueryString(); 222 + String query = stmt.getPreparedStatement().getQuery();
216 try { 223 try {
217 query = toStringWithValues(stmt, ProtocolVersion.V5); 224 query = toStringWithValues(stmt, ProtocolVersion.V5);
218 } catch (Exception e) { 225 } catch (Exception e) {
@@ -225,16 +232,16 @@ public abstract class AbstractBufferedRateExecutor<T extends AsyncTask, F extend @@ -225,16 +232,16 @@ public abstract class AbstractBufferedRateExecutor<T extends AsyncTask, F extend
225 } 232 }
226 233
227 private static String toStringWithValues(BoundStatement boundStatement, ProtocolVersion protocolVersion) { 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 int index = 0; 239 int index = 0;
233 - for (ColumnDefinitions.Definition def : defs) { 240 + for (ColumnDefinition def : defs) {
234 DataType type = def.getType(); 241 DataType type = def.getType();
235 TypeCodec<Object> codec = codecRegistry.codecFor(type); 242 TypeCodec<Object> codec = codecRegistry.codecFor(type);
236 if (boundStatement.getBytesUnsafe(index) != null) { 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 String replacement = Matcher.quoteReplacement(codec.format(value)); 245 String replacement = Matcher.quoteReplacement(codec.format(value));
239 query = query.replaceFirst("\\?", replacement); 246 query = query.replaceFirst("\\?", replacement);
240 } 247 }
@@ -15,8 +15,7 @@ @@ -15,8 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao; 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 import org.cassandraunit.BaseCassandraUnit; 19 import org.cassandraunit.BaseCassandraUnit;
21 import org.cassandraunit.CQLDataLoader; 20 import org.cassandraunit.CQLDataLoader;
22 import org.cassandraunit.dataset.CQLDataSet; 21 import org.cassandraunit.dataset.CQLDataSet;
@@ -27,8 +26,7 @@ import java.util.List; @@ -27,8 +26,7 @@ import java.util.List;
27 public class CustomCassandraCQLUnit extends BaseCassandraUnit { 26 public class CustomCassandraCQLUnit extends BaseCassandraUnit {
28 protected List<CQLDataSet> dataSets; 27 protected List<CQLDataSet> dataSets;
29 28
30 - public Session session;  
31 - public Cluster cluster; 29 + public CqlSession session;
32 30
33 public CustomCassandraCQLUnit(List<CQLDataSet> dataSets) { 31 public CustomCassandraCQLUnit(List<CQLDataSet> dataSets) {
34 this.dataSets = dataSets; 32 this.dataSets = dataSets;
@@ -65,11 +63,7 @@ public class CustomCassandraCQLUnit extends BaseCassandraUnit { @@ -65,11 +63,7 @@ public class CustomCassandraCQLUnit extends BaseCassandraUnit {
65 63
66 @Override 64 @Override
67 protected void load() { 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 CQLDataLoader dataLoader = new CQLDataLoader(session); 67 CQLDataLoader dataLoader = new CQLDataLoader(session);
74 dataSets.forEach(dataLoader::load); 68 dataSets.forEach(dataLoader::load);
75 session = dataLoader.getSession(); 69 session = dataLoader.getSession();
@@ -79,20 +73,16 @@ public class CustomCassandraCQLUnit extends BaseCassandraUnit { @@ -79,20 +73,16 @@ public class CustomCassandraCQLUnit extends BaseCassandraUnit {
79 @Override 73 @Override
80 protected void after() { 74 protected void after() {
81 super.after(); 75 super.after();
82 - try (Cluster c = cluster; Session s = session) { 76 + try (CqlSession s = session) {
83 session = null; 77 session = null;
84 - cluster = null;  
85 } 78 }
86 System.setSecurityManager(null); 79 System.setSecurityManager(null);
87 } 80 }
88 81
89 // Getters for those who do not like to directly access fields 82 // Getters for those who do not like to directly access fields
90 83
91 - public Session getSession() { 84 + public CqlSession getSession() {
92 return session; 85 return session;
93 } 86 }
94 87
95 - public Cluster getCluster() {  
96 - return cluster;  
97 - }  
98 } 88 }
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 -}  
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import com.fasterxml.jackson.databind.ObjectMapper; 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import org.junit.runner.RunWith; 21 import org.junit.runner.RunWith;
@@ -134,7 +134,7 @@ public abstract class AbstractServiceTest { @@ -134,7 +134,7 @@ public abstract class AbstractServiceTest {
134 134
135 protected Event generateEvent(TenantId tenantId, EntityId entityId, String eventType, String eventUid) throws IOException { 135 protected Event generateEvent(TenantId tenantId, EntityId entityId, String eventType, String eventUid) throws IOException {
136 if (tenantId == null) { 136 if (tenantId == null) {
137 - tenantId = new TenantId(UUIDs.timeBased()); 137 + tenantId = new TenantId(Uuids.timeBased());
138 } 138 }
139 Event event = new Event(); 139 Event event = new Event();
140 event.setTenantId(tenantId); 140 event.setTenantId(tenantId);
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import org.junit.After; 19 import org.junit.After;
20 import org.junit.Assert; 20 import org.junit.Assert;
21 import org.junit.Before; 21 import org.junit.Before;
@@ -59,8 +59,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { @@ -59,8 +59,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
59 59
60 @Test 60 @Test
61 public void testSaveAndFetchAlarm() throws ExecutionException, InterruptedException { 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 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); 65 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
66 66
@@ -96,8 +96,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { @@ -96,8 +96,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
96 96
97 @Test 97 @Test
98 public void testFindAlarm() throws ExecutionException, InterruptedException { 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 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); 102 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
103 103
@@ -197,8 +197,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { @@ -197,8 +197,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
197 197
198 @Test 198 @Test
199 public void testDeleteAlarm() throws ExecutionException, InterruptedException { 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 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); 203 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
204 204
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import org.apache.commons.lang3.RandomStringUtils; 19 import org.apache.commons.lang3.RandomStringUtils;
20 import org.junit.After; 20 import org.junit.After;
21 import org.junit.Assert; 21 import org.junit.Assert;
@@ -104,7 +104,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest { @@ -104,7 +104,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
104 Asset asset = new Asset(); 104 Asset asset = new Asset();
105 asset.setName("My asset"); 105 asset.setName("My asset");
106 asset.setType("default"); 106 asset.setType("default");
107 - asset.setTenantId(new TenantId(UUIDs.timeBased())); 107 + asset.setTenantId(new TenantId(Uuids.timeBased()));
108 assetService.saveAsset(asset); 108 assetService.saveAsset(asset);
109 } 109 }
110 110
@@ -116,7 +116,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest { @@ -116,7 +116,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
116 asset.setTenantId(tenantId); 116 asset.setTenantId(tenantId);
117 asset = assetService.saveAsset(asset); 117 asset = assetService.saveAsset(asset);
118 try { 118 try {
119 - assetService.assignAssetToCustomer(tenantId, asset.getId(), new CustomerId(UUIDs.timeBased())); 119 + assetService.assignAssetToCustomer(tenantId, asset.getId(), new CustomerId(Uuids.timeBased()));
120 } finally { 120 } finally {
121 assetService.deleteAsset(tenantId, asset.getId()); 121 assetService.deleteAsset(tenantId, asset.getId());
122 } 122 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import org.apache.commons.lang3.RandomStringUtils; 19 import org.apache.commons.lang3.RandomStringUtils;
20 import org.junit.After; 20 import org.junit.After;
21 import org.junit.Assert; 21 import org.junit.Assert;
@@ -105,7 +105,7 @@ public abstract class BaseCustomerServiceTest extends AbstractServiceTest { @@ -105,7 +105,7 @@ public abstract class BaseCustomerServiceTest extends AbstractServiceTest {
105 public void testSaveCustomerWithInvalidTenant() { 105 public void testSaveCustomerWithInvalidTenant() {
106 Customer customer = new Customer(); 106 Customer customer = new Customer();
107 customer.setTitle("My customer"); 107 customer.setTitle("My customer");
108 - customer.setTenantId(new TenantId(UUIDs.timeBased())); 108 + customer.setTenantId(new TenantId(Uuids.timeBased()));
109 customerService.saveCustomer(customer); 109 customerService.saveCustomer(customer);
110 } 110 }
111 111
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import org.apache.commons.lang3.RandomStringUtils; 19 import org.apache.commons.lang3.RandomStringUtils;
20 import org.junit.After; 20 import org.junit.After;
21 import org.junit.Assert; 21 import org.junit.Assert;
@@ -98,7 +98,7 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest { @@ -98,7 +98,7 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest {
98 public void testSaveDashboardWithInvalidTenant() { 98 public void testSaveDashboardWithInvalidTenant() {
99 Dashboard dashboard = new Dashboard(); 99 Dashboard dashboard = new Dashboard();
100 dashboard.setTitle("My dashboard"); 100 dashboard.setTitle("My dashboard");
101 - dashboard.setTenantId(new TenantId(UUIDs.timeBased())); 101 + dashboard.setTenantId(new TenantId(Uuids.timeBased()));
102 dashboardService.saveDashboard(dashboard); 102 dashboardService.saveDashboard(dashboard);
103 } 103 }
104 104
@@ -109,7 +109,7 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest { @@ -109,7 +109,7 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest {
109 dashboard.setTenantId(tenantId); 109 dashboard.setTenantId(tenantId);
110 dashboard = dashboardService.saveDashboard(dashboard); 110 dashboard = dashboardService.saveDashboard(dashboard);
111 try { 111 try {
112 - dashboardService.assignDashboardToCustomer(tenantId, dashboard.getId(), new CustomerId(UUIDs.timeBased())); 112 + dashboardService.assignDashboardToCustomer(tenantId, dashboard.getId(), new CustomerId(Uuids.timeBased()));
113 } finally { 113 } finally {
114 dashboardService.deleteDashboard(tenantId, dashboard.getId()); 114 dashboardService.deleteDashboard(tenantId, dashboard.getId());
115 } 115 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import org.junit.After; 19 import org.junit.After;
20 import org.junit.Assert; 20 import org.junit.Assert;
21 import org.junit.Before; 21 import org.junit.Before;
@@ -109,7 +109,7 @@ public abstract class BaseDeviceCredentialsServiceTest extends AbstractServiceTe @@ -109,7 +109,7 @@ public abstract class BaseDeviceCredentialsServiceTest extends AbstractServiceTe
109 device.setTenantId(tenantId); 109 device.setTenantId(tenantId);
110 device = deviceService.saveDevice(device); 110 device = deviceService.saveDevice(device);
111 DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId()); 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 newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime()); 113 newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime());
114 newDeviceCredentials.setDeviceId(deviceCredentials.getDeviceId()); 114 newDeviceCredentials.setDeviceId(deviceCredentials.getDeviceId());
115 newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType()); 115 newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType());
@@ -129,7 +129,7 @@ public abstract class BaseDeviceCredentialsServiceTest extends AbstractServiceTe @@ -129,7 +129,7 @@ public abstract class BaseDeviceCredentialsServiceTest extends AbstractServiceTe
129 device.setTenantId(tenantId); 129 device.setTenantId(tenantId);
130 device = deviceService.saveDevice(device); 130 device = deviceService.saveDevice(device);
131 DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId()); 131 DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId());
132 - deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased())); 132 + deviceCredentials.setDeviceId(new DeviceId(Uuids.timeBased()));
133 try { 133 try {
134 deviceCredentialsService.updateDeviceCredentials(tenantId, deviceCredentials); 134 deviceCredentialsService.updateDeviceCredentials(tenantId, deviceCredentials);
135 } finally { 135 } finally {
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import org.apache.commons.lang3.RandomStringUtils; 19 import org.apache.commons.lang3.RandomStringUtils;
20 import org.junit.After; 20 import org.junit.After;
21 import org.junit.Assert; 21 import org.junit.Assert;
@@ -110,7 +110,7 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest { @@ -110,7 +110,7 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
110 Device device = new Device(); 110 Device device = new Device();
111 device.setName("My device"); 111 device.setName("My device");
112 device.setType("default"); 112 device.setType("default");
113 - device.setTenantId(new TenantId(UUIDs.timeBased())); 113 + device.setTenantId(new TenantId(Uuids.timeBased()));
114 deviceService.saveDevice(device); 114 deviceService.saveDevice(device);
115 } 115 }
116 116
@@ -122,7 +122,7 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest { @@ -122,7 +122,7 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
122 device.setTenantId(tenantId); 122 device.setTenantId(tenantId);
123 device = deviceService.saveDevice(device); 123 device = deviceService.saveDevice(device);
124 try { 124 try {
125 - deviceService.assignDeviceToCustomer(tenantId, device.getId(), new CustomerId(UUIDs.timeBased())); 125 + deviceService.assignDeviceToCustomer(tenantId, device.getId(), new CustomerId(Uuids.timeBased()));
126 } finally { 126 } finally {
127 deviceService.deleteDevice(tenantId, device.getId()); 127 deviceService.deleteDevice(tenantId, device.getId());
128 } 128 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import org.junit.After; 19 import org.junit.After;
20 import org.junit.Assert; 20 import org.junit.Assert;
21 import org.junit.Before; 21 import org.junit.Before;
@@ -47,8 +47,8 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { @@ -47,8 +47,8 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
47 47
48 @Test 48 @Test
49 public void testSaveRelation() throws ExecutionException, InterruptedException { 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 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); 53 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
54 54
@@ -65,9 +65,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { @@ -65,9 +65,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
65 65
66 @Test 66 @Test
67 public void testDeleteRelation() throws ExecutionException, InterruptedException { 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 EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); 72 EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
73 EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE); 73 EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE);
@@ -86,9 +86,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { @@ -86,9 +86,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
86 86
87 @Test 87 @Test
88 public void testDeleteEntityRelations() throws ExecutionException, InterruptedException { 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 EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); 93 EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
94 EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE); 94 EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE);
@@ -105,10 +105,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { @@ -105,10 +105,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
105 105
106 @Test 106 @Test
107 public void testFindFrom() throws ExecutionException, InterruptedException { 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 EntityRelation relationA1 = new EntityRelation(parentA, childA, EntityRelation.CONTAINS_TYPE); 113 EntityRelation relationA1 = new EntityRelation(parentA, childA, EntityRelation.CONTAINS_TYPE);
114 EntityRelation relationA2 = new EntityRelation(parentA, childB, EntityRelation.CONTAINS_TYPE); 114 EntityRelation relationA2 = new EntityRelation(parentA, childB, EntityRelation.CONTAINS_TYPE);
@@ -157,10 +157,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { @@ -157,10 +157,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
157 157
158 @Test 158 @Test
159 public void testFindTo() throws ExecutionException, InterruptedException { 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 EntityRelation relationA1 = new EntityRelation(parentA, childA, EntityRelation.CONTAINS_TYPE); 165 EntityRelation relationA1 = new EntityRelation(parentA, childA, EntityRelation.CONTAINS_TYPE);
166 EntityRelation relationA2 = new EntityRelation(parentA, childB, EntityRelation.CONTAINS_TYPE); 166 EntityRelation relationA2 = new EntityRelation(parentA, childB, EntityRelation.CONTAINS_TYPE);
@@ -207,9 +207,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { @@ -207,9 +207,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
207 @Test 207 @Test
208 public void testCyclicRecursiveRelation() throws ExecutionException, InterruptedException { 208 public void testCyclicRecursiveRelation() throws ExecutionException, InterruptedException {
209 // A -> B -> C -> A 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 EntityRelation relationA = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE); 214 EntityRelation relationA = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE);
215 EntityRelation relationB = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE); 215 EntityRelation relationB = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE);
@@ -239,10 +239,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { @@ -239,10 +239,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
239 @Test 239 @Test
240 public void testRecursiveRelation() throws ExecutionException, InterruptedException { 240 public void testRecursiveRelation() throws ExecutionException, InterruptedException {
241 // A -> B -> [C,D] 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 EntityRelation relationAB = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE); 247 EntityRelation relationAB = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE);
248 EntityRelation relationBC = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE); 248 EntityRelation relationBC = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE);
@@ -272,7 +272,7 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { @@ -272,7 +272,7 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
272 @Test(expected = DataValidationException.class) 272 @Test(expected = DataValidationException.class)
273 public void testSaveRelationWithEmptyFrom() throws ExecutionException, InterruptedException { 273 public void testSaveRelationWithEmptyFrom() throws ExecutionException, InterruptedException {
274 EntityRelation relation = new EntityRelation(); 274 EntityRelation relation = new EntityRelation();
275 - relation.setTo(new AssetId(UUIDs.timeBased())); 275 + relation.setTo(new AssetId(Uuids.timeBased()));
276 relation.setType(EntityRelation.CONTAINS_TYPE); 276 relation.setType(EntityRelation.CONTAINS_TYPE);
277 Assert.assertTrue(saveRelation(relation)); 277 Assert.assertTrue(saveRelation(relation));
278 } 278 }
@@ -280,7 +280,7 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { @@ -280,7 +280,7 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
280 @Test(expected = DataValidationException.class) 280 @Test(expected = DataValidationException.class)
281 public void testSaveRelationWithEmptyTo() throws ExecutionException, InterruptedException { 281 public void testSaveRelationWithEmptyTo() throws ExecutionException, InterruptedException {
282 EntityRelation relation = new EntityRelation(); 282 EntityRelation relation = new EntityRelation();
283 - relation.setFrom(new AssetId(UUIDs.timeBased())); 283 + relation.setFrom(new AssetId(Uuids.timeBased()));
284 relation.setType(EntityRelation.CONTAINS_TYPE); 284 relation.setType(EntityRelation.CONTAINS_TYPE);
285 Assert.assertTrue(saveRelation(relation)); 285 Assert.assertTrue(saveRelation(relation));
286 } 286 }
@@ -288,8 +288,8 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { @@ -288,8 +288,8 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
288 @Test(expected = DataValidationException.class) 288 @Test(expected = DataValidationException.class)
289 public void testSaveRelationWithEmptyType() throws ExecutionException, InterruptedException { 289 public void testSaveRelationWithEmptyType() throws ExecutionException, InterruptedException {
290 EntityRelation relation = new EntityRelation(); 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 Assert.assertTrue(saveRelation(relation)); 293 Assert.assertTrue(saveRelation(relation));
294 } 294 }
295 } 295 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import com.fasterxml.jackson.databind.ObjectMapper; 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import org.apache.commons.lang3.RandomStringUtils; 20 import org.apache.commons.lang3.RandomStringUtils;
21 import org.junit.After; 21 import org.junit.After;
@@ -94,7 +94,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { @@ -94,7 +94,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
94 public void testSaveRuleChainWithInvalidTenant() { 94 public void testSaveRuleChainWithInvalidTenant() {
95 RuleChain ruleChain = new RuleChain(); 95 RuleChain ruleChain = new RuleChain();
96 ruleChain.setName("My RuleChain"); 96 ruleChain.setName("My RuleChain");
97 - ruleChain.setTenantId(new TenantId(UUIDs.timeBased())); 97 + ruleChain.setTenantId(new TenantId(Uuids.timeBased()));
98 ruleChainService.saveRuleChain(ruleChain); 98 ruleChainService.saveRuleChain(ruleChain);
99 } 99 }
100 100
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import com.fasterxml.jackson.databind.ObjectMapper; 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import org.junit.After; 21 import org.junit.After;
@@ -141,7 +141,7 @@ public abstract class BaseWidgetTypeServiceTest extends AbstractServiceTest { @@ -141,7 +141,7 @@ public abstract class BaseWidgetTypeServiceTest extends AbstractServiceTest {
141 WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle); 141 WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
142 142
143 WidgetType widgetType = new WidgetType(); 143 WidgetType widgetType = new WidgetType();
144 - widgetType.setTenantId(new TenantId(UUIDs.timeBased())); 144 + widgetType.setTenantId(new TenantId(Uuids.timeBased()));
145 widgetType.setBundleAlias(savedWidgetsBundle.getAlias()); 145 widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
146 widgetType.setName("Widget Type"); 146 widgetType.setName("Widget Type");
147 widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class)); 147 widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service; 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 import org.junit.After; 19 import org.junit.After;
20 import org.junit.Assert; 20 import org.junit.Assert;
21 import org.junit.Before; 21 import org.junit.Before;
@@ -88,7 +88,7 @@ public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest { @@ -88,7 +88,7 @@ public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest {
88 public void testSaveWidgetsBundleWithInvalidTenant() { 88 public void testSaveWidgetsBundleWithInvalidTenant() {
89 WidgetsBundle widgetsBundle = new WidgetsBundle(); 89 WidgetsBundle widgetsBundle = new WidgetsBundle();
90 widgetsBundle.setTitle("My widgets bundle"); 90 widgetsBundle.setTitle("My widgets bundle");
91 - widgetsBundle.setTenantId(new TenantId(UUIDs.timeBased())); 91 + widgetsBundle.setTenantId(new TenantId(Uuids.timeBased()));
92 widgetsBundleService.saveWidgetsBundle(widgetsBundle); 92 widgetsBundleService.saveWidgetsBundle(widgetsBundle);
93 } 93 }
94 94
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service.attributes; 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 import org.junit.Assert; 19 import org.junit.Assert;
20 import org.junit.Before; 20 import org.junit.Before;
21 import org.junit.Test; 21 import org.junit.Test;
@@ -47,7 +47,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest { @@ -47,7 +47,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest {
47 47
48 @Test 48 @Test
49 public void saveAndFetch() throws Exception { 49 public void saveAndFetch() throws Exception {
50 - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 50 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
51 KvEntry attrValue = new StringDataEntry("attribute1", "value1"); 51 KvEntry attrValue = new StringDataEntry("attribute1", "value1");
52 AttributeKvEntry attr = new BaseAttributeKvEntry(attrValue, 42L); 52 AttributeKvEntry attr = new BaseAttributeKvEntry(attrValue, 42L);
53 attributesService.save(SYSTEM_TENANT_ID, deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attr)).get(); 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,7 +58,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest {
58 58
59 @Test 59 @Test
60 public void saveMultipleTypeAndFetch() throws Exception { 60 public void saveMultipleTypeAndFetch() throws Exception {
61 - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 61 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
62 KvEntry attrOldValue = new StringDataEntry("attribute1", "value1"); 62 KvEntry attrOldValue = new StringDataEntry("attribute1", "value1");
63 AttributeKvEntry attrOld = new BaseAttributeKvEntry(attrOldValue, 42L); 63 AttributeKvEntry attrOld = new BaseAttributeKvEntry(attrOldValue, 42L);
64 64
@@ -78,7 +78,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest { @@ -78,7 +78,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest {
78 78
79 @Test 79 @Test
80 public void findAll() throws Exception { 80 public void findAll() throws Exception {
81 - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 81 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
82 82
83 KvEntry attrAOldValue = new StringDataEntry("A", "value1"); 83 KvEntry attrAOldValue = new StringDataEntry("A", "value1");
84 AttributeKvEntry attrAOld = new BaseAttributeKvEntry(attrAOldValue, 42L); 84 AttributeKvEntry attrAOld = new BaseAttributeKvEntry(attrAOldValue, 42L);
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service.event; 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 import org.junit.Assert; 19 import org.junit.Assert;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.thingsboard.server.common.data.DataConstants; 21 import org.thingsboard.server.common.data.DataConstants;
@@ -40,8 +40,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest { @@ -40,8 +40,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest {
40 40
41 @Test 41 @Test
42 public void saveEvent() throws Exception { 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 Event saved = eventService.save(event); 45 Event saved = eventService.save(event);
46 Optional<Event> loaded = eventService.findEvent(event.getTenantId(), event.getEntityId(), event.getType(), event.getUid()); 46 Optional<Event> loaded = eventService.findEvent(event.getTenantId(), event.getEntityId(), event.getType(), event.getUid());
47 Assert.assertTrue(loaded.isPresent()); 47 Assert.assertTrue(loaded.isPresent());
@@ -51,8 +51,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest { @@ -51,8 +51,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest {
51 51
52 @Test 52 @Test
53 public void saveEventIfNotExists() throws Exception { 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 Optional<Event> saved = eventService.saveIfNotExists(event); 56 Optional<Event> saved = eventService.saveIfNotExists(event);
57 Assert.assertTrue(saved.isPresent()); 57 Assert.assertTrue(saved.isPresent());
58 saved = eventService.saveIfNotExists(event); 58 saved = eventService.saveIfNotExists(event);
@@ -67,8 +67,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest { @@ -67,8 +67,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest {
67 long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC); 67 long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
68 long timeAfterEndTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC); 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 saveEventWithProvidedTime(timeBeforeStartTime, customerId, tenantId); 72 saveEventWithProvidedTime(timeBeforeStartTime, customerId, tenantId);
73 Event savedEvent = saveEventWithProvidedTime(eventTime, customerId, tenantId); 73 Event savedEvent = saveEventWithProvidedTime(eventTime, customerId, tenantId);
74 Event savedEvent2 = saveEventWithProvidedTime(eventTime+1, customerId, tenantId); 74 Event savedEvent2 = saveEventWithProvidedTime(eventTime+1, customerId, tenantId);
@@ -102,8 +102,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest { @@ -102,8 +102,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest {
102 long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC); 102 long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
103 long timeAfterEndTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC); 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 saveEventWithProvidedTime(timeBeforeStartTime, customerId, tenantId); 107 saveEventWithProvidedTime(timeBeforeStartTime, customerId, tenantId);
108 Event savedEvent = saveEventWithProvidedTime(eventTime, customerId, tenantId); 108 Event savedEvent = saveEventWithProvidedTime(eventTime, customerId, tenantId);
109 Event savedEvent2 = saveEventWithProvidedTime(eventTime+1, customerId, tenantId); 109 Event savedEvent2 = saveEventWithProvidedTime(eventTime+1, customerId, tenantId);
@@ -131,7 +131,7 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest { @@ -131,7 +131,7 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest {
131 131
132 private Event saveEventWithProvidedTime(long time, EntityId entityId, TenantId tenantId) throws IOException { 132 private Event saveEventWithProvidedTime(long time, EntityId entityId, TenantId tenantId) throws IOException {
133 Event event = generateEvent(tenantId, entityId, DataConstants.STATS, null); 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 return eventService.save(event); 135 return eventService.save(event);
136 } 136 }
137 -}  
  137 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service.timeseries; 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 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
20 import org.junit.*; 20 import org.junit.*;
21 import org.thingsboard.server.common.data.EntityView; 21 import org.thingsboard.server.common.data.EntityView;
@@ -84,7 +84,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { @@ -84,7 +84,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
84 84
85 @Test 85 @Test
86 public void testFindAllLatest() throws Exception { 86 public void testFindAllLatest() throws Exception {
87 - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 87 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
88 88
89 saveEntries(deviceId, TS - 2); 89 saveEntries(deviceId, TS - 2);
90 saveEntries(deviceId, TS - 1); 90 saveEntries(deviceId, TS - 1);
@@ -132,7 +132,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { @@ -132,7 +132,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
132 132
133 @Test 133 @Test
134 public void testFindLatest() throws Exception { 134 public void testFindLatest() throws Exception {
135 - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 135 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
136 136
137 saveEntries(deviceId, TS - 2); 137 saveEntries(deviceId, TS - 2);
138 saveEntries(deviceId, TS - 1); 138 saveEntries(deviceId, TS - 1);
@@ -151,7 +151,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { @@ -151,7 +151,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
151 151
152 @Test 152 @Test
153 public void testFindByQueryAscOrder() throws Exception { 153 public void testFindByQueryAscOrder() throws Exception {
154 - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 154 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
155 155
156 saveEntries(deviceId, TS - 2); 156 saveEntries(deviceId, TS - 2);
157 saveEntries(deviceId, TS - 1); 157 saveEntries(deviceId, TS - 1);
@@ -177,7 +177,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { @@ -177,7 +177,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
177 177
178 @Test 178 @Test
179 public void testFindByQueryDescOrder() throws Exception { 179 public void testFindByQueryDescOrder() throws Exception {
180 - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 180 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
181 181
182 saveEntries(deviceId, TS - 2); 182 saveEntries(deviceId, TS - 2);
183 saveEntries(deviceId, TS - 1); 183 saveEntries(deviceId, TS - 1);
@@ -203,7 +203,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { @@ -203,7 +203,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
203 203
204 @Test 204 @Test
205 public void testDeleteDeviceTsDataWithOverwritingLatest() throws Exception { 205 public void testDeleteDeviceTsDataWithOverwritingLatest() throws Exception {
206 - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 206 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
207 207
208 saveEntries(deviceId, 10000); 208 saveEntries(deviceId, 10000);
209 saveEntries(deviceId, 20000); 209 saveEntries(deviceId, 20000);
@@ -223,7 +223,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { @@ -223,7 +223,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
223 223
224 @Test 224 @Test
225 public void testFindDeviceTsData() throws Exception { 225 public void testFindDeviceTsData() throws Exception {
226 - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 226 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
227 List<TsKvEntry> entries = new ArrayList<>(); 227 List<TsKvEntry> entries = new ArrayList<>();
228 228
229 entries.add(save(deviceId, 5000, 100)); 229 entries.add(save(deviceId, 5000, 100));
@@ -374,7 +374,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { @@ -374,7 +374,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
374 374
375 @Test 375 @Test
376 public void testFindDeviceLongAndDoubleTsData() throws Exception { 376 public void testFindDeviceLongAndDoubleTsData() throws Exception {
377 - DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 377 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
378 List<TsKvEntry> entries = new ArrayList<>(); 378 List<TsKvEntry> entries = new ArrayList<>();
379 379
380 entries.add(save(deviceId, 5000, 100)); 380 entries.add(save(deviceId, 5000, 100));
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.asset; 16 package org.thingsboard.server.dao.sql.asset;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.google.common.util.concurrent.ListenableFuture; 19 import com.google.common.util.concurrent.ListenableFuture;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.springframework.beans.factory.annotation.Autowired; 21 import org.springframework.beans.factory.annotation.Autowired;
@@ -50,12 +50,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest { @@ -50,12 +50,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
50 50
51 @Test 51 @Test
52 public void testFindAssetsByTenantId() { 52 public void testFindAssetsByTenantId() {
53 - UUID tenantId1 = UUIDs.timeBased();  
54 - UUID tenantId2 = UUIDs.timeBased();  
55 - UUID customerId1 = UUIDs.timeBased();  
56 - UUID customerId2 = UUIDs.timeBased(); 53 + UUID tenantId1 = Uuids.timeBased();
  54 + UUID tenantId2 = Uuids.timeBased();
  55 + UUID customerId1 = Uuids.timeBased();
  56 + UUID customerId2 = Uuids.timeBased();
57 for (int i = 0; i < 60; i++) { 57 for (int i = 0; i < 60; i++) {
58 - UUID assetId = UUIDs.timeBased(); 58 + UUID assetId = Uuids.timeBased();
59 UUID tenantId = i % 2 == 0 ? tenantId1 : tenantId2; 59 UUID tenantId = i % 2 == 0 ? tenantId1 : tenantId2;
60 UUID customerId = i % 2 == 0 ? customerId1 : customerId2; 60 UUID customerId = i % 2 == 0 ? customerId1 : customerId2;
61 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1"); 61 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1");
@@ -77,12 +77,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest { @@ -77,12 +77,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
77 77
78 @Test 78 @Test
79 public void testFindAssetsByTenantIdAndCustomerId() { 79 public void testFindAssetsByTenantIdAndCustomerId() {
80 - UUID tenantId1 = UUIDs.timeBased();  
81 - UUID tenantId2 = UUIDs.timeBased();  
82 - UUID customerId1 = UUIDs.timeBased();  
83 - UUID customerId2 = UUIDs.timeBased(); 80 + UUID tenantId1 = Uuids.timeBased();
  81 + UUID tenantId2 = Uuids.timeBased();
  82 + UUID customerId1 = Uuids.timeBased();
  83 + UUID customerId2 = Uuids.timeBased();
84 for (int i = 0; i < 60; i++) { 84 for (int i = 0; i < 60; i++) {
85 - UUID assetId = UUIDs.timeBased(); 85 + UUID assetId = Uuids.timeBased();
86 UUID tenantId = i % 2 == 0 ? tenantId1 : tenantId2; 86 UUID tenantId = i % 2 == 0 ? tenantId1 : tenantId2;
87 UUID customerId = i % 2 == 0 ? customerId1 : customerId2; 87 UUID customerId = i % 2 == 0 ? customerId1 : customerId2;
88 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1"); 88 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1");
@@ -103,11 +103,11 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest { @@ -103,11 +103,11 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
103 103
104 @Test 104 @Test
105 public void testFindAssetsByTenantIdAndIdsAsync() throws ExecutionException, InterruptedException { 105 public void testFindAssetsByTenantIdAndIdsAsync() throws ExecutionException, InterruptedException {
106 - UUID tenantId = UUIDs.timeBased();  
107 - UUID customerId = UUIDs.timeBased(); 106 + UUID tenantId = Uuids.timeBased();
  107 + UUID customerId = Uuids.timeBased();
108 List<UUID> searchIds = new ArrayList<>(); 108 List<UUID> searchIds = new ArrayList<>();
109 for (int i = 0; i < 30; i++) { 109 for (int i = 0; i < 30; i++) {
110 - UUID assetId = UUIDs.timeBased(); 110 + UUID assetId = Uuids.timeBased();
111 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1"); 111 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1");
112 if (i % 3 == 0) { 112 if (i % 3 == 0) {
113 searchIds.add(assetId); 113 searchIds.add(assetId);
@@ -123,12 +123,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest { @@ -123,12 +123,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
123 123
124 @Test 124 @Test
125 public void testFindAssetsByTenantIdCustomerIdAndIdsAsync() throws ExecutionException, InterruptedException { 125 public void testFindAssetsByTenantIdCustomerIdAndIdsAsync() throws ExecutionException, InterruptedException {
126 - UUID tenantId = UUIDs.timeBased();  
127 - UUID customerId1 = UUIDs.timeBased();  
128 - UUID customerId2 = UUIDs.timeBased(); 126 + UUID tenantId = Uuids.timeBased();
  127 + UUID customerId1 = Uuids.timeBased();
  128 + UUID customerId2 = Uuids.timeBased();
129 List<UUID> searchIds = new ArrayList<>(); 129 List<UUID> searchIds = new ArrayList<>();
130 for (int i = 0; i < 30; i++) { 130 for (int i = 0; i < 30; i++) {
131 - UUID assetId = UUIDs.timeBased(); 131 + UUID assetId = Uuids.timeBased();
132 UUID customerId = i%2 == 0 ? customerId1 : customerId2; 132 UUID customerId = i%2 == 0 ? customerId1 : customerId2;
133 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1"); 133 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1");
134 if (i % 3 == 0) { 134 if (i % 3 == 0) {
@@ -145,12 +145,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest { @@ -145,12 +145,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
145 145
146 @Test 146 @Test
147 public void testFindAssetsByTenantIdAndName() { 147 public void testFindAssetsByTenantIdAndName() {
148 - UUID assetId1 = UUIDs.timeBased();  
149 - UUID assetId2 = UUIDs.timeBased();  
150 - UUID tenantId1 = UUIDs.timeBased();  
151 - UUID tenantId2 = UUIDs.timeBased();  
152 - UUID customerId1 = UUIDs.timeBased();  
153 - UUID customerId2 = UUIDs.timeBased(); 148 + UUID assetId1 = Uuids.timeBased();
  149 + UUID assetId2 = Uuids.timeBased();
  150 + UUID tenantId1 = Uuids.timeBased();
  151 + UUID tenantId2 = Uuids.timeBased();
  152 + UUID customerId1 = Uuids.timeBased();
  153 + UUID customerId2 = Uuids.timeBased();
154 String name = "TEST_ASSET"; 154 String name = "TEST_ASSET";
155 saveAsset(assetId1, tenantId1, customerId1, name, "TYPE_1"); 155 saveAsset(assetId1, tenantId1, customerId1, name, "TYPE_1");
156 saveAsset(assetId2, tenantId2, customerId2, name, "TYPE_1"); 156 saveAsset(assetId2, tenantId2, customerId2, name, "TYPE_1");
@@ -175,22 +175,22 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest { @@ -175,22 +175,22 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
175 175
176 @Test 176 @Test
177 public void testFindTenantAssetTypesAsync() throws ExecutionException, InterruptedException { 177 public void testFindTenantAssetTypesAsync() throws ExecutionException, InterruptedException {
178 - UUID assetId1 = UUIDs.timeBased();  
179 - UUID assetId2 = UUIDs.timeBased();  
180 - UUID tenantId1 = UUIDs.timeBased();  
181 - UUID tenantId2 = UUIDs.timeBased();  
182 - UUID customerId1 = UUIDs.timeBased();  
183 - UUID customerId2 = UUIDs.timeBased();  
184 - saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_1", "TYPE_1");  
185 - saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_2", "TYPE_1");  
186 - saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_3", "TYPE_2");  
187 - saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_4", "TYPE_3");  
188 - saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_5", "TYPE_3");  
189 - saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_6", "TYPE_3");  
190 -  
191 - saveAsset(UUIDs.timeBased(), tenantId2, customerId2, "TEST_ASSET_7", "TYPE_4");  
192 - saveAsset(UUIDs.timeBased(), tenantId2, customerId2, "TEST_ASSET_8", "TYPE_1");  
193 - saveAsset(UUIDs.timeBased(), tenantId2, customerId2, "TEST_ASSET_9", "TYPE_1"); 178 + UUID assetId1 = Uuids.timeBased();
  179 + UUID assetId2 = Uuids.timeBased();
  180 + UUID tenantId1 = Uuids.timeBased();
  181 + UUID tenantId2 = Uuids.timeBased();
  182 + UUID customerId1 = Uuids.timeBased();
  183 + UUID customerId2 = Uuids.timeBased();
  184 + saveAsset(Uuids.timeBased(), tenantId1, customerId1, "TEST_ASSET_1", "TYPE_1");
  185 + saveAsset(Uuids.timeBased(), tenantId1, customerId1, "TEST_ASSET_2", "TYPE_1");
  186 + saveAsset(Uuids.timeBased(), tenantId1, customerId1, "TEST_ASSET_3", "TYPE_2");
  187 + saveAsset(Uuids.timeBased(), tenantId1, customerId1, "TEST_ASSET_4", "TYPE_3");
  188 + saveAsset(Uuids.timeBased(), tenantId1, customerId1, "TEST_ASSET_5", "TYPE_3");
  189 + saveAsset(Uuids.timeBased(), tenantId1, customerId1, "TEST_ASSET_6", "TYPE_3");
  190 +
  191 + saveAsset(Uuids.timeBased(), tenantId2, customerId2, "TEST_ASSET_7", "TYPE_4");
  192 + saveAsset(Uuids.timeBased(), tenantId2, customerId2, "TEST_ASSET_8", "TYPE_1");
  193 + saveAsset(Uuids.timeBased(), tenantId2, customerId2, "TEST_ASSET_9", "TYPE_1");
194 194
195 List<EntitySubtype> tenant1Types = assetDao.findTenantAssetTypesAsync(tenantId1).get(); 195 List<EntitySubtype> tenant1Types = assetDao.findTenantAssetTypesAsync(tenantId1).get();
196 assertNotNull(tenant1Types); 196 assertNotNull(tenant1Types);
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.component; 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 import org.junit.Test; 19 import org.junit.Test;
20 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.thingsboard.server.common.data.id.ComponentDescriptorId; 21 import org.thingsboard.server.common.data.id.ComponentDescriptorId;
@@ -77,7 +77,7 @@ public class JpaBaseComponentDescriptorDaoTest extends AbstractJpaDaoTest { @@ -77,7 +77,7 @@ public class JpaBaseComponentDescriptorDaoTest extends AbstractJpaDaoTest {
77 77
78 private void createComponentDescriptor(ComponentType type, ComponentScope scope, int index) { 78 private void createComponentDescriptor(ComponentType type, ComponentScope scope, int index) {
79 ComponentDescriptor component = new ComponentDescriptor(); 79 ComponentDescriptor component = new ComponentDescriptor();
80 - component.setId(new ComponentDescriptorId(UUIDs.timeBased())); 80 + component.setId(new ComponentDescriptorId(Uuids.timeBased()));
81 component.setType(type); 81 component.setType(type);
82 component.setScope(scope); 82 component.setScope(scope);
83 component.setName("COMPONENT_" + index); 83 component.setName("COMPONENT_" + index);
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.customer; 16 package org.thingsboard.server.dao.sql.customer;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import org.junit.Test; 19 import org.junit.Test;
20 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.thingsboard.server.common.data.Customer; 21 import org.thingsboard.server.common.data.Customer;
@@ -43,8 +43,8 @@ public class JpaCustomerDaoTest extends AbstractJpaDaoTest { @@ -43,8 +43,8 @@ public class JpaCustomerDaoTest extends AbstractJpaDaoTest {
43 43
44 @Test 44 @Test
45 public void testFindByTenantId() { 45 public void testFindByTenantId() {
46 - UUID tenantId1 = UUIDs.timeBased();  
47 - UUID tenantId2 = UUIDs.timeBased(); 46 + UUID tenantId1 = Uuids.timeBased();
  47 + UUID tenantId2 = Uuids.timeBased();
48 48
49 for (int i = 0; i < 20; i++) { 49 for (int i = 0; i < 20; i++) {
50 createCustomer(tenantId1, i); 50 createCustomer(tenantId1, i);
@@ -62,7 +62,7 @@ public class JpaCustomerDaoTest extends AbstractJpaDaoTest { @@ -62,7 +62,7 @@ public class JpaCustomerDaoTest extends AbstractJpaDaoTest {
62 62
63 @Test 63 @Test
64 public void testFindCustomersByTenantIdAndTitle() { 64 public void testFindCustomersByTenantIdAndTitle() {
65 - UUID tenantId = UUIDs.timeBased(); 65 + UUID tenantId = Uuids.timeBased();
66 66
67 for (int i = 0; i < 10; i++) { 67 for (int i = 0; i < 10; i++) {
68 createCustomer(tenantId, i); 68 createCustomer(tenantId, i);
@@ -75,7 +75,7 @@ public class JpaCustomerDaoTest extends AbstractJpaDaoTest { @@ -75,7 +75,7 @@ public class JpaCustomerDaoTest extends AbstractJpaDaoTest {
75 75
76 private void createCustomer(UUID tenantId, int index) { 76 private void createCustomer(UUID tenantId, int index) {
77 Customer customer = new Customer(); 77 Customer customer = new Customer();
78 - customer.setId(new CustomerId(UUIDs.timeBased())); 78 + customer.setId(new CustomerId(Uuids.timeBased()));
79 customer.setTenantId(new TenantId(tenantId)); 79 customer.setTenantId(new TenantId(tenantId));
80 customer.setTitle("CUSTOMER_" + index); 80 customer.setTitle("CUSTOMER_" + index);
81 customerDao.save(new TenantId(tenantId), customer); 81 customerDao.save(new TenantId(tenantId), customer);
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.dashboard; 16 package org.thingsboard.server.dao.sql.dashboard;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import org.junit.Assert; 19 import org.junit.Assert;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.springframework.beans.factory.annotation.Autowired; 21 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,8 +41,8 @@ public class JpaDashboardInfoDaoTest extends AbstractJpaDaoTest { @@ -41,8 +41,8 @@ public class JpaDashboardInfoDaoTest extends AbstractJpaDaoTest {
41 41
42 @Test 42 @Test
43 public void testFindDashboardsByTenantId() { 43 public void testFindDashboardsByTenantId() {
44 - UUID tenantId1 = UUIDs.timeBased();  
45 - UUID tenantId2 = UUIDs.timeBased(); 44 + UUID tenantId1 = Uuids.timeBased();
  45 + UUID tenantId2 = Uuids.timeBased();
46 46
47 for (int i = 0; i < 20; i++) { 47 for (int i = 0; i < 20; i++) {
48 createDashboard(tenantId1, i); 48 createDashboard(tenantId1, i);
@@ -59,7 +59,7 @@ public class JpaDashboardInfoDaoTest extends AbstractJpaDaoTest { @@ -59,7 +59,7 @@ public class JpaDashboardInfoDaoTest extends AbstractJpaDaoTest {
59 59
60 private void createDashboard(UUID tenantId, int index) { 60 private void createDashboard(UUID tenantId, int index) {
61 DashboardInfo dashboardInfo = new DashboardInfo(); 61 DashboardInfo dashboardInfo = new DashboardInfo();
62 - dashboardInfo.setId(new DashboardId(UUIDs.timeBased())); 62 + dashboardInfo.setId(new DashboardId(Uuids.timeBased()));
63 dashboardInfo.setTenantId(new TenantId(tenantId)); 63 dashboardInfo.setTenantId(new TenantId(tenantId));
64 dashboardInfo.setTitle("DASHBOARD_" + index); 64 dashboardInfo.setTitle("DASHBOARD_" + index);
65 dashboardInfoDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, dashboardInfo); 65 dashboardInfoDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, dashboardInfo);
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.device; 16 package org.thingsboard.server.dao.sql.device;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.google.common.util.concurrent.ListenableFuture; 19 import com.google.common.util.concurrent.ListenableFuture;
20 import com.google.common.util.concurrent.ListeningExecutorService; 20 import com.google.common.util.concurrent.ListeningExecutorService;
21 import com.google.common.util.concurrent.MoreExecutors; 21 import com.google.common.util.concurrent.MoreExecutors;
@@ -49,10 +49,10 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest { @@ -49,10 +49,10 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
49 49
50 @Test 50 @Test
51 public void testFindDevicesByTenantId() { 51 public void testFindDevicesByTenantId() {
52 - UUID tenantId1 = UUIDs.timeBased();  
53 - UUID tenantId2 = UUIDs.timeBased();  
54 - UUID customerId1 = UUIDs.timeBased();  
55 - UUID customerId2 = UUIDs.timeBased(); 52 + UUID tenantId1 = Uuids.timeBased();
  53 + UUID tenantId2 = Uuids.timeBased();
  54 + UUID customerId1 = Uuids.timeBased();
  55 + UUID customerId2 = Uuids.timeBased();
56 createDevices(tenantId1, tenantId2, customerId1, customerId2, 40); 56 createDevices(tenantId1, tenantId2, customerId1, customerId2, 40);
57 57
58 PageLink pageLink = new PageLink(15, 0, "SEARCH_TEXT"); 58 PageLink pageLink = new PageLink(15, 0, "SEARCH_TEXT");
@@ -67,8 +67,8 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest { @@ -67,8 +67,8 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
67 67
68 @Test 68 @Test
69 public void testFindAsync() throws ExecutionException, InterruptedException { 69 public void testFindAsync() throws ExecutionException, InterruptedException {
70 - UUID tenantId = UUIDs.timeBased();  
71 - UUID customerId = UUIDs.timeBased(); 70 + UUID tenantId = Uuids.timeBased();
  71 + UUID customerId = Uuids.timeBased();
72 Device device = getDevice(tenantId, customerId); 72 Device device = getDevice(tenantId, customerId);
73 deviceDao.save(new TenantId(tenantId), device); 73 deviceDao.save(new TenantId(tenantId), device);
74 74
@@ -85,16 +85,16 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest { @@ -85,16 +85,16 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
85 85
86 @Test 86 @Test
87 public void testFindDevicesByTenantIdAndIdsAsync() throws ExecutionException, InterruptedException { 87 public void testFindDevicesByTenantIdAndIdsAsync() throws ExecutionException, InterruptedException {
88 - UUID tenantId1 = UUIDs.timeBased();  
89 - UUID customerId1 = UUIDs.timeBased();  
90 - UUID tenantId2 = UUIDs.timeBased();  
91 - UUID customerId2 = UUIDs.timeBased(); 88 + UUID tenantId1 = Uuids.timeBased();
  89 + UUID customerId1 = Uuids.timeBased();
  90 + UUID tenantId2 = Uuids.timeBased();
  91 + UUID customerId2 = Uuids.timeBased();
92 92
93 List<UUID> deviceIds = new ArrayList<>(); 93 List<UUID> deviceIds = new ArrayList<>();
94 94
95 for(int i = 0; i < 5; i++) { 95 for(int i = 0; i < 5; i++) {
96 - UUID deviceId1 = UUIDs.timeBased();  
97 - UUID deviceId2 = UUIDs.timeBased(); 96 + UUID deviceId1 = Uuids.timeBased();
  97 + UUID deviceId2 = Uuids.timeBased();
98 deviceDao.save(new TenantId(tenantId1), getDevice(tenantId1, customerId1, deviceId1)); 98 deviceDao.save(new TenantId(tenantId1), getDevice(tenantId1, customerId1, deviceId1));
99 deviceDao.save(new TenantId(tenantId2), getDevice(tenantId2, customerId2, deviceId2)); 99 deviceDao.save(new TenantId(tenantId2), getDevice(tenantId2, customerId2, deviceId2));
100 deviceIds.add(deviceId1); 100 deviceIds.add(deviceId1);
@@ -108,16 +108,16 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest { @@ -108,16 +108,16 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
108 108
109 @Test 109 @Test
110 public void testFindDevicesByTenantIdAndCustomerIdAndIdsAsync() throws ExecutionException, InterruptedException { 110 public void testFindDevicesByTenantIdAndCustomerIdAndIdsAsync() throws ExecutionException, InterruptedException {
111 - UUID tenantId1 = UUIDs.timeBased();  
112 - UUID customerId1 = UUIDs.timeBased();  
113 - UUID tenantId2 = UUIDs.timeBased();  
114 - UUID customerId2 = UUIDs.timeBased(); 111 + UUID tenantId1 = Uuids.timeBased();
  112 + UUID customerId1 = Uuids.timeBased();
  113 + UUID tenantId2 = Uuids.timeBased();
  114 + UUID customerId2 = Uuids.timeBased();
115 115
116 List<UUID> deviceIds = new ArrayList<>(); 116 List<UUID> deviceIds = new ArrayList<>();
117 117
118 for(int i = 0; i < 20; i++) { 118 for(int i = 0; i < 20; i++) {
119 - UUID deviceId1 = UUIDs.timeBased();  
120 - UUID deviceId2 = UUIDs.timeBased(); 119 + UUID deviceId1 = Uuids.timeBased();
  120 + UUID deviceId2 = Uuids.timeBased();
121 deviceDao.save(new TenantId(tenantId1), getDevice(tenantId1, customerId1, deviceId1)); 121 deviceDao.save(new TenantId(tenantId1), getDevice(tenantId1, customerId1, deviceId1));
122 deviceDao.save(new TenantId(tenantId2), getDevice(tenantId2, customerId2, deviceId2)); 122 deviceDao.save(new TenantId(tenantId2), getDevice(tenantId2, customerId2, deviceId2));
123 deviceIds.add(deviceId1); 123 deviceIds.add(deviceId1);
@@ -137,7 +137,7 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest { @@ -137,7 +137,7 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
137 } 137 }
138 138
139 private Device getDevice(UUID tenantId, UUID customerID) { 139 private Device getDevice(UUID tenantId, UUID customerID) {
140 - return getDevice(tenantId, customerID, UUIDs.timeBased()); 140 + return getDevice(tenantId, customerID, Uuids.timeBased());
141 } 141 }
142 142
143 private Device getDevice(UUID tenantId, UUID customerID, UUID deviceId) { 143 private Device getDevice(UUID tenantId, UUID customerID, UUID deviceId) {
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.event; 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 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import com.fasterxml.jackson.databind.ObjectMapper; 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import com.github.springtestdbunit.annotation.DatabaseSetup; 21 import com.github.springtestdbunit.annotation.DatabaseSetup;
@@ -57,9 +57,9 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest { @@ -57,9 +57,9 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest {
57 57
58 @Test 58 @Test
59 public void testSaveIfNotExists() { 59 public void testSaveIfNotExists() {
60 - UUID eventId = UUIDs.timeBased();  
61 - UUID tenantId = UUIDs.timeBased();  
62 - UUID entityId = UUIDs.timeBased(); 60 + UUID eventId = Uuids.timeBased();
  61 + UUID tenantId = Uuids.timeBased();
  62 + UUID entityId = Uuids.timeBased();
63 Event event = getEvent(eventId, tenantId, entityId); 63 Event event = getEvent(eventId, tenantId, entityId);
64 Optional<Event> optEvent1 = eventDao.saveIfNotExists(event); 64 Optional<Event> optEvent1 = eventDao.saveIfNotExists(event);
65 assertTrue("Optional is expected to be non-empty", optEvent1.isPresent()); 65 assertTrue("Optional is expected to be non-empty", optEvent1.isPresent());
@@ -83,9 +83,9 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest { @@ -83,9 +83,9 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest {
83 83
84 @Test 84 @Test
85 public void findEventsByEntityIdAndPageLink() { 85 public void findEventsByEntityIdAndPageLink() {
86 - UUID tenantId = UUIDs.timeBased();  
87 - UUID entityId1 = UUIDs.timeBased();  
88 - UUID entityId2 = UUIDs.timeBased(); 86 + UUID tenantId = Uuids.timeBased();
  87 + UUID entityId1 = Uuids.timeBased();
  88 + UUID entityId2 = Uuids.timeBased();
89 long startTime = System.currentTimeMillis(); 89 long startTime = System.currentTimeMillis();
90 long endTime = createEventsTwoEntities(tenantId, entityId1, entityId2, startTime, 20); 90 long endTime = createEventsTwoEntities(tenantId, entityId1, entityId2, startTime, 20);
91 91
@@ -117,9 +117,9 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest { @@ -117,9 +117,9 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest {
117 117
118 @Test 118 @Test
119 public void findEventsByEntityIdAndEventTypeAndPageLink() { 119 public void findEventsByEntityIdAndEventTypeAndPageLink() {
120 - UUID tenantId = UUIDs.timeBased();  
121 - UUID entityId1 = UUIDs.timeBased();  
122 - UUID entityId2 = UUIDs.timeBased(); 120 + UUID tenantId = Uuids.timeBased();
  121 + UUID entityId1 = Uuids.timeBased();
  122 + UUID entityId2 = Uuids.timeBased();
123 long startTime = System.currentTimeMillis(); 123 long startTime = System.currentTimeMillis();
124 long endTime = createEventsTwoEntitiesTwoTypes(tenantId, entityId1, entityId2, startTime, 20); 124 long endTime = createEventsTwoEntitiesTwoTypes(tenantId, entityId1, entityId2, startTime, 20);
125 125
@@ -147,10 +147,10 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest { @@ -147,10 +147,10 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest {
147 private long createEventsTwoEntitiesTwoTypes(UUID tenantId, UUID entityId1, UUID entityId2, long startTime, int count) { 147 private long createEventsTwoEntitiesTwoTypes(UUID tenantId, UUID entityId1, UUID entityId2, long startTime, int count) {
148 for (int i = 0; i < count / 2; i++) { 148 for (int i = 0; i < count / 2; i++) {
149 String type = i % 2 == 0 ? STATS : ALARM; 149 String type = i % 2 == 0 ? STATS : ALARM;
150 - UUID eventId1 = UUIDs.timeBased(); 150 + UUID eventId1 = Uuids.timeBased();
151 Event event1 = getEvent(eventId1, tenantId, entityId1, type); 151 Event event1 = getEvent(eventId1, tenantId, entityId1, type);
152 eventDao.save(new TenantId(tenantId), event1); 152 eventDao.save(new TenantId(tenantId), event1);
153 - UUID eventId2 = UUIDs.timeBased(); 153 + UUID eventId2 = Uuids.timeBased();
154 Event event2 = getEvent(eventId2, tenantId, entityId2, type); 154 Event event2 = getEvent(eventId2, tenantId, entityId2, type);
155 eventDao.save(new TenantId(tenantId), event2); 155 eventDao.save(new TenantId(tenantId), event2);
156 } 156 }
@@ -159,10 +159,10 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest { @@ -159,10 +159,10 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest {
159 159
160 private long createEventsTwoEntities(UUID tenantId, UUID entityId1, UUID entityId2, long startTime, int count) { 160 private long createEventsTwoEntities(UUID tenantId, UUID entityId1, UUID entityId2, long startTime, int count) {
161 for (int i = 0; i < count / 2; i++) { 161 for (int i = 0; i < count / 2; i++) {
162 - UUID eventId1 = UUIDs.timeBased(); 162 + UUID eventId1 = Uuids.timeBased();
163 Event event1 = getEvent(eventId1, tenantId, entityId1); 163 Event event1 = getEvent(eventId1, tenantId, entityId1);
164 eventDao.save(new TenantId(tenantId), event1); 164 eventDao.save(new TenantId(tenantId), event1);
165 - UUID eventId2 = UUIDs.timeBased(); 165 + UUID eventId2 = Uuids.timeBased();
166 Event event2 = getEvent(eventId2, tenantId, entityId2); 166 Event event2 = getEvent(eventId2, tenantId, entityId2);
167 eventDao.save(new TenantId(tenantId), event2); 167 eventDao.save(new TenantId(tenantId), event2);
168 } 168 }
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.tenant; 16 package org.thingsboard.server.dao.sql.tenant;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.github.springtestdbunit.annotation.DatabaseSetup; 19 import com.github.springtestdbunit.annotation.DatabaseSetup;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.springframework.beans.factory.annotation.Autowired; 21 import org.springframework.beans.factory.annotation.Autowired;
@@ -69,7 +69,7 @@ public class JpaTenantDaoTest extends AbstractJpaDaoTest { @@ -69,7 +69,7 @@ public class JpaTenantDaoTest extends AbstractJpaDaoTest {
69 69
70 private void createTenant(String region, String title, int index) { 70 private void createTenant(String region, String title, int index) {
71 Tenant tenant = new Tenant(); 71 Tenant tenant = new Tenant();
72 - tenant.setId(new TenantId(UUIDs.timeBased())); 72 + tenant.setId(new TenantId(Uuids.timeBased()));
73 tenant.setRegion(region); 73 tenant.setRegion(region);
74 tenant.setTitle(title + "_" + index); 74 tenant.setTitle(title + "_" + index);
75 tenantDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, tenant); 75 tenantDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, tenant);
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.user; 16 package org.thingsboard.server.dao.sql.user;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import com.fasterxml.jackson.databind.ObjectMapper; 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import com.github.springtestdbunit.annotation.DatabaseSetup; 21 import com.github.springtestdbunit.annotation.DatabaseSetup;
@@ -71,8 +71,8 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest { @@ -71,8 +71,8 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest {
71 @Test 71 @Test
72 @DatabaseSetup("classpath:dbunit/empty_dataset.xml") 72 @DatabaseSetup("classpath:dbunit/empty_dataset.xml")
73 public void testFindTenantAdmins() { 73 public void testFindTenantAdmins() {
74 - UUID tenantId = UUIDs.timeBased();  
75 - UUID customerId = UUIDs.timeBased(); 74 + UUID tenantId = Uuids.timeBased();
  75 + UUID customerId = Uuids.timeBased();
76 create30Adminsand60Users(tenantId, customerId); 76 create30Adminsand60Users(tenantId, customerId);
77 PageLink pageLink = new PageLink(20); 77 PageLink pageLink = new PageLink(20);
78 PageData<User> tenantAdmins1 = userDao.findTenantAdmins(tenantId, pageLink); 78 PageData<User> tenantAdmins1 = userDao.findTenantAdmins(tenantId, pageLink);
@@ -90,8 +90,8 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest { @@ -90,8 +90,8 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest {
90 @Test 90 @Test
91 @DatabaseSetup("classpath:dbunit/empty_dataset.xml") 91 @DatabaseSetup("classpath:dbunit/empty_dataset.xml")
92 public void testFindCustomerUsers() { 92 public void testFindCustomerUsers() {
93 - UUID tenantId = UUIDs.timeBased();  
94 - UUID customerId = UUIDs.timeBased(); 93 + UUID tenantId = Uuids.timeBased();
  94 + UUID customerId = Uuids.timeBased();
95 create30Adminsand60Users(tenantId, customerId); 95 create30Adminsand60Users(tenantId, customerId);
96 PageLink pageLink = new PageLink(40); 96 PageLink pageLink = new PageLink(40);
97 PageData<User> customerUsers1 = userDao.findCustomerUsers(tenantId, customerId, pageLink); 97 PageData<User> customerUsers1 = userDao.findCustomerUsers(tenantId, customerId, pageLink);
@@ -138,7 +138,7 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest { @@ -138,7 +138,7 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest {
138 138
139 private void saveUser(UUID tenantId, UUID customerId) { 139 private void saveUser(UUID tenantId, UUID customerId) {
140 User user = new User(); 140 User user = new User();
141 - UUID id = UUIDs.timeBased(); 141 + UUID id = Uuids.timeBased();
142 user.setId(new UserId(id)); 142 user.setId(new UserId(id));
143 user.setTenantId(new TenantId(tenantId)); 143 user.setTenantId(new TenantId(tenantId));
144 user.setCustomerId(new CustomerId(customerId)); 144 user.setCustomerId(new CustomerId(customerId));
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.widget; 16 package org.thingsboard.server.dao.sql.widget;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.github.springtestdbunit.annotation.DatabaseOperation; 19 import com.github.springtestdbunit.annotation.DatabaseOperation;
20 import com.github.springtestdbunit.annotation.DatabaseSetup; 20 import com.github.springtestdbunit.annotation.DatabaseSetup;
21 import com.github.springtestdbunit.annotation.DatabaseTearDown; 21 import com.github.springtestdbunit.annotation.DatabaseTearDown;
@@ -78,8 +78,8 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest { @@ -78,8 +78,8 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
78 @Test 78 @Test
79 @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL) 79 @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL)
80 public void testFindWidgetsBundlesByTenantId() { 80 public void testFindWidgetsBundlesByTenantId() {
81 - UUID tenantId1 = UUIDs.timeBased();  
82 - UUID tenantId2 = UUIDs.timeBased(); 81 + UUID tenantId1 = Uuids.timeBased();
  82 + UUID tenantId2 = Uuids.timeBased();
83 // Create a bunch of widgetBundles 83 // Create a bunch of widgetBundles
84 for (int i= 0; i < 10; i++) { 84 for (int i= 0; i < 10; i++) {
85 createWidgetBundles(3, tenantId1, "WB1_"); 85 createWidgetBundles(3, tenantId1, "WB1_");
@@ -104,8 +104,8 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest { @@ -104,8 +104,8 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
104 @Test 104 @Test
105 @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL) 105 @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL)
106 public void testFindAllWidgetsBundlesByTenantId() { 106 public void testFindAllWidgetsBundlesByTenantId() {
107 - UUID tenantId1 = UUIDs.timeBased();  
108 - UUID tenantId2 = UUIDs.timeBased(); 107 + UUID tenantId1 = Uuids.timeBased();
  108 + UUID tenantId2 = Uuids.timeBased();
109 // Create a bunch of widgetBundles 109 // Create a bunch of widgetBundles
110 for (int i= 0; i < 10; i++) { 110 for (int i= 0; i < 10; i++) {
111 createWidgetBundles( 5, tenantId1,"WB1_"); 111 createWidgetBundles( 5, tenantId1,"WB1_");
@@ -134,7 +134,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest { @@ -134,7 +134,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
134 @DatabaseSetup("classpath:dbunit/empty_dataset.xml") 134 @DatabaseSetup("classpath:dbunit/empty_dataset.xml")
135 @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml", type= DatabaseOperation.DELETE_ALL) 135 @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml", type= DatabaseOperation.DELETE_ALL)
136 public void testSearchTextNotFound() { 136 public void testSearchTextNotFound() {
137 - UUID tenantId = UUIDs.timeBased(); 137 + UUID tenantId = Uuids.timeBased();
138 createWidgetBundles(5, tenantId, "ABC_"); 138 createWidgetBundles(5, tenantId, "ABC_");
139 createSystemWidgetBundles(5, "SYS_"); 139 createSystemWidgetBundles(5, "SYS_");
140 140
@@ -148,7 +148,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest { @@ -148,7 +148,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
148 WidgetsBundle widgetsBundle = new WidgetsBundle(); 148 WidgetsBundle widgetsBundle = new WidgetsBundle();
149 widgetsBundle.setAlias(prefix + i); 149 widgetsBundle.setAlias(prefix + i);
150 widgetsBundle.setTitle(prefix + i); 150 widgetsBundle.setTitle(prefix + i);
151 - widgetsBundle.setId(new WidgetsBundleId(UUIDs.timeBased())); 151 + widgetsBundle.setId(new WidgetsBundleId(Uuids.timeBased()));
152 widgetsBundle.setTenantId(new TenantId(tenantId)); 152 widgetsBundle.setTenantId(new TenantId(tenantId));
153 widgetsBundleDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, widgetsBundle); 153 widgetsBundleDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, widgetsBundle);
154 } 154 }
@@ -159,7 +159,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest { @@ -159,7 +159,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
159 widgetsBundle.setAlias(prefix + i); 159 widgetsBundle.setAlias(prefix + i);
160 widgetsBundle.setTitle(prefix + i); 160 widgetsBundle.setTitle(prefix + i);
161 widgetsBundle.setTenantId(new TenantId(NULL_UUID)); 161 widgetsBundle.setTenantId(new TenantId(NULL_UUID));
162 - widgetsBundle.setId(new WidgetsBundleId(UUIDs.timeBased())); 162 + widgetsBundle.setId(new WidgetsBundleId(Uuids.timeBased()));
163 widgetsBundleDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, widgetsBundle); 163 widgetsBundleDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, widgetsBundle);
164 } 164 }
165 } 165 }
@@ -43,8 +43,9 @@ @@ -43,8 +43,9 @@
43 <logback.version>1.2.3</logback.version> 43 <logback.version>1.2.3</logback.version>
44 <mockito.version>1.9.5</mockito.version> 44 <mockito.version>1.9.5</mockito.version>
45 <rat.version>0.10</rat.version> 45 <rat.version>0.10</rat.version>
46 - <cassandra.version>3.6.0</cassandra.version>  
47 - <cassandra-unit.version>3.5.0.1</cassandra-unit.version> 46 + <cassandra.version>4.6.0</cassandra.version>
  47 + <metrics.version>4.0.5</metrics.version>
  48 + <cassandra-unit.version>4.3.1.0</cassandra-unit.version>
48 <takari-cpsuite.version>1.2.7</takari-cpsuite.version> 49 <takari-cpsuite.version>1.2.7</takari-cpsuite.version>
49 <guava.version>28.2-jre</guava.version> 50 <guava.version>28.2-jre</guava.version>
50 <caffeine.version>2.6.1</caffeine.version> 51 <caffeine.version>2.6.1</caffeine.version>
@@ -657,19 +658,19 @@ @@ -657,19 +658,19 @@
657 <version>${netty.version}</version> 658 <version>${netty.version}</version>
658 </dependency> 659 </dependency>
659 <dependency> 660 <dependency>
660 - <groupId>com.datastax.cassandra</groupId>  
661 - <artifactId>cassandra-driver-core</artifactId> 661 + <groupId>com.datastax.oss</groupId>
  662 + <artifactId>java-driver-core</artifactId>
662 <version>${cassandra.version}</version> 663 <version>${cassandra.version}</version>
663 </dependency> 664 </dependency>
664 <dependency> 665 <dependency>
665 - <groupId>com.datastax.cassandra</groupId>  
666 - <artifactId>cassandra-driver-mapping</artifactId> 666 + <groupId>com.datastax.oss</groupId>
  667 + <artifactId>java-driver-query-builder</artifactId>
667 <version>${cassandra.version}</version> 668 <version>${cassandra.version}</version>
668 </dependency> 669 </dependency>
669 <dependency> 670 <dependency>
670 - <groupId>com.datastax.cassandra</groupId>  
671 - <artifactId>cassandra-driver-extras</artifactId>  
672 - <version>${cassandra.version}</version> 671 + <groupId>io.dropwizard.metrics</groupId>
  672 + <artifactId>metrics-jmx</artifactId>
  673 + <version>${metrics.version}</version>
673 </dependency> 674 </dependency>
674 <dependency> 675 <dependency>
675 <groupId>org.apache.commons</groupId> 676 <groupId>org.apache.commons</groupId>
@@ -74,18 +74,8 @@ @@ -74,18 +74,8 @@
74 <scope>provided</scope> 74 <scope>provided</scope>
75 </dependency> 75 </dependency>
76 <dependency> 76 <dependency>
77 - <groupId>com.datastax.cassandra</groupId>  
78 - <artifactId>cassandra-driver-core</artifactId>  
79 - <scope>provided</scope>  
80 - </dependency>  
81 - <dependency>  
82 - <groupId>com.datastax.cassandra</groupId>  
83 - <artifactId>cassandra-driver-mapping</artifactId>  
84 - <scope>provided</scope>  
85 - </dependency>  
86 - <dependency>  
87 - <groupId>com.datastax.cassandra</groupId>  
88 - <artifactId>cassandra-driver-extras</artifactId> 77 + <groupId>com.datastax.oss</groupId>
  78 + <artifactId>java-driver-core</artifactId>
89 <scope>provided</scope> 79 <scope>provided</scope>
90 </dependency> 80 </dependency>
91 <dependency> 81 <dependency>
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.api; 16 package org.thingsboard.rule.engine.api;
17 17
18 -import com.datastax.driver.core.ResultSetFuture;  
19 import io.netty.channel.EventLoopGroup; 18 import io.netty.channel.EventLoopGroup;
20 import org.springframework.data.redis.core.RedisTemplate; 19 import org.springframework.data.redis.core.RedisTemplate;
21 import org.thingsboard.common.util.ListeningExecutor; 20 import org.thingsboard.common.util.ListeningExecutor;
@@ -37,6 +36,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService; @@ -37,6 +36,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService;
37 import org.thingsboard.server.dao.device.DeviceService; 36 import org.thingsboard.server.dao.device.DeviceService;
38 import org.thingsboard.server.dao.entityview.EntityViewService; 37 import org.thingsboard.server.dao.entityview.EntityViewService;
39 import org.thingsboard.server.dao.nosql.CassandraStatementTask; 38 import org.thingsboard.server.dao.nosql.CassandraStatementTask;
  39 +import org.thingsboard.server.dao.nosql.TbResultSetFuture;
40 import org.thingsboard.server.dao.relation.RelationService; 40 import org.thingsboard.server.dao.relation.RelationService;
41 import org.thingsboard.server.dao.rule.RuleChainService; 41 import org.thingsboard.server.dao.rule.RuleChainService;
42 import org.thingsboard.server.dao.tenant.TenantService; 42 import org.thingsboard.server.dao.tenant.TenantService;
@@ -207,7 +207,7 @@ public interface TbContext { @@ -207,7 +207,7 @@ public interface TbContext {
207 207
208 CassandraCluster getCassandraCluster(); 208 CassandraCluster getCassandraCluster();
209 209
210 - ResultSetFuture submitCassandraTask(CassandraStatementTask task); 210 + TbResultSetFuture submitCassandraTask(CassandraStatementTask task);
211 211
212 @Deprecated 212 @Deprecated
213 RedisTemplate<String, Object> getRedisTemplate(); 213 RedisTemplate<String, Object> getRedisTemplate();
@@ -134,6 +134,10 @@ @@ -134,6 +134,10 @@
134 <groupId>org.slf4j</groupId> 134 <groupId>org.slf4j</groupId>
135 <artifactId>slf4j-log4j12</artifactId> 135 <artifactId>slf4j-log4j12</artifactId>
136 </exclusion> 136 </exclusion>
  137 + <exclusion>
  138 + <groupId>org.hibernate</groupId>
  139 + <artifactId>hibernate-validator</artifactId>
  140 + </exclusion>
137 </exclusions> 141 </exclusions>
138 <scope>test</scope> 142 <scope>test</scope>
139 </dependency> 143 </dependency>
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.action; 16 package org.thingsboard.rule.engine.action;
17 17
18 -import com.datastax.driver.core.utils.UUIDs;  
19 import com.google.gson.Gson; 18 import com.google.gson.Gson;
20 import com.google.gson.JsonObject; 19 import com.google.gson.JsonObject;
21 import lombok.extern.slf4j.Slf4j; 20 import lombok.extern.slf4j.Slf4j;
@@ -99,4 +98,4 @@ public class TbMsgCountNode implements TbNode { @@ -99,4 +98,4 @@ public class TbMsgCountNode implements TbNode {
99 @Override 98 @Override
100 public void destroy() { 99 public void destroy() {
101 } 100 }
102 -}  
  101 +}
@@ -15,8 +15,12 @@ @@ -15,8 +15,12 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.action; 16 package org.thingsboard.rule.engine.action;
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.BoundStatementBuilder;
  22 +import com.datastax.oss.driver.api.core.cql.PreparedStatement;
  23 +import com.datastax.oss.driver.api.core.cql.Statement;
20 import com.google.common.base.Function; 24 import com.google.common.base.Function;
21 import com.google.common.util.concurrent.Futures; 25 import com.google.common.util.concurrent.Futures;
22 import com.google.common.util.concurrent.ListenableFuture; 26 import com.google.common.util.concurrent.ListenableFuture;
@@ -30,22 +34,19 @@ import org.thingsboard.rule.engine.api.util.TbNodeUtils; @@ -30,22 +34,19 @@ import org.thingsboard.rule.engine.api.util.TbNodeUtils;
30 import org.thingsboard.server.common.data.plugin.ComponentType; 34 import org.thingsboard.server.common.data.plugin.ComponentType;
31 import org.thingsboard.server.common.msg.TbMsg; 35 import org.thingsboard.server.common.msg.TbMsg;
32 import org.thingsboard.server.dao.cassandra.CassandraCluster; 36 import org.thingsboard.server.dao.cassandra.CassandraCluster;
33 -import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec;  
34 -import org.thingsboard.server.dao.model.type.EntityTypeCodec;  
35 -import org.thingsboard.server.dao.model.type.JsonCodec; 37 +import org.thingsboard.server.dao.cassandra.guava.GuavaSession;
36 import org.thingsboard.server.dao.nosql.CassandraStatementTask; 38 import org.thingsboard.server.dao.nosql.CassandraStatementTask;
  39 +import org.thingsboard.server.dao.nosql.TbResultSetFuture;
37 40
38 import javax.annotation.Nullable; 41 import javax.annotation.Nullable;
39 import java.util.ArrayList; 42 import java.util.ArrayList;
40 import java.util.List; 43 import java.util.List;
41 import java.util.Map; 44 import java.util.Map;
42 -import java.util.concurrent.ExecutionException;  
43 import java.util.concurrent.ExecutorService; 45 import java.util.concurrent.ExecutorService;
44 import java.util.concurrent.Executors; 46 import java.util.concurrent.Executors;
45 import java.util.concurrent.atomic.AtomicInteger; 47 import java.util.concurrent.atomic.AtomicInteger;
46 48
47 import static org.thingsboard.common.util.DonAsynchron.withCallback; 49 import static org.thingsboard.common.util.DonAsynchron.withCallback;
48 -import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;  
49 50
50 @Slf4j 51 @Slf4j
51 @RuleNode(type = ComponentType.ACTION, 52 @RuleNode(type = ComponentType.ACTION,
@@ -69,7 +70,7 @@ public class TbSaveToCustomCassandraTableNode implements TbNode { @@ -69,7 +70,7 @@ public class TbSaveToCustomCassandraTableNode implements TbNode {
69 private static final String ENTITY_ID = "$entityId"; 70 private static final String ENTITY_ID = "$entityId";
70 71
71 private TbSaveToCustomCassandraTableNodeConfiguration config; 72 private TbSaveToCustomCassandraTableNodeConfiguration config;
72 - private Session session; 73 + private GuavaSession session;
73 private CassandraCluster cassandraCluster; 74 private CassandraCluster cassandraCluster;
74 private ConsistencyLevel defaultWriteLevel; 75 private ConsistencyLevel defaultWriteLevel;
75 private PreparedStatement saveStmt; 76 private PreparedStatement saveStmt;
@@ -113,27 +114,14 @@ public class TbSaveToCustomCassandraTableNode implements TbNode { @@ -113,27 +114,14 @@ public class TbSaveToCustomCassandraTableNode implements TbNode {
113 return getSession().prepare(query); 114 return getSession().prepare(query);
114 } 115 }
115 116
116 - private Session getSession() { 117 + private GuavaSession getSession() {
117 if (session == null) { 118 if (session == null) {
118 session = cassandraCluster.getSession(); 119 session = cassandraCluster.getSession();
119 defaultWriteLevel = cassandraCluster.getDefaultWriteConsistencyLevel(); 120 defaultWriteLevel = cassandraCluster.getDefaultWriteConsistencyLevel();
120 - CodecRegistry registry = session.getCluster().getConfiguration().getCodecRegistry();  
121 - registerCodecIfNotFound(registry, new JsonCodec());  
122 - registerCodecIfNotFound(registry, new ComponentLifecycleStateCodec());  
123 - registerCodecIfNotFound(registry, new EntityTypeCodec());  
124 } 121 }
125 return session; 122 return session;
126 } 123 }
127 124
128 - private void registerCodecIfNotFound(CodecRegistry registry, TypeCodec<?> codec) {  
129 - try {  
130 - registry.codecFor(codec.getCqlType(), codec.getJavaType());  
131 - } catch (CodecNotFoundException e) {  
132 - registry.register(codec);  
133 - }  
134 - }  
135 -  
136 -  
137 private PreparedStatement getSaveStmt() { 125 private PreparedStatement getSaveStmt() {
138 fieldsMap = config.getFieldsMapping(); 126 fieldsMap = config.getFieldsMapping();
139 if (fieldsMap.isEmpty()) { 127 if (fieldsMap.isEmpty()) {
@@ -179,22 +167,22 @@ public class TbSaveToCustomCassandraTableNode implements TbNode { @@ -179,22 +167,22 @@ public class TbSaveToCustomCassandraTableNode implements TbNode {
179 throw new IllegalStateException("Invalid message structure, it is not a JSON Object:" + data); 167 throw new IllegalStateException("Invalid message structure, it is not a JSON Object:" + data);
180 } else { 168 } else {
181 JsonObject dataAsObject = data.getAsJsonObject(); 169 JsonObject dataAsObject = data.getAsJsonObject();
182 - BoundStatement stmt = saveStmt.bind(); 170 + BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(saveStmt.bind());
183 AtomicInteger i = new AtomicInteger(0); 171 AtomicInteger i = new AtomicInteger(0);
184 fieldsMap.forEach((key, value) -> { 172 fieldsMap.forEach((key, value) -> {
185 if (key.equals(ENTITY_ID)) { 173 if (key.equals(ENTITY_ID)) {
186 - stmt.setUUID(i.get(), msg.getOriginator().getId()); 174 + stmtBuilder.setUuid(i.get(), msg.getOriginator().getId());
187 } else if (dataAsObject.has(key)) { 175 } else if (dataAsObject.has(key)) {
188 if (dataAsObject.get(key).isJsonPrimitive()) { 176 if (dataAsObject.get(key).isJsonPrimitive()) {
189 JsonPrimitive primitive = dataAsObject.get(key).getAsJsonPrimitive(); 177 JsonPrimitive primitive = dataAsObject.get(key).getAsJsonPrimitive();
190 if (primitive.isNumber()) { 178 if (primitive.isNumber()) {
191 - stmt.setLong(i.get(), dataAsObject.get(key).getAsLong()); 179 + stmtBuilder.setLong(i.get(), dataAsObject.get(key).getAsLong());
192 } else if (primitive.isBoolean()) { 180 } else if (primitive.isBoolean()) {
193 - stmt.setBool(i.get(), dataAsObject.get(key).getAsBoolean()); 181 + stmtBuilder.setBoolean(i.get(), dataAsObject.get(key).getAsBoolean());
194 } else if (primitive.isString()) { 182 } else if (primitive.isString()) {
195 - stmt.setString(i.get(), dataAsObject.get(key).getAsString()); 183 + stmtBuilder.setString(i.get(), dataAsObject.get(key).getAsString());
196 } else { 184 } else {
197 - stmt.setToNull(i.get()); 185 + stmtBuilder.setToNull(i.get());
198 } 186 }
199 } else { 187 } else {
200 throw new IllegalStateException("Message data key: '" + key + "' with value: '" + value + "' is not a JSON Primitive!"); 188 throw new IllegalStateException("Message data key: '" + key + "' with value: '" + value + "' is not a JSON Primitive!");
@@ -204,15 +192,15 @@ public class TbSaveToCustomCassandraTableNode implements TbNode { @@ -204,15 +192,15 @@ public class TbSaveToCustomCassandraTableNode implements TbNode {
204 } 192 }
205 i.getAndIncrement(); 193 i.getAndIncrement();
206 }); 194 });
207 - return getFuture(executeAsyncWrite(ctx, stmt), rs -> null); 195 + return getFuture(executeAsyncWrite(ctx, stmtBuilder.build()), rs -> null);
208 } 196 }
209 } 197 }
210 198
211 - private ResultSetFuture executeAsyncWrite(TbContext ctx, Statement statement) { 199 + private TbResultSetFuture executeAsyncWrite(TbContext ctx, Statement statement) {
212 return executeAsync(ctx, statement, defaultWriteLevel); 200 return executeAsync(ctx, statement, defaultWriteLevel);
213 } 201 }
214 202
215 - private ResultSetFuture executeAsync(TbContext ctx, Statement statement, ConsistencyLevel level) { 203 + private TbResultSetFuture executeAsync(TbContext ctx, Statement statement, ConsistencyLevel level) {
216 if (log.isDebugEnabled()) { 204 if (log.isDebugEnabled()) {
217 log.debug("Execute cassandra async statement {}", statementToString(statement)); 205 log.debug("Execute cassandra async statement {}", statementToString(statement));
218 } 206 }
@@ -224,20 +212,20 @@ public class TbSaveToCustomCassandraTableNode implements TbNode { @@ -224,20 +212,20 @@ public class TbSaveToCustomCassandraTableNode implements TbNode {
224 212
225 private static String statementToString(Statement statement) { 213 private static String statementToString(Statement statement) {
226 if (statement instanceof BoundStatement) { 214 if (statement instanceof BoundStatement) {
227 - return ((BoundStatement) statement).preparedStatement().getQueryString(); 215 + return ((BoundStatement) statement).getPreparedStatement().getQuery();
228 } else { 216 } else {
229 return statement.toString(); 217 return statement.toString();
230 } 218 }
231 } 219 }
232 220
233 - private <T> ListenableFuture<T> getFuture(ResultSetFuture future, java.util.function.Function<ResultSet, T> transformer) {  
234 - return Futures.transform(future, new Function<ResultSet, T>() { 221 + private <T> ListenableFuture<T> getFuture(TbResultSetFuture future, java.util.function.Function<AsyncResultSet, T> transformer) {
  222 + return Futures.transform(future, new Function<AsyncResultSet, T>() {
235 @Nullable 223 @Nullable
236 @Override 224 @Override
237 - public T apply(@Nullable ResultSet input) { 225 + public T apply(@Nullable AsyncResultSet input) {
238 return transformer.apply(input); 226 return transformer.apply(input);
239 } 227 }
240 }, readResultsProcessingExecutor); 228 }, readResultsProcessingExecutor);
241 } 229 }
242 230
243 -}  
  231 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.rpc; 16 package org.thingsboard.rule.engine.rpc;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.google.gson.Gson; 19 import com.google.gson.Gson;
20 import com.google.gson.JsonElement; 20 import com.google.gson.JsonElement;
21 import com.google.gson.JsonObject; 21 import com.google.gson.JsonObject;
@@ -82,7 +82,7 @@ public class TbSendRPCRequestNode implements TbNode { @@ -82,7 +82,7 @@ public class TbSendRPCRequestNode implements TbNode {
82 boolean oneway = !StringUtils.isEmpty(tmp) && Boolean.parseBoolean(tmp); 82 boolean oneway = !StringUtils.isEmpty(tmp) && Boolean.parseBoolean(tmp);
83 83
84 tmp = msg.getMetaData().getValue("requestUUID"); 84 tmp = msg.getMetaData().getValue("requestUUID");
85 - UUID requestUUID = !StringUtils.isEmpty(tmp) ? UUID.fromString(tmp) : UUIDs.timeBased(); 85 + UUID requestUUID = !StringUtils.isEmpty(tmp) ? UUID.fromString(tmp) : Uuids.timeBased();
86 tmp = msg.getMetaData().getValue("originServiceId"); 86 tmp = msg.getMetaData().getValue("originServiceId");
87 String originServiceId = !StringUtils.isEmpty(tmp) ? tmp : null; 87 String originServiceId = !StringUtils.isEmpty(tmp) ? tmp : null;
88 88
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.action; 16 package org.thingsboard.rule.engine.action;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import com.fasterxml.jackson.databind.ObjectMapper; 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import com.google.common.util.concurrent.Futures; 21 import com.google.common.util.concurrent.Futures;
@@ -89,13 +89,13 @@ public class TbAlarmNodeTest { @@ -89,13 +89,13 @@ public class TbAlarmNodeTest {
89 @Captor 89 @Captor
90 private ArgumentCaptor<Consumer<Throwable>> failureCaptor; 90 private ArgumentCaptor<Consumer<Throwable>> failureCaptor;
91 91
92 - private RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased());  
93 - private RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); 92 + private RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
  93 + private RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
94 94
95 private ListeningExecutor dbExecutor; 95 private ListeningExecutor dbExecutor;
96 96
97 - private EntityId originator = new DeviceId(UUIDs.timeBased());  
98 - private TenantId tenantId = new TenantId(UUIDs.timeBased()); 97 + private EntityId originator = new DeviceId(Uuids.timeBased());
  98 + private TenantId tenantId = new TenantId(Uuids.timeBased());
99 private TbMsgMetaData metaData = new TbMsgMetaData(); 99 private TbMsgMetaData metaData = new TbMsgMetaData();
100 private String rawJson = "{\"name\": \"Vit\", \"passed\": 5}"; 100 private String rawJson = "{\"name\": \"Vit\", \"passed\": 5}";
101 101
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.filter; 16 package org.thingsboard.rule.engine.filter;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.fasterxml.jackson.databind.ObjectMapper; 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import com.google.common.util.concurrent.Futures; 20 import com.google.common.util.concurrent.Futures;
21 import com.google.common.util.concurrent.ListenableFuture; 21 import com.google.common.util.concurrent.ListenableFuture;
@@ -58,8 +58,8 @@ public class TbJsFilterNodeTest { @@ -58,8 +58,8 @@ public class TbJsFilterNodeTest {
58 @Mock 58 @Mock
59 private ScriptEngine scriptEngine; 59 private ScriptEngine scriptEngine;
60 60
61 - private RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased());  
62 - private RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); 61 + private RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
  62 + private RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
63 63
64 @Test 64 @Test
65 public void falseEvaluationDoNotSendMsg() throws TbNodeException, ScriptException { 65 public void falseEvaluationDoNotSendMsg() throws TbNodeException, ScriptException {
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.filter; 16 package org.thingsboard.rule.engine.filter;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.fasterxml.jackson.databind.ObjectMapper; 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import com.google.common.collect.Sets; 20 import com.google.common.collect.Sets;
21 import com.google.common.util.concurrent.Futures; 21 import com.google.common.util.concurrent.Futures;
@@ -60,8 +60,8 @@ public class TbJsSwitchNodeTest { @@ -60,8 +60,8 @@ public class TbJsSwitchNodeTest {
60 @Mock 60 @Mock
61 private ScriptEngine scriptEngine; 61 private ScriptEngine scriptEngine;
62 62
63 - private RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased());  
64 - private RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); 63 + private RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
  64 + private RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
65 65
66 @Test 66 @Test
67 public void multipleRoutesAreAllowed() throws TbNodeException, ScriptException { 67 public void multipleRoutesAreAllowed() throws TbNodeException, ScriptException {
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.mail; 16 package org.thingsboard.rule.engine.mail;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.fasterxml.jackson.databind.ObjectMapper; 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.junit.runner.RunWith; 21 import org.junit.runner.RunWith;
@@ -47,12 +47,12 @@ public class TbMsgToEmailNodeTest { @@ -47,12 +47,12 @@ public class TbMsgToEmailNodeTest {
47 @Mock 47 @Mock
48 private TbContext ctx; 48 private TbContext ctx;
49 49
50 - private EntityId originator = new DeviceId(UUIDs.timeBased()); 50 + private EntityId originator = new DeviceId(Uuids.timeBased());
51 private TbMsgMetaData metaData = new TbMsgMetaData(); 51 private TbMsgMetaData metaData = new TbMsgMetaData();
52 private String rawJson = "{\"name\": \"temp\", \"passed\": 5 , \"complex\": {\"val\":12, \"count\":100}}"; 52 private String rawJson = "{\"name\": \"temp\", \"passed\": 5 , \"complex\": {\"val\":12, \"count\":100}}";
53 53
54 - private RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased());  
55 - private RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); 54 + private RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
  55 + private RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
56 56
57 @Test 57 @Test
58 public void msgCanBeConverted() throws IOException { 58 public void msgCanBeConverted() throws IOException {
@@ -107,4 +107,4 @@ public class TbMsgToEmailNodeTest { @@ -107,4 +107,4 @@ public class TbMsgToEmailNodeTest {
107 } 107 }
108 } 108 }
109 109
110 -}  
  110 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.metadata; 16 package org.thingsboard.rule.engine.metadata;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.fasterxml.jackson.databind.ObjectMapper; 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import com.google.common.collect.Lists; 20 import com.google.common.collect.Lists;
21 import com.google.common.util.concurrent.Futures; 21 import com.google.common.util.concurrent.Futures;
@@ -88,8 +88,8 @@ public class TbGetCustomerAttributeNodeTest { @@ -88,8 +88,8 @@ public class TbGetCustomerAttributeNodeTest {
88 88
89 private TbMsg msg; 89 private TbMsg msg;
90 90
91 - private RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased());  
92 - private RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); 91 + private RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
  92 + private RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
93 93
94 @Before 94 @Before
95 public void init() throws TbNodeException { 95 public void init() throws TbNodeException {
@@ -107,8 +107,8 @@ public class TbGetCustomerAttributeNodeTest { @@ -107,8 +107,8 @@ public class TbGetCustomerAttributeNodeTest {
107 107
108 @Test 108 @Test
109 public void errorThrownIfCannotLoadAttributes() { 109 public void errorThrownIfCannotLoadAttributes() {
110 - UserId userId = new UserId(UUIDs.timeBased());  
111 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 110 + UserId userId = new UserId(Uuids.timeBased());
  111 + CustomerId customerId = new CustomerId(Uuids.timeBased());
112 User user = new User(); 112 User user = new User();
113 user.setCustomerId(customerId); 113 user.setCustomerId(customerId);
114 114
@@ -132,8 +132,8 @@ public class TbGetCustomerAttributeNodeTest { @@ -132,8 +132,8 @@ public class TbGetCustomerAttributeNodeTest {
132 132
133 @Test 133 @Test
134 public void errorThrownIfCannotLoadAttributesAsync() { 134 public void errorThrownIfCannotLoadAttributesAsync() {
135 - UserId userId = new UserId(UUIDs.timeBased());  
136 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 135 + UserId userId = new UserId(Uuids.timeBased());
  136 + CustomerId customerId = new CustomerId(Uuids.timeBased());
137 User user = new User(); 137 User user = new User();
138 user.setCustomerId(customerId); 138 user.setCustomerId(customerId);
139 139
@@ -157,8 +157,8 @@ public class TbGetCustomerAttributeNodeTest { @@ -157,8 +157,8 @@ public class TbGetCustomerAttributeNodeTest {
157 157
158 @Test 158 @Test
159 public void failedChainUsedIfCustomerCannotBeFound() { 159 public void failedChainUsedIfCustomerCannotBeFound() {
160 - UserId userId = new UserId(UUIDs.timeBased());  
161 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 160 + UserId userId = new UserId(Uuids.timeBased());
  161 + CustomerId customerId = new CustomerId(Uuids.timeBased());
162 User user = new User(); 162 User user = new User();
163 user.setCustomerId(customerId); 163 user.setCustomerId(customerId);
164 164
@@ -175,15 +175,15 @@ public class TbGetCustomerAttributeNodeTest { @@ -175,15 +175,15 @@ public class TbGetCustomerAttributeNodeTest {
175 175
176 @Test 176 @Test
177 public void customerAttributeAddedInMetadata() { 177 public void customerAttributeAddedInMetadata() {
178 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 178 + CustomerId customerId = new CustomerId(Uuids.timeBased());
179 msg = TbMsg.newMsg( "CUSTOMER", customerId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); 179 msg = TbMsg.newMsg( "CUSTOMER", customerId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId);
180 entityAttributeFetched(customerId); 180 entityAttributeFetched(customerId);
181 } 181 }
182 182
183 @Test 183 @Test
184 public void usersCustomerAttributesFetched() { 184 public void usersCustomerAttributesFetched() {
185 - UserId userId = new UserId(UUIDs.timeBased());  
186 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 185 + UserId userId = new UserId(Uuids.timeBased());
  186 + CustomerId customerId = new CustomerId(Uuids.timeBased());
187 User user = new User(); 187 User user = new User();
188 user.setCustomerId(customerId); 188 user.setCustomerId(customerId);
189 189
@@ -197,8 +197,8 @@ public class TbGetCustomerAttributeNodeTest { @@ -197,8 +197,8 @@ public class TbGetCustomerAttributeNodeTest {
197 197
198 @Test 198 @Test
199 public void assetsCustomerAttributesFetched() { 199 public void assetsCustomerAttributesFetched() {
200 - AssetId assetId = new AssetId(UUIDs.timeBased());  
201 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 200 + AssetId assetId = new AssetId(Uuids.timeBased());
  201 + CustomerId customerId = new CustomerId(Uuids.timeBased());
202 Asset asset = new Asset(); 202 Asset asset = new Asset();
203 asset.setCustomerId(customerId); 203 asset.setCustomerId(customerId);
204 204
@@ -212,8 +212,8 @@ public class TbGetCustomerAttributeNodeTest { @@ -212,8 +212,8 @@ public class TbGetCustomerAttributeNodeTest {
212 212
213 @Test 213 @Test
214 public void deviceCustomerAttributesFetched() { 214 public void deviceCustomerAttributesFetched() {
215 - DeviceId deviceId = new DeviceId(UUIDs.timeBased());  
216 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 215 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
  216 + CustomerId customerId = new CustomerId(Uuids.timeBased());
217 Device device = new Device(); 217 Device device = new Device();
218 device.setCustomerId(customerId); 218 device.setCustomerId(customerId);
219 219
@@ -239,8 +239,8 @@ public class TbGetCustomerAttributeNodeTest { @@ -239,8 +239,8 @@ public class TbGetCustomerAttributeNodeTest {
239 node.init(null, nodeConfiguration); 239 node.init(null, nodeConfiguration);
240 240
241 241
242 - DeviceId deviceId = new DeviceId(UUIDs.timeBased());  
243 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 242 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
  243 + CustomerId customerId = new CustomerId(Uuids.timeBased());
244 Device device = new Device(); 244 Device device = new Device();
245 device.setCustomerId(customerId); 245 device.setCustomerId(customerId);
246 246
@@ -271,4 +271,4 @@ public class TbGetCustomerAttributeNodeTest { @@ -271,4 +271,4 @@ public class TbGetCustomerAttributeNodeTest {
271 verify(ctx).tellSuccess(msg); 271 verify(ctx).tellSuccess(msg);
272 assertEquals(msg.getMetaData().getValue("tempo"), "high"); 272 assertEquals(msg.getMetaData().getValue("tempo"), "high");
273 } 273 }
274 -}  
  274 +}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.transform; 16 package org.thingsboard.rule.engine.transform;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.fasterxml.jackson.databind.ObjectMapper; 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import com.google.common.util.concurrent.Futures; 20 import com.google.common.util.concurrent.Futures;
21 import com.google.common.util.concurrent.ListenableFuture; 21 import com.google.common.util.concurrent.ListenableFuture;
@@ -84,13 +84,13 @@ public class TbChangeOriginatorNodeTest { @@ -84,13 +84,13 @@ public class TbChangeOriginatorNodeTest {
84 @Test 84 @Test
85 public void originatorCanBeChangedToCustomerId() throws TbNodeException { 85 public void originatorCanBeChangedToCustomerId() throws TbNodeException {
86 init(); 86 init();
87 - AssetId assetId = new AssetId(UUIDs.timeBased());  
88 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 87 + AssetId assetId = new AssetId(Uuids.timeBased());
  88 + CustomerId customerId = new CustomerId(Uuids.timeBased());
89 Asset asset = new Asset(); 89 Asset asset = new Asset();
90 asset.setCustomerId(customerId); 90 asset.setCustomerId(customerId);
91 91
92 - RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased());  
93 - RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); 92 + RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
  93 + RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
94 94
95 TbMsg msg = TbMsg.newMsg( "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); 95 TbMsg msg = TbMsg.newMsg( "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId);
96 96
@@ -112,13 +112,13 @@ public class TbChangeOriginatorNodeTest { @@ -112,13 +112,13 @@ public class TbChangeOriginatorNodeTest {
112 @Test 112 @Test
113 public void newChainCanBeStarted() throws TbNodeException { 113 public void newChainCanBeStarted() throws TbNodeException {
114 init(); 114 init();
115 - AssetId assetId = new AssetId(UUIDs.timeBased());  
116 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 115 + AssetId assetId = new AssetId(Uuids.timeBased());
  116 + CustomerId customerId = new CustomerId(Uuids.timeBased());
117 Asset asset = new Asset(); 117 Asset asset = new Asset();
118 asset.setCustomerId(customerId); 118 asset.setCustomerId(customerId);
119 119
120 - RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased());  
121 - RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); 120 + RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
  121 + RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
122 122
123 TbMsg msg = TbMsg.newMsg( "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId); 123 TbMsg msg = TbMsg.newMsg( "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId);
124 124
@@ -139,13 +139,13 @@ public class TbChangeOriginatorNodeTest { @@ -139,13 +139,13 @@ public class TbChangeOriginatorNodeTest {
139 @Test 139 @Test
140 public void exceptionThrownIfCannotFindNewOriginator() throws TbNodeException { 140 public void exceptionThrownIfCannotFindNewOriginator() throws TbNodeException {
141 init(); 141 init();
142 - AssetId assetId = new AssetId(UUIDs.timeBased());  
143 - CustomerId customerId = new CustomerId(UUIDs.timeBased()); 142 + AssetId assetId = new AssetId(Uuids.timeBased());
  143 + CustomerId customerId = new CustomerId(Uuids.timeBased());
144 Asset asset = new Asset(); 144 Asset asset = new Asset();
145 asset.setCustomerId(customerId); 145 asset.setCustomerId(customerId);
146 146
147 - RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased());  
148 - RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); 147 + RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
  148 + RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
149 149
150 TbMsg msg = TbMsg.newMsg( "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId); 150 TbMsg msg = TbMsg.newMsg( "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId);
151 151
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.transform; 16 package org.thingsboard.rule.engine.transform;
17 17
18 -import com.datastax.driver.core.utils.UUIDs; 18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 import com.fasterxml.jackson.databind.ObjectMapper; 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import com.google.common.util.concurrent.Futures; 20 import com.google.common.util.concurrent.Futures;
21 import com.google.common.util.concurrent.ListenableFuture; 21 import com.google.common.util.concurrent.ListenableFuture;
@@ -67,8 +67,8 @@ public class TbTransformMsgNodeTest { @@ -67,8 +67,8 @@ public class TbTransformMsgNodeTest {
67 metaData.putValue("temp", "7"); 67 metaData.putValue("temp", "7");
68 String rawJson = "{\"passed\": 5}"; 68 String rawJson = "{\"passed\": 5}";
69 69
70 - RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased());  
71 - RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); 70 + RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
  71 + RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
72 TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON,rawJson, ruleChainId, ruleNodeId); 72 TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON,rawJson, ruleChainId, ruleNodeId);
73 TbMsg transformedMsg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, "{new}", ruleChainId, ruleNodeId); 73 TbMsg transformedMsg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, "{new}", ruleChainId, ruleNodeId);
74 mockJsExecutor(); 74 mockJsExecutor();
@@ -89,8 +89,8 @@ public class TbTransformMsgNodeTest { @@ -89,8 +89,8 @@ public class TbTransformMsgNodeTest {
89 metaData.putValue("temp", "7"); 89 metaData.putValue("temp", "7");
90 String rawJson = "{\"passed\": 5"; 90 String rawJson = "{\"passed\": 5";
91 91
92 - RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased());  
93 - RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); 92 + RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
  93 + RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
94 TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId); 94 TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId);
95 mockJsExecutor(); 95 mockJsExecutor();
96 when(scriptEngine.executeUpdateAsync(msg)).thenReturn(Futures.immediateFailedFuture(new IllegalStateException("error"))); 96 when(scriptEngine.executeUpdateAsync(msg)).thenReturn(Futures.immediateFailedFuture(new IllegalStateException("error")));
@@ -57,8 +57,8 @@ @@ -57,8 +57,8 @@
57 <version>3.11.6</version> 57 <version>3.11.6</version>
58 </dependency> 58 </dependency>
59 <dependency> 59 <dependency>
60 - <groupId>com.datastax.cassandra</groupId>  
61 - <artifactId>cassandra-driver-core</artifactId> 60 + <groupId>com.datastax.oss</groupId>
  61 + <artifactId>java-driver-core</artifactId>
62 </dependency> 62 </dependency>
63 <dependency> 63 <dependency>
64 <groupId>commons-io</groupId> 64 <groupId>commons-io</groupId>