Skip to content

[3.4.2] Cassandra cloud connects to Datastax Astra DB#7110

Closed
smatvienko-tb wants to merge 1 commit into
thingsboard:develop/3.4.2from
smatvienko-tb:cassandra-cloud-astra
Closed

[3.4.2] Cassandra cloud connects to Datastax Astra DB#7110
smatvienko-tb wants to merge 1 commit into
thingsboard:develop/3.4.2from
smatvienko-tb:cassandra-cloud-astra

Conversation

@smatvienko-tb

@smatvienko-tb smatvienko-tb commented Aug 17, 2022

Copy link
Copy Markdown
Contributor

Cassandra cloud connects to Datastax Astra DB

This PR allows connecting to Cassandra on the cloud (Datastax Astra DB)

Decoupled 'CREATE KEYSPACE' into a separate service. For cloud, we have to create keyspace manually using cloud UI, then create a user and token to access the cloud.

Refactored GuavaSessionBuilder and GuavaDriverContext: deprecated constructor replaced to support the newest features, like cloud bundles.

new env vars in YAML:

    # /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:}"

The result is on the screenshots:
image
image
image

You need a 'Database administrator' role to install the Thingsboard schema
image

Schema install for on-premise Cassandra got a new line schema-keyspace.cql:
image

For the cloud install is running without creating keyspace:

image

Before decoupling keyspace creation, cloud install fired exception:
image

Before refactoring GuavaSessionBuilder and GuavaDriverContext the cloud connection failed like that:

2022-08-18 01:06:07,783 [s0-admin-1] WARN  c.d.o.d.i.c.c.ControlConnection - [s0] Error connecting to Node(endPoint=8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com:29042:a837fe38-9fd5-49a6-958e-7f7ca71ae890, hostId=null, hashCode=6d6ca852), trying next node (ConnectionInitException: [s0|control|id: 0xcd628587, L:/10.8.0.66:19332 - R:8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com/34.77.135.39:29042] Protocol initialization request, step 1 (OPTIONS): unexpected failure (com.datastax.oss.driver.api.core.connection.ClosedConnectionException: Lost connection to remote peer))
2022-08-18 01:06:07,887 [s0-admin-1] WARN  c.d.o.d.i.c.c.ControlConnection - [s0] Error connecting to Node(endPoint=8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com:29042:b16cc260-ee81-4017-b6cf-6b793a5b9935, hostId=null, hashCode=1808cb7d), trying next node (ConnectionInitException: [s0|control|id: 0x9dd712b1, L:/10.8.0.66:12602 - R:8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com/34.78.6.86:29042] Protocol initialization request, step 1 (OPTIONS): unexpected failure (com.datastax.oss.driver.api.core.connection.ClosedConnectionException: Lost connection to remote peer))
2022-08-18 01:06:07,995 [s0-admin-1] WARN  c.d.o.d.i.c.c.ControlConnection - [s0] Error connecting to Node(endPoint=8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com:29042:ba266e06-dfa4-4171-88cb-75758881bcba, hostId=null, hashCode=160cca48), trying next node (ConnectionInitException: [s0|control|id: 0x16f5a8ec, L:/10.8.0.66:38954 - R:8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com/34.140.171.129:29042] Protocol initialization request, step 1 (OPTIONS): unexpected failure (com.datastax.oss.driver.api.core.connection.ClosedConnectionException: Lost connection to remote peer))

