Class AstraClientConfig

java.lang.Object
com.datastax.astra.sdk.config.AstraClientConfig
All Implemented Interfaces:
Serializable

public class AstraClientConfig extends Object implements Serializable
Helper and configure for Astra.
Author:
Cedrick LUNVEN (@clunven)
See Also:
  • Field Details

    • ENV_USER_HOME

      public static final String ENV_USER_HOME
      User home folder.
      See Also:
    • DEFAULT_SCB_FOLDER

      public static final String DEFAULT_SCB_FOLDER
      Where to download cloud secure bundles.
    • ASTRA_DB_ID

      public static final String ASTRA_DB_ID
      Initialize parameters from Environment variables.
      See Also:
    • ASTRA_DB_REGION

      public static final String ASTRA_DB_REGION
      ENV VAR to get current or default region (local datacenter).
      See Also:
    • ASTRA_DB_CLIENT_ID

      public static final String ASTRA_DB_CLIENT_ID
      ENV VAR to get part of the token: client id.
      See Also:
    • ASTRA_DB_CLIENT_SECRET

      public static final String ASTRA_DB_CLIENT_SECRET
      ENV VAR to get part of the token: client Secret.
      See Also:
    • ASTRA_DB_KEYSPACE

      public static final String ASTRA_DB_KEYSPACE
      ENV VAR to get the keyspace to be selected.
      See Also:
    • ASTRA_DB_SCB_FOLDER

      public static final String ASTRA_DB_SCB_FOLDER
      SECURE BUNDLE FOR EACH REGIONS.
      See Also:
    • GRPC_PORT

      public static final int GRPC_PORT
      Port for grpc in Astra.
      See Also:
  • Constructor Details

    • AstraClientConfig

      public AstraClientConfig()
      Reading environment variables
  • Method Details

    • withToken

      public AstraClientConfig withToken(String applicationToken)
      Provide token.
      Parameters:
      applicationToken - token
      Returns:
      self reference
    • withClientId

      public AstraClientConfig withClientId(String clientId)
      Provide clientId.
      Parameters:
      clientId - clientId
      Returns:
      self reference
    • withClientSecret

      public AstraClientConfig withClientSecret(String clientSecret)
      Provide clientSecret.
      Parameters:
      clientSecret - clientSecret
      Returns:
      self reference
    • getToken

      public String getToken()
      Getter accessor for attribute 'token'.
      Returns:
      current value of 'token'
    • getClientId

      public String getClientId()
      Getter accessor for attribute 'clientId'.
      Returns:
      current value of 'clientId'
    • getClientSecret

      public String getClientSecret()
      Getter accessor for attribute 'clientSecret'.
      Returns:
      current value of 'clientSecret'
    • withDatabaseId

      public AstraClientConfig withDatabaseId(String databaseId)
      Provider database identifier
      Parameters:
      databaseId - databaseId
      Returns:
      self reference
    • withDatabaseRegion

      public AstraClientConfig withDatabaseRegion(String databaseRegion)
      Provider database identifier
      Parameters:
      databaseRegion - databaseRegion
      Returns:
      self reference
    • getDatabaseId

      public String getDatabaseId()
      Getter accessor for attribute 'databaseId'.
      Returns:
      current value of 'databaseId'
    • getDatabaseRegion

      public String getDatabaseRegion()
      Getter accessor for attribute 'databaseRegion'.
      Returns:
      current value of 'databaseRegion'
    • getStargateConfig

      public io.stargate.sdk.StargateClientBuilder getStargateConfig()
      Getter accessor for attribute 'stargateConfig'.
      Returns:
      current value of 'stargateConfig'
    • withHttpRequestConfig

      public AstraClientConfig withHttpRequestConfig(org.apache.hc.client5.http.config.RequestConfig reqConfig)
      Enable fine Grained configuration of the HTTP Client.
      Parameters:
      reqConfig - request configuration
      Returns:
      self reference
    • withHttpRetryConfig

      public AstraClientConfig withHttpRetryConfig(com.evanlennick.retry4j.config.RetryConfig retryConfig)
      Enable fine Grained configuration of the HTTP Retries.
      Parameters:
      retryConfig - retry configuration
      Returns:
      self reference
    • addHttpObserver

      public AstraClientConfig addHttpObserver(String name, io.stargate.sdk.audit.ServiceCallObserver observer)
      Api Invocations trigger some events processed in observer.
      Parameters:
      name - unique identifier
      observer - instance of your Observer
      Returns:
      self reference
    • withHttpObservers

      public AstraClientConfig withHttpObservers(Map<String,io.stargate.sdk.audit.ServiceCallObserver> observers)
      Api Invocations trigger some events processed in observer.
      Parameters:
      observers - observers lists
      Returns:
      self reference
    • enableGrpc

      public AstraClientConfig enableGrpc()
      Enable gRPC
      Returns:
      reference enforcing cqlSession disabled
    • getSecureConnectBundleFolder

      public String getSecureConnectBundleFolder()
      Getter accessor for attribute 'secureConnectBundleFolder'.
      Returns:
      current value of 'secureConnectBundleFolder'
    • secureConnectBundleFolder

      public AstraClientConfig secureConnectBundleFolder(String path)
      Provide path of the SCB.
      Parameters:
      path - target scb
      Returns:
      reference to current scb
    • isEnabledDownloadSecureConnectBundle

      public boolean isEnabledDownloadSecureConnectBundle()
      Getter for downloadSecureConnectBundle.
      Returns:
      downloadSecureConnectBundle value
    • isEnabledCrossRegionFailOver

      public boolean isEnabledCrossRegionFailOver()
      Getter for crossRegionFailOver.
      Returns:
      crossRegionFailOver value
    • enableDownloadSecureConnectBundle

      public AstraClientConfig enableDownloadSecureConnectBundle()
      Enable SCB downloads.
      Returns:
      current reference.
    • enableCrossRegionFailOver

      public AstraClientConfig enableCrossRegionFailOver()
      Enable crossRegionFailOver
      Returns:
      current reference.
    • disableDownloadSecureConnectBundle

      public AstraClientConfig disableDownloadSecureConnectBundle()
      Disable SCB downloads.
      Returns:
      current reference.
    • disableCrossRegionFailOver

      public AstraClientConfig disableCrossRegionFailOver()
      Disable crossRegionFailOver
      Returns:
      current reference.
    • withCqlCloudSecureConnectBundle

      public AstraClientConfig withCqlCloudSecureConnectBundle(String scbFile)
      Populate Secure connect bundle
      Parameters:
      scbFile - path of cloud secure bundle
      Returns:
      current reference
    • enableCql

      public AstraClientConfig enableCql()
      Enable CqlSession
      Returns:
      reference enforcing cqlSession disabled
    • withCqlDriverConfig

      public AstraClientConfig withCqlDriverConfig(com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder conf)
      Populate config.
      Parameters:
      conf - configuration
      Returns:
      current reference
    • withCqlConsistencyLevel

      public AstraClientConfig withCqlConsistencyLevel(com.datastax.oss.driver.api.core.ConsistencyLevel cl)
      Populate Consistency level
      Parameters:
      cl - consistency level
      Returns:
      current reference
    • withCqlDriverConfigurationFile

      public AstraClientConfig withCqlDriverConfigurationFile(File configFile)
      Populate configuration file
      Parameters:
      configFile - configuration file
      Returns:
      current reference
    • withCqlKeyspace

      public AstraClientConfig withCqlKeyspace(String keyspace)
      Fill Keyspaces.
      Parameters:
      keyspace - keyspace name
      Returns:
      current reference
    • withCqlOptionBoolean

      public AstraClientConfig withCqlOptionBoolean(com.datastax.oss.driver.api.core.config.TypedDriverOption<Boolean> option, Boolean du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionBooleanDC

      public AstraClientConfig withCqlOptionBooleanDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Boolean> option, Boolean du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionBooleanList

      public AstraClientConfig withCqlOptionBooleanList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Boolean>> option, List<Boolean> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionBooleanListDC

      public AstraClientConfig withCqlOptionBooleanListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Boolean>> option, List<Boolean> du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionClass

      public AstraClientConfig withCqlOptionClass(com.datastax.oss.driver.api.core.config.TypedDriverOption<Class<?>> option, Class<?> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionClassDC

      public AstraClientConfig withCqlOptionClassDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Class<?>> option, Class<?> du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionClassList

      public AstraClientConfig withCqlOptionClassList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Class<?>>> option, List<Class<?>> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionClassListDC

      public AstraClientConfig withCqlOptionClassListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Class<?>>> option, List<Class<?>> du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDouble

      public AstraClientConfig withCqlOptionDouble(com.datastax.oss.driver.api.core.config.TypedDriverOption<Double> option, Double du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDoubleDC

      public AstraClientConfig withCqlOptionDoubleDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Double> option, Double du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDoubleList

      public AstraClientConfig withCqlOptionDoubleList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Double>> option, List<Double> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDoubleListDC

      public AstraClientConfig withCqlOptionDoubleListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Double>> option, List<Double> du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDuration

      public AstraClientConfig withCqlOptionDuration(com.datastax.oss.driver.api.core.config.TypedDriverOption<Duration> option, Duration du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDurationDC

      public AstraClientConfig withCqlOptionDurationDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Duration> option, Duration du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDurationList

      public AstraClientConfig withCqlOptionDurationList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Duration>> option, List<Duration> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionDurationListDC

      public AstraClientConfig withCqlOptionDurationListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Duration>> option, List<Duration> du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionInteger

      public AstraClientConfig withCqlOptionInteger(com.datastax.oss.driver.api.core.config.TypedDriverOption<Integer> option, Integer du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionIntegerDC

      public AstraClientConfig withCqlOptionIntegerDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Integer> option, Integer du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionIntegerList

      public AstraClientConfig withCqlOptionIntegerList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Integer>> option, List<Integer> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionIntegerListDC

      public AstraClientConfig withCqlOptionIntegerListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Integer>> option, List<Integer> du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionLong

      public AstraClientConfig withCqlOptionLong(com.datastax.oss.driver.api.core.config.TypedDriverOption<Long> option, Long du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionLongDC

      public AstraClientConfig withCqlOptionLongDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<Long> option, Long du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionLongList

      public AstraClientConfig withCqlOptionLongList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Long>> option, List<Long> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionLongListDC

      public AstraClientConfig withCqlOptionLongListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<Long>> option, List<Long> du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionString

      public AstraClientConfig withCqlOptionString(com.datastax.oss.driver.api.core.config.TypedDriverOption<String> option, String du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionStringDC

      public AstraClientConfig withCqlOptionStringDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<String> option, String du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionStringList

      public AstraClientConfig withCqlOptionStringList(com.datastax.oss.driver.api.core.config.TypedDriverOption<List<String>> option, List<String> du)
      Add a property to the Cql Context.
      Parameters:
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlOptionStringListDC

      public AstraClientConfig withCqlOptionStringListDC(String dc, com.datastax.oss.driver.api.core.config.TypedDriverOption<List<String>> option, List<String> du)
      Add a property to the Cql Context.
      Parameters:
      dc - stargate datacenter
      option - current option
      du - option value
      Returns:
      current reference
    • withCqlMetricsRegistry

      public AstraClientConfig withCqlMetricsRegistry(Object mr)
      Provide a metrics registry.
      Parameters:
      mr - metrics registry
      Returns:
      self reference
    • withCqlRequestTracker

      public AstraClientConfig withCqlRequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker rt)
      Provide a request tracker.
      Parameters:
      rt - request tracker
      Returns:
      self reference
    • withCqlSecureConnectBundleFolder

      public AstraClientConfig withCqlSecureConnectBundleFolder(String scbPath)
      Provide clientSecret.
      Parameters:
      scbPath - secure bundle
      Returns:
      self reference
    • buildScbFileName

      public static String buildScbFileName(String dId, String dbRegion)
      Helper to build the path (use multiple times).
      Parameters:
      dId - database id
      dbRegion - database region
      Returns:
      filename
    • loadFromAstraRc

      public AstraClientConfig loadFromAstraRc()
      Some settings can be loaded from ~/.astrarc in you machine.
      Returns:
      AstraClientBuilder configuration
    • build

      public AstraClient build()
      Final build.
      Returns:
      return the target object