Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
clun committed May 24, 2024
1 parent 0da617f commit 73be9fa
Show file tree
Hide file tree
Showing 19 changed files with 415 additions and 97 deletions.
45 changes: 20 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,35 @@
<sonar.organization>clun-datastax</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

<astra-sdk.version>0.7.3</astra-sdk.version>
<astra-sdk.version>1.2.8-SNAPSHOT</astra-sdk.version>
<astra-db-java.version>1.2.0</astra-db-java.version>
<jansi.version>2.4.1</jansi.version>
<airline.version>2.9.0</airline.version>
<slf4j.version>2.0.9</slf4j.version>
<airline.version>3.0.0</airline.version>
<slf4j.version>2.0.13</slf4j.version>
<httpclient.version>5.1.2</httpclient.version>
<jackson-datatype.version>2.15.3</jackson-datatype.version>
<commons-compress.version>1.25.0</commons-compress.version>
<commons-compress.version>1.26.2</commons-compress.version>
<!-- Junit -->
<junit-jupiter.version>5.10.1</junit-jupiter.version>
<awaitibility.version>4.2.0</awaitibility.version>
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<awaitibility.version>4.2.1</awaitibility.version>
<!-- Java -->
<maven.plugin.compiler.source>17</maven.plugin.compiler.source>
<maven.plugin.compiler.target>17</maven.plugin.compiler.target>
<maven.plugin.javadoc.source>17</maven.plugin.javadoc.source>
<!-- Maven -->
<version.maven.plugin.assembly>3.6.0</version.maven.plugin.assembly>
<version.maven.plugin.compiler>3.11.0</version.maven.plugin.compiler>
<version.maven.plugin.assembly>3.7.1</version.maven.plugin.assembly>
<version.maven.plugin.compiler>3.12.1</version.maven.plugin.compiler>
<version.maven.plugin.coveralls>4.3.0</version.maven.plugin.coveralls>
<version.maven.plugin.dependency>3.6.1</version.maven.plugin.dependency>
<version.maven.plugin.exec>3.1.0</version.maven.plugin.exec>
<version.maven.plugin.exec>3.3.0</version.maven.plugin.exec>
<version.maven.plugin.jacoco>0.8.11</version.maven.plugin.jacoco>
<version.maven.plugin.javadoc>3.6.0</version.maven.plugin.javadoc>
<version.maven.plugin.jar>3.3.0</version.maven.plugin.jar>
<version.maven.plugin.license>2.3.0</version.maven.plugin.license>
<version.maven.plugin.native>0.9.28</version.maven.plugin.native>
<version.maven.plugin.jar>3.4.1</version.maven.plugin.jar>
<version.maven.plugin.license>2.4.0</version.maven.plugin.license>
<version.maven.plugin.native>0.10.2</version.maven.plugin.native>
<version.maven.plugin.release>3.0.1</version.maven.plugin.release>
<version.maven.plugin.resources>3.3.1</version.maven.plugin.resources>
<version.maven.plugin.shade>3.5.1</version.maven.plugin.shade>
<version.maven.plugin.shade>3.5.3</version.maven.plugin.shade>
<version.maven.plugin.surefire>3.2.5</version.maven.plugin.surefire>
</properties>

Expand All @@ -64,19 +65,13 @@
<!-- Http client wrapping Calls -->
<dependency>
<groupId>com.datastax.astra</groupId>
<artifactId>astra-db-client</artifactId>
<artifactId>astra-sdk-devops</artifactId>
<version>${astra-sdk.version}</version>
<exclusions>
<exclusion>
<groupId>com.datastax.stargate</groupId>
<artifactId>stargate-sdk-grpc</artifactId>
</exclusion>

<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.datastax.astra</groupId>
<artifactId>astra-db-java</artifactId>
<version>${astra-db-java.version}</version>
</dependency>