com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 3 nodes, use getAllErrors() for more): Node(endPoint=8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com:29042:a837fe38-9fd5-49a6-958e-7f7ca71ae890, hostId=null, hashCode=6d6ca852): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|id: 0xcd628587, L:/10.8.0.66:19332 - R:8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com/34.77.135.39:29042] Protocol initialization request, step 1 (OPTIONS): unexpected failure (com.datastax.oss.driver.api.core.connection.ClosedConnectionException: Lost connection to remote peer)], Node(endPoint=8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com:29042:b16cc260-ee81-4017-b6cf-6b793a5b9935, hostId=null, hashCode=1808cb7d): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|id: 0x9dd712b1, L:/10.8.0.66:12602 - R:8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com/34.78.6.86:29042] Protocol initialization request, step 1 (OPTIONS): unexpected failure (com.datastax.oss.driver.api.core.connection.ClosedConnectionException: Lost connection to remote peer)], Node(endPoint=8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com:29042:ba266e06-dfa4-4171-88cb-75758881bcba, hostId=null, hashCode=160cca48): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|id: 0x16f5a8ec, L:/10.8.0.66:38954 - R:8ca57896-18c4-4a61-bb26-e2fc05985081-europe-west1.db.astra.datastax.com/34.140.171.129:29042] Protocol initialization request, step 1 (OPTIONS): unexpected failure (com.datastax.oss.driver.api.core.connection.ClosedConnectionException: Lost connection to remote peer)]

The total spending during the test takes about 8 hours with 3k telemetry points per second:
image

Test with docker-compose.yml :

version: '3'
services:
  tb:
    image: "thingsboard/tb-postgres:3.4.1-SNAPSHOT"
    network_mode: "host"
    restart: "always"
    volumes:
      - /home/your_user/projects/astra/secure-connect-thingsboard.zip:/etc/thingsboard/astra/secure-connect-thingsboard.zip
    environment:
      HTTP_BIND_PORT: "8080"
      DATABASE_TS_TYPE: "cassandra"
      PERSIST_STATE_TO_TELEMETRY: "true" # Persist device state to the Cassandra. Default is false (Postgres, as device server_scope attributes)
      # Cassandra on cloud
      CASSANDRA_CLOUD_SECURE_BUNDLE_PATH: "/etc/thingsboard/astra/secure-connect-thingsboard.zip"
      # dbadmin
      CASSANDRA_CLOUD_CLIENT_ID: "KNpxZasfKNpxZasfKNpxZasf"
      CASSANDRA_CLOUD_CLIENT_SECRET: "6Rht+1oh8H_v4f3dbFiZ.KHBim6Rht+1oh8H_v4f3dbFiZ.KHBim6Rht+1oh8H_v4f3dbFiZ.KHBim"

Performance test to put some telemetry:

docker run -it --rm --network host --name tb-perf-test \
           --pull always --log-driver none \
           --env REST_URL=http://127.0.0.1:8080 \
           --env MQTT_HOST=127.0.0.1 \
           --env REST_USERNAME=tenant@thingsboard.org \
           --env REST_PASSWORD=tenant \
           --env DEVICE_END_IDX=1111 \
           --env MESSAGES_PER_SECOND=1000 \
           --env DURATION_IN_SECONDS=86400 \
           --env ALARMS_PER_SECOND=1 \
           --env DEVICE_CREATE_ON_START=true \
           --env TEST_PAYLOAD_TYPE=SMART_METER \
           thingsboard/tb-ce-performance-test:latest

General checklist

  • You have reviewed the guidelines document.
  • PR name contains fix version. For example, "[3.3.4] Hotfix of some UI component" or "[3.4] New Super Feature".
  • Description references specific issue.
  • Description contains human-readable scope of changes.
  • Description contains brief notes about what needs to be added to the documentation.
  • No merge conflicts, commented blocks of code, code formatting issues.
  • Changes are backward compatible or upgrade script is provided.
  • Similar PR is opened for PE version to simplify merge. Required for internal contributors only.

Front-End feature checklist

  • Screenshots with affected component(s) are added. The best option is to provide 2 screens: before and after changes;
  • If you change the widget or other API, ensure it is backward-compatible or upgrade script is present.
  • Ensure new API is documented here

Back-End feature checklist

  • Added corresponding unit and/or integration test(s). Provide written explanation in the PR description if you have failed to add tests.
  • If new dependency was added: the dependency tree is checked for conflicts.
  • If new service was added: the service is marked with corresponding @TbCoreComponent, @TbRuleEngineComponent, @TbTransportComponent, etc.
  • If new REST API was added: the RestClient.java was updated, issue for Python REST client is created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants