Skip to content

Commit

Permalink
Add cassandra support
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiLandiak committed Nov 8, 2024
1 parent 697dd8a commit 0ea2094
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void clearEvents(@Parameter(description = ENTITY_TYPE_PARAM_DESCRIPTION,
checkParameter("EntityId", strEntityId);
checkParameter("EntityType", strEntityType);
EntityId entityId = EntityIdFactory.getByTypeAndId(strEntityType, strEntityId);
// TODO: voba - merge comment
// Edge-only: only READ operation
// checkEntityId(entityId, Operation.WRITE);
checkEntityId(entityId, Operation.READ);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public void createOAuth2Templates() throws Exception {

@Override
public void loadDemoData() throws Exception {
/* voba - merge comment
/* Edge-only: no ability to load demo data on Edge
Tenant demoTenant = new Tenant();
demoTenant.setRegion("Global");
demoTenant.setTitle("Tenant");
Expand Down
117 changes: 115 additions & 2 deletions application/src/main/resources/tb-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,122 @@ ui:
database:
ts_max_intervals: "${DATABASE_TS_MAX_INTERVALS:700}" # Max number of DB queries generated by a single API call to fetch telemetry records
ts:
type: "${DATABASE_TS_TYPE:sql}" # sql or timescale (for hybrid mode, DATABASE_TS_TYPE value should be timescale)
type: "${DATABASE_TS_TYPE:sql}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)
ts_latest:
type: "${DATABASE_TS_LATEST_TYPE:sql}" # sql or timescale (for hybrid mode, DATABASE_TS_TYPE value should be timescale)
type: "${DATABASE_TS_LATEST_TYPE:sql}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)

# Cassandra driver configuration parameters
cassandra:
# Thingsboard cluster name
cluster_name: "${CASSANDRA_CLUSTER_NAME:Thingsboard Cluster}"
# Thingsboard keyspace name
keyspace_name: "${CASSANDRA_KEYSPACE_NAME:thingsboard}"
# Specify node list
url: "${CASSANDRA_URL:127.0.0.1:9042}"
# Specify the local data center name
local_datacenter: "${CASSANDRA_LOCAL_DATACENTER:datacenter1}"
ssl:
# Enable/disable secure connection
enabled: "${CASSANDRA_USE_SSL:false}"
# Enable/disable validation of Cassandra server hostname
# If enabled, the hostname of the Cassandra server must match the CN of the server certificate
hostname_validation: "${CASSANDRA_SSL_HOSTNAME_VALIDATION:true}"
# Set trust store for client authentication of the server (optional, uses trust store from default SSLContext if not set)
trust_store: "${CASSANDRA_SSL_TRUST_STORE:}"
# The password for Cassandra trust store key
trust_store_password: "${CASSANDRA_SSL_TRUST_STORE_PASSWORD:}"
# Set key store for server authentication of the client (optional, uses key store from default SSLContext if not set)
# A key store is only needed if the Cassandra server requires client authentication
key_store: "${CASSANDRA_SSL_KEY_STORE:}"
# The password for the Cassandra key store
key_store_password: "${CASSANDRA_SSL_KEY_STORE_PASSWORD:}"
# Comma-separated list of cipher suites (optional, uses Java default cipher suites if not set)
cipher_suites: "${CASSANDRA_SSL_CIPHER_SUITES:}"
# Enable/disable JMX
jmx: "${CASSANDRA_USE_JMX:false}"
# Enable/disable metrics collection.
metrics: "${CASSANDRA_USE_METRICS:false}"
# NONE SNAPPY LZ4
compression: "${CASSANDRA_COMPRESSION:none}"
# Specify cassandra cluster initialization timeout in milliseconds (if no hosts are available during startup)
init_timeout_ms: "${CASSANDRA_CLUSTER_INIT_TIMEOUT_MS:300000}"
# Specify cassandra cluster initialization retry interval (if no hosts available during startup)
init_retry_interval_ms: "${CASSANDRA_CLUSTER_INIT_RETRY_INTERVAL_MS:3000}"
# Cassandra max local requests per connection
max_requests_per_connection_local: "${CASSANDRA_MAX_REQUESTS_PER_CONNECTION_LOCAL:32768}"
# Cassandra max remote requests per connection
max_requests_per_connection_remote: "${CASSANDRA_MAX_REQUESTS_PER_CONNECTION_REMOTE:32768}"
# Credential parameters
credentials: "${CASSANDRA_USE_CREDENTIALS:false}"
# Specify your username
username: "${CASSANDRA_USERNAME:}"
# Specify your password
password: "${CASSANDRA_PASSWORD:}"
# Astra DB connect https://astra.datastax.com/
cloud:
# /etc/thingsboard/astra/secure-connect-thingsboard.zip
secure_connect_bundle_path: "${CASSANDRA_CLOUD_SECURE_BUNDLE_PATH:}"
# DucitQPHMzPCBOZqFYexAfKk
client_id: "${CASSANDRA_CLOUD_CLIENT_ID:}"
# ZnF7FpuHp43FP5BzM+KY8wGmSb4Ql6BhT4Z7sOU13ze+gXQ-n7OkFpNuB,oACUIQObQnK0g4bSPoZhK5ejkcF9F.j6f64j71Sr.tiRe0Fsq2hPS1ZCGSfAaIgg63IydG
client_secret: "${CASSANDRA_CLOUD_CLIENT_SECRET:}"

# Cassandra cluster connection socket parameters #
socket:
# Sets the timeout, in milliseconds, of a native connection from ThingsBoard to Cassandra. The default value is 5000
connect_timeout: "${CASSANDRA_SOCKET_TIMEOUT:5000}"
# Timeout before closing the connection. Value set in milliseconds
read_timeout: "${CASSANDRA_SOCKET_READ_TIMEOUT:20000}"
# Gets if TCP keep-alive must be used
keep_alive: "${CASSANDRA_SOCKET_KEEP_ALIVE:true}"
# Enable/Disable reuse-address. The socket option allows for the reuse of local addresses and ports
reuse_address: "${CASSANDRA_SOCKET_REUSE_ADDRESS:true}"
# Sets the linger-on-close timeout. By default, this option is not set by the driver. The actual value will be the default from the underlying Netty transport
so_linger: "${CASSANDRA_SOCKET_SO_LINGER:}"
# Enable/Disable Nagle's algorithm
tcp_no_delay: "${CASSANDRA_SOCKET_TCP_NO_DELAY:false}"
# Sets a hint to the size of the underlying buffers for incoming network I/O. By default, this option is not set by the driver. The actual value will be the default from the underlying Netty transport
receive_buffer_size: "${CASSANDRA_SOCKET_RECEIVE_BUFFER_SIZE:}"
# Returns the hint to the size of the underlying buffers for outgoing network I/O. By default, this option is not set by the driver. The actual value will be the default from the underlying Netty transport
send_buffer_size: "${CASSANDRA_SOCKET_SEND_BUFFER_SIZE:}"

# Cassandra cluster connection query parameters
query:
# Consistency levels in Cassandra can be configured to manage availability versus data accuracy. The consistency level defaults to ONE for all write and read operations
read_consistency_level: "${CASSANDRA_READ_CONSISTENCY_LEVEL:ONE}"
# Consistency levels in Cassandra can be configured to manage availability versus data accuracy. The consistency level defaults to ONE for all write and read operations
write_consistency_level: "${CASSANDRA_WRITE_CONSISTENCY_LEVEL:ONE}"
# The fetch size specifies how many rows will be returned at once by Cassandra (in other words, it’s the size of each page)
default_fetch_size: "${CASSANDRA_DEFAULT_FETCH_SIZE:2000}"
# Specify partitioning size for timestamp key-value storage. Example: MINUTES, HOURS, DAYS, MONTHS, INDEFINITE
ts_key_value_partitioning: "${TS_KV_PARTITIONING:MONTHS}"
# Enable/Disable timestamp key-value partioning on read queries
use_ts_key_value_partitioning_on_read: "${USE_TS_KV_PARTITIONING_ON_READ:true}"
# The number of partitions that are cached in memory of each service. It is useful to decrease the load of re-inserting the same partitions again
ts_key_value_partitions_max_cache_size: "${TS_KV_PARTITIONS_MAX_CACHE_SIZE:100000}"
# Timeseries Time To Live (in seconds) for Cassandra Record. 0 - record has never expired
ts_key_value_ttl: "${TS_KV_TTL:0}"
# Maximum number of Cassandra queries that are waiting for execution
buffer_size: "${CASSANDRA_QUERY_BUFFER_SIZE:200000}"
# Maximum number of concurrent Cassandra queries
concurrent_limit: "${CASSANDRA_QUERY_CONCURRENT_LIMIT:1000}"
# Max time in milliseconds query waits for execution
permit_max_wait_time: "${PERMIT_MAX_WAIT_TIME:120000}"
# Amount of threads to dispatch cassandra queries
dispatcher_threads: "${CASSANDRA_QUERY_DISPATCHER_THREADS:2}"
callback_threads: "${CASSANDRA_QUERY_CALLBACK_THREADS:4}" # Buffered rate executor (read, write) for managing I/O rate. See "nosql-*-callback" threads in JMX
result_processing_threads: "${CASSANDRA_QUERY_RESULT_PROCESSING_THREADS:50}" # Result set transformer and processing. See "cassandra-callback" threads in JMX
# Cassandra query queue polling interval in milliseconds
poll_ms: "${CASSANDRA_QUERY_POLL_MS:50}"
# Interval in milliseconds for printing Cassandra query queue statistic
rate_limit_print_interval_ms: "${CASSANDRA_QUERY_RATE_LIMIT_PRINT_MS:10000}"
# set all data type values except target to null for the same ts on save
set_null_values_enabled: "${CASSANDRA_QUERY_SET_NULL_VALUES_ENABLED:true}"
# log one of cassandra queries with specified frequency (0 - logging is disabled)
print_queries_freq: "${CASSANDRA_QUERY_PRINT_FREQ:0}"
tenant_rate_limits:
# Whether to print rate-limited tenant names when printing Cassandra query queue statistic
print_tenant_names: "${CASSANDRA_QUERY_TENANT_RATE_LIMITS_PRINT_TENANT_NAMES:false}"

# SQL configuration parameters
sql:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.thingsboard.server.dao.service.DaoNoSqlTest;
import org.thingsboard.server.transport.coap.telemetry.timeseries.AbstractCoapTimeseriesIntegrationTest;

// Edge-only: merge comment
// NoSQL is not supported on edge
// @DaoNoSqlTest
@DaoNoSqlTest
public class CoapTimeseriesNoSqlIntegrationTest extends AbstractCoapTimeseriesIntegrationTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.thingsboard.server.dao.service.DaoNoSqlTest;
import org.thingsboard.server.transport.coap.telemetry.timeseries.AbstractCoapTimeseriesJsonIntegrationTest;

// Edge-only: merge comment
// NoSQL is not supported on edge
// @DaoNoSqlTest
@DaoNoSqlTest
public class CoapTimeseriesNoSqlJsonIntegrationTest extends AbstractCoapTimeseriesJsonIntegrationTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.thingsboard.server.dao.service.DaoNoSqlTest;
import org.thingsboard.server.transport.coap.telemetry.timeseries.AbstractCoapTimeseriesProtoIntegrationTest;

// Edge-only: merge comment
// NoSQL is not supported on edge
// @DaoNoSqlTest
@DaoNoSqlTest
public class CoapTimeseriesNoSqlProtoIntegrationTest extends AbstractCoapTimeseriesProtoIntegrationTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.thingsboard.server.dao.service.DaoNoSqlTest;
import org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest;

// Edge-only: merge comment
// NoSQL is not supported on edge
// @DaoNoSqlTest
@DaoNoSqlTest
public class MqttTimeseriesNoSqlIntegrationTest extends AbstractMqttTimeseriesIntegrationTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.thingsboard.server.dao.service.DaoNoSqlTest;
import org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.AbstractMqttTimeseriesJsonIntegrationTest;

// Edge-only: merge comment
// NoSQL is not supported on edge
// @DaoNoSqlTest
@DaoNoSqlTest
public class MqttTimeseriesNoSqlJsonIntegrationTest extends AbstractMqttTimeseriesJsonIntegrationTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.thingsboard.server.dao.service.DaoNoSqlTest;
import org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.AbstractMqttTimeseriesProtoIntegrationTest;

// Edge-only: merge comment
// NoSQL is not supported on edge
// @DaoNoSqlTest
@DaoNoSqlTest
public class MqttTimeseriesNoSqlProtoIntegrationTest extends AbstractMqttTimeseriesProtoIntegrationTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import org.junit.extensions.cpsuite.ClasspathSuite.ClassnameFilters;
import org.junit.runner.RunWith;

// Edge-only: merge comment
// Timescale DB is not supported on edge
// @RunWith(ClasspathSuite.class)
@RunWith(ClasspathSuite.class)
@ClassnameFilters({
"org.thingsboard.server.dao.service.*.nosql.*ServiceTimescaleTest",
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,6 @@ public void testFindDeviceById() {

@Test
public void testFindDeviceTypesByTenantId() throws Exception {

// TODO: @voba device profiles are not created on edge at the moment
deviceProfileService.findOrCreateDeviceProfile(tenantId, "typeA");
deviceProfileService.findOrCreateDeviceProfile(tenantId, "typeB");
deviceProfileService.findOrCreateDeviceProfile(tenantId, "typeC");

List<Device> devices = new ArrayList<>();
try {
for (int i = 0; i < 3; i++) {
Expand Down Expand Up @@ -734,11 +728,6 @@ public void testFindDevicesByTenantIdAndName() {

@Test
public void testFindDevicesByTenantIdAndType() {

// TODO: @voba device profiles are not created on edge at the moment
deviceProfileService.findOrCreateDeviceProfile(tenantId, "typeA");
deviceProfileService.findOrCreateDeviceProfile(tenantId, "typeB");

String title1 = "Device title 1";
String type1 = "typeA";
List<Device> devicesType1 = new ArrayList<>();
Expand Down Expand Up @@ -948,10 +937,6 @@ public void testFindDevicesByTenantIdCustomerIdAndName() {
@Test
public void testFindDevicesByTenantIdCustomerIdAndType() {

// TODO: @voba device profiles are not created on edge at the moment
deviceProfileService.findOrCreateDeviceProfile(tenantId, "typeC");
deviceProfileService.findOrCreateDeviceProfile(tenantId, "typeD");

Customer customer = new Customer();
customer.setTitle("Test customer");
customer.setTenantId(tenantId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class AdminSettingsClientTest extends AbstractContainerTest {

@Test
public void testTenantAdminSettings() {
// TODO: voba

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

boolean ruleChainNode() default false;

// TODO: voba - merge comment
// Edge-only: RuleChainType.EDGE exists only on Cloud side
//RuleChainType[] ruleChainTypes() default {RuleChainType.CORE, RuleChainType.EDGE};

RuleChainType[] ruleChainTypes() default {RuleChainType.CORE};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<mat-icon>close</mat-icon>{{ 'action.cancel' | translate }}</button>
<mat-divider class="tb-toolbar-divider" vertical></mat-divider>
</ng-container>
<!-- @voba: not visible on edge
<!-- Edge-only: not visible on edge
<ng-container *ngIf="currentDashboardId && isEdit && isTenantAdmin()">
<button class="lt-lg:!hidden gt-lg:!hidden" mat-icon-button
#versionControlIconButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
[class.!hidden]="isEdit">
{{'device-profile.export' | translate }}
</button>
<!-- @voba: not visible on edge
<!-- Edge-only: not visible on edge
<button mat-raised-button color="primary"
[disabled]="(isLoading$ | async)"
(click)="onEntityAction($event, 'setDefault')"
Expand Down Expand Up @@ -79,7 +79,7 @@
[queueType]="serviceType"
formControlName="defaultQueueName">
</tb-queue-autocomplete>
<!-- @voba: not visible on edge
<!-- Edge-only: not visible on edge
<tb-rule-chain-autocomplete
labelText="device-profile.default-edge-rule-chain"
formControlName="defaultEdgeRuleChainId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class DeviceProfilesTableConfigResolver {
isEnabled: () => true,
onAction: ($event, entity) => this.exportDeviceProfile($event, entity)
},
/* @voba: not visible on edge
/* Edge-only: not visible on edge
{
name: this.translate.instant('device-profile.set-default'),
icon: 'flag',
Expand Down

0 comments on commit 0ea2094

Please sign in to comment.