<dependency>
Expand Down
55 changes: 50 additions & 5 deletions src/main/dist/astra-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ function _complete_astra_group_db_command_listcollections() {
COMMANDS=$1

FLAG_OPTS="--no-color -v --verbose"
ARG_OPTS="--token -cf --config-file -o -conf --env --config --output"
ARG_OPTS="--token -cf --config-file --keyspace -o -conf --env -k --config --output"

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
SAW_ARG=$?
Expand All @@ -1389,6 +1389,11 @@ function _complete_astra_group_db_command_listcollections() {
echo ${COMPREPLY[@]}
return 0
;;
-k|--keyspace)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-conf|--config)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
Expand Down Expand Up @@ -1421,7 +1426,7 @@ function _complete_astra_group_db_command_deletecollection() {
COMMANDS=$1

FLAG_OPTS="--no-color --async -v --verbose"
ARG_OPTS="--token -cf --config-file -o -c -conf --timeout --collection --env --config --output"
ARG_OPTS="--token --config-file --keyspace -o --timeout --config -cf -c -conf --collection --env -k --output"

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
SAW_ARG=$?
Expand All @@ -1439,6 +1444,11 @@ function _complete_astra_group_db_command_deletecollection() {
echo ${COMPREPLY[@]}
return 0
;;
-k|--keyspace)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-conf|--config)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
Expand Down Expand Up @@ -1481,7 +1491,7 @@ function _complete_astra_group_db_command_createcollection() {
COMMANDS=$1

FLAG_OPTS="--no-color --async -v --verbose"
ARG_OPTS="--token -m --config-file -o --metric --timeout --config -cf --dimension -c -d -conf --collection --env --output"
ARG_OPTS="--token -m --keyspace --config-file --indexing-allow -o --metric --embedding-model --default-id --timeout --config --indexing-deny -cf --dimension -c -d -conf --collection --embedding-provider --env -k --output"

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
SAW_ARG=$?
Expand All @@ -1494,7 +1504,12 @@ function _complete_astra_group_db_command_createcollection() {
echo ${COMPREPLY[@]}
return 0
;;
-cf|--config-file)
--indexing-allow)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-k|--keyspace)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
Expand All @@ -1504,12 +1519,17 @@ function _complete_astra_group_db_command_createcollection() {
echo ${COMPREPLY[@]}
return 0
;;
--embedding-model)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-conf|--config)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-c|--collection)
--default-id)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
Expand All @@ -1524,6 +1544,26 @@ function _complete_astra_group_db_command_createcollection() {
echo ${COMPREPLY[@]}
return 0
;;
--indexing-deny)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-cf|--config-file)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-c|--collection)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
--embedding-provider)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
--env)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
Expand Down Expand Up @@ -2684,6 +2724,11 @@ function _complete_astra_group_db_command_createcdc() {
echo ${COMPREPLY[@]}
return 0
;;
-p, --partition)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
--table)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/dtsx/astra/cli/AstraCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import com.datastax.astra.client.exception.AuthenticationException;
import com.dtsx.astra.cli.config.ConfigCreateCmd;
import com.dtsx.astra.cli.config.ConfigDeleteCmd;
import com.dtsx.astra.cli.config.ConfigDescribeCmd;
Expand Down Expand Up @@ -316,7 +317,7 @@ public static ExitCode run(Class<?> clazz, String[] args) {
} catch(ParseException ex) {
LoggerShell.exception(ex,"Command is not properly formatted.");
return ExitCode.UNRECOGNIZED_COMMAND;
} catch (InvalidTokenException | TokenNotFoundException |
} catch (InvalidTokenException | TokenNotFoundException | AuthenticationException | com.dtsx.astra.sdk.exception.AuthenticationException |
FileSystemException | ConfigurationException e) {
AstraCliConsole.outputError(ExitCode.CONFIGURATION, e.getMessage());
return ExitCode.CONFIGURATION;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/dtsx/astra/cli/config/ConfigCreateCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.github.rvesse.airline.annotations.Arguments;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;
import com.github.rvesse.airline.annotations.restrictions.Required;

/**
* Create a new section in configuration.
Expand Down Expand Up @@ -65,7 +64,7 @@ public void execute() {
throw new InvalidTokenException(token);
}
// validate token at the same time
AstraEnvironment targetEnv = AstraCliUtils.lookupEnvironment(env);
AstraEnvironment targetEnv = AstraCliUtils.parseEnvironment(env);
Organization o = new AstraOpsClient(token, targetEnv).getOrganization();
if (sectionName == null) {
sectionName = o.getName();
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/dtsx/astra/cli/config/SetupCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import com.dtsx.astra.cli.core.out.LoggerShell;
import com.dtsx.astra.cli.utils.AstraCliUtils;
import com.dtsx.astra.sdk.AstraOpsClient;
import com.dtsx.astra.sdk.org.domain.Organization;
import com.dtsx.astra.sdk.utils.AstraEnvironment;
import com.dtsx.astra.sdk.utils.AstraRc;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;

Expand Down Expand Up @@ -61,7 +59,7 @@ public class SetupCmd extends AbstractCmd {
/** {@inheritDoc} */
@Override
public void execute() {
AstraEnvironment targetEnv = AstraCliUtils.lookupEnvironment(env);
AstraEnvironment targetEnv = AstraCliUtils.parseEnvironment(env);
// As not token is provided we ask for it in the console
if (token == null || token.isBlank()) {
verbose = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
import com.dtsx.astra.cli.config.AstraCliConfiguration;
import com.dtsx.astra.cli.core.out.OutputFormat;
import com.dtsx.astra.cli.utils.AstraCliUtils;
import com.dtsx.astra.sdk.utils.AstraEnvironment;
import com.github.rvesse.airline.annotations.Option;
import com.github.rvesse.airline.parser.errors.ParseRestrictionViolatedException;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

/**
Expand Down Expand Up @@ -63,7 +59,7 @@ public void run() {
validateOptions();

ctx().init(new CoreOptions(verbose, noColor, OutputFormat.valueOf(output.toUpperCase(Locale.ROOT)), configFilename));
ctx().initToken(new TokenOptions(token, configSectionName, AstraCliUtils.lookupEnvironment(env)));
ctx().initToken(new TokenOptions(token, configSectionName, AstraCliUtils.parseEnvironment(env)));
execute();
}

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/dtsx/astra/cli/core/CliContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* #L%
*/

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.DataAPIOptions;
import com.dtsx.astra.cli.config.AstraCliConfiguration;
import com.dtsx.astra.cli.core.exception.InvalidTokenException;
import com.dtsx.astra.cli.core.exception.TokenNotFoundException;
Expand Down Expand Up @@ -82,6 +84,9 @@ public static synchronized CliContext getInstance() {
/** Single for Ops Client. */
private AstraOpsClient devopsApiClient;

/** Singleton for Data API Client. */
private DataAPIClient dataAPIClient;

/**
* Should initialize the client based on provided parameters.
*
Expand Down Expand Up @@ -240,6 +245,36 @@ public AstraOpsClient getApiDevops() {
return devopsApiClient;
}

/**
* Initializing and Retrieving the Data API Client for vector Operations.
*
* @return
* instance od DataAPIClient for current configuration
*/
public DataAPIClient getDataAPIClient() {
if (dataAPIClient == null) {
dataAPIClient = new DataAPIClient(getToken(),
DataAPIOptions.builder()
.withDestination(getDestination())
.build());
}
return dataAPIClient;
}

/**
* Mapping for AstraEnvironment to DataApiDestination which is broader to work with DSE.
*
* @return
* destination for the data api
*/
private DataAPIOptions.DataAPIDestination getDestination() {
return switch (getAstraEnvironment()) {
case DEV -> DataAPIOptions.DataAPIDestination.ASTRA_DEV;
case TEST -> DataAPIOptions.DataAPIDestination.ASTRA_TEST;
default -> DataAPIOptions.DataAPIDestination.ASTRA;
};
}

/**
* Validate a token for a target environment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class InvalidRegionException extends InvalidArgumentException {
* current region
*/
public InvalidRegionException(String cloud, String region) {
super(String.format("Region '%s' is valid for cloud '%s'.", region, cloud));
super(String.format("Region '%s' is invalid for the cloud '%s'.", region, cloud));
}

/**
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/com/dtsx/astra/cli/db/DaoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
* limitations under the License.
* #L%
*/

import com.datastax.astra.client.admin.AstraDBAdmin;
import com.dtsx.astra.cli.core.CliContext;
import com.dtsx.astra.cli.core.exception.InvalidArgumentException;
import com.dtsx.astra.cli.core.out.LoggerShell;
import com.dtsx.astra.cli.db.exception.DatabaseNameNotUniqueException;
import com.dtsx.astra.cli.utils.AstraCliUtils;
import com.dtsx.astra.cli.utils.FileUtils;
import com.dtsx.astra.sdk.AstraDB;
import com.dtsx.astra.sdk.AstraOpsClient;
import com.dtsx.astra.sdk.db.AstraDBOpsClient;
import com.dtsx.astra.sdk.db.DbOpsClient;
import com.dtsx.astra.sdk.db.domain.Database;
Expand Down Expand Up @@ -72,7 +70,6 @@ public static synchronized DaoDatabase getInstance() {
private DaoDatabase() {
}


/**
* Access unique db.
*
Expand Down Expand Up @@ -102,13 +99,24 @@ public Database getDatabase(String databaseName)
* @return
* astraDB
*/
public AstraDB getAstraDB(String databaseName) {
public com.datastax.astra.client.Database getDataAPIDatabase(String databaseName) {
return getDataAPIDatabase(databaseName, AstraDBAdmin.DEFAULT_NAMESPACE);
}

/**
* Accessing the AstraDB client for a vectorDB.
*
* @param databaseName
* database name
* @return
* instance of a client for the DataAPI
*/
public com.datastax.astra.client.Database getDataAPIDatabase(String databaseName, String keyspace) {
Database db = getDatabase(databaseName);
if (db.getInfo().getDbType() == null) {
throw new IllegalArgumentException("Database %s is not a vector database".formatted(databaseName));
}
AstraOpsClient ops = CliContext.getInstance().getApiDevops();
return new AstraDB(ops.getToken(), UUID.fromString(db.getId()), db.getInfo().getRegion(),ops.getEnvironment());
return CliContext.getInstance().getDataAPIClient().getDatabase(UUID.fromString(db.getId()), keyspace);
}

/**
Expand Down
Loading

0 comments on commit 73be9fa

Please sign in to comment.