Commit 76300e400e1e1882c69780eb1d1959071cb8446c

Authored by Igor Kulikov
1 parent b81370b6

Update Cassandra Driver

Showing 99 changed files with 1235 additions and 1388 deletions

Too many changes to show.

To preserve performance only 99 of 109 files are displayed.

... ... @@ -111,6 +111,10 @@
111 111 <groupId>org.slf4j</groupId>
112 112 <artifactId>slf4j-log4j12</artifactId>
113 113 </exclusion>
  114 + <exclusion>
  115 + <groupId>org.hibernate</groupId>
  116 + <artifactId>hibernate-validator</artifactId>
  117 + </exclusion>
114 118 </exclusions>
115 119 <scope>test</scope>
116 120 </dependency>
... ... @@ -241,6 +245,12 @@
241 245 <groupId>org.springframework.boot</groupId>
242 246 <artifactId>spring-boot-starter-test</artifactId>
243 247 <scope>test</scope>
  248 + <exclusions>
  249 + <exclusion>
  250 + <groupId>com.vaadin.external.google</groupId>
  251 + <artifactId>android-json</artifactId>
  252 + </exclusion>
  253 + </exclusions>
244 254 </dependency>
245 255 <dependency>
246 256 <groupId>org.springframework.security</groupId>
... ...
... ... @@ -16,7 +16,6 @@
16 16 package org.thingsboard.server.actors.ruleChain;
17 17
18 18 import akka.actor.ActorRef;
19   -import com.datastax.driver.core.ResultSetFuture;
20 19 import com.fasterxml.jackson.core.JsonProcessingException;
21 20 import com.fasterxml.jackson.databind.ObjectMapper;
22 21 import io.netty.channel.EventLoopGroup;
... ... @@ -53,6 +52,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService;
53 52 import org.thingsboard.server.dao.device.DeviceService;
54 53 import org.thingsboard.server.dao.entityview.EntityViewService;
55 54 import org.thingsboard.server.dao.nosql.CassandraStatementTask;
  55 +import org.thingsboard.server.dao.nosql.TbResultSetFuture;
