Skip to content
Cedrick Lunven edited this page Sep 8, 2021 · 51 revisions

License Apache2

Overview

This SDK (Software Development Kit) makes it easy to call Stargate and/or Astra services using idiomatic Java APIs. On top of clients for the different API, the SDK provides a Spring Boot starter to ease integration with Spring Applications.

overview of the SDK coverage

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 Central

Maven dependency in pom.xml

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

Gradle dependency in build.gradle

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

Initialising SDK to work with Astra

📘 (a) Prerequisite: Setup Astra your Instance

You will need an Astra account and some credentials (Astra Token). Based on the provided parameters the underlying Apis will be enabled or not. (devops, rest data, rest document graphQL, pulsar client)

Please follow those 2 tutorials to set up your Astra instance:

📘 (b) Setup AstraClient object

AstraClient client = AstraClient.builder()
 .databaseId("astra_cluster_id")           // Unique identifier for your database instance
 .cloudProviderRegion("astra_db_region")   // Cloud Provider region picked for you instance
 .keyspace("ks1")                          // (optional) Set your keyspace

 .appToken("AstraCS:......")               // App Token will be used as ApiKey for Devops, Docs and REST Api.
 .clientId("TWRvjlcrgfZYfhcxGZhUlAAA")     // Will be used as your username
 .clientSecret("7xKSrZPLbWxDJ0WXyj..")     // Will be used as your password

 .secureConnectBundle("/tmp/sec.zip")      // (optional) if not provided download in ~/.astra
 .build();

📘 (c) Overview of parameters for AstraClient.builder

Param Name DevOps API REST and Docs API GraphQL API CqlSession API Pulsar Client
appToken (part of token) required 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 Rest,Document, Graph Apis but also the CqlSession.

📘 (a) 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

📘 Working with file ~/.astrarc

cat ~/.astrarc

[default]
ASTRA_DB_APPLICATION_TOKEN=AstraCS:GmSdU.....
ASTRA_DB_CLIENT_ID=GmSdUgw....
ASTRA_DB_CLIENT_SECRET=pL7QcZgN....
ASTRA_DB_ID=33a7527a-aaf9-4f9f-9758-96216efff3d5
ASTRA_DB_KEYSPACE=ks1
ASTRA_DB_REGION=eu-central-1
ASTRA_DB_SECURE_BUNDLE=

[sandbox]
ASTRA_DB_APPLICATION_TOKEN=AstraCS:GmSdU.....
ASTRA_DB_CLIENT_ID=GmSdUgw....
ASTRA_DB_CLIENT_SECRET=pL7QcZgN....
ASTRA_DB_ID=33a7527a-aaf9-4f9f-9758-96216efff3d5
ASTRA_DB_KEYSPACE=ks1
ASTRA_DB_REGION=eu-central-1
ASTRA_DB_SECURE_BUNDLE=

## 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](/Astra-Document-API)|
|**Same interfaces as drivers in REST**| Use the [REST API]() or [GraphQL API]() to begin interacting with your database.|


Clone this wiki locally