Skip to content
Cedrick Lunven edited this page Jun 21, 2021 · 51 revisions

License Apache2

Overview

The SDK makes it easy to call Stargate and/or Astra services using idiomatic Java APIs. On top of the SDK, the repository provides a Spring Boot starter to ease integration with Spring Application.

Installation

You need JDK 11.0.9+ and a dependency management tool such as Maven or Gradle. (The SDK has been build with the HttpClient provided in JDK 11) It is a single library providing support for the 5 API(s) listed above. Please change the SDK-version with the latest version.

Maven dependency in pom.xml

<dependency>
  <groupId>com.datastax.astra</groupId>
  <artifactId>astra-sdk-java</artifactId>
  <version>${SDK-version}</version>
</dependency>

Gradle dependency in build.gradle

dependencies {
    astra_sdk 'com.datastax.astra:astra-sdk-java:${sdk-version}'
}

Initialising the SDK with Astra

📘 Setup Astra Instance

To use Astra you need an Astra account and credentials with Astra Token. Then, based on the values you provided the underlying Apis will be enabled or not.

Please follow those 2 tutorials to set up your instance

📘 Setup AstraClient wrapper

AstraClient client = AstraClient.builder()
 .appToken("AstraCS:......").              // App Token will be used as ApiKey for Devops, Docs and REST Api.
 .databaseId("astra_cluster_id").          // Unique identifier for your instance
 .cloudProviderRegion("astra_db_region")   // Cloud Provider region picked for you instance

 // (For CqlSession only)
 .clientId("TWRvjlcrgfZYfhcxGZhUlAAA")     // Will be used as your username
 .clientSecret("7xKSrZPLbWxDJ0WXyj..")     // Will be used as your password
 .keyspace("ks1")                          // (optional) Set your keyspace
 .secureConnectBundle("/tmp/sec.zip").     // (optional) if not provided download in ~/.astra
 .build();

📘 Overview of parameters for AstraClient.builder

Param Name DevOps API REST and Docs API GraphQL API CqlSession API
application Token (part of token) required required required --
clientId (part of token) optional -- -- required
clientSecret (part of token) optional -- -- required
databaseId -- required required required
database Cloud Region -- required required required
keyspace -- -- -- optional
Secure Connect Bundle -- -- -- optional

Initialising the SDK with Local Stargate

Astra is not required to work with the SDK. A standalone installation of Stargate exposes the Rest/Document/Graph Apis and the CqlSession.

📘 Setup Stargate Instance

To install Stargate on your environment please check out the following guide

Instead of the token shown for Astra, you will use a user and a password and will authenticate against a dedicated authenticationUrl. Make sure to create a user at the Cassandra level and enable RBAC.

📘 Setup StargateClient wrapper

StargateClient client = StargateClient.builder()
  .username("k8ssandra-superuser")           // Mandatory username
  .password("JxzrPOnvDGqfEOQ0EySQ")          // Mandatory password
  .endPointAuth("http://localhost:8081")     // Mandatory authencation url, defaulting to http://localhost:8081
  .endPointRest("http://localhost:8082")     // Rest and Document Apis
  .endPointGraphQL("http://localhost:8080")  // GraphQL Api
  
  // Cqlsession Only
  .addCqlContactPoint("127.0.0.", 9042)      // Contact Point
  .localDc("dc1")                            // Local Datacenter is mandatory driver 4x+
  .keypace("ks1")                            // (optional) Set your keyspace
  .build();

📘 Overview of parameters for StargateClient.builder

Param Name REST and Doc APIs GraphQL API CqlSession API
username required required required
password required required required
Authentication endpoint required required required
Rest Api endpoint required -- --
GraphQL Api endpoint -- required --
Contact Points -- -- required
Local DataCenter Name (localDc) -- -- required
keyspace -- -- optional

Which Api to pick based on your needs

Choice Description
Operate Astra (provisionning, IAM) Use the Devops API
ReUse DataStax drivers Use the CQL API leveraging DataStax drivers to manage database connections for your application.
Use Schemaless Use schemaless JSON Documents with the Document API
Same interfaces as drivers in REST Use the REST API or GraphQL API to begin interacting with your database.