56 56 import org.thingsboard.server.dao.relation.RelationService;
57 57 import org.thingsboard.server.dao.rule.RuleChainService;
58 58 import org.thingsboard.server.dao.tenant.TenantService;
... ... @@ -405,7 +405,7 @@ class DefaultTbContext implements TbContext {
405 405 }
406 406
407 407 @Override
408   - public ResultSetFuture submitCassandraTask(CassandraStatementTask task) {
  408 + public TbResultSetFuture submitCassandraTask(CassandraStatementTask task) {
409 409 return mainCtx.getCassandraBufferedRateExecutor().submit(task);
410 410 }
411 411
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.controller;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
19 18 import com.fasterxml.jackson.core.type.TypeReference;
20 19 import com.fasterxml.jackson.databind.JsonNode;
21 20 import com.fasterxml.jackson.databind.ObjectMapper;
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.service.install;
17 17
18   -import com.datastax.driver.core.exceptions.InvalidQueryException;
  18 +import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException;
19 19 import lombok.extern.slf4j.Slf4j;
20 20 import org.springframework.context.annotation.Profile;
21 21 import org.springframework.stereotype.Service;
... ...
... ... @@ -15,25 +15,27 @@
15 15 */
16 16 package org.thingsboard.server.service.install.cql;
17 17
18   -import com.datastax.driver.core.BoundStatement;
19   -import com.datastax.driver.core.DataType;
20   -import com.datastax.driver.core.KeyspaceMetadata;
21   -import com.datastax.driver.core.PreparedStatement;
22   -import com.datastax.driver.core.ResultSet;
23   -import com.datastax.driver.core.Row;
24   -import com.datastax.driver.core.Session;
25   -import com.datastax.driver.core.SimpleStatement;
26   -import com.datastax.driver.core.Statement;
27   -import com.datastax.driver.core.TableMetadata;
  18 +import com.datastax.oss.driver.api.core.cql.BoundStatementBuilder;
  19 +import com.datastax.oss.driver.api.core.cql.PreparedStatement;
  20 +import com.datastax.oss.driver.api.core.cql.ResultSet;
  21 +import com.datastax.oss.driver.api.core.cql.Row;
  22 +import com.datastax.oss.driver.api.core.cql.SimpleStatement;
  23 +import com.datastax.oss.driver.api.core.cql.Statement;
  24 +import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
  25 +import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata;
  26 +import com.datastax.oss.driver.api.core.type.DataType;
  27 +import com.datastax.oss.protocol.internal.ProtocolConstants;
28 28 import org.apache.commons.csv.CSVFormat;
29 29 import org.apache.commons.csv.CSVParser;
30 30 import org.apache.commons.csv.CSVPrinter;
31 31 import org.apache.commons.csv.CSVRecord;
  32 +import org.thingsboard.server.dao.cassandra.guava.GuavaSession;
32 33
33 34 import java.io.IOException;
34 35 import java.nio.file.Files;
35 36 import java.nio.file.Path;
36 37 import java.nio.file.StandardCopyOption;
  38 +import java.time.Instant;
37 39 import java.util.ArrayList;
38 40 import java.util.Date;
39 41 import java.util.Iterator;
... ... @@ -44,12 +46,12 @@ import static org.thingsboard.server.service.install.DatabaseHelper.CSV_DUMP_FOR
44 46
45 47 public class CassandraDbHelper {
46 48
47   - public static Path dumpCfIfExists(KeyspaceMetadata ks, Session session, String cfName,
  49 + public static Path dumpCfIfExists(KeyspaceMetadata ks, GuavaSession session, String cfName,
48 50 String[] columns, String[] defaultValues, String dumpPrefix) throws Exception {
49 51 return dumpCfIfExists(ks, session, cfName, columns, defaultValues, dumpPrefix, false);
50 52 }
51 53
52   - public static Path dumpCfIfExists(KeyspaceMetadata ks, Session session, String cfName,
  54 + public static Path dumpCfIfExists(KeyspaceMetadata ks, GuavaSession session, String cfName,
53 55 String[] columns, String[] defaultValues, String dumpPrefix, boolean printHeader) throws Exception {
54 56 if (ks.getTable(cfName) != null) {
55 57 Path dumpFile = Files.createTempFile(dumpPrefix, null);
... ... @@ -59,8 +61,8 @@ public class CassandraDbHelper {
59 61 csvFormat = csvFormat.withHeader(columns);
60 62 }
61 63 try (CSVPrinter csvPrinter = new CSVPrinter(Files.newBufferedWriter(dumpFile), csvFormat)) {
62   - Statement stmt = new SimpleStatement("SELECT * FROM " + cfName);
63   - stmt.setFetchSize(1000);
  64 + Statement stmt = SimpleStatement.newInstance("SELECT * FROM " + cfName);
  65 + stmt.setPageSize(1000);
64 66 ResultSet rs = session.execute(stmt);
65 67 Iterator<Row> iter = rs.iterator();
66 68 while (iter.hasNext()) {
... ... @@ -95,12 +97,12 @@ public class CassandraDbHelper {
95 97 Files.move(tmp, targetDumpFile, StandardCopyOption.REPLACE_EXISTING);
96 98 }
97 99
98   - public static void loadCf(KeyspaceMetadata ks, Session session, String cfName, String[] columns, Path sourceFile) throws Exception {
  100 + public static void loadCf(KeyspaceMetadata ks, GuavaSession session, String cfName, String[] columns, Path sourceFile) throws Exception {
99 101 loadCf(ks, session, cfName, columns, sourceFile, false);
100 102 }
101 103
102   - public static void loadCf(KeyspaceMetadata ks, Session session, String cfName, String[] columns, Path sourceFile, boolean parseHeader) throws Exception {
103   - TableMetadata tableMetadata = ks.getTable(cfName);
  104 + public static void loadCf(KeyspaceMetadata ks, GuavaSession session, String cfName, String[] columns, Path sourceFile, boolean parseHeader) throws Exception {
  105 + TableMetadata tableMetadata = ks.getTable(cfName).get();
104 106 PreparedStatement prepared = session.prepare(createInsertStatement(cfName, columns));
105 107 CSVFormat csvFormat = CSV_DUMP_FORMAT;
106 108 if (parseHeader) {
... ... @@ -110,11 +112,11 @@ public class CassandraDbHelper {
110 112 }
111 113 try (CSVParser csvParser = new CSVParser(Files.newBufferedReader(sourceFile), csvFormat)) {
112 114 csvParser.forEach(record -> {
113   - BoundStatement boundStatement = prepared.bind();
  115 + BoundStatementBuilder boundStatementBuilder = new BoundStatementBuilder(prepared.bind());
114 116 for (String column : columns) {
115   - setColumnValue(tableMetadata, column, record, boundStatement);
  117 + setColumnValue(tableMetadata, column, record, boundStatementBuilder);
116 118 }
117   - session.execute(boundStatement);
  119 + session.execute(boundStatementBuilder.build());
118 120 });
119 121 }
120 122 }
... ... @@ -136,27 +138,27 @@ public class CassandraDbHelper {
136 138 }
137 139
138 140 private static String getColumnValue(String column, String defaultValue, Row row) {
139   - int index = row.getColumnDefinitions().getIndexOf(column);
  141 + int index = row.getColumnDefinitions().firstIndexOf(column);
140 142 if (index > -1) {
141 143 String str;
142   - DataType type = row.getColumnDefinitions().getType(index);
  144 + DataType type = row.getColumnDefinitions().get(index).getType();
143 145 try {
144 146 if (row.isNull(index)) {
145 147 return null;
146   - } else if (type == DataType.cdouble()) {
  148 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.DOUBLE) {
147 149 str = new Double(row.getDouble(index)).toString();
148   - } else if (type == DataType.cint()) {
  150 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.INT) {
149 151 str = new Integer(row.getInt(index)).toString();
150   - } else if (type == DataType.bigint()) {
  152 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.BIGINT) {
151 153 str = new Long(row.getLong(index)).toString();
152   - } else if (type == DataType.uuid()) {
153   - str = row.getUUID(index).toString();
154   - } else if (type == DataType.timeuuid()) {
155   - str = row.getUUID(index).toString();
156   - } else if (type == DataType.cfloat()) {
  154 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.UUID) {
  155 + str = row.getUuid(index).toString();
  156 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMEUUID) {
  157 + str = row.getUuid(index).toString();
  158 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.FLOAT) {
157 159 str = new Float(row.getFloat(index)).toString();
158   - } else if (type == DataType.timestamp()) {
159   - str = ""+row.getTimestamp(index).getTime();
  160 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMESTAMP) {
  161 + str = ""+row.getInstant(index).toEpochMilli();
160 162 } else {
161 163 str = row.getString(index);
162 164 }
... ... @@ -186,27 +188,27 @@ public class CassandraDbHelper {
186 188 }
187 189
188 190 private static void setColumnValue(TableMetadata tableMetadata, String column,
189   - CSVRecord record, BoundStatement boundStatement) {
  191 + CSVRecord record, BoundStatementBuilder boundStatementBuilder) {
190 192 String value = record.get(column);
191   - DataType type = tableMetadata.getColumn(column).getType();
  193 + DataType type = tableMetadata.getColumn(column).get().getType();
192 194 if (value == null) {
193   - boundStatement.setToNull(column);
194   - } else if (type == DataType.cdouble()) {
195   - boundStatement.setDouble(column, Double.valueOf(value));
196   - } else if (type == DataType.cint()) {
197   - boundStatement.setInt(column, Integer.valueOf(value));
198   - } else if (type == DataType.bigint()) {
199   - boundStatement.setLong(column, Long.valueOf(value));
200   - } else if (type == DataType.uuid()) {
201   - boundStatement.setUUID(column, UUID.fromString(value));
202   - } else if (type == DataType.timeuuid()) {
203   - boundStatement.setUUID(column, UUID.fromString(value));
204   - } else if (type == DataType.cfloat()) {
205   - boundStatement.setFloat(column, Float.valueOf(value));
206   - } else if (type == DataType.timestamp()) {
207   - boundStatement.setTimestamp(column, new Date(Long.valueOf(value)));
  195 + boundStatementBuilder.setToNull(column);
  196 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.DOUBLE) {
  197 + boundStatementBuilder.setDouble(column, Double.valueOf(value));
  198 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.INT) {
  199 + boundStatementBuilder.setInt(column, Integer.valueOf(value));
  200 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.BIGINT) {
  201 + boundStatementBuilder.setLong(column, Long.valueOf(value));
  202 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.UUID) {
  203 + boundStatementBuilder.setUuid(column, UUID.fromString(value));
  204 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMEUUID) {
  205 + boundStatementBuilder.setUuid(column, UUID.fromString(value));
  206 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.FLOAT) {
  207 + boundStatementBuilder.setFloat(column, Float.valueOf(value));
  208 + } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMESTAMP) {
  209 + boundStatementBuilder.setInstant(column, Instant.ofEpochMilli(Long.valueOf(value)));
208 210 } else {
209   - boundStatement.setString(column, value);
  211 + boundStatementBuilder.setString(column, value);
210 212 }
211 213 }
212 214
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.service.install.migrate;
17 17
18   -import com.datastax.driver.core.Row;
  18 +import com.datastax.oss.driver.api.core.cql.Row;
19 19 import lombok.Data;
20 20 import org.thingsboard.server.common.data.UUIDConverter;
21 21
... ... @@ -105,7 +105,7 @@ public class CassandraToSqlColumn {
105 105 } else {
106 106 switch (this.type) {
107 107 case ID:
108   - return UUIDConverter.fromTimeUUID(row.getUUID(index));
  108 + return UUIDConverter.fromTimeUUID(row.getUuid(index));
109 109 case DOUBLE:
110 110 return Double.toString(row.getDouble(index));
111 111 case INTEGER:
... ... @@ -115,7 +115,7 @@ public class CassandraToSqlColumn {
115 115 case BIGINT:
116 116 return Long.toString(row.getLong(index));
117 117 case BOOLEAN:
118   - return Boolean.toString(row.getBool(index));
  118 + return Boolean.toString(row.getBoolean(index));
119 119 case STRING:
120 120 case JSON:
121 121 case ENUM_TO_INT:
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.service.install.migrate;
17 17
18   -import com.datastax.driver.core.Row;
  18 +import com.datastax.oss.driver.api.core.cql.Row;
19 19
20 20 import java.util.UUID;
21 21
... ... @@ -29,7 +29,7 @@ public class CassandraToSqlEventTsColumn extends CassandraToSqlColumn {
29 29
30 30 @Override
31 31 public String getColumnValue(Row row) {
32   - UUID id = row.getUUID(getIndex());
  32 + UUID id = row.getUuid(getIndex());
33 33 long ts = getTs(id);
34 34 return ts + "";
35 35 }
... ... @@ -37,4 +37,4 @@ public class CassandraToSqlEventTsColumn extends CassandraToSqlColumn {
37 37 private long getTs(UUID uuid) {
38 38 return (uuid.timestamp() - EPOCH_DIFF) / 10000;
39 39 }
40   -}
\ No newline at end of file
  40 +}
... ...
... ... @@ -15,20 +15,17 @@
15 15 */
16 16 package org.thingsboard.server.service.install.migrate;
17 17
18   -import com.datastax.driver.core.ResultSet;
19   -import com.datastax.driver.core.Row;
20   -import com.datastax.driver.core.Session;
21   -import com.datastax.driver.core.SimpleStatement;
22   -import com.datastax.driver.core.Statement;
  18 +import com.datastax.oss.driver.api.core.cql.ResultSet;
  19 +import com.datastax.oss.driver.api.core.cql.Row;
  20 +import com.datastax.oss.driver.api.core.cql.SimpleStatement;
  21 +import com.datastax.oss.driver.api.core.cql.Statement;
23 22 import lombok.Data;
24 23 import lombok.extern.slf4j.Slf4j;
25   -import org.hibernate.exception.ConstraintViolationException;
26 24 import org.hibernate.internal.util.JdbcExceptionHelper;
27 25 import org.postgresql.util.PSQLException;
28 26 import org.thingsboard.server.common.data.UUIDConverter;
29   -import org.thingsboard.server.dao.exception.DataValidationException;
  27 +import org.thingsboard.server.dao.cassandra.guava.GuavaSession;
30 28
31   -import java.sql.BatchUpdateException;
32 29 import java.sql.Connection;
33 30 import java.sql.DatabaseMetaData;
34 31 import java.sql.PreparedStatement;
... ... @@ -38,7 +35,6 @@ import java.util.Arrays;
38 35 import java.util.Iterator;
39 36 import java.util.List;
40 37 import java.util.Optional;
41   -import java.util.stream.Collectors;
42 38
43 39 @Data
44 40 @Slf4j
... ... @@ -78,7 +74,7 @@ public class CassandraToSqlTable {
78 74 }
79 75 }
80 76
81   - public void migrateToSql(Session session, Connection conn) throws SQLException {
  77 + public void migrateToSql(GuavaSession session, Connection conn) throws SQLException {
82 78 log.info("[{}] Migrating data from cassandra '{}' Column Family to '{}' SQL table...", this.sqlTableName, this.cassandraCf, this.sqlTableName);
83 79 DatabaseMetaData metadata = conn.getMetaData();
84 80 java.sql.ResultSet resultSet = metadata.getColumns(null, null, this.sqlTableName, null);
... ... @@ -92,7 +88,7 @@ public class CassandraToSqlTable {
92 88 }
93 89 this.sqlInsertStatement = createSqlInsertStatement(conn);
94 90 Statement cassandraSelectStatement = createCassandraSelectStatement();
95   - cassandraSelectStatement.setFetchSize(100);
  91 + cassandraSelectStatement.setPageSize(100);
96 92 ResultSet rs = session.execute(cassandraSelectStatement);
97 93 Iterator<Row> iter = rs.iterator();
98 94 int rowCounter = 0;
... ... @@ -281,7 +277,7 @@ public class CassandraToSqlTable {
281 277 }
282 278 selectStatementBuilder.deleteCharAt(selectStatementBuilder.length() - 1);
283 279 selectStatementBuilder.append(" FROM ").append(cassandraCf);
284   - return new SimpleStatement(selectStatementBuilder.toString());
  280 + return SimpleStatement.newInstance(selectStatementBuilder.toString());
285 281 }
286 282
287 283 private PreparedStatement createSqlInsertStatement(Connection conn) throws SQLException {
... ...
... ... @@ -178,7 +178,7 @@ cassandra:
178 178 # Enable/disable JMX
179 179 jmx: "${CASSANDRA_USE_JMX:true}"
180 180 # Enable/disable metrics collection.
181   - metrics: "${CASSANDRA_DISABLE_METRICS:true}"
  181 + metrics: "${CASSANDRA_USE_METRICS:true}"
182 182 # NONE SNAPPY LZ4
183 183 compression: "${CASSANDRA_COMPRESSION:none}"
184 184 # Specify cassandra cluster initialization timeout in milliseconds (if no hosts available during startup)
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.controller;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.core.type.TypeReference;
20 20 import org.apache.commons.lang3.RandomStringUtils;
21 21 import org.junit.After;
... ... @@ -206,7 +206,7 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
206 206 asset.setType("default");
207 207 Asset savedAsset = doPost("/api/asset", asset, Asset.class);
208 208
209   - doPost("/api/customer/" + UUIDs.timeBased().toString()
  209 + doPost("/api/customer/" + Uuids.timeBased().toString()
210 210 + "/asset/" + savedAsset.getId().getId().toString())
211 211 .andExpect(status().isNotFound());
212 212 }
... ...
... ... @@ -24,7 +24,7 @@ import java.util.ArrayList;
24 24 import java.util.Collections;
25 25 import java.util.List;
26 26
27   -import com.datastax.driver.core.utils.UUIDs;
  27 +import com.datastax.oss.driver.api.core.uuid.Uuids;
28 28 import org.apache.commons.lang3.RandomStringUtils;
29 29 import org.thingsboard.server.common.data.*;
30 30 import org.thingsboard.server.common.data.id.CustomerId;
... ... @@ -158,7 +158,7 @@ public abstract class BaseDashboardControllerTest extends AbstractControllerTest
158 158 dashboard.setTitle("My dashboard");
159 159 Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
160 160
161   - doPost("/api/customer/" + UUIDs.timeBased().toString()
  161 + doPost("/api/customer/" + Uuids.timeBased().toString()
162 162 + "/dashboard/" + savedDashboard.getId().getId().toString())
163 163 .andExpect(status().isNotFound());
164 164 }
... ...
... ... @@ -23,7 +23,7 @@ import java.util.ArrayList;
23 23 import java.util.Collections;
24 24 import java.util.List;
25 25
26   -import com.datastax.driver.core.utils.UUIDs;
  26 +import com.datastax.oss.driver.api.core.uuid.Uuids;
27 27 import org.apache.commons.lang3.RandomStringUtils;
28 28 import org.thingsboard.server.common.data.*;
29 29 import org.thingsboard.server.common.data.id.CustomerId;
... ... @@ -215,7 +215,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
215 215 device.setType("default");
216 216 Device savedDevice = doPost("/api/device", device, Device.class);
217 217
218   - doPost("/api/customer/" + UUIDs.timeBased().toString()
  218 + doPost("/api/customer/" + Uuids.timeBased().toString()
219 219 + "/device/" + savedDevice.getId().getId().toString())
220 220 .andExpect(status().isNotFound());
221 221 }
... ... @@ -333,7 +333,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
333 333 Device savedDevice = doPost("/api/device", device, Device.class);
334 334 DeviceCredentials deviceCredentials =
335 335 doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
336   - DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(UUIDs.timeBased()));
  336 + DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(Uuids.timeBased()));
337 337 newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime());
338 338 newDeviceCredentials.setDeviceId(deviceCredentials.getDeviceId());
339 339 newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType());
... ... @@ -351,7 +351,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
351 351 Device savedDevice = doPost("/api/device", device, Device.class);
352 352 DeviceCredentials deviceCredentials =
353 353 doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
354   - deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased()));
  354 + deviceCredentials.setDeviceId(new DeviceId(Uuids.timeBased()));
355 355 doPost("/api/device/credentials", deviceCredentials)
356 356 .andExpect(status().isNotFound());
357 357 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.controller;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.core.type.TypeReference;
20 20 import lombok.extern.slf4j.Slf4j;
21 21 import org.apache.commons.lang3.RandomStringUtils;
... ... @@ -176,7 +176,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
176 176 @Test
177 177 public void testAssignEntityViewToNonExistentCustomer() throws Exception {
178 178 EntityView savedView = getNewSavedEntityView("Test entity view");
179   - doPost("/api/customer/" + UUIDs.timeBased().toString() + "/device/" + savedView.getId().getId().toString())
  179 + doPost("/api/customer/" + Uuids.timeBased().toString() + "/device/" + savedView.getId().getId().toString())
180 180 .andExpect(status().isNotFound());
181 181 }
182 182
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.mqtt.rpc;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import io.netty.handler.codec.mqtt.MqttQoS;
20 20 import lombok.extern.slf4j.Slf4j;
21 21 import org.apache.commons.lang3.StringUtils;
... ... @@ -143,7 +143,7 @@ public abstract class AbstractMqttServerSideRpcIntegrationTest extends AbstractC
143 143 @Test
144 144 public void testServerMqttOneWayRpcDeviceDoesNotExist() throws Exception {
145 145 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"25\",\"value\": 1}}";
146   - String nonExistentDeviceId = UUIDs.timeBased().toString();
  146 + String nonExistentDeviceId = Uuids.timeBased().toString();
147 147
148 148 String result = doPostAsync("/api/plugins/rpc/oneway/" + nonExistentDeviceId, setGpioRequest, String.class,
149 149 status().isNotFound());
... ... @@ -200,7 +200,7 @@ public abstract class AbstractMqttServerSideRpcIntegrationTest extends AbstractC
200 200 @Test
201 201 public void testServerMqttTwoWayRpcDeviceDoesNotExist() throws Exception {
202 202 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"28\",\"value\": 1}}";
203   - String nonExistentDeviceId = UUIDs.timeBased().toString();
  203 + String nonExistentDeviceId = Uuids.timeBased().toString();
204 204
205 205 String result = doPostAsync("/api/plugins/rpc/twoway/" + nonExistentDeviceId, setGpioRequest, String.class,
206 206 status().isNotFound());
... ...
... ... @@ -16,7 +16,6 @@
16 16 package org.thingsboard.server.rules.flow;
17 17
18 18 import akka.actor.ActorRef;
19   -import com.datastax.driver.core.utils.UUIDs;
20 19 import lombok.extern.slf4j.Slf4j;
21 20 import org.junit.After;
22 21 import org.junit.Assert;
... ...
... ... @@ -16,7 +16,6 @@
16 16 package org.thingsboard.server.rules.lifecycle;
17 17
18 18 import akka.actor.ActorRef;
19   -import com.datastax.driver.core.utils.UUIDs;
20 19 import lombok.extern.slf4j.Slf4j;
21 20 import org.junit.After;
22 21 import org.junit.Assert;
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.service.cluster.routing;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import lombok.extern.slf4j.Slf4j;
20 20 import org.junit.Assert;
21 21 import org.junit.Before;
... ... @@ -101,7 +101,7 @@ public class HashPartitionServiceTest {
101 101 public void testDispersionOnMillionDevices() {
102 102 List<DeviceId> devices = new ArrayList<>();
103 103 for (int i = 0; i < ITERATIONS; i++) {
104   - devices.add(new DeviceId(UUIDs.timeBased()));
  104 + devices.add(new DeviceId(Uuids.timeBased()));
105 105 }
106 106 testDevicesDispersion(devices);
107 107 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.service.script;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.google.common.collect.Sets;
20 20 import org.junit.After;
21 21 import org.junit.Before;
... ... @@ -41,7 +41,7 @@ public class RuleNodeJsScriptEngineTest {
41 41 private ScriptEngine scriptEngine;
42 42 private TestNashornJsInvokeService jsSandboxService;
43 43
44   - private EntityId ruleNodeId = new RuleNodeId(UUIDs.timeBased());
  44 + private EntityId ruleNodeId = new RuleNodeId(Uuids.timeBased());
45 45
46 46 @Before
47 47 public void beforeTest() throws Exception {
... ... @@ -247,4 +247,4 @@ public class RuleNodeJsScriptEngineTest {
247 247 }
248 248 }
249 249
250   -}
\ No newline at end of file
  250 +}
... ...
... ... @@ -78,18 +78,13 @@
78 78 <scope>provided</scope>
79 79 </dependency>
80 80 <dependency>
81   - <groupId>com.datastax.cassandra</groupId>
82   - <artifactId>cassandra-driver-core</artifactId>
  81 + <groupId>com.datastax.oss</groupId>
  82 + <artifactId>java-driver-core</artifactId>
83 83 <scope>provided</scope>
84 84 </dependency>
85 85 <dependency>
86   - <groupId>com.datastax.cassandra</groupId>
87   - <artifactId>cassandra-driver-mapping</artifactId>
88   - <scope>provided</scope>
89   - </dependency>
90   - <dependency>
91   - <groupId>com.datastax.cassandra</groupId>
92   - <artifactId>cassandra-driver-extras</artifactId>
  86 + <groupId>io.dropwizard.metrics</groupId>
  87 + <artifactId>metrics-jmx</artifactId>
93 88 <scope>provided</scope>
94 89 </dependency>
95 90 <dependency>
... ...
... ... @@ -16,117 +16,50 @@
16 16 package org.thingsboard.server.dao.cassandra;
17 17
18 18
19   -import com.datastax.driver.core.Cluster;
20   -import com.datastax.driver.core.ConsistencyLevel;
21   -import com.datastax.driver.core.HostDistance;
22   -import com.datastax.driver.core.PoolingOptions;
23   -import com.datastax.driver.core.ProtocolOptions.Compression;
24   -import com.datastax.driver.core.Session;
25   -import com.datastax.driver.mapping.DefaultPropertyMapper;
26   -import com.datastax.driver.mapping.Mapper;
27   -import com.datastax.driver.mapping.MappingConfiguration;
28   -import com.datastax.driver.mapping.MappingManager;
29   -import com.datastax.driver.mapping.PropertyAccessStrategy;
  19 +import com.codahale.metrics.MetricRegistry;
  20 +import com.codahale.metrics.jmx.JmxReporter;
  21 +import com.datastax.oss.driver.api.core.ConsistencyLevel;
30 22 import lombok.extern.slf4j.Slf4j;
31   -import org.apache.commons.lang3.StringUtils;
32 23 import org.springframework.beans.factory.annotation.Autowired;
33 24 import org.springframework.beans.factory.annotation.Value;
34 25 import org.springframework.core.env.Environment;
  26 +import org.thingsboard.server.dao.cassandra.guava.GuavaSession;
  27 +import org.thingsboard.server.dao.cassandra.guava.GuavaSessionBuilder;
  28 +import org.thingsboard.server.dao.cassandra.guava.GuavaSessionUtils;
35 29
36 30 import javax.annotation.PreDestroy;
37   -import java.net.InetSocketAddress;
38   -import java.util.ArrayList;
39   -import java.util.Collections;
40   -import java.util.List;
41 31
42 32 @Slf4j
43 33 public abstract class AbstractCassandraCluster {
44 34
45   - private static final String COMMA = ",";
46   - private static final String COLON = ":";
47   -
48   - @Value("${cassandra.cluster_name}")
49   - private String clusterName;
50   - @Value("${cassandra.url}")
51   - private String url;
52   - @Value("${cassandra.compression}")
53   - private String compression;
54   - @Value("${cassandra.ssl}")
55   - private Boolean ssl;
56 35 @Value("${cassandra.jmx}")
57 36 private Boolean jmx;
58 37 @Value("${cassandra.metrics}")
59 38 private Boolean metrics;
60   - @Value("${cassandra.credentials}")
61   - private Boolean credentials;
62   - @Value("${cassandra.username}")
63   - private String username;
64   - @Value("${cassandra.password}")
65   - private String password;
66   - @Value("${cassandra.init_timeout_ms}")
67   - private long initTimeout;
68   - @Value("${cassandra.init_retry_interval_ms}")
69   - private long initRetryInterval;
70   - @Value("${cassandra.max_requests_per_connection_local:32768}")
71   - private int max_requests_local;
72   - @Value("${cassandra.max_requests_per_connection_remote:32768}")
73   - private int max_requests_remote;
74 39
75 40 @Autowired
76   - private CassandraSocketOptions socketOpts;
77   -
78   - @Autowired
79   - private CassandraQueryOptions queryOpts;
  41 + private CassandraDriverOptions driverOptions;
80 42
81 43 @Autowired
82 44 private Environment environment;
83 45
84   - private Cluster cluster;
85   - private Cluster.Builder clusterBuilder;
  46 + private GuavaSessionBuilder sessionBuilder;
86 47
87   - private Session session;
  48 + private GuavaSession session;
88 49
89   - private MappingManager mappingManager;
90   -
91   - public <T> Mapper<T> getMapper(Class<T> clazz) {
92   - return mappingManager.mapper(clazz);
93   - }
  50 + private JmxReporter reporter;
94 51
95 52 private String keyspaceName;
96 53
97 54 protected void init(String keyspaceName) {
98 55 this.keyspaceName = keyspaceName;
99   - this.clusterBuilder = Cluster.builder()
100   - .addContactPointsWithPorts(getContactPoints(url))
101   - .withClusterName(clusterName)
102   - .withSocketOptions(socketOpts.getOpts())
103   - .withPoolingOptions(new PoolingOptions()
104   - .setMaxRequestsPerConnection(HostDistance.LOCAL, max_requests_local)
105   - .setMaxRequestsPerConnection(HostDistance.REMOTE, max_requests_remote));
106   - this.clusterBuilder.withQueryOptions(queryOpts.getOpts());
107   - this.clusterBuilder.withCompression(StringUtils.isEmpty(compression) ? Compression.NONE : Compression.valueOf(compression.toUpperCase()));
108   - if (ssl) {
109   - this.clusterBuilder.withSSL();
110   - }
111   - if (!jmx) {
112   - this.clusterBuilder.withoutJMXReporting();
113   - }
114   - if (!metrics) {
115   - this.clusterBuilder.withoutMetrics();
116   - }
117   - if (credentials) {
118   - this.clusterBuilder.withCredentials(username, password);
119   - }
  56 + this.sessionBuilder = GuavaSessionUtils.builder().withConfigLoader(this.driverOptions.getLoader());
120 57 if (!isInstall()) {
121 58 initSession();
122 59 }
123 60 }
124 61
125   - public Cluster getCluster() {
126   - return cluster;
127   - }
128   -
129   - public Session getSession() {
  62 + public GuavaSession getSession() {
130 63 if (!isInstall()) {
131 64 return session;
132 65 } else {
... ... @@ -146,64 +79,40 @@ public abstract class AbstractCassandraCluster {
146 79 }
147 80
148 81 private void initSession() {
149   - long endTime = System.currentTimeMillis() + initTimeout;
150   - while (System.currentTimeMillis() < endTime) {
151   - try {
152   - cluster = clusterBuilder.build();
153   - cluster.init();
154   - if (this.keyspaceName != null) {
155   - session = cluster.connect(keyspaceName);
156   - } else {
157   - session = cluster.connect();
158   - }
159   -// For Cassandra Driver version 3.5.0
160   - DefaultPropertyMapper propertyMapper = new DefaultPropertyMapper();
161   - propertyMapper.setPropertyAccessStrategy(PropertyAccessStrategy.FIELDS);
162   - MappingConfiguration configuration = MappingConfiguration.builder().withPropertyMapper(propertyMapper).build();
163   - mappingManager = new MappingManager(session, configuration);
164   -// For Cassandra Driver version 3.0.0
165   -// mappingManager = new MappingManager(session);
166   - break;
167   - } catch (Exception e) {
168   - log.warn("Failed to initialize cassandra cluster due to {}. Will retry in {} ms", e.getMessage(), initRetryInterval);
169   - try {
170   - Thread.sleep(initRetryInterval);
171   - } catch (InterruptedException ie) {
172   - log.warn("Failed to wait until retry", ie);
173   - Thread.currentThread().interrupt();
174   - }
175   - }
  82 + if (this.keyspaceName != null) {
  83 + this.sessionBuilder.withKeyspace(this.keyspaceName);
  84 + }
  85 + this.sessionBuilder.withLocalDatacenter("datacenter1");
  86 + session = sessionBuilder.build();
  87 + if (this.metrics && this.jmx) {
  88 + MetricRegistry registry =
  89 + session.getMetrics().orElseThrow(
  90 + () -> new IllegalStateException("Metrics are disabled"))
  91 + .getRegistry();
  92 + this.reporter =
  93 + JmxReporter.forRegistry(registry)
  94 + .inDomain("com.datastax.oss.driver")
  95 + .build();
  96 + this.reporter.start();
176 97 }
177 98 }
178 99
179 100 @PreDestroy
180 101 public void close() {
181   - if (cluster != null) {
182   - cluster.close();
  102 + if (reporter != null) {
  103 + reporter.stop();
183 104 }
184   - }
185   -
186   - private List<InetSocketAddress> getContactPoints(String url) {
187   - List<InetSocketAddress> result;
188   - if (StringUtils.isBlank(url)) {
189   - result = Collections.emptyList();
190   - } else {
191   - result = new ArrayList<>();
192   - for (String hostPort : url.split(COMMA)) {
193   - String host = hostPort.split(COLON)[0];
194   - Integer port = Integer.valueOf(hostPort.split(COLON)[1]);
195   - result.add(new InetSocketAddress(host, port));
196   - }
  105 + if (session != null) {
  106 + session.close();
197 107 }
198   - return result;
199 108 }
200 109
201 110 public ConsistencyLevel getDefaultReadConsistencyLevel() {
202   - return queryOpts.getDefaultReadConsistencyLevel();
  111 + return driverOptions.getDefaultReadConsistencyLevel();
203 112 }
204 113
205 114 public ConsistencyLevel getDefaultWriteConsistencyLevel() {
206   - return queryOpts.getDefaultWriteConsistencyLevel();
  115 + return driverOptions.getDefaultWriteConsistencyLevel();
207 116 }
208 117
209 118 }
... ...
  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 13 * See the License for the specific language governing permissions and
14 14 * limitations under the License.
15 15 */
16   -package org.thingsboard.server.dao.model.type;
  16 +package org.thingsboard.server.dao.cassandra.guava;
17 17
18   -import com.datastax.driver.extras.codecs.json.JacksonJsonCodec;
19   -import com.fasterxml.jackson.databind.JsonNode;
  18 +import com.datastax.oss.driver.api.core.session.Session;
  19 +import com.datastax.oss.driver.internal.core.session.SessionWrapper;
20 20
21   -public class JsonCodec extends JacksonJsonCodec<JsonNode> {
  21 +public class DefaultGuavaSession extends SessionWrapper implements GuavaSession {
22 22
23   - public JsonCodec() {
24   - super(JsonNode.class);
  23 + public DefaultGuavaSession(Session delegate) {
  24 + super(delegate);
25 25 }
26   -
27 26 }
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.cassandra.guava;
  17 +
  18 +import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
  19 +import com.datastax.oss.driver.api.core.cql.PrepareRequest;
  20 +import com.datastax.oss.driver.api.core.cql.Statement;
  21 +import com.datastax.oss.driver.api.core.metadata.Node;
  22 +import com.datastax.oss.driver.api.core.metadata.NodeStateListener;
  23 +import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener;
  24 +import com.datastax.oss.driver.api.core.session.ProgrammaticArguments;
  25 +import com.datastax.oss.driver.api.core.tracker.RequestTracker;
  26 +import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
  27 +import com.datastax.oss.driver.internal.core.context.DefaultDriverContext;
  28 +import com.datastax.oss.driver.internal.core.cql.CqlPrepareAsyncProcessor;
  29 +import com.datastax.oss.driver.internal.core.cql.CqlPrepareSyncProcessor;
  30 +import com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor;
  31 +import com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor;
  32 +import com.datastax.oss.driver.internal.core.session.RequestProcessorRegistry;
  33 +import java.util.List;
  34 +import java.util.Map;
  35 +import java.util.function.Predicate;
  36 +
  37 +/**
  38 + * A Custom {@link DefaultDriverContext} that overrides {@link #getRequestProcessorRegistry()} to
  39 + * return a {@link RequestProcessorRegistry} that includes processors for returning guava futures.
  40 + */
  41 +public class GuavaDriverContext extends DefaultDriverContext {
  42 +
  43 + public GuavaDriverContext(
  44 + DriverConfigLoader configLoader,
  45 + List<TypeCodec<?>> typeCodecs,
  46 + NodeStateListener nodeStateListener,
  47 + SchemaChangeListener schemaChangeListener,
  48 + RequestTracker requestTracker,
  49 + Map<String, String> localDatacenters,
  50 + Map<String, Predicate<Node>> nodeFilters,
  51 + ClassLoader classLoader) {
  52 + super(
  53 + configLoader,
  54 + ProgrammaticArguments.builder()
  55 + .addTypeCodecs(typeCodecs.toArray(new TypeCodec<?>[0]))
  56 + .withNodeStateListener(nodeStateListener)
  57 + .withSchemaChangeListener(schemaChangeListener)
  58 + .withRequestTracker(requestTracker)
  59 + .withLocalDatacenters(localDatacenters)
  60 + .withNodeFilters(nodeFilters)
  61 + .withClassLoader(classLoader)
  62 + .build());
  63 + }
  64 +
  65 + @Override
  66 + public RequestProcessorRegistry buildRequestProcessorRegistry() {
  67 + // Register the typical request processors, except instead of the normal async processors,
  68 + // use GuavaRequestAsyncProcessor to return ListenableFutures in async methods.
  69 +
  70 + CqlRequestAsyncProcessor cqlRequestAsyncProcessor = new CqlRequestAsyncProcessor();
  71 + CqlPrepareAsyncProcessor cqlPrepareAsyncProcessor = new CqlPrepareAsyncProcessor();
  72 + CqlRequestSyncProcessor cqlRequestSyncProcessor =
  73 + new CqlRequestSyncProcessor(cqlRequestAsyncProcessor);
  74 +
  75 + return new RequestProcessorRegistry(
  76 + getSessionName(),
  77 + cqlRequestSyncProcessor,
  78 + new CqlPrepareSyncProcessor(cqlPrepareAsyncProcessor),
  79 + new GuavaRequestAsyncProcessor<>(
  80 + cqlRequestAsyncProcessor, Statement.class, GuavaSession.ASYNC),
  81 + new GuavaRequestAsyncProcessor<>(
  82 + cqlPrepareAsyncProcessor, PrepareRequest.class, GuavaSession.ASYNC_PREPARED));
  83 + }
  84 +}
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.cassandra.guava;
  17 +
  18 +import com.datastax.oss.driver.api.core.session.Request;
  19 +import com.datastax.oss.driver.api.core.type.reflect.GenericType;
  20 +import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
  21 +import com.datastax.oss.driver.internal.core.session.DefaultSession;
  22 +import com.datastax.oss.driver.internal.core.session.RequestProcessor;
  23 +import com.google.common.util.concurrent.Futures;
  24 +import com.google.common.util.concurrent.ListenableFuture;
  25 +import com.google.common.util.concurrent.SettableFuture;
  26 +import java.util.concurrent.CompletionStage;
  27 +
  28 +/**
  29 + * Wraps a {@link RequestProcessor} that returns {@link CompletionStage}s and converts them to a
  30 + * {@link ListenableFuture}s.
  31 + *
  32 + * @param <T> The type of request
  33 + * @param <U> The type of responses enclosed in the future response.
  34 + */
  35 +public class GuavaRequestAsyncProcessor<T extends Request, U>
  36 + implements RequestProcessor<T, ListenableFuture<U>> {
  37 +
  38 + private final RequestProcessor<T, CompletionStage<U>> subProcessor;
  39 +
  40 + private final GenericType resultType;
  41 +
  42 + private final Class<?> requestClass;
  43 +
  44 + GuavaRequestAsyncProcessor(
  45 + RequestProcessor<T, CompletionStage<U>> subProcessor,
  46 + Class<?> requestClass,
  47 + GenericType resultType) {
  48 + this.subProcessor = subProcessor;
  49 + this.requestClass = requestClass;
  50 + this.resultType = resultType;
  51 + }
  52 +
  53 + @Override
  54 + public boolean canProcess(Request request, GenericType resultType) {
  55 + return requestClass.isInstance(request) && resultType.equals(this.resultType);
  56 + }
  57 +
  58 + @Override
  59 + public ListenableFuture<U> process(
  60 + T request, DefaultSession session, InternalDriverContext context, String sessionLogPrefix) {
  61 + SettableFuture<U> future = SettableFuture.create();
  62 + subProcessor
  63 + .process(request, session, context, sessionLogPrefix)
  64 + .whenComplete(
  65 + (r, ex) -> {
  66 + if (ex != null) {
  67 + future.setException(ex);
  68 + } else {
  69 + future.set(r);
  70 + }
  71 + });
  72 + return future;
  73 + }
  74 +
  75 + @Override
  76 + public ListenableFuture<U> newFailure(RuntimeException error) {
  77 + return Futures.immediateFailedFuture(error);
  78 + }
  79 +}
... ...
common/dao-api/src/main/java/org/thingsboard/server/dao/cassandra/guava/GuavaSession.java renamed from dao/src/main/java/org/thingsboard/server/dao/model/type/ComponentLifecycleStateCodec.java
... ... @@ -13,15 +13,39 @@
13 13 * See the License for the specific language governing permissions and
14 14 * limitations under the License.
15 15 */
16   -package org.thingsboard.server.dao.model.type;
  16 +package org.thingsboard.server.dao.cassandra.guava;
17 17
18   -import com.datastax.driver.extras.codecs.enums.EnumNameCodec;
19   -import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
  18 +import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
  19 +import com.datastax.oss.driver.api.core.cql.PreparedStatement;
  20 +import com.datastax.oss.driver.api.core.cql.SimpleStatement;
  21 +import com.datastax.oss.driver.api.core.cql.Statement;
  22 +import com.datastax.oss.driver.api.core.cql.SyncCqlSession;
  23 +import com.datastax.oss.driver.api.core.session.Session;
  24 +import com.datastax.oss.driver.api.core.type.reflect.GenericType;
  25 +import com.datastax.oss.driver.internal.core.cql.DefaultPrepareRequest;
  26 +import com.google.common.util.concurrent.ListenableFuture;
20 27
21   -public class ComponentLifecycleStateCodec extends EnumNameCodec<ComponentLifecycleState> {
  28 +public interface GuavaSession extends Session, SyncCqlSession {
22 29
23   - public ComponentLifecycleStateCodec() {
24   - super(ComponentLifecycleState.class);
  30 + GenericType<ListenableFuture<AsyncResultSet>> ASYNC =
  31 + new GenericType<ListenableFuture<AsyncResultSet>>() {};
  32 +
  33 + GenericType<ListenableFuture<PreparedStatement>> ASYNC_PREPARED =
  34 + new GenericType<ListenableFuture<PreparedStatement>>() {};
  35 +
  36 + default ListenableFuture<AsyncResultSet> executeAsync(Statement<?> statement) {
  37 + return this.execute(statement, ASYNC);
  38 + }
  39 +
  40 + default ListenableFuture<AsyncResultSet> executeAsync(String statement) {
  41 + return this.executeAsync(SimpleStatement.newInstance(statement));
25 42 }
26 43
  44 + default ListenableFuture<PreparedStatement> prepareAsync(SimpleStatement statement) {
  45 + return this.execute(new DefaultPrepareRequest(statement), ASYNC_PREPARED);
  46 + }
  47 +
  48 + default ListenableFuture<PreparedStatement> prepareAsync(String statement) {
  49 + return this.prepareAsync(SimpleStatement.newInstance(statement));
  50 + }
27 51 }
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.cassandra.guava;
  17 +
  18 +import com.datastax.oss.driver.api.core.CqlSession;
  19 +import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
  20 +import com.datastax.oss.driver.api.core.context.DriverContext;
  21 +import com.datastax.oss.driver.api.core.metadata.Node;
  22 +import com.datastax.oss.driver.api.core.metadata.NodeStateListener;
  23 +import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener;
  24 +import com.datastax.oss.driver.api.core.session.SessionBuilder;
  25 +import com.datastax.oss.driver.api.core.tracker.RequestTracker;
  26 +import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
  27 +import edu.umd.cs.findbugs.annotations.NonNull;
  28 +import java.util.List;
  29 +import java.util.Map;
  30 +import java.util.function.Predicate;
  31 +
  32 +public class GuavaSessionBuilder extends SessionBuilder<GuavaSessionBuilder, GuavaSession> {
  33 +
  34 + @Override
  35 + protected DriverContext buildContext(
  36 + DriverConfigLoader configLoader,
  37 + List<TypeCodec<?>> typeCodecs,
  38 + NodeStateListener nodeStateListener,
  39 + SchemaChangeListener schemaChangeListener,
  40 + RequestTracker requestTracker,
  41 + Map<String, String> localDatacenters,
  42 + Map<String, Predicate<Node>> nodeFilters,
  43 + ClassLoader classLoader) {
  44 + return new GuavaDriverContext(
  45 + configLoader,
  46 + typeCodecs,
  47 + nodeStateListener,
  48 + schemaChangeListener,
  49 + requestTracker,
  50 + localDatacenters,
  51 + nodeFilters,
  52 + classLoader);
  53 + }
  54 +
  55 + @Override
  56 + protected GuavaSession wrap(@NonNull CqlSession defaultSession) {
  57 + return new DefaultGuavaSession(defaultSession);
  58 + }
  59 +}
... ...
common/dao-api/src/main/java/org/thingsboard/server/dao/cassandra/guava/GuavaSessionUtils.java renamed from dao/src/main/java/org/thingsboard/server/dao/model/type/EntityTypeCodec.java
... ... @@ -13,15 +13,10 @@
13 13 * See the License for the specific language governing permissions and
14 14 * limitations under the License.
15 15 */
16   -package org.thingsboard.server.dao.model.type;
  16 +package org.thingsboard.server.dao.cassandra.guava;
17 17
18   -import com.datastax.driver.extras.codecs.enums.EnumNameCodec;
19   -import org.thingsboard.server.common.data.EntityType;
20   -
21   -public class EntityTypeCodec extends EnumNameCodec<EntityType> {
22   -
23   - public EntityTypeCodec() {
24   - super(EntityType.class);
  18 +public class GuavaSessionUtils {
  19 + public static GuavaSessionBuilder builder() {
  20 + return new GuavaSessionBuilder();
25 21 }
26   -
27 22 }
... ...
... ... @@ -15,10 +15,10 @@
15 15 */
16 16 package org.thingsboard.server.dao.nosql;
17 17
18   -import com.datastax.driver.core.Session;
19   -import com.datastax.driver.core.Statement;
  18 +import com.datastax.oss.driver.api.core.cql.Statement;
20 19 import lombok.Data;
21 20 import org.thingsboard.server.common.data.id.TenantId;
  21 +import org.thingsboard.server.dao.cassandra.guava.GuavaSession;
22 22 import org.thingsboard.server.dao.util.AsyncTask;
23 23
24 24 /**
... ... @@ -28,7 +28,7 @@ import org.thingsboard.server.dao.util.AsyncTask;
28 28 public class CassandraStatementTask implements AsyncTask {
29 29
30 30 private final TenantId tenantId;
31   - private final Session session;
  31 + private final GuavaSession session;
32 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 15 */
16 16 package org.thingsboard.server.dao.nosql;
17 17
18   -import com.datastax.driver.core.ResultSet;
19   -import com.datastax.driver.core.ResultSetFuture;
  18 +import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
  19 +import com.google.common.util.concurrent.ListenableFuture;
20 20 import com.google.common.util.concurrent.SettableFuture;
21 21
22 22 import java.util.concurrent.ExecutionException;
... ... @@ -27,21 +27,19 @@ import java.util.concurrent.TimeoutException;
27 27 /**
28 28 * Created by ashvayka on 24.10.18.
29 29 */
30   -public class TbResultSetFuture implements ResultSetFuture {
  30 +public class TbResultSetFuture implements ListenableFuture<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 35 this.mainFuture = mainFuture;
36 36 }
37 37
38   - @Override
39   - public ResultSet getUninterruptibly() {
  38 + public AsyncResultSet getUninterruptibly() {
40 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 43 return getSafe(timeout, unit);
46 44 }
47 45
... ... @@ -61,12 +59,12 @@ public class TbResultSetFuture implements ResultSetFuture {
61 59 }
62 60
63 61 @Override
64   - public ResultSet get() throws InterruptedException, ExecutionException {
  62 + public AsyncResultSet get() throws InterruptedException, ExecutionException {
65 63 return mainFuture.get();
66 64 }
67 65
68 66 @Override
69   - public ResultSet get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
  67 + public AsyncResultSet get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
70 68 return mainFuture.get(timeout, unit);
71 69 }
72 70
... ... @@ -75,7 +73,7 @@ public class TbResultSetFuture implements ResultSetFuture {
75 73 mainFuture.addListener(listener, executor);
76 74 }
77 75
78   - private ResultSet getSafe() {
  76 + private AsyncResultSet getSafe() {
79 77 try {
80 78 return mainFuture.get();
81 79 } catch (InterruptedException | ExecutionException e) {
... ... @@ -83,7 +81,7 @@ public class TbResultSetFuture implements ResultSetFuture {
83 81 }
84 82 }
85 83
86   - private ResultSet getSafe(long timeout, TimeUnit unit) throws TimeoutException {
  84 + private AsyncResultSet getSafe(long timeout, TimeUnit unit) throws TimeoutException {
87 85 try {
88 86 return mainFuture.get(timeout, unit);
89 87 } catch (InterruptedException | ExecutionException e) {
... ...
... ... @@ -67,8 +67,8 @@
67 67 <scope>test</scope>
68 68 </dependency>
69 69 <dependency>
70   - <groupId>com.datastax.cassandra</groupId>
71   - <artifactId>cassandra-driver-core</artifactId>
  70 + <groupId>com.datastax.oss</groupId>
  71 + <artifactId>java-driver-core</artifactId>
72 72 <scope>test</scope>
73 73 </dependency>
74 74 </dependencies>
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.common.data;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.junit.Assert;
20 20 import org.junit.Test;
21 21 import org.junit.runner.RunWith;
... ... @@ -61,8 +61,8 @@ public class UUIDConverterTest {
61 61 before = tmp;
62 62 }
63 63
64   - String beforeStr = UUIDConverter.fromTimeUUID(UUIDs.startOf(before));
65   - String afterStr = UUIDConverter.fromTimeUUID(UUIDs.startOf(after));
  64 + String beforeStr = UUIDConverter.fromTimeUUID(Uuids.startOf(before));
  65 + String afterStr = UUIDConverter.fromTimeUUID(Uuids.startOf(after));
66 66
67 67 if (afterStr.compareTo(beforeStr) < 0) {
68 68 System.out.println("Before: " + before + " | " + beforeStr);
... ...
... ... @@ -120,18 +120,18 @@
120 120 <groupId>org.springframework.security</groupId>
121 121 <artifactId>spring-security-oauth2-client</artifactId>
122 122 </dependency>
123   - <dependency>
124   - <groupId>com.datastax.cassandra</groupId>
125   - <artifactId>cassandra-driver-core</artifactId>
126   - </dependency>
127   - <dependency>
128   - <groupId>com.datastax.cassandra</groupId>
129   - <artifactId>cassandra-driver-mapping</artifactId>
130   - </dependency>
131   - <dependency>
132   - <groupId>com.datastax.cassandra</groupId>
133   - <artifactId>cassandra-driver-extras</artifactId>
134   - </dependency>
  123 + <dependency>
  124 + <groupId>com.datastax.oss</groupId>
  125 + <artifactId>java-driver-core</artifactId>
  126 + </dependency>
  127 + <dependency>
  128 + <groupId>com.datastax.oss</groupId>
  129 + <artifactId>java-driver-query-builder</artifactId>
  130 + </dependency>
  131 + <dependency>
  132 + <groupId>io.dropwizard.metrics</groupId>
  133 + <artifactId>metrics-jmx</artifactId>
  134 + </dependency>
135 135 <dependency>
136 136 <groupId>io.takari.junit</groupId>
137 137 <artifactId>takari-cpsuite</artifactId>
... ... @@ -149,6 +149,10 @@
149 149 <groupId>org.slf4j</groupId>
150 150 <artifactId>slf4j-log4j12</artifactId>
151 151 </exclusion>
  152 + <exclusion>
  153 + <groupId>org.hibernate</groupId>
  154 + <artifactId>hibernate-validator</artifactId>
  155 + </exclusion>
152 156 </exclusions>
153 157 <scope>test</scope>
154 158 </dependency>
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.springframework.data.domain.Page;
20 20 import org.springframework.data.domain.PageRequest;
21 21 import org.springframework.data.domain.Pageable;
... ... @@ -49,7 +49,7 @@ public abstract class DaoUtil {
49 49
50 50 public static String startTimeToId(Long startTime) {
51 51 if (startTime != null) {
52   - UUID startOf = UUIDs.startOf(startTime);
  52 + UUID startOf = Uuids.startOf(startTime);
53 53 return UUIDConverter.fromTimeUUID(startOf);
54 54 } else {
55 55 return null;
... ... @@ -58,7 +58,7 @@ public abstract class DaoUtil {
58 58
59 59 public static String endTimeToId(Long endTime) {
60 60 if (endTime != null) {
61   - UUID endOf = UUIDs.endOf(endTime);
  61 + UUID endOf = Uuids.endOf(endTime);
62 62 return UUIDConverter.fromTimeUUID(endOf);
63 63 } else {
64 64 return null;
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.audit;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 21 import com.fasterxml.jackson.databind.node.ArrayNode;
... ... @@ -296,7 +296,7 @@ public class AuditLogServiceImpl implements AuditLogService {
296 296 ActionStatus actionStatus,
297 297 String actionFailureDetails) {
298 298 AuditLog result = new AuditLog();
299   - result.setId(new AuditLogId(UUIDs.timeBased()));
  299 + result.setId(new AuditLogId(Uuids.timeBased()));
300 300 result.setTenantId(tenantId);
301 301 result.setEntityId(entityId);
302 302 result.setEntityName(entityName);
... ...
1   -/**
2   - * Copyright © 2016-2020 The Thingsboard Authors
3   - *
4   - * Licensed under the Apache License, Version 2.0 (the "License");
5   - * you may not use this file except in compliance with the License.
6   - * You may obtain a copy of the License at
7   - *
8   - * http://www.apache.org/licenses/LICENSE-2.0
9   - *
10   - * Unless required by applicable law or agreed to in writing, software
11   - * distributed under the License is distributed on an "AS IS" BASIS,
12   - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   - * See the License for the specific language governing permissions and
14   - * limitations under the License.
15   - */
16   -package org.thingsboard.server.dao.model;
17   -
18   -import com.datastax.driver.mapping.annotations.Column;
19   -import com.datastax.driver.mapping.annotations.PartitionKey;
20   -import com.datastax.driver.mapping.annotations.Table;
21   -import org.thingsboard.server.common.data.EntitySubtype;
22   -import org.thingsboard.server.common.data.EntityType;
23   -import org.thingsboard.server.common.data.id.TenantId;
24   -import org.thingsboard.server.dao.model.type.EntityTypeCodec;
25   -
26   -import java.util.UUID;
27   -
28   -import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_COLUMN_FAMILY_NAME;
29   -import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY;
30   -import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_TENANT_ID_PROPERTY;
31   -import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_TYPE_PROPERTY;
32   -
33   -@Table(name = ENTITY_SUBTYPE_COLUMN_FAMILY_NAME)
34   -public class EntitySubtypeEntity {
35   -
36   - @PartitionKey(value = 0)
37   - @Column(name = ENTITY_SUBTYPE_TENANT_ID_PROPERTY)
38   - private UUID tenantId;
39   -
40   - @PartitionKey(value = 1)
41   - @Column(name = ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, codec = EntityTypeCodec.class)
42   - private EntityType entityType;
43   -
44   - @PartitionKey(value = 2)
45   - @Column(name = ENTITY_SUBTYPE_TYPE_PROPERTY)
46   - private String type;
47   -
48   - public EntitySubtypeEntity() {
49   - super();
50   - }
51   -
52   - public EntitySubtypeEntity(EntitySubtype entitySubtype) {
53   - this.tenantId = entitySubtype.getTenantId().getId();
54   - this.entityType = entitySubtype.getEntityType();
55   - this.type = entitySubtype.getType();
56   - }
57   -
58   - public UUID getTenantId() {
59   - return tenantId;
60   - }
61   -
62   - public void setTenantId(UUID tenantId) {
63   - this.tenantId = tenantId;
64   - }
65   -
66   - public EntityType getEntityType() {
67   - return entityType;
68   - }
69   -
70   - public void setEntityType(EntityType entityType) {
71   - this.entityType = entityType;
72   - }
73   -
74   - public String getType() {
75   - return type;
76   - }
77   -
78   - public void setType(String type) {
79   - this.type = type;
80   - }
81   -
82   -
83   - @Override
84   - public boolean equals(Object o) {
85   - if (this == o) return true;
86   - if (o == null || getClass() != o.getClass()) return false;
87   -
88   - EntitySubtypeEntity that = (EntitySubtypeEntity) o;
89   -
90   - if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) return false;
91   - if (entityType != that.entityType) return false;
92   - return type != null ? type.equals(that.type) : that.type == null;
93   -
94   - }
95   -
96   - @Override
97   - public int hashCode() {
98   - int result = tenantId != null ? tenantId.hashCode() : 0;
99   - result = 31 * result + (entityType != null ? entityType.hashCode() : 0);
100   - result = 31 * result + (type != null ? type.hashCode() : 0);
101   - return result;
102   - }
103   -
104   - @Override
105   - public String toString() {
106   - final StringBuilder sb = new StringBuilder("EntitySubtypeEntity{");
107   - sb.append("tenantId=").append(tenantId);
108   - sb.append(", entityType=").append(entityType);
109   - sb.append(", type='").append(type).append('\'');
110   - sb.append('}');
111   - return sb.toString();
112   - }
113   -
114   - public EntitySubtype toEntitySubtype() {
115   - EntitySubtype entitySubtype = new EntitySubtype();
116   - entitySubtype.setTenantId(new TenantId(tenantId));
117   - entitySubtype.setEntityType(entityType);
118   - entitySubtype.setType(type);
119   - return entitySubtype;
120   - }
121   -}
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.apache.commons.lang3.ArrayUtils;
20 20 import org.thingsboard.server.common.data.UUIDConverter;
21 21 import org.thingsboard.server.common.data.id.TenantId;
... ... @@ -28,7 +28,7 @@ public class ModelConstants {
28 28 private ModelConstants() {
29 29 }
30 30
31   - public static final UUID NULL_UUID = UUIDs.startOf(0);
  31 + public static final UUID NULL_UUID = Uuids.startOf(0);
32 32 public static final String NULL_UUID_STR = UUIDConverter.fromTimeUUID(NULL_UUID);
33 33 public static final TenantId SYSTEM_TENANT = new TenantId(ModelConstants.NULL_UUID);
34 34
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -154,7 +154,7 @@ public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity
154 154
155 155 protected Alarm toAlarm() {
156 156 Alarm alarm = new Alarm(new AlarmId(UUIDConverter.fromString(id)));
157   - alarm.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id)));
  157 + alarm.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id)));
158 158 if (tenantId != null) {
159 159 alarm.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
160 160 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -116,7 +116,7 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
116 116
117 117 protected Asset toAsset() {
118 118 Asset asset = new Asset(new AssetId(UUIDConverter.fromString(id)));
119   - asset.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id)));
  119 + asset.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id)));
120 120 if (tenantId != null) {
121 121 asset.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
122 122 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -104,7 +104,7 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti
104 104
105 105 protected Device toDevice() {
106 106 Device device = new Device(new DeviceId(getUuid()));
107   - device.setCreatedTime(UUIDs.unixTimestamp(getUuid()));
  107 + device.setCreatedTime(Uuids.unixTimestamp(getUuid()));
108 108 if (tenantId != null) {
109 109 device.setTenantId(new TenantId(toUUID(tenantId)));
110 110 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 21 import lombok.Data;
... ... @@ -147,7 +147,7 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas
147 147
148 148 protected EntityView toEntityView() {
149 149 EntityView entityView = new EntityView(new EntityViewId(getUuid()));
150   - entityView.setCreatedTime(UUIDs.unixTimestamp(getUuid()));
  150 + entityView.setCreatedTime(Uuids.unixTimestamp(getUuid()));
151 151
152 152 if (entityId != null) {
153 153 entityView.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), toUUID(entityId).toString()));
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -65,10 +65,10 @@ public final class AdminSettingsEntity extends BaseSqlEntity<AdminSettings> impl
65 65 @Override
66 66 public AdminSettings toData() {
67 67 AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(UUIDConverter.fromString(id)));
68   - adminSettings.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id)));
  68 + adminSettings.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id)));
69 69 adminSettings.setKey(key);
70 70 adminSettings.setJsonValue(jsonValue);
71 71 return adminSettings;
72 72 }
73 73
74   -}
\ No newline at end of file
  74 +}
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -129,7 +129,7 @@ public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntit
129 129 @Override
130 130 public AuditLog toData() {
131 131 AuditLog auditLog = new AuditLog(new AuditLogId(this.getUuid()));
132   - auditLog.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  132 + auditLog.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
133 133 if (tenantId != null) {
134 134 auditLog.setTenantId(new TenantId(toUUID(tenantId)));
135 135 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -112,7 +112,7 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea
112 112 @Override
113 113 public Customer toData() {
114 114 Customer customer = new Customer(new CustomerId(this.getUuid()));
115   - customer.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  115 + customer.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
116 116 customer.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
117 117 customer.setTitle(title);
118 118 customer.setCountry(country);
... ... @@ -126,4 +126,4 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea
126 126 customer.setAdditionalInfo(additionalInfo);
127 127 return customer;
128 128 }
129   -}
\ No newline at end of file
  129 +}
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.core.JsonProcessingException;
20 20 import com.fasterxml.jackson.databind.JavaType;
21 21 import com.fasterxml.jackson.databind.JsonNode;
... ... @@ -104,7 +104,7 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
104 104 @Override
105 105 public Dashboard toData() {
106 106 Dashboard dashboard = new Dashboard(new DashboardId(this.getUuid()));
107   - dashboard.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  107 + dashboard.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
108 108 if (tenantId != null) {
109 109 dashboard.setTenantId(new TenantId(toUUID(tenantId)));
110 110 }
... ... @@ -119,4 +119,4 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
119 119 dashboard.setConfiguration(configuration);
120 120 return dashboard;
121 121 }
122   -}
\ No newline at end of file
  122 +}
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.core.JsonProcessingException;
20 20 import com.fasterxml.jackson.databind.JavaType;
21 21 import com.fasterxml.jackson.databind.ObjectMapper;
... ... @@ -98,7 +98,7 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
98 98 @Override
99 99 public DashboardInfo toData() {
100 100 DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(this.getUuid()));
101   - dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  101 + dashboardInfo.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
102 102 if (tenantId != null) {
103 103 dashboardInfo.setTenantId(new TenantId(toUUID(tenantId)));
104 104 }
... ... @@ -113,4 +113,4 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
113 113 return dashboardInfo;
114 114 }
115 115
116   -}
\ No newline at end of file
  116 +}
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import lombok.Data;
20 20 import lombok.EqualsAndHashCode;
21 21 import org.thingsboard.server.common.data.id.DeviceCredentialsId;
... ... @@ -70,7 +70,7 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia
70 70 @Override
71 71 public DeviceCredentials toData() {
72 72 DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(this.getUuid()));
73   - deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  73 + deviceCredentials.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
74 74 if (deviceId != null) {
75 75 deviceCredentials.setDeviceId(new DeviceId(toUUID(deviceId)));
76 76 }
... ... @@ -80,4 +80,4 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia
80 80 return deviceCredentials;
81 81 }
82 82
83   -}
\ No newline at end of file
  83 +}
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -103,7 +103,7 @@ public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Eve
103 103 @Override
104 104 public Event toData() {
105 105 Event event = new Event(new EventId(this.getUuid()));
106   - event.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  106 + event.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
107 107 event.setTenantId(new TenantId(toUUID(tenantId)));
108 108 event.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, toUUID(entityId)));
109 109 event.setBody(body);
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -101,7 +101,7 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT
101 101 @Override
102 102 public RuleChain toData() {
103 103 RuleChain ruleChain = new RuleChain(new RuleChainId(this.getUuid()));
104   - ruleChain.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  104 + ruleChain.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
105 105 ruleChain.setTenantId(new TenantId(toUUID(tenantId)));
106 106 ruleChain.setName(name);
107 107 if (firstRuleNodeId != null) {
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -95,7 +95,7 @@ public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTex
95 95 @Override
96 96 public RuleNode toData() {
97 97 RuleNode ruleNode = new RuleNode(new RuleNodeId(this.getUuid()));
98   - ruleNode.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  98 + ruleNode.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
99 99 if (ruleChainId != null) {
100 100 ruleNode.setRuleChainId(new RuleChainId(toUUID(ruleChainId)));
101 101 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -122,7 +122,7 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT
122 122 @Override
123 123 public Tenant toData() {
124 124 Tenant tenant = new Tenant(new TenantId(this.getUuid()));
125   - tenant.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  125 + tenant.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
126 126 tenant.setTitle(title);
127 127 tenant.setRegion(region);
128 128 tenant.setCountry(country);
... ... @@ -140,4 +140,4 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT
140 140 }
141 141
142 142
143   -}
\ No newline at end of file
  143 +}
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import lombok.Data;
20 20 import lombok.EqualsAndHashCode;
21 21 import org.thingsboard.server.common.data.id.UserCredentialsId;
... ... @@ -70,7 +70,7 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials>
70 70 @Override
71 71 public UserCredentials toData() {
72 72 UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(this.getUuid()));
73   - userCredentials.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  73 + userCredentials.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
74 74 if (userId != null) {
75 75 userCredentials.setUserId(new UserId(toUUID(userId)));
76 76 }
... ... @@ -81,4 +81,4 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials>
81 81 return userCredentials;
82 82 }
83 83
84   -}
\ No newline at end of file
  84 +}
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -109,7 +109,7 @@ public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity<
109 109 @Override
110 110 public User toData() {
111 111 User user = new User(new UserId(this.getUuid()));
112   - user.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  112 + user.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
113 113 user.setAuthority(authority);
114 114 if (tenantId != null) {
115 115 user.setTenantId(new TenantId(fromString(tenantId)));
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
... ... @@ -76,7 +76,7 @@ public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implement
76 76 @Override
77 77 public WidgetType toData() {
78 78 WidgetType widgetType = new WidgetType(new WidgetTypeId(this.getUuid()));
79   - widgetType.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  79 + widgetType.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
80 80 if (tenantId != null) {
81 81 widgetType.setTenantId(new TenantId(toUUID(tenantId)));
82 82 }
... ...
... ... @@ -16,7 +16,7 @@
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18 18
19   -import com.datastax.driver.core.utils.UUIDs;
  19 +import com.datastax.oss.driver.api.core.uuid.Uuids;
20 20 import lombok.Data;
21 21 import lombok.EqualsAndHashCode;
22 22 import org.thingsboard.server.common.data.UUIDConverter;
... ... @@ -77,7 +77,7 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> impl
77 77 @Override
78 78 public WidgetsBundle toData() {
79 79 WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(UUIDConverter.fromString(id)));
80   - widgetsBundle.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id)));
  80 + widgetsBundle.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id)));
81 81 if (tenantId != null) {
82 82 widgetsBundle.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
83 83 }
... ...
1   -/**
2   - * Copyright © 2016-2020 The Thingsboard Authors
3   - *
4   - * Licensed under the Apache License, Version 2.0 (the "License");
5   - * you may not use this file except in compliance with the License.
6   - * You may obtain a copy of the License at
7   - *
8   - * http://www.apache.org/licenses/LICENSE-2.0
9   - *
10   - * Unless required by applicable law or agreed to in writing, software
11   - * distributed under the License is distributed on an "AS IS" BASIS,
12   - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   - * See the License for the specific language governing permissions and
14   - * limitations under the License.
15   - */
16   -package org.thingsboard.server.dao.model.wrapper;
17   -
18   -
19   -import com.datastax.driver.core.ResultSet;
20   -
21   -public class EntityResultSet<T> {
22   -
23   - private ResultSet resultSet;
24   - private T entity;
25   -
26   - public EntityResultSet(ResultSet resultSet, T entity) {
27   - this.resultSet = resultSet;
28   - this.entity = entity;
29   - }
30   -
31   - public T getEntity() {
32   - return entity;
33   - }
34   -
35   - public boolean wasApplied() {
36   - return resultSet.wasApplied();
37   - }
38   -}
... ... @@ -15,9 +15,11 @@
15 15 */
16 16 package org.thingsboard.server.dao.nosql;
17 17
18   -import com.datastax.driver.core.ResultSet;
19   -import com.datastax.driver.core.ResultSetFuture;
  18 +import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
  19 +import com.datastax.oss.driver.api.core.cql.Row;
20 20 import com.google.common.base.Function;
  21 +import com.google.common.collect.Lists;
  22 +import com.google.common.util.concurrent.AsyncFunction;
21 23 import com.google.common.util.concurrent.Futures;
22 24 import com.google.common.util.concurrent.ListenableFuture;
23 25 import org.thingsboard.common.util.ThingsBoardThreadFactory;
... ... @@ -25,8 +27,11 @@ import org.thingsboard.common.util.ThingsBoardThreadFactory;
25 27 import javax.annotation.Nullable;
26 28 import javax.annotation.PostConstruct;
27 29 import javax.annotation.PreDestroy;
  30 +import java.util.ArrayList;
  31 +import java.util.List;
28 32 import java.util.concurrent.ExecutorService;
29 33 import java.util.concurrent.Executors;
  34 +import java.util.stream.Collectors;
30 35
31 36 /**
32 37 * Created by ashvayka on 21.02.17.
... ... @@ -47,13 +52,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 57 @Nullable
53 58 @Override
54   - public T apply(@Nullable ResultSet input) {
  59 + public T apply(@Nullable AsyncResultSet input) {
55 60 return transformer.apply(input);
56 61 }
57 62 }, readResultsProcessingExecutor);
58 63 }
  64 +
  65 + protected <T> ListenableFuture<T> getFutureAsync(TbResultSetFuture future, com.google.common.util.concurrent.AsyncFunction<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 15 */
16 16 package org.thingsboard.server.dao.nosql;
17 17
18   -import com.datastax.driver.core.*;
19   -import com.datastax.driver.core.exceptions.CodecNotFoundException;
  18 +import com.datastax.oss.driver.api.core.ConsistencyLevel;
  19 +import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
  20 +import com.datastax.oss.driver.api.core.cql.BoundStatement;
  21 +import com.datastax.oss.driver.api.core.cql.PreparedStatement;
  22 +import com.datastax.oss.driver.api.core.cql.Statement;
20 23 import lombok.extern.slf4j.Slf4j;
21 24 import org.springframework.beans.factory.annotation.Autowired;
22 25 import org.springframework.beans.factory.annotation.Qualifier;
23 26 import org.thingsboard.server.common.data.id.TenantId;
24 27 import org.thingsboard.server.dao.cassandra.CassandraCluster;
25   -import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec;
26   -import org.thingsboard.server.dao.model.type.EntityTypeCodec;
27   -import org.thingsboard.server.dao.model.type.JsonCodec;
  28 +import org.thingsboard.server.dao.cassandra.guava.GuavaSession;
28 29
29 30 import java.util.concurrent.ConcurrentHashMap;
30 31 import java.util.concurrent.ConcurrentMap;
... ... @@ -41,20 +42,16 @@ public abstract class CassandraAbstractDao {
41 42 @Autowired
42 43 private CassandraBufferedRateExecutor rateLimiter;
43 44
44   - private Session session;
  45 + private GuavaSession session;
45 46
46 47 private ConsistencyLevel defaultReadLevel;
47 48 private ConsistencyLevel defaultWriteLevel;
48 49
49   - private Session getSession() {
  50 + private GuavaSession getSession() {
50 51 if (session == null) {
51 52 session = cluster.getSession();
52 53 defaultReadLevel = cluster.getDefaultReadConsistencyLevel();
53 54 defaultWriteLevel = cluster.getDefaultWriteConsistencyLevel();
54   - CodecRegistry registry = session.getCluster().getConfiguration().getCodecRegistry();
55   - registerCodecIfNotFound(registry, new JsonCodec());
56   - registerCodecIfNotFound(registry, new ComponentLifecycleStateCodec());
57   - registerCodecIfNotFound(registry, new EntityTypeCodec());
58 55 }
59 56 return session;
60 57 }
... ... @@ -63,38 +60,30 @@ public abstract class CassandraAbstractDao {
63 60 return preparedStatementMap.computeIfAbsent(query, i -> getSession().prepare(i));
64 61 }
65 62
66   - private void registerCodecIfNotFound(CodecRegistry registry, TypeCodec<?> codec) {
67   - try {
68   - registry.codecFor(codec.getCqlType(), codec.getJavaType());
69   - } catch (CodecNotFoundException e) {
70   - registry.register(codec);
71   - }
72   - }
73   -
74   - protected ResultSet executeRead(TenantId tenantId, Statement statement) {
  63 + protected AsyncResultSet executeRead(TenantId tenantId, Statement statement) {
75 64 return execute(tenantId, statement, defaultReadLevel);
76 65 }
77 66
78   - protected ResultSet executeWrite(TenantId tenantId, Statement statement) {
  67 + protected AsyncResultSet executeWrite(TenantId tenantId, Statement statement) {
79 68 return execute(tenantId, statement, defaultWriteLevel);
80 69 }
81 70
82   - protected ResultSetFuture executeAsyncRead(TenantId tenantId, Statement statement) {
  71 + protected TbResultSetFuture executeAsyncRead(TenantId tenantId, Statement statement) {
83 72 return executeAsync(tenantId, statement, defaultReadLevel);
84 73 }
85 74
86   - protected ResultSetFuture executeAsyncWrite(TenantId tenantId, Statement statement) {
  75 + protected TbResultSetFuture executeAsyncWrite(TenantId tenantId, Statement statement) {
87 76 return executeAsync(tenantId, statement, defaultWriteLevel);
88 77 }
89 78
90   - private ResultSet execute(TenantId tenantId, Statement statement, ConsistencyLevel level) {
  79 + private AsyncResultSet execute(TenantId tenantId, Statement statement, ConsistencyLevel level) {
91 80 if (log.isDebugEnabled()) {
92 81 log.debug("Execute cassandra statement {}", statementToString(statement));
93 82 }
94 83 return executeAsync(tenantId, statement, level).getUninterruptibly();
95 84 }
96 85
97   - private ResultSetFuture executeAsync(TenantId tenantId, Statement statement, ConsistencyLevel level) {
  86 + private TbResultSetFuture executeAsync(TenantId tenantId, Statement statement, ConsistencyLevel level) {
98 87 if (log.isDebugEnabled()) {
99 88 log.debug("Execute cassandra async statement {}", statementToString(statement));
100 89 }
... ... @@ -106,9 +95,9 @@ public abstract class CassandraAbstractDao {
106 95
107 96 private static String statementToString(Statement statement) {
108 97 if (statement instanceof BoundStatement) {
109   - return ((BoundStatement) statement).preparedStatement().getQueryString();
  98 + return ((BoundStatement) statement).getPreparedStatement().getQuery();
110 99 } else {
111 100 return statement.toString();
112 101 }
113 102 }
114   -}
\ No newline at end of file
  103 +}
... ...
... ... @@ -15,8 +15,8 @@
15 15 */
16 16 package org.thingsboard.server.dao.nosql;
17 17
18   -import com.datastax.driver.core.ResultSet;
19   -import com.datastax.driver.core.ResultSetFuture;
  18 +import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
  19 +import com.google.common.util.concurrent.ListenableFuture;
20 20 import com.google.common.util.concurrent.SettableFuture;
21 21 import lombok.extern.slf4j.Slf4j;
22 22 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -39,7 +39,7 @@ import java.util.Map;
39 39 @Component
40 40 @Slf4j
41 41 @NoSqlAnyDao
42   -public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor<CassandraStatementTask, ResultSetFuture, ResultSet> {
  42 +public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor<CassandraStatementTask, TbResultSetFuture, AsyncResultSet> {
43 43
44 44 @Autowired
45 45 private EntityService entityService;
... ... @@ -107,17 +107,17 @@ public class CassandraBufferedRateExecutor extends AbstractBufferedRateExecutor<
107 107 }
108 108
109 109 @Override
110   - protected SettableFuture<ResultSet> create() {
  110 + protected SettableFuture<AsyncResultSet> create() {
111 111 return SettableFuture.create();
112 112 }
113 113
114 114 @Override
115   - protected ResultSetFuture wrap(CassandraStatementTask task, SettableFuture<ResultSet> future) {
  115 + protected TbResultSetFuture wrap(CassandraStatementTask task, SettableFuture<AsyncResultSet> future) {
116 116 return new TbResultSetFuture(future);
117 117 }
118 118
119 119 @Override
120   - protected ResultSetFuture execute(AsyncTaskContext<CassandraStatementTask, ResultSet> taskCtx) {
  120 + protected ListenableFuture<AsyncResultSet> execute(AsyncTaskContext<CassandraStatementTask, AsyncResultSet> taskCtx) {
121 121 CassandraStatementTask task = taskCtx.getTask();
122 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 15 */
16 16 package org.thingsboard.server.dao.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.google.common.collect.Lists;
20 20 import com.google.common.util.concurrent.ListenableFuture;
21 21 import lombok.extern.slf4j.Slf4j;
... ... @@ -59,7 +59,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
59 59 setSearchText(entity);
60 60 log.debug("Saving entity {}", entity);
61 61 if (entity.getUuid() == null) {
62   - entity.setUuid(UUIDs.timeBased());
  62 + entity.setUuid(Uuids.timeBased());
63 63 }
64 64 entity = getCrudRepository().save(entity);
65 65 return DaoUtil.getData(entity);
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.springframework.data.jpa.domain.Specification;
20 20 import org.thingsboard.server.common.data.UUIDConverter;
21 21 import org.thingsboard.server.common.data.page.TimePageLink;
... ... @@ -40,12 +40,12 @@ public abstract class JpaAbstractSearchTimeDao<E extends BaseEntity<D>, D> exten
40 40 public Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
41 41 List<Predicate> predicates = new ArrayList<>();
42 42 if (pageLink.getStartTime() != null) {
43   - UUID startOf = UUIDs.startOf(pageLink.getStartTime());
  43 + UUID startOf = Uuids.startOf(pageLink.getStartTime());
44 44 Predicate lowerBound = criteriaBuilder.greaterThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(startOf));
45 45 predicates.add(lowerBound);
46 46 }
47 47 if (pageLink.getEndTime() != null) {
48   - UUID endOf = UUIDs.endOf(pageLink.getEndTime());
  48 + UUID endOf = Uuids.endOf(pageLink.getEndTime());
49 49 Predicate upperBound = criteriaBuilder.lessThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(endOf));
50 50 predicates.add(upperBound);
51 51 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.component;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.springframework.beans.factory.annotation.Autowired;
20 20 import org.springframework.data.repository.CrudRepository;
21 21 import org.springframework.stereotype.Component;
... ... @@ -64,7 +64,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp
64 64 @Override
65 65 public Optional<ComponentDescriptor> saveIfNotExist(TenantId tenantId, ComponentDescriptor component) {
66 66 if (component.getId() == null) {
67   - component.setId(new ComponentDescriptorId(UUIDs.timeBased()));
  67 + component.setId(new ComponentDescriptorId(Uuids.timeBased()));
68 68 }
69 69 if (!componentDescriptorRepository.existsById(UUIDConverter.fromTimeUUID(component.getId().getId()))) {
70 70 ComponentDescriptorEntity componentDescriptorEntity = new ComponentDescriptorEntity(component);
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.event;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.google.common.util.concurrent.ListenableFuture;
20 20 import lombok.extern.slf4j.Slf4j;
21 21 import org.apache.commons.lang3.StringUtils;
... ... @@ -75,7 +75,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
75 75 public Event save(TenantId tenantId, Event event) {
76 76 log.debug("Save event [{}] ", event);
77 77 if (event.getId() == null) {
78   - event.setId(new EventId(UUIDs.timeBased()));
  78 + event.setId(new EventId(Uuids.timeBased()));
79 79 }
80 80 if (StringUtils.isEmpty(event.getUid())) {
81 81 event.setUid(event.getId().toString());
... ... @@ -87,7 +87,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
87 87 public ListenableFuture<Event> saveAsync(Event event) {
88 88 log.debug("Save event [{}] ", event);
89 89 if (event.getId() == null) {
90   - event.setId(new EventId(UUIDs.timeBased()));
  90 + event.setId(new EventId(Uuids.timeBased()));
91 91 }
92 92 if (StringUtils.isEmpty(event.getUid())) {
93 93 event.setUid(event.getId().toString());
... ... @@ -152,7 +152,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
152 152 entity.setTenantId(UUIDConverter.fromTimeUUID(systemTenantId));
153 153 }
154 154 if (entity.getUuid() == null) {
155   - entity.setUuid(UUIDs.timeBased());
  155 + entity.setUuid(Uuids.timeBased());
156 156 }
157 157 if (StringUtils.isEmpty(entity.getEventUid())) {
158 158 entity.setEventUid(entity.getUuid().toString());
... ...
... ... @@ -15,8 +15,10 @@
15 15 */
16 16 package org.thingsboard.server.dao.timeseries;
17 17
18   -import com.datastax.driver.core.ResultSet;
19   -import com.datastax.driver.core.Row;
  18 +import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
  19 +import com.datastax.oss.driver.api.core.cql.Row;
  20 +import com.google.common.util.concurrent.Futures;
  21 +import com.google.common.util.concurrent.ListenableFuture;
20 22 import lombok.extern.slf4j.Slf4j;
21 23 import org.thingsboard.server.common.data.kv.Aggregation;
22 24 import org.thingsboard.server.common.data.kv.BasicTsKvEntry;
... ... @@ -27,16 +29,19 @@ import org.thingsboard.server.common.data.kv.JsonDataEntry;
27 29 import org.thingsboard.server.common.data.kv.LongDataEntry;
28 30 import org.thingsboard.server.common.data.kv.StringDataEntry;
29 31 import org.thingsboard.server.common.data.kv.TsKvEntry;
  32 +import org.thingsboard.server.dao.nosql.ResultSetUtils;
30 33
31 34 import javax.annotation.Nullable;
32 35 import java.util.List;
33 36 import java.util.Optional;
  37 +import java.util.concurrent.Executor;
  38 +import java.util.stream.Collectors;
34 39
35 40 /**
36 41 * Created by ashvayka on 20.02.17.
37 42 */
38 43 @Slf4j
39   -public class AggregatePartitionsFunction implements com.google.common.base.Function<List<ResultSet>, Optional<TsKvEntry>> {
  44 +public class AggregatePartitionsFunction implements com.google.common.util.concurrent.AsyncFunction<List<AsyncResultSet>, Optional<TsKvEntry>> {
40 45
41 46 private static final int LONG_CNT_POS = 0;
42 47 private static final int DOUBLE_CNT_POS = 1;
... ... @@ -52,33 +57,39 @@ public class AggregatePartitionsFunction implements com.google.common.base.Funct
52 57 private final Aggregation aggregation;
53 58 private final String key;
54 59 private final long ts;
  60 + private final Executor executor;
55 61
56   - public AggregatePartitionsFunction(Aggregation aggregation, String key, long ts) {
  62 + public AggregatePartitionsFunction(Aggregation aggregation, String key, long ts, Executor executor) {
57 63 this.aggregation = aggregation;
58 64 this.key = key;
59 65 this.ts = ts;
  66 + this.executor = executor;
60 67 }
61 68
62 69 @Override
63   - public Optional<TsKvEntry> apply(@Nullable List<ResultSet> rsList) {
64   - try {
65   - log.trace("[{}][{}][{}] Going to aggregate data", key, ts, aggregation);
66   - if (rsList == null || rsList.isEmpty()) {
67   - return Optional.empty();
68   - }
69   -
70   - AggregationResult aggResult = new AggregationResult();
71   -
72   - for (ResultSet rs : rsList) {
73   - for (Row row : rs.all()) {
74   - processResultSetRow(row, aggResult);
  70 + public ListenableFuture<Optional<TsKvEntry>> apply(@Nullable List<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 95 private void processResultSetRow(Row row, AggregationResult aggResult) {
... ... @@ -181,7 +192,7 @@ public class AggregatePartitionsFunction implements com.google.common.base.Funct
181 192
182 193 private Boolean getBooleanValue(Row row) {
183 194 if (aggregation == Aggregation.MIN || aggregation == Aggregation.MAX) {
184   - return row.getBool(BOOL_POS);
  195 + return row.getBoolean(BOOL_POS);
185 196 } else {
186 197 return null; //NOSONAR, null is used for further comparison
187 198 }
... ...
... ... @@ -15,14 +15,14 @@
15 15 */
16 16 package org.thingsboard.server.dao.timeseries;
17 17
18   -import com.datastax.driver.core.BoundStatement;
19   -import com.datastax.driver.core.PreparedStatement;
20   -import com.datastax.driver.core.ResultSet;
21   -import com.datastax.driver.core.ResultSetFuture;
22   -import com.datastax.driver.core.Row;
23   -import com.datastax.driver.core.Statement;
24   -import com.datastax.driver.core.querybuilder.QueryBuilder;
25   -import com.datastax.driver.core.querybuilder.Select;
  18 +import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
  19 +import com.datastax.oss.driver.api.core.cql.BoundStatement;
  20 +import com.datastax.oss.driver.api.core.cql.BoundStatementBuilder;
  21 +import com.datastax.oss.driver.api.core.cql.PreparedStatement;
  22 +import com.datastax.oss.driver.api.core.cql.Row;
  23 +import com.datastax.oss.driver.api.core.cql.Statement;
  24 +import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
  25 +import com.datastax.oss.driver.api.querybuilder.select.Select;
26 26 import com.google.common.base.Function;
27 27 import com.google.common.util.concurrent.AsyncFunction;
28 28 import com.google.common.util.concurrent.FutureCallback;
... ... @@ -52,6 +52,7 @@ import org.thingsboard.server.common.data.kv.StringDataEntry;
52 52 import org.thingsboard.server.common.data.kv.TsKvEntry;
53 53 import org.thingsboard.server.dao.model.ModelConstants;
54 54 import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao;
  55 +import org.thingsboard.server.dao.nosql.TbResultSetFuture;
55 56 import org.thingsboard.server.dao.util.NoSqlTsDao;
56 57
57 58 import javax.annotation.Nullable;
... ... @@ -69,7 +70,7 @@ import java.util.Optional;
69 70 import java.util.concurrent.ExecutionException;
70 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 76 * @author Andrew Shvayka
... ... @@ -189,8 +190,8 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
189 190 if (isFixedPartitioning()) { //no need to fetch partitions from DB
190 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 197 private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(TenantId tenantId, EntityId entityId, ReadTsKvQuery query) {
... ... @@ -225,20 +226,41 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
225 226 resultFuture.set(cursor.getData());
226 227 } else {
227 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 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 266 @Override
... ... @@ -256,31 +278,35 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
256 278 final long endTs = query.getEndTs();
257 279 final long ts = startTs + (endTs - startTs) / 2;
258 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 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 296 return partitions -> {
272 297 try {
273 298 PreparedStatement proto = getFetchStmt(aggregation, DESC_ORDER);
274   - List<ResultSetFuture> futures = new ArrayList<>(partitions.size());
  299 + List<TbResultSetFuture> futures = new ArrayList<>(partitions.size());
275 300 for (Long partition : partitions) {
276 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 310 log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId());
285 311 futures.add(executeAsyncRead(tenantId, stmt));
286 312 }
... ... @@ -294,21 +320,23 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
294 320
295 321 @Override
296 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 328 log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId());
302 329 return getFuture(executeAsyncRead(tenantId, stmt), rs -> convertResultToTsKvEntry(key, rs.one()));
303 330 }
304 331
305 332 @Override
306 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 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 342 @Override
... ... @@ -320,16 +348,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
320 348 if (setNullValuesEnabled) {
321 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 354 .setString(2, tsKvEntry.getKey())
327 355 .setLong(3, partition)
328 356 .setLong(4, tsKvEntry.getTs());
329   - addValue(tsKvEntry, stmt, 5);
  357 + addValue(tsKvEntry, stmtBuilder, 5);
330 358 if (ttl > 0) {
331   - stmt.setInt(6, (int) ttl);
  359 + stmtBuilder.setInt(6, (int) ttl);
332 360 }
  361 + BoundStatement stmt = stmtBuilder.build();
333 362 futures.add(getFuture(executeAsyncWrite(tenantId, stmt), rs -> null));
334 363 return Futures.transform(Futures.allAsList(futures), result -> null, MoreExecutors.directExecutor());
335 364 }
... ... @@ -370,16 +399,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
370 399 }
371 400
372 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 405 .setString(2, tsKvEntry.getKey())
377 406 .setLong(3, partition)
378 407 .setLong(4, tsKvEntry.getTs());
379   - stmt.setToNull(getColumnName(type));
  408 + stmtBuilder.setToNull(getColumnName(type));
380 409 if (ttl > 0) {
381   - stmt.setInt(6, (int) ttl);
  410 + stmtBuilder.setInt(6, (int) ttl);
382 411 }
  412 + BoundStatement stmt = stmtBuilder.build();
383 413 return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null);
384 414 }
385 415
... ... @@ -391,14 +421,15 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
391 421 ttl = computeTtl(ttl);
392 422 long partition = toPartitionTs(tsKvEntryTs);
393 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 427 .setLong(2, partition)
398 428 .setString(3, key);
399 429 if (ttl > 0) {
400   - stmt.setInt(4, (int) ttl);
  430 + stmtBuilder.setInt(4, (int) ttl);
401 431 }
  432 + BoundStatement stmt = stmtBuilder.build();
402 433 return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null);
403 434 }
404 435
... ... @@ -415,9 +446,9 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
415 446
416 447 @Override
417 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 452 .setString(2, tsKvEntry.getKey())
422 453 .setLong(3, tsKvEntry.getTs())
423 454 .set(4, tsKvEntry.getBooleanValue().orElse(null), Boolean.class)
... ... @@ -426,10 +457,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
426 457 .set(7, tsKvEntry.getDoubleValue().orElse(null), Double.class);
427 458 Optional<String> jsonV = tsKvEntry.getJsonValue();
428 459 if (jsonV.isPresent()) {
429   - stmt.setString(8, tsKvEntry.getJsonValue().get());
  460 + stmtBuilder.setString(8, tsKvEntry.getJsonValue().get());
430 461 } else {
431   - stmt.setToNull(8);
  462 + stmtBuilder.setToNull(8);
432 463 }
  464 + BoundStatement stmt = stmtBuilder.build();
433 465
434 466 return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null);
435 467 }
... ... @@ -439,10 +471,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
439 471 long minPartition = toPartitionTs(query.getStartTs());
440 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 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 479 Futures.addCallback(partitionsListFuture, new FutureCallback<List<Long>>() {
448 480 @Override
... ... @@ -464,17 +496,19 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
464 496 resultFuture.set(null);
465 497 } else {
466 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 510 @Override
477   - public void onSuccess(@Nullable ResultSet result) {
  511 + public void onSuccess(@Nullable AsyncResultSet result) {
478 512 deleteAsync(tenantId, cursor, resultFuture);
479 513 }
480 514
... ... @@ -568,10 +602,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
568 602 }
569 603
570 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 609 log.debug("Remove request: {}", delete.toString());
576 610 return getFuture(executeAsyncWrite(tenantId, delete), rs -> null);
577 611 }
... ... @@ -583,10 +617,10 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
583 617 if (minPartition == maxPartition) {
584 618 return Futures.immediateFuture(null);
585 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 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 625 Futures.addCallback(partitionsListFuture, new FutureCallback<List<Long>>() {
592 626 @Override
... ... @@ -617,15 +651,17 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
617 651 resultFuture.set(null);
618 652 } else {
619 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 663 @Override
628   - public void onSuccess(@Nullable ResultSet result) {
  664 + public void onSuccess(@Nullable AsyncResultSet result) {
629 665 deletePartitionAsync(tenantId, cursor, resultFuture);
630 666 }
631 667
... ... @@ -648,6 +684,11 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
648 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 692 private List<TsKvEntry> convertResultToTsKvEntryList(List<Row> rows) {
652 693 List<TsKvEntry> entries = new ArrayList<>(rows.size());
653 694 if (!rows.isEmpty()) {
... ... @@ -706,12 +747,14 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
706 747 * Select existing partitions from the table
707 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 760 private PreparedStatement getSaveStmt(DataType dataType) {
... ... @@ -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 929 switch (kvEntry.getDataType()) {
887 930 case BOOLEAN:
888 931 Optional<Boolean> booleanValue = kvEntry.getBooleanValue();
889   - booleanValue.ifPresent(b -> stmt.setBool(column, b));
  932 + booleanValue.ifPresent(b -> stmt.setBoolean(column, b));
890 933 break;
891 934 case STRING:
892 935 Optional<String> stringValue = kvEntry.getStrValue();
... ...
... ... @@ -15,7 +15,14 @@
15 15 */
16 16 package org.thingsboard.server.dao.util;
17 17
18   -import com.datastax.driver.core.*;
  18 +import com.datastax.oss.driver.api.core.ProtocolVersion;
  19 +import com.datastax.oss.driver.api.core.cql.BoundStatement;
  20 +import com.datastax.oss.driver.api.core.cql.ColumnDefinition;
  21 +import com.datastax.oss.driver.api.core.cql.ColumnDefinitions;
  22 +import com.datastax.oss.driver.api.core.cql.PreparedStatement;
  23 +import com.datastax.oss.driver.api.core.type.DataType;
  24 +import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
  25 +import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry;
19 26 import com.google.common.util.concurrent.FutureCallback;
20 27 import com.google.common.util.concurrent.Futures;
21 28 import com.google.common.util.concurrent.ListenableFuture;
... ... @@ -212,7 +219,7 @@ public abstract class AbstractBufferedRateExecutor<T extends AsyncTask, F extend
212 219 CassandraStatementTask cassStmtTask = (CassandraStatementTask) taskCtx.getTask();
213 220 if (cassStmtTask.getStatement() instanceof BoundStatement) {
214 221 BoundStatement stmt = (BoundStatement) cassStmtTask.getStatement();
215   - String query = stmt.preparedStatement().getQueryString();
  222 + String query = stmt.getPreparedStatement().getQuery();
216 223 try {
217 224 query = toStringWithValues(stmt, ProtocolVersion.V5);
218 225 } catch (Exception e) {
... ... @@ -225,16 +232,16 @@ public abstract class AbstractBufferedRateExecutor<T extends AsyncTask, F extend
225 232 }
226 233
227 234 private static String toStringWithValues(BoundStatement boundStatement, ProtocolVersion protocolVersion) {
228   - CodecRegistry codecRegistry = boundStatement.preparedStatement().getCodecRegistry();
229   - PreparedStatement preparedStatement = boundStatement.preparedStatement();
230   - String query = preparedStatement.getQueryString();
231   - ColumnDefinitions defs = preparedStatement.getVariables();
  235 + CodecRegistry codecRegistry = boundStatement.codecRegistry();
  236 + PreparedStatement preparedStatement = boundStatement.getPreparedStatement();
  237 + String query = preparedStatement.getQuery();
  238 + ColumnDefinitions defs = preparedStatement.getVariableDefinitions();
232 239 int index = 0;
233   - for (ColumnDefinitions.Definition def : defs) {
  240 + for (ColumnDefinition def : defs) {
234 241 DataType type = def.getType();
235 242 TypeCodec<Object> codec = codecRegistry.codecFor(type);
236 243 if (boundStatement.getBytesUnsafe(index) != null) {
237   - Object value = codec.deserialize(boundStatement.getBytesUnsafe(index), protocolVersion);
  244 + Object value = codec.decode(boundStatement.getBytesUnsafe(index), protocolVersion);
238 245 String replacement = Matcher.quoteReplacement(codec.format(value));
239 246 query = query.replaceFirst("\\?", replacement);
240 247 }
... ...
... ... @@ -15,8 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao;
17 17
18   -import com.datastax.driver.core.Cluster;
19   -import com.datastax.driver.core.Session;
  18 +import com.datastax.oss.driver.api.core.CqlSession;
20 19 import org.cassandraunit.BaseCassandraUnit;
21 20 import org.cassandraunit.CQLDataLoader;
22 21 import org.cassandraunit.dataset.CQLDataSet;
... ... @@ -27,8 +26,7 @@ import java.util.List;
27 26 public class CustomCassandraCQLUnit extends BaseCassandraUnit {
28 27 protected List<CQLDataSet> dataSets;
29 28
30   - public Session session;
31   - public Cluster cluster;
  29 + public CqlSession session;
32 30
33 31 public CustomCassandraCQLUnit(List<CQLDataSet> dataSets) {
34 32 this.dataSets = dataSets;
... ... @@ -65,11 +63,7 @@ public class CustomCassandraCQLUnit extends BaseCassandraUnit {
65 63
66 64 @Override
67 65 protected void load() {
68   - String hostIp = EmbeddedCassandraServerHelper.getHost();
69   - int port = EmbeddedCassandraServerHelper.getNativeTransportPort();
70   - cluster = new Cluster.Builder().addContactPoints(hostIp).withPort(port).withSocketOptions(getSocketOptions())
71   - .build();
72   - session = cluster.connect();
  66 + session = EmbeddedCassandraServerHelper.getSession();
73 67 CQLDataLoader dataLoader = new CQLDataLoader(session);
74 68 dataSets.forEach(dataLoader::load);
75 69 session = dataLoader.getSession();
... ... @@ -79,20 +73,16 @@ public class CustomCassandraCQLUnit extends BaseCassandraUnit {
79 73 @Override
80 74 protected void after() {
81 75 super.after();
82   - try (Cluster c = cluster; Session s = session) {
  76 + try (CqlSession s = session) {
83 77 session = null;
84   - cluster = null;
85 78 }
86 79 System.setSecurityManager(null);
87 80 }
88 81
89 82 // Getters for those who do not like to directly access fields
90 83
91   - public Session getSession() {
  84 + public CqlSession getSession() {
92 85 return session;
93 86 }
94 87
95   - public Cluster getCluster() {
96   - return cluster;
97   - }
98 88 }
... ...
1   -/**
2   - * Copyright © 2016-2020 The Thingsboard Authors
3   - *
4   - * Licensed under the Apache License, Version 2.0 (the "License");
5   - * you may not use this file except in compliance with the License.
6   - * You may obtain a copy of the License at
7   - *
8   - * http://www.apache.org/licenses/LICENSE-2.0
9   - *
10   - * Unless required by applicable law or agreed to in writing, software
11   - * distributed under the License is distributed on an "AS IS" BASIS,
12   - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   - * See the License for the specific language governing permissions and
14   - * limitations under the License.
15   - */
16   -package org.thingsboard.server.dao.nosql;
17   -
18   -import com.datastax.driver.core.ProtocolVersion;
19   -import com.datastax.driver.core.ResultSet;
20   -import com.datastax.driver.core.ResultSetFuture;
21   -import com.datastax.driver.core.Row;
22   -import com.datastax.driver.core.Session;
23   -import com.datastax.driver.core.Statement;
24   -import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
25   -import com.google.common.util.concurrent.Futures;
26   -import com.google.common.util.concurrent.ListenableFuture;
27   -import com.google.common.util.concurrent.MoreExecutors;
28   -import org.junit.Test;
29   -import org.junit.runner.RunWith;
30   -import org.mockito.Mock;
31   -import org.mockito.Mockito;
32   -import org.mockito.runners.MockitoJUnitRunner;
33   -import org.mockito.stubbing.Answer;
34   -import org.thingsboard.server.dao.exception.BufferLimitException;
35   -import org.thingsboard.server.dao.util.AsyncRateLimiter;
36   -
37   -import java.util.concurrent.CountDownLatch;
38   -import java.util.concurrent.ExecutionException;
39   -import java.util.concurrent.Executors;
40   -import java.util.concurrent.TimeoutException;
41   -
42   -import static org.junit.Assert.assertSame;
43   -import static org.junit.Assert.assertTrue;
44   -import static org.junit.Assert.fail;
45   -import static org.mockito.Mockito.times;
46   -import static org.mockito.Mockito.verify;
47   -import static org.mockito.Mockito.verifyNoMoreInteractions;
48   -import static org.mockito.Mockito.when;
49   -
50   -@RunWith(MockitoJUnitRunner.class)
51   -public class RateLimitedResultSetFutureTest {
52   -
53   - private RateLimitedResultSetFuture resultSetFuture;
54   -
55   - @Mock
56   - private AsyncRateLimiter rateLimiter;
57   - @Mock
58   - private Session session;
59   - @Mock
60   - private Statement statement;
61   - @Mock
62   - private ResultSetFuture realFuture;
63   - @Mock
64   - private ResultSet rows;
65   - @Mock
66   - private Row row;
67   -
68   - @Test
69   - public void doNotReleasePermissionIfRateLimitFutureFailed() throws InterruptedException {
70   - when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFailedFuture(new BufferLimitException()));
71   - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
72   - Thread.sleep(1000L);
73   - verify(rateLimiter).acquireAsync();
74   - try {
75   - assertTrue(resultSetFuture.isDone());
76   - fail();
77   - } catch (Exception e) {
78   - assertTrue(e instanceof IllegalStateException);
79   - Throwable actualCause = e.getCause();
80   - assertTrue(actualCause instanceof ExecutionException);
81   - }
82   - verifyNoMoreInteractions(session, rateLimiter, statement);
83   -
84   - }
85   -
86   - @Test
87   - public void getUninterruptiblyDelegateToCassandra() throws InterruptedException, ExecutionException {
88   - when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFuture(null));
89   - when(session.executeAsync(statement)).thenReturn(realFuture);
90   - Mockito.doAnswer((Answer<Void>) invocation -> {
91   - Object[] args = invocation.getArguments();
92   - Runnable task = (Runnable) args[0];
93   - task.run();
94   - return null;
95   - }).when(realFuture).addListener(Mockito.any(), Mockito.any());
96   -
97   - when(realFuture.getUninterruptibly()).thenReturn(rows);
98   -
99   - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
100   - ResultSet actual = resultSetFuture.getUninterruptibly();
101   - assertSame(rows, actual);
102   - verify(rateLimiter, times(1)).acquireAsync();
103   - verify(rateLimiter, times(1)).release();
104   - }
105   -
106   - @Test
107   - public void addListenerAllowsFutureTransformation() throws InterruptedException, ExecutionException {
108   - when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFuture(null));
109   - when(session.executeAsync(statement)).thenReturn(realFuture);
110   - Mockito.doAnswer((Answer<Void>) invocation -> {
111   - Object[] args = invocation.getArguments();
112   - Runnable task = (Runnable) args[0];
113   - task.run();
114   - return null;
115   - }).when(realFuture).addListener(Mockito.any(), Mockito.any());
116   -
117   - when(realFuture.get()).thenReturn(rows);
118   - when(rows.one()).thenReturn(row);
119   -
120   - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
121   -
122   - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor());
123   - Row actualRow = transform.get();
124   -
125   - assertSame(row, actualRow);
126   - verify(rateLimiter, times(1)).acquireAsync();
127   - verify(rateLimiter, times(1)).release();
128   - }
129   -
130   - @Test
131   - public void immidiateCassandraExceptionReturnsPermit() throws InterruptedException, ExecutionException {
132   - when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFuture(null));
133   - when(session.executeAsync(statement)).thenThrow(new UnsupportedFeatureException(ProtocolVersion.V3, "hjg"));
134   - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
135   - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor());
136   - try {
137   - transform.get();
138   - fail();
139   - } catch (Exception e) {
140   - assertTrue(e instanceof ExecutionException);
141   - }
142   - verify(rateLimiter, times(1)).acquireAsync();
143   - verify(rateLimiter, times(1)).release();
144   - }
145   -
146   - @Test
147   - public void queryTimeoutReturnsPermit() throws InterruptedException, ExecutionException {
148   - when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFuture(null));
149   - when(session.executeAsync(statement)).thenReturn(realFuture);
150   - Mockito.doAnswer((Answer<Void>) invocation -> {
151   - Object[] args = invocation.getArguments();
152   - Runnable task = (Runnable) args[0];
153   - task.run();
154   - return null;
155   - }).when(realFuture).addListener(Mockito.any(), Mockito.any());
156   -
157   - when(realFuture.get()).thenThrow(new ExecutionException("Fail", new TimeoutException("timeout")));
158   - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
159   - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor());
160   - try {
161   - transform.get();
162   - fail();
163   - } catch (Exception e) {
164   - assertTrue(e instanceof ExecutionException);
165   - }
166   - verify(rateLimiter, times(1)).acquireAsync();
167   - verify(rateLimiter, times(1)).release();
168   - }
169   -
170   - @Test
171   - public void expiredQueryReturnPermit() throws InterruptedException, ExecutionException {
172   - CountDownLatch latch = new CountDownLatch(1);
173   - ListenableFuture<Void> future = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1)).submit(() -> {
174   - latch.await();
175   - return null;
176   - });
177   - when(rateLimiter.acquireAsync()).thenReturn(future);
178   - resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
179   -
180   - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor());
181   -// TimeUnit.MILLISECONDS.sleep(200);
182   - future.cancel(false);
183   - latch.countDown();
184   -
185   - try {
186   - transform.get();
187   - fail();
188   - } catch (Exception e) {
189   - assertTrue(e instanceof ExecutionException);
190   - }
191   - verify(rateLimiter, times(1)).acquireAsync();
192   - verify(rateLimiter, times(1)).release();
193   - }
194   -
195   -}
\ No newline at end of file
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 21 import org.junit.runner.RunWith;
... ... @@ -134,7 +134,7 @@ public abstract class AbstractServiceTest {
134 134
135 135 protected Event generateEvent(TenantId tenantId, EntityId entityId, String eventType, String eventUid) throws IOException {
136 136 if (tenantId == null) {
137   - tenantId = new TenantId(UUIDs.timeBased());
  137 + tenantId = new TenantId(Uuids.timeBased());
138 138 }
139 139 Event event = new Event();
140 140 event.setTenantId(tenantId);
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.junit.After;
20 20 import org.junit.Assert;
21 21 import org.junit.Before;
... ... @@ -59,8 +59,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
59 59
60 60 @Test
61 61 public void testSaveAndFetchAlarm() throws ExecutionException, InterruptedException {
62   - AssetId parentId = new AssetId(UUIDs.timeBased());
63   - AssetId childId = new AssetId(UUIDs.timeBased());
  62 + AssetId parentId = new AssetId(Uuids.timeBased());
  63 + AssetId childId = new AssetId(Uuids.timeBased());
64 64
65 65 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
66 66
... ... @@ -96,8 +96,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
96 96
97 97 @Test
98 98 public void testFindAlarm() throws ExecutionException, InterruptedException {
99   - AssetId parentId = new AssetId(UUIDs.timeBased());
100   - AssetId childId = new AssetId(UUIDs.timeBased());
  99 + AssetId parentId = new AssetId(Uuids.timeBased());
  100 + AssetId childId = new AssetId(Uuids.timeBased());
101 101
102 102 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
103 103
... ... @@ -197,8 +197,8 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
197 197
198 198 @Test
199 199 public void testDeleteAlarm() throws ExecutionException, InterruptedException {
200   - AssetId parentId = new AssetId(UUIDs.timeBased());
201   - AssetId childId = new AssetId(UUIDs.timeBased());
  200 + AssetId parentId = new AssetId(Uuids.timeBased());
  201 + AssetId childId = new AssetId(Uuids.timeBased());
202 202
203 203 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
204 204
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.apache.commons.lang3.RandomStringUtils;
20 20 import org.junit.After;
21 21 import org.junit.Assert;
... ... @@ -104,7 +104,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
104 104 Asset asset = new Asset();
105 105 asset.setName("My asset");
106 106 asset.setType("default");
107   - asset.setTenantId(new TenantId(UUIDs.timeBased()));
  107 + asset.setTenantId(new TenantId(Uuids.timeBased()));
108 108 assetService.saveAsset(asset);
109 109 }
110 110
... ... @@ -116,7 +116,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
116 116 asset.setTenantId(tenantId);
117 117 asset = assetService.saveAsset(asset);
118 118 try {
119   - assetService.assignAssetToCustomer(tenantId, asset.getId(), new CustomerId(UUIDs.timeBased()));
  119 + assetService.assignAssetToCustomer(tenantId, asset.getId(), new CustomerId(Uuids.timeBased()));
120 120 } finally {
121 121 assetService.deleteAsset(tenantId, asset.getId());
122 122 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.apache.commons.lang3.RandomStringUtils;
20 20 import org.junit.After;
21 21 import org.junit.Assert;
... ... @@ -105,7 +105,7 @@ public abstract class BaseCustomerServiceTest extends AbstractServiceTest {
105 105 public void testSaveCustomerWithInvalidTenant() {
106 106 Customer customer = new Customer();
107 107 customer.setTitle("My customer");
108   - customer.setTenantId(new TenantId(UUIDs.timeBased()));
  108 + customer.setTenantId(new TenantId(Uuids.timeBased()));
109 109 customerService.saveCustomer(customer);
110 110 }
111 111
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.apache.commons.lang3.RandomStringUtils;
20 20 import org.junit.After;
21 21 import org.junit.Assert;
... ... @@ -98,7 +98,7 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest {
98 98 public void testSaveDashboardWithInvalidTenant() {
99 99 Dashboard dashboard = new Dashboard();
100 100 dashboard.setTitle("My dashboard");
101   - dashboard.setTenantId(new TenantId(UUIDs.timeBased()));
  101 + dashboard.setTenantId(new TenantId(Uuids.timeBased()));
102 102 dashboardService.saveDashboard(dashboard);
103 103 }
104 104
... ... @@ -109,7 +109,7 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest {
109 109 dashboard.setTenantId(tenantId);
110 110 dashboard = dashboardService.saveDashboard(dashboard);
111 111 try {
112   - dashboardService.assignDashboardToCustomer(tenantId, dashboard.getId(), new CustomerId(UUIDs.timeBased()));
  112 + dashboardService.assignDashboardToCustomer(tenantId, dashboard.getId(), new CustomerId(Uuids.timeBased()));
113 113 } finally {
114 114 dashboardService.deleteDashboard(tenantId, dashboard.getId());
115 115 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.junit.After;
20 20 import org.junit.Assert;
21 21 import org.junit.Before;
... ... @@ -109,7 +109,7 @@ public abstract class BaseDeviceCredentialsServiceTest extends AbstractServiceTe
109 109 device.setTenantId(tenantId);
110 110 device = deviceService.saveDevice(device);
111 111 DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId());
112   - DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(UUIDs.timeBased()));
  112 + DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(Uuids.timeBased()));
113 113 newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime());
114 114 newDeviceCredentials.setDeviceId(deviceCredentials.getDeviceId());
115 115 newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType());
... ... @@ -129,7 +129,7 @@ public abstract class BaseDeviceCredentialsServiceTest extends AbstractServiceTe
129 129 device.setTenantId(tenantId);
130 130 device = deviceService.saveDevice(device);
131 131 DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId());
132   - deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased()));
  132 + deviceCredentials.setDeviceId(new DeviceId(Uuids.timeBased()));
133 133 try {
134 134 deviceCredentialsService.updateDeviceCredentials(tenantId, deviceCredentials);
135 135 } finally {
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.apache.commons.lang3.RandomStringUtils;
20 20 import org.junit.After;
21 21 import org.junit.Assert;
... ... @@ -110,7 +110,7 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
110 110 Device device = new Device();
111 111 device.setName("My device");
112 112 device.setType("default");
113   - device.setTenantId(new TenantId(UUIDs.timeBased()));
  113 + device.setTenantId(new TenantId(Uuids.timeBased()));
114 114 deviceService.saveDevice(device);
115 115 }
116 116
... ... @@ -122,7 +122,7 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
122 122 device.setTenantId(tenantId);
123 123 device = deviceService.saveDevice(device);
124 124 try {
125   - deviceService.assignDeviceToCustomer(tenantId, device.getId(), new CustomerId(UUIDs.timeBased()));
  125 + deviceService.assignDeviceToCustomer(tenantId, device.getId(), new CustomerId(Uuids.timeBased()));
126 126 } finally {
127 127 deviceService.deleteDevice(tenantId, device.getId());
128 128 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.junit.After;
20 20 import org.junit.Assert;
21 21 import org.junit.Before;
... ... @@ -47,8 +47,8 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
47 47
48 48 @Test
49 49 public void testSaveRelation() throws ExecutionException, InterruptedException {
50   - AssetId parentId = new AssetId(UUIDs.timeBased());
51   - AssetId childId = new AssetId(UUIDs.timeBased());
  50 + AssetId parentId = new AssetId(Uuids.timeBased());
  51 + AssetId childId = new AssetId(Uuids.timeBased());
52 52
53 53 EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
54 54
... ... @@ -65,9 +65,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
65 65
66 66 @Test
67 67 public void testDeleteRelation() throws ExecutionException, InterruptedException {
68   - AssetId parentId = new AssetId(UUIDs.timeBased());
69   - AssetId childId = new AssetId(UUIDs.timeBased());
70   - AssetId subChildId = new AssetId(UUIDs.timeBased());
  68 + AssetId parentId = new AssetId(Uuids.timeBased());
  69 + AssetId childId = new AssetId(Uuids.timeBased());
  70 + AssetId subChildId = new AssetId(Uuids.timeBased());
71 71
72 72 EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
73 73 EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE);
... ... @@ -86,9 +86,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
86 86
87 87 @Test
88 88 public void testDeleteEntityRelations() throws ExecutionException, InterruptedException {
89   - AssetId parentId = new AssetId(UUIDs.timeBased());
90   - AssetId childId = new AssetId(UUIDs.timeBased());
91   - AssetId subChildId = new AssetId(UUIDs.timeBased());
  89 + AssetId parentId = new AssetId(Uuids.timeBased());
  90 + AssetId childId = new AssetId(Uuids.timeBased());
  91 + AssetId subChildId = new AssetId(Uuids.timeBased());
92 92
93 93 EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
94 94 EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE);
... ... @@ -105,10 +105,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
105 105
106 106 @Test
107 107 public void testFindFrom() throws ExecutionException, InterruptedException {
108   - AssetId parentA = new AssetId(UUIDs.timeBased());
109   - AssetId parentB = new AssetId(UUIDs.timeBased());
110   - AssetId childA = new AssetId(UUIDs.timeBased());
111   - AssetId childB = new AssetId(UUIDs.timeBased());
  108 + AssetId parentA = new AssetId(Uuids.timeBased());
  109 + AssetId parentB = new AssetId(Uuids.timeBased());
  110 + AssetId childA = new AssetId(Uuids.timeBased());
  111 + AssetId childB = new AssetId(Uuids.timeBased());
112 112
113 113 EntityRelation relationA1 = new EntityRelation(parentA, childA, EntityRelation.CONTAINS_TYPE);
114 114 EntityRelation relationA2 = new EntityRelation(parentA, childB, EntityRelation.CONTAINS_TYPE);
... ... @@ -157,10 +157,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
157 157
158 158 @Test
159 159 public void testFindTo() throws ExecutionException, InterruptedException {
160   - AssetId parentA = new AssetId(UUIDs.timeBased());
161   - AssetId parentB = new AssetId(UUIDs.timeBased());
162   - AssetId childA = new AssetId(UUIDs.timeBased());
163   - AssetId childB = new AssetId(UUIDs.timeBased());
  160 + AssetId parentA = new AssetId(Uuids.timeBased());
  161 + AssetId parentB = new AssetId(Uuids.timeBased());
  162 + AssetId childA = new AssetId(Uuids.timeBased());
  163 + AssetId childB = new AssetId(Uuids.timeBased());
164 164
165 165 EntityRelation relationA1 = new EntityRelation(parentA, childA, EntityRelation.CONTAINS_TYPE);
166 166 EntityRelation relationA2 = new EntityRelation(parentA, childB, EntityRelation.CONTAINS_TYPE);
... ... @@ -207,9 +207,9 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
207 207 @Test
208 208 public void testCyclicRecursiveRelation() throws ExecutionException, InterruptedException {
209 209 // A -> B -> C -> A
210   - AssetId assetA = new AssetId(UUIDs.timeBased());
211   - AssetId assetB = new AssetId(UUIDs.timeBased());
212   - AssetId assetC = new AssetId(UUIDs.timeBased());
  210 + AssetId assetA = new AssetId(Uuids.timeBased());
  211 + AssetId assetB = new AssetId(Uuids.timeBased());
  212 + AssetId assetC = new AssetId(Uuids.timeBased());
213 213
214 214 EntityRelation relationA = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE);
215 215 EntityRelation relationB = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE);
... ... @@ -239,10 +239,10 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
239 239 @Test
240 240 public void testRecursiveRelation() throws ExecutionException, InterruptedException {
241 241 // A -> B -> [C,D]
242   - AssetId assetA = new AssetId(UUIDs.timeBased());
243   - AssetId assetB = new AssetId(UUIDs.timeBased());
244   - AssetId assetC = new AssetId(UUIDs.timeBased());
245   - DeviceId deviceD = new DeviceId(UUIDs.timeBased());
  242 + AssetId assetA = new AssetId(Uuids.timeBased());
  243 + AssetId assetB = new AssetId(Uuids.timeBased());
  244 + AssetId assetC = new AssetId(Uuids.timeBased());
  245 + DeviceId deviceD = new DeviceId(Uuids.timeBased());
246 246
247 247 EntityRelation relationAB = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE);
248 248 EntityRelation relationBC = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE);
... ... @@ -272,7 +272,7 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
272 272 @Test(expected = DataValidationException.class)
273 273 public void testSaveRelationWithEmptyFrom() throws ExecutionException, InterruptedException {
274 274 EntityRelation relation = new EntityRelation();
275   - relation.setTo(new AssetId(UUIDs.timeBased()));
  275 + relation.setTo(new AssetId(Uuids.timeBased()));
276 276 relation.setType(EntityRelation.CONTAINS_TYPE);
277 277 Assert.assertTrue(saveRelation(relation));
278 278 }
... ... @@ -280,7 +280,7 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
280 280 @Test(expected = DataValidationException.class)
281 281 public void testSaveRelationWithEmptyTo() throws ExecutionException, InterruptedException {
282 282 EntityRelation relation = new EntityRelation();
283   - relation.setFrom(new AssetId(UUIDs.timeBased()));
  283 + relation.setFrom(new AssetId(Uuids.timeBased()));
284 284 relation.setType(EntityRelation.CONTAINS_TYPE);
285 285 Assert.assertTrue(saveRelation(relation));
286 286 }
... ... @@ -288,8 +288,8 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest {
288 288 @Test(expected = DataValidationException.class)
289 289 public void testSaveRelationWithEmptyType() throws ExecutionException, InterruptedException {
290 290 EntityRelation relation = new EntityRelation();
291   - relation.setFrom(new AssetId(UUIDs.timeBased()));
292   - relation.setTo(new AssetId(UUIDs.timeBased()));
  291 + relation.setFrom(new AssetId(Uuids.timeBased()));
  292 + relation.setTo(new AssetId(Uuids.timeBased()));
293 293 Assert.assertTrue(saveRelation(relation));
294 294 }
295 295 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 20 import org.apache.commons.lang3.RandomStringUtils;
21 21 import org.junit.After;
... ... @@ -94,7 +94,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
94 94 public void testSaveRuleChainWithInvalidTenant() {
95 95 RuleChain ruleChain = new RuleChain();
96 96 ruleChain.setName("My RuleChain");
97   - ruleChain.setTenantId(new TenantId(UUIDs.timeBased()));
  97 + ruleChain.setTenantId(new TenantId(Uuids.timeBased()));
98 98 ruleChainService.saveRuleChain(ruleChain);
99 99 }
100 100
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 21 import org.junit.After;
... ... @@ -141,7 +141,7 @@ public abstract class BaseWidgetTypeServiceTest extends AbstractServiceTest {
141 141 WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
142 142
143 143 WidgetType widgetType = new WidgetType();
144   - widgetType.setTenantId(new TenantId(UUIDs.timeBased()));
  144 + widgetType.setTenantId(new TenantId(Uuids.timeBased()));
145 145 widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
146 146 widgetType.setName("Widget Type");
147 147 widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.junit.After;
20 20 import org.junit.Assert;
21 21 import org.junit.Before;
... ... @@ -88,7 +88,7 @@ public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest {
88 88 public void testSaveWidgetsBundleWithInvalidTenant() {
89 89 WidgetsBundle widgetsBundle = new WidgetsBundle();
90 90 widgetsBundle.setTitle("My widgets bundle");
91   - widgetsBundle.setTenantId(new TenantId(UUIDs.timeBased()));
  91 + widgetsBundle.setTenantId(new TenantId(Uuids.timeBased()));
92 92 widgetsBundleService.saveWidgetsBundle(widgetsBundle);
93 93 }
94 94
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service.attributes;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.junit.Assert;
20 20 import org.junit.Before;
21 21 import org.junit.Test;
... ... @@ -47,7 +47,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest {
47 47
48 48 @Test
49 49 public void saveAndFetch() throws Exception {
50   - DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  50 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
51 51 KvEntry attrValue = new StringDataEntry("attribute1", "value1");
52 52 AttributeKvEntry attr = new BaseAttributeKvEntry(attrValue, 42L);
53 53 attributesService.save(SYSTEM_TENANT_ID, deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attr)).get();
... ... @@ -58,7 +58,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest {
58 58
59 59 @Test
60 60 public void saveMultipleTypeAndFetch() throws Exception {
61   - DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  61 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
62 62 KvEntry attrOldValue = new StringDataEntry("attribute1", "value1");
63 63 AttributeKvEntry attrOld = new BaseAttributeKvEntry(attrOldValue, 42L);
64 64
... ... @@ -78,7 +78,7 @@ public abstract class BaseAttributesServiceTest extends AbstractServiceTest {
78 78
79 79 @Test
80 80 public void findAll() throws Exception {
81   - DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  81 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
82 82
83 83 KvEntry attrAOldValue = new StringDataEntry("A", "value1");
84 84 AttributeKvEntry attrAOld = new BaseAttributeKvEntry(attrAOldValue, 42L);
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service.event;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.junit.Assert;
20 20 import org.junit.Test;
21 21 import org.thingsboard.server.common.data.DataConstants;
... ... @@ -40,8 +40,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest {
40 40
41 41 @Test
42 42 public void saveEvent() throws Exception {
43   - DeviceId devId = new DeviceId(UUIDs.timeBased());
44   - Event event = generateEvent(null, devId, "ALARM", UUIDs.timeBased().toString());
  43 + DeviceId devId = new DeviceId(Uuids.timeBased());
  44 + Event event = generateEvent(null, devId, "ALARM", Uuids.timeBased().toString());
45 45 Event saved = eventService.save(event);
46 46 Optional<Event> loaded = eventService.findEvent(event.getTenantId(), event.getEntityId(), event.getType(), event.getUid());
47 47 Assert.assertTrue(loaded.isPresent());
... ... @@ -51,8 +51,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest {
51 51
52 52 @Test
53 53 public void saveEventIfNotExists() throws Exception {
54   - DeviceId devId = new DeviceId(UUIDs.timeBased());
55   - Event event = generateEvent(null, devId, "ALARM", UUIDs.timeBased().toString());
  54 + DeviceId devId = new DeviceId(Uuids.timeBased());
  55 + Event event = generateEvent(null, devId, "ALARM", Uuids.timeBased().toString());
56 56 Optional<Event> saved = eventService.saveIfNotExists(event);
57 57 Assert.assertTrue(saved.isPresent());
58 58 saved = eventService.saveIfNotExists(event);
... ... @@ -67,8 +67,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest {
67 67 long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
68 68 long timeAfterEndTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC);
69 69
70   - CustomerId customerId = new CustomerId(UUIDs.timeBased());
71   - TenantId tenantId = new TenantId(UUIDs.timeBased());
  70 + CustomerId customerId = new CustomerId(Uuids.timeBased());
  71 + TenantId tenantId = new TenantId(Uuids.timeBased());
72 72 saveEventWithProvidedTime(timeBeforeStartTime, customerId, tenantId);
73 73 Event savedEvent = saveEventWithProvidedTime(eventTime, customerId, tenantId);
74 74 Event savedEvent2 = saveEventWithProvidedTime(eventTime+1, customerId, tenantId);
... ... @@ -102,8 +102,8 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest {
102 102 long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
103 103 long timeAfterEndTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC);
104 104
105   - CustomerId customerId = new CustomerId(UUIDs.timeBased());
106   - TenantId tenantId = new TenantId(UUIDs.timeBased());
  105 + CustomerId customerId = new CustomerId(Uuids.timeBased());
  106 + TenantId tenantId = new TenantId(Uuids.timeBased());
107 107 saveEventWithProvidedTime(timeBeforeStartTime, customerId, tenantId);
108 108 Event savedEvent = saveEventWithProvidedTime(eventTime, customerId, tenantId);
109 109 Event savedEvent2 = saveEventWithProvidedTime(eventTime+1, customerId, tenantId);
... ... @@ -131,7 +131,7 @@ public abstract class BaseEventServiceTest extends AbstractServiceTest {
131 131
132 132 private Event saveEventWithProvidedTime(long time, EntityId entityId, TenantId tenantId) throws IOException {
133 133 Event event = generateEvent(tenantId, entityId, DataConstants.STATS, null);
134   - event.setId(new EventId(UUIDs.startOf(time)));
  134 + event.setId(new EventId(Uuids.startOf(time)));
135 135 return eventService.save(event);
136 136 }
137   -}
\ No newline at end of file
  137 +}
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.service.timeseries;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import lombok.extern.slf4j.Slf4j;
20 20 import org.junit.*;
21 21 import org.thingsboard.server.common.data.EntityView;
... ... @@ -84,7 +84,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
84 84
85 85 @Test
86 86 public void testFindAllLatest() throws Exception {
87   - DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  87 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
88 88
89 89 saveEntries(deviceId, TS - 2);
90 90 saveEntries(deviceId, TS - 1);
... ... @@ -132,7 +132,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
132 132
133 133 @Test
134 134 public void testFindLatest() throws Exception {
135   - DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  135 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
136 136
137 137 saveEntries(deviceId, TS - 2);
138 138 saveEntries(deviceId, TS - 1);
... ... @@ -151,7 +151,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
151 151
152 152 @Test
153 153 public void testFindByQueryAscOrder() throws Exception {
154   - DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  154 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
155 155
156 156 saveEntries(deviceId, TS - 2);
157 157 saveEntries(deviceId, TS - 1);
... ... @@ -177,7 +177,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
177 177
178 178 @Test
179 179 public void testFindByQueryDescOrder() throws Exception {
180   - DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  180 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
181 181
182 182 saveEntries(deviceId, TS - 2);
183 183 saveEntries(deviceId, TS - 1);
... ... @@ -203,7 +203,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
203 203
204 204 @Test
205 205 public void testDeleteDeviceTsDataWithOverwritingLatest() throws Exception {
206   - DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  206 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
207 207
208 208 saveEntries(deviceId, 10000);
209 209 saveEntries(deviceId, 20000);
... ... @@ -223,7 +223,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
223 223
224 224 @Test
225 225 public void testFindDeviceTsData() throws Exception {
226   - DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  226 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
227 227 List<TsKvEntry> entries = new ArrayList<>();
228 228
229 229 entries.add(save(deviceId, 5000, 100));
... ... @@ -374,7 +374,7 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
374 374
375 375 @Test
376 376 public void testFindDeviceLongAndDoubleTsData() throws Exception {
377   - DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  377 + DeviceId deviceId = new DeviceId(Uuids.timeBased());
378 378 List<TsKvEntry> entries = new ArrayList<>();
379 379
380 380 entries.add(save(deviceId, 5000, 100));
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 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 19 import com.google.common.util.concurrent.ListenableFuture;
20 20 import org.junit.Test;
21 21 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -50,12 +50,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
50 50
51 51 @Test
52 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 57 for (int i = 0; i < 60; i++) {
58   - UUID assetId = UUIDs.timeBased();
  58 + UUID assetId = Uuids.timeBased();
59 59 UUID tenantId = i % 2 == 0 ? tenantId1 : tenantId2;
60 60 UUID customerId = i % 2 == 0 ? customerId1 : customerId2;
61 61 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1");
... ... @@ -77,12 +77,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
77 77
78 78 @Test
79 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 84 for (int i = 0; i < 60; i++) {
85   - UUID assetId = UUIDs.timeBased();
  85 + UUID assetId = Uuids.timeBased();
86 86 UUID tenantId = i % 2 == 0 ? tenantId1 : tenantId2;
87 87 UUID customerId = i % 2 == 0 ? customerId1 : customerId2;
88 88 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1");
... ... @@ -103,11 +103,11 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
103 103
104 104 @Test
105 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 108 List<UUID> searchIds = new ArrayList<>();
109 109 for (int i = 0; i < 30; i++) {
110   - UUID assetId = UUIDs.timeBased();
  110 + UUID assetId = Uuids.timeBased();
111 111 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1");
112 112 if (i % 3 == 0) {
113 113 searchIds.add(assetId);
... ... @@ -123,12 +123,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
123 123
124 124 @Test
125 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 129 List<UUID> searchIds = new ArrayList<>();
130 130 for (int i = 0; i < 30; i++) {
131   - UUID assetId = UUIDs.timeBased();
  131 + UUID assetId = Uuids.timeBased();
132 132 UUID customerId = i%2 == 0 ? customerId1 : customerId2;
133 133 saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1");
134 134 if (i % 3 == 0) {
... ... @@ -145,12 +145,12 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
145 145
146 146 @Test
147 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 154 String name = "TEST_ASSET";
155 155 saveAsset(assetId1, tenantId1, customerId1, name, "TYPE_1");
156 156 saveAsset(assetId2, tenantId2, customerId2, name, "TYPE_1");
... ... @@ -175,22 +175,22 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
175 175
176 176 @Test
177 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 195 List<EntitySubtype> tenant1Types = assetDao.findTenantAssetTypesAsync(tenantId1).get();
196 196 assertNotNull(tenant1Types);
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.component;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.junit.Test;
20 20 import org.springframework.beans.factory.annotation.Autowired;
21 21 import org.thingsboard.server.common.data.id.ComponentDescriptorId;
... ... @@ -77,7 +77,7 @@ public class JpaBaseComponentDescriptorDaoTest extends AbstractJpaDaoTest {
77 77
78 78 private void createComponentDescriptor(ComponentType type, ComponentScope scope, int index) {
79 79 ComponentDescriptor component = new ComponentDescriptor();
80   - component.setId(new ComponentDescriptorId(UUIDs.timeBased()));
  80 + component.setId(new ComponentDescriptorId(Uuids.timeBased()));
81 81 component.setType(type);
82 82 component.setScope(scope);
83 83 component.setName("COMPONENT_" + index);
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 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 19 import org.junit.Test;
20 20 import org.springframework.beans.factory.annotation.Autowired;
21 21 import org.thingsboard.server.common.data.Customer;
... ... @@ -43,8 +43,8 @@ public class JpaCustomerDaoTest extends AbstractJpaDaoTest {
43 43
44 44 @Test
45 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 49 for (int i = 0; i < 20; i++) {
50 50 createCustomer(tenantId1, i);
... ... @@ -62,7 +62,7 @@ public class JpaCustomerDaoTest extends AbstractJpaDaoTest {
62 62
63 63 @Test
64 64 public void testFindCustomersByTenantIdAndTitle() {
65   - UUID tenantId = UUIDs.timeBased();
  65 + UUID tenantId = Uuids.timeBased();
66 66
67 67 for (int i = 0; i < 10; i++) {
68 68 createCustomer(tenantId, i);
... ... @@ -75,7 +75,7 @@ public class JpaCustomerDaoTest extends AbstractJpaDaoTest {
75 75
76 76 private void createCustomer(UUID tenantId, int index) {
77 77 Customer customer = new Customer();
78   - customer.setId(new CustomerId(UUIDs.timeBased()));
  78 + customer.setId(new CustomerId(Uuids.timeBased()));
79 79 customer.setTenantId(new TenantId(tenantId));
80 80 customer.setTitle("CUSTOMER_" + index);
81 81 customerDao.save(new TenantId(tenantId), customer);
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 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 19 import org.junit.Assert;
20 20 import org.junit.Test;
21 21 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -41,8 +41,8 @@ public class JpaDashboardInfoDaoTest extends AbstractJpaDaoTest {
41 41
42 42 @Test
43 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 47 for (int i = 0; i < 20; i++) {
48 48 createDashboard(tenantId1, i);
... ... @@ -59,7 +59,7 @@ public class JpaDashboardInfoDaoTest extends AbstractJpaDaoTest {
59 59
60 60 private void createDashboard(UUID tenantId, int index) {
61 61 DashboardInfo dashboardInfo = new DashboardInfo();
62   - dashboardInfo.setId(new DashboardId(UUIDs.timeBased()));
  62 + dashboardInfo.setId(new DashboardId(Uuids.timeBased()));
63 63 dashboardInfo.setTenantId(new TenantId(tenantId));
64 64 dashboardInfo.setTitle("DASHBOARD_" + index);
65 65 dashboardInfoDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, dashboardInfo);
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 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 19 import com.google.common.util.concurrent.ListenableFuture;
20 20 import com.google.common.util.concurrent.ListeningExecutorService;
21 21 import com.google.common.util.concurrent.MoreExecutors;
... ... @@ -49,10 +49,10 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
49 49
50 50 @Test
51 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 56 createDevices(tenantId1, tenantId2, customerId1, customerId2, 40);
57 57
58 58 PageLink pageLink = new PageLink(15, 0, "SEARCH_TEXT");
... ... @@ -67,8 +67,8 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
67 67
68 68 @Test
69 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 72 Device device = getDevice(tenantId, customerId);
73 73 deviceDao.save(new TenantId(tenantId), device);
74 74
... ... @@ -85,16 +85,16 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
85 85
86 86 @Test
87 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 93 List<UUID> deviceIds = new ArrayList<>();
94 94
95 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 98 deviceDao.save(new TenantId(tenantId1), getDevice(tenantId1, customerId1, deviceId1));
99 99 deviceDao.save(new TenantId(tenantId2), getDevice(tenantId2, customerId2, deviceId2));
100 100 deviceIds.add(deviceId1);
... ... @@ -108,16 +108,16 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
108 108
109 109 @Test
110 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 116 List<UUID> deviceIds = new ArrayList<>();
117 117
118 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 121 deviceDao.save(new TenantId(tenantId1), getDevice(tenantId1, customerId1, deviceId1));
122 122 deviceDao.save(new TenantId(tenantId2), getDevice(tenantId2, customerId2, deviceId2));
123 123 deviceIds.add(deviceId1);
... ... @@ -137,7 +137,7 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
137 137 }
138 138
139 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 143 private Device getDevice(UUID tenantId, UUID customerID, UUID deviceId) {
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.event;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
  18 +import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 21 import com.github.springtestdbunit.annotation.DatabaseSetup;
... ... @@ -57,9 +57,9 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest {
57 57
58 58 @Test
59 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 63 Event event = getEvent(eventId, tenantId, entityId);
64 64 Optional<Event> optEvent1 = eventDao.saveIfNotExists(event);
65 65 assertTrue("Optional is expected to be non-empty", optEvent1.isPresent());
... ... @@ -83,9 +83,9 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest {
83 83
84 84 @Test
85 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 89 long startTime = System.currentTimeMillis();
90 90 long endTime = createEventsTwoEntities(tenantId, entityId1, entityId2, startTime, 20);
91 91
... ... @@ -117,9 +117,9 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest {
117 117
118 118 @Test
119 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 123 long startTime = System.currentTimeMillis();
124 124 long endTime = createEventsTwoEntitiesTwoTypes(tenantId, entityId1, entityId2, startTime, 20);
125 125
... ... @@ -147,10 +147,10 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest {
147 147 private long createEventsTwoEntitiesTwoTypes(UUID tenantId, UUID entityId1, UUID entityId2, long startTime, int count) {
148 148 for (int i = 0; i < count / 2; i++) {
149 149 String type = i % 2 == 0 ? STATS : ALARM;
150   - UUID eventId1 = UUIDs.timeBased();
  150 + UUID eventId1 = Uuids.timeBased();
151 151 Event event1 = getEvent(eventId1, tenantId, entityId1, type);
152 152 eventDao.save(new TenantId(tenantId), event1);
153   - UUID eventId2 = UUIDs.timeBased();
  153 + UUID eventId2 = Uuids.timeBased();
154 154 Event event2 = getEvent(eventId2, tenantId, entityId2, type);
155 155 eventDao.save(new TenantId(tenantId), event2);
156 156 }
... ... @@ -159,10 +159,10 @@ public class JpaBaseEventDaoTest extends AbstractJpaDaoTest {
159 159
160 160 private long createEventsTwoEntities(UUID tenantId, UUID entityId1, UUID entityId2, long startTime, int count) {
161 161 for (int i = 0; i < count / 2; i++) {
162   - UUID eventId1 = UUIDs.timeBased();
  162 + UUID eventId1 = Uuids.timeBased();
163 163 Event event1 = getEvent(eventId1, tenantId, entityId1);
164 164 eventDao.save(new TenantId(tenantId), event1);
165   - UUID eventId2 = UUIDs.timeBased();
  165 + UUID eventId2 = Uuids.timeBased();
166 166 Event event2 = getEvent(eventId2, tenantId, entityId2);
167 167 eventDao.save(new TenantId(tenantId), event2);
168 168 }
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 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 19 import com.github.springtestdbunit.annotation.DatabaseSetup;
20 20 import org.junit.Test;
21 21 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -69,7 +69,7 @@ public class JpaTenantDaoTest extends AbstractJpaDaoTest {
69 69
70 70 private void createTenant(String region, String title, int index) {
71 71 Tenant tenant = new Tenant();
72   - tenant.setId(new TenantId(UUIDs.timeBased()));
  72 + tenant.setId(new TenantId(Uuids.timeBased()));
73 73 tenant.setRegion(region);
74 74 tenant.setTitle(title + "_" + index);
75 75 tenantDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, tenant);
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 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 19 import com.fasterxml.jackson.databind.JsonNode;
20 20 import com.fasterxml.jackson.databind.ObjectMapper;
21 21 import com.github.springtestdbunit.annotation.DatabaseSetup;
... ... @@ -71,8 +71,8 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest {
71 71 @Test
72 72 @DatabaseSetup("classpath:dbunit/empty_dataset.xml")
73 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 76 create30Adminsand60Users(tenantId, customerId);
77 77 PageLink pageLink = new PageLink(20);
78 78 PageData<User> tenantAdmins1 = userDao.findTenantAdmins(tenantId, pageLink);
... ... @@ -90,8 +90,8 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest {
90 90 @Test
91 91 @DatabaseSetup("classpath:dbunit/empty_dataset.xml")
92 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 95 create30Adminsand60Users(tenantId, customerId);
96 96 PageLink pageLink = new PageLink(40);
97 97 PageData<User> customerUsers1 = userDao.findCustomerUsers(tenantId, customerId, pageLink);
... ... @@ -138,7 +138,7 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest {
138 138
139 139 private void saveUser(UUID tenantId, UUID customerId) {
140 140 User user = new User();
141   - UUID id = UUIDs.timeBased();
  141 + UUID id = Uuids.timeBased();
142 142 user.setId(new UserId(id));
143 143 user.setTenantId(new TenantId(tenantId));
144 144 user.setCustomerId(new CustomerId(customerId));
... ...
... ... @@ -15,7 +15,7 @@
15 15 */
16 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 19 import com.github.springtestdbunit.annotation.DatabaseOperation;
20 20 import com.github.springtestdbunit.annotation.DatabaseSetup;
21 21 import com.github.springtestdbunit.annotation.DatabaseTearDown;
... ... @@ -78,8 +78,8 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
78 78 @Test
79 79 @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL)
80 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 83 // Create a bunch of widgetBundles
84 84 for (int i= 0; i < 10; i++) {
85 85 createWidgetBundles(3, tenantId1, "WB1_");
... ... @@ -104,8 +104,8 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
104 104 @Test
105 105 @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL)
106 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 109 // Create a bunch of widgetBundles
110 110 for (int i= 0; i < 10; i++) {
111 111 createWidgetBundles( 5, tenantId1,"WB1_");
... ... @@ -134,7 +134,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
134 134 @DatabaseSetup("classpath:dbunit/empty_dataset.xml")
135 135 @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml", type= DatabaseOperation.DELETE_ALL)
136 136 public void testSearchTextNotFound() {
137   - UUID tenantId = UUIDs.timeBased();
  137 + UUID tenantId = Uuids.timeBased();
138 138 createWidgetBundles(5, tenantId, "ABC_");
139 139 createSystemWidgetBundles(5, "SYS_");
140 140
... ... @@ -148,7 +148,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
148 148 WidgetsBundle widgetsBundle = new WidgetsBundle();
149 149 widgetsBundle.setAlias(prefix + i);
150 150 widgetsBundle.setTitle(prefix + i);
151   - widgetsBundle.setId(new WidgetsBundleId(UUIDs.timeBased()));
  151 + widgetsBundle.setId(new WidgetsBundleId(Uuids.timeBased()));
152 152 widgetsBundle.setTenantId(new TenantId(tenantId));
153 153 widgetsBundleDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, widgetsBundle);
154 154 }
... ... @@ -159,7 +159,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
159 159 widgetsBundle.setAlias(prefix + i);
160 160 widgetsBundle.setTitle(prefix + i);
161 161 widgetsBundle.setTenantId(new TenantId(NULL_UUID));
162   - widgetsBundle.setId(new WidgetsBundleId(UUIDs.timeBased()));
  162 + widgetsBundle.setId(new WidgetsBundleId(Uuids.timeBased()));
163 163 widgetsBundleDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, widgetsBundle);
164 164 }
165 165 }
... ...
... ... @@ -43,8 +43,9 @@
43 43 <logback.version>1.2.3</logback.version>
44 44 <mockito.version>1.9.5</mockito.version>
45 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 49 <takari-cpsuite.version>1.2.7</takari-cpsuite.version>
49 50 <guava.version>28.2-jre</guava.version>
50 51 <caffeine.version>2.6.1</caffeine.version>
... ... @@ -657,19 +658,19 @@
657 658 <version>${netty.version}</version>
658 659 </dependency>
659 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 663 <version>${cassandra.version}</version>
663 664 </dependency>
664 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 668 <version>${cassandra.version}</version>
668 669 </dependency>
669 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 674 </dependency>
674 675 <dependency>
675 676 <groupId>org.apache.commons</groupId>
... ...
... ... @@ -74,18 +74,8 @@
74 74 <scope>provided</scope>
75 75 </dependency>
76 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 79 <scope>provided</scope>
90 80 </dependency>
91 81 <dependency>
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.rule.engine.api;
17 17
18   -import com.datastax.driver.core.ResultSetFuture;
19 18 import io.netty.channel.EventLoopGroup;
20 19 import org.springframework.data.redis.core.RedisTemplate;
21 20 import org.thingsboard.common.util.ListeningExecutor;
... ... @@ -37,6 +36,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService;
37 36 import org.thingsboard.server.dao.device.DeviceService;
38 37 import org.thingsboard.server.dao.entityview.EntityViewService;
39 38 import org.thingsboard.server.dao.nosql.CassandraStatementTask;
  39 +import org.thingsboard.server.dao.nosql.TbResultSetFuture;
40 40 import org.thingsboard.server.dao.relation.RelationService;
41 41 import org.thingsboard.server.dao.rule.RuleChainService;
42 42 import org.thingsboard.server.dao.tenant.TenantService;
... ... @@ -207,7 +207,7 @@ public interface TbContext {
207 207
208 208 CassandraCluster getCassandraCluster();
209 209
210   - ResultSetFuture submitCassandraTask(CassandraStatementTask task);
  210 + TbResultSetFuture submitCassandraTask(CassandraStatementTask task);
211 211
212 212 @Deprecated
213 213 RedisTemplate<String, Object> getRedisTemplate();
... ...
... ... @@ -134,6 +134,10 @@
134 134 <groupId>org.slf4j</groupId>
135 135 <artifactId>slf4j-log4j12</artifactId>
136 136 </exclusion>
  137 + <exclusion>
  138 + <groupId>org.hibernate</groupId>
  139 + <artifactId>hibernate-validator</artifactId>
  140 + </exclusion>
137 141 </exclusions>
138 142 <scope>test</scope>
139 143 </dependency>
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.rule.engine.action;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
19 18 import com.google.gson.Gson;
20 19 import com.google.gson.JsonObject;
21 20 import lombok.extern.slf4j.Slf4j;
... ... @@ -99,4 +98,4 @@ public class TbMsgCountNode implements TbNode {
99 98 @Override
100 99 public void destroy() {
101 100 }
102   -}
\ No newline at end of file
  101 +}
... ...