Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

article

Erick Ramirez avatar image
Erick Ramirez posted Erick Ramirez edited

HOW TO - Connect to Astra DB from JanusGraph

Overview

This article provides the steps for connecting to Astra DB from a JanusGraph server.

JanusGraph uses the Java driver to connect to Cassandra as the storage backend. The Java driver itself supports connections to Astra DB natively. For example:

CqlSession session = CqlSession.builder()
  .withCloudSecureConnectBundle(Paths.get("/path/to/secure-connect-db_name.zip"))
  .withAuthCredentials("token", ASTRA_APP_TOKEN)
  .withKeyspace("keyspace_name")
  .build();

However, JanusGraph does not expose this functionality so you will need to manually unpack the secure connect bundle and use its contents to configure JanusGraph.

At a high level, it involves:

  1. Generating an application token for your Astra DB.
  2. Downloading the secure bundle for your Astra DB.
  3. Configuring your JanusGraph installation.

Prerequisites

This article assumes you have a running installation of JanusGraph server. This was written and tested on JanusGraph v0.6.0. It has not been tested on older versions of JanusGraph.

You will also need to generate an application token and download the secure bundle for your Astra DB.

You will need to choose which keyspace to use to store your graph. If it doesn't exist, you will need to create the keyspace on the Astra UI.

Procedure

NOTE: For simplicity, the secure connect bundle has been placed in /path/to/scb.

DB INFORMATION

On the JanusGraph server, unpack your secure bundle. For example:

$ cd /path/to/scb
$ unzip secure-connect-getvaxxed.zip

Here is an example file listing after unpacking the bundle:

/
  path/
    to/
      scb/
        ca.crt
        cert
        cert.pfx
        config.json
        cqlshrc
        identity.jks
        key
        trustStore.jks

Obtain information about your database from the config.json file. Here is an example:

{
  "host": "70bf8560-105f-11ec-a3ea-0800200c9a66-us-west1.db.astra.datastax.com",
  "port": 98765,
  "cql_port": 34567,
  "keyspace": "getvaxxed",
  "localDC": "us-west1",
  "caCertLocation": "./ca.crt",
  "keyLocation": "./key",
  "certLocation": "./cert",
  "keyStoreLocation": "./identity.jks",
  "keyStorePassword": "Kga1OJ83EF2oBQYR5",
  "trustStoreLocation": "./trustStore.jks",
  "trustStorePassword": "n8F9ptJO3H7YRxTW1",
  "csvLocation": "./data",
  "pfxCertPassword": "9b3HgFChtY60m4nfJ"
}

We will use this information to configure Astra DB as the storage backend for JanusGraph.

GRAPH STORAGE

On the JanusGraph server, modify the CQL storage configuration file:

$ cd janusgraph-0.6.0
$ vi conf/janusgraph-cql.properties

Make the necessary changes using this template:

# basic CQL settings
gremlin.graph=org.janusgraph.core.JanusGraphFactory
storage.backend=cql
storage.hostname=CONFIG-JSON-HOST
storage.port=CONFIG-JSON-CQL-PORT
storage.username=token               <----- do NOT change this
storage.password=ASTRA_APP_TOKEN
storage.cql.keyspace=GRAPH_KEYSPACE
storage.cql.local-datacenter=CONFIG-JSON-LOCALDC

# SSL related settings
storage.cql.ssl.enabled=true
storage.cql.ssl.truststore.location=/path/to/scb/trustStore.jks
storage.cql.ssl.truststore.password=CONFIG-JSON-TRUSTSTOREPASSWORD
storage.cql.ssl.keystore.location=/path/to/scb/identity.jks
storage.cql.ssl.keystore.keypassword=CONFIG-JSON-KEYSTOREPASSWORD
storage.cql.ssl.keystore.storepassword=CONFIG-JSON-KEYSTOREPASSWORD
storage.cql.ssl.client-authentication-enabled=true

# consistency settings
storage.cql.read-consistency-level=LOCAL_QUORUM
storage.cql.write-consistency-level=LOCAL_QUORUM

WARNING - The username to connect to Astra is the literal string token. Do NOT set this value to your DB's client ID.

IMPORTANT - The ASTRA_APP_TOKEN is from the token you generated in the Prerequisites section above.

Using the example values in the config.json above, my conf/janusgraph-cql.properties would contain:

# basic CQL settings
gremlin.graph=org.janusgraph.core.JanusGraphFactory
storage.backend=cql
storage.hostname=70bf8560-105f-11ec-a3ea-0800200c9a66-us-west1.db.astra.datastax.com
storage.port=34567
storage.username=token
storage.password=AstraCS:AbCwZYOKqvXHZWRvpbvHqXYz:47820923e5be3b7b9e689bc18614c631d5fdd8b435e68613433651fd20fexyz0
storage.cql.keyspace=getvaxxed
storage.cql.local-datacenter=us-west1

# SSL related settings
storage.cql.ssl.enabled=true
storage.cql.ssl.truststore.location=/path/to/scb/trustStore.jks
storage.cql.ssl.truststore.password=n8F9ptJO3H7YRxTW1
storage.cql.ssl.keystore.location=/path/to/scb/identity.jks
storage.cql.ssl.keystore.keypassword=Kga1OJ83EF2oBQYR5
storage.cql.ssl.keystore.storepassword=Kga1OJ83EF2oBQYR5
storage.cql.ssl.client-authentication-enabled=true

# consistency settings
storage.cql.read-consistency-level=LOCAL_QUORUM
storage.cql.write-consistency-level=LOCAL_QUORUM

Final test

Start a Gremlin console:

$ bin/gremlin.sh

         \,,,/
         (o o)
-----oOOo-(3)-oOOo-----
gremlin>

Load a graph using Astra as the storage backend with:

gremlin> graph = JanusGraphFactory.open('conf/janusgraph-cql.properties')
==>standardjanusgraph[cql:[70bf8560-105f-11ec-a3ea-0800200c9a66-us-west1.db.astra.datastax.com]]

Note that it is normal to see some warnings on the Gremlin console. I have attached a text file with a sample output so you know what to expect.

In the Astra CQL Console, I can see JanusGraph created the following tables in the getvaxxed keyspace:

token@cqlsh> USE getvaxxed;
token@cqlsh:getvaxxed> DESCRIBE TABLES;

edgestore_lock_  graphindex_lock_         janusgraph_ids   
txlog            systemlog                graphindex       
edgestore        system_properties_lock_  system_properties
astra dbjanusgraph
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Article

Contributors

Erick Ramirez contributed to this article