Skip to content

Commit

Permalink
delete-table, truncate-table, list-tables, reflection-config for data…
Browse files Browse the repository at this point in the history
… api 2.0
  • Loading branch information
clun committed Jan 15, 2025
1 parent 7cd151b commit 2553042
Show file tree
Hide file tree
Showing 37 changed files with 1,521 additions and 155 deletions.
29 changes: 22 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>Command Line Interface for DataStax Astra</description>
<packaging>jar</packaging>
<inceptionYear>2022</inceptionYear>
<version>0.5</version>
<version>0.6</version>
<url>https://github.com/datastax/astra-cli</url>
<properties>

Expand All @@ -19,16 +19,16 @@
<sonar.organization>clun-datastax</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

<astra-sdk.version>1.2.8</astra-sdk.version>
<astra-db-java.version>1.4.5</astra-db-java.version>
<astra-sdk.version>1.2.9</astra-sdk.version>
<astra-db-java.version>2.0.0-PREVIEW</astra-db-java.version>
<jansi.version>2.4.1</jansi.version>
<airline.version>3.0.0</airline.version>
<slf4j.version>2.0.16</slf4j.version>
<httpclient.version>5.1.2</httpclient.version>
<jackson-datatype.version>2.17.2</jackson-datatype.version>
<jackson.version>2.18.2</jackson.version>
<commons-compress.version>1.27.1</commons-compress.version>
<!-- TEST -->
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<junit-jupiter.version>5.11.4</junit-jupiter.version>
<awaitibility.version>4.2.2</awaitibility.version>
<!-- Java -->
<maven.plugin.compiler.source>17</maven.plugin.compiler.source>
Expand All @@ -45,7 +45,7 @@
<version.maven.plugin.javadoc>3.6.0</version.maven.plugin.javadoc>
<version.maven.plugin.jar>3.4.2</version.maven.plugin.jar>
<version.maven.plugin.license>2.4.0</version.maven.plugin.license>
<version.maven.plugin.native>0.10.3</version.maven.plugin.native>
<version.maven.plugin.native>0.10.4</version.maven.plugin.native>
<version.maven.plugin.release>3.1.1</version.maven.plugin.release>
<version.maven.plugin.resources>3.3.1</version.maven.plugin.resources>
<version.maven.plugin.shade>3.6.0</version.maven.plugin.shade>
Expand Down Expand Up @@ -94,7 +94,22 @@
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-datatype.version}</version>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
Expand Down
186 changes: 183 additions & 3 deletions src/main/dist/astra-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ function _complete_astra_group_db() {
CURR_CMD=${COMP_WORDS[2]}
fi

COMMANDS="list-regions delete-keyspace list-clouds download-scb delete-region list-regions-vector describe-collection create-region delete create-keyspace list-cdc create-collection list-regions-classic load delete-collection get unload create delete-cdc create-cdc resume list-keyspaces list-collections list-regions-serverless count create-dotenv list get-endpoint-playground describe cqlsh get-endpoint-api get-endpoint-swagger status"
COMMANDS="list-regions delete-keyspace list-clouds download-scb delete-region list-regions-vector describe-collection create-region delete create-keyspace list-embedding-providers list-cdc create-collection list-regions-classic load delete-collection get unload create delete-cdc create-cdc describe-embedding-provider resume list-keyspaces list-collections list-tables list-regions-serverless count create-dotenv list get-endpoint-playground describe cqlsh get-endpoint-api get-endpoint-swagger status"
if [[ ${COMP_CWORD} -eq 2 ]]; then
COMPREPLY=( $(_complete_astra_group_db_command_list "${COMMANDS}" ) )
DEFAULT_GROUP_COMMAND_COMPLETIONS=(${COMPREPLY[@]})
Expand Down Expand Up @@ -585,6 +585,21 @@ function _complete_astra_group_db() {
echo ${COMPREPLY[@]}
return $?
;;
list-tables)
COMPREPLY=( $(_complete_astra_group_db_command_listtables "${COMMANDS}" ) )
echo ${COMPREPLY[@]}
return $?
;;
list-embedding-providers)
COMPREPLY=( $(_complete_astra_group_db_command_listembeddingproviders "${COMMANDS}" ) )
echo ${COMPREPLY[@]}
return $?
;;
describe-embedding-provider)
COMPREPLY=( $(_complete_astra_group_db_command_describeembeddingprovider "${COMMANDS}" ) )
echo ${COMPREPLY[@]}
return $?
;;
create-region)
COMPREPLY=( $(_complete_astra_group_db_command_createregion "${COMMANDS}" ) )
echo ${COMPREPLY[@]}
Expand Down Expand Up @@ -1430,7 +1445,7 @@ function _complete_astra_group_db_command_deletecollection() {
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
COMMANDS=$1

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

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
Expand Down Expand Up @@ -1495,7 +1510,7 @@ function _complete_astra_group_db_command_createcollection() {
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
COMMANDS=$1

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

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
Expand Down Expand Up @@ -1658,6 +1673,171 @@ function _complete_astra_group_db_command_describecollection() {
return 0
}

function _complete_astra_group_db_command_listtables() {
# Get completion data
COMPREPLY=()
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
COMMANDS=$1

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

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
SAW_ARG=$?
if [[ ${SAW_ARG} -eq 0 ]]; then
ARG_VALUES=
ARG_GENERATED_VALUES=
case ${PREV_WORD} in
--token)
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
;;
-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[@]}
return 0
;;
--env)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-o|--output)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
esac
fi

ARGUMENTS=
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
}

function _complete_astra_group_db_command_listembeddingproviders() {
# Get completion data
COMPREPLY=()
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
COMMANDS=$1

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

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
SAW_ARG=$?
if [[ ${SAW_ARG} -eq 0 ]]; then
ARG_VALUES=
ARG_GENERATED_VALUES=
case ${PREV_WORD} in
--token)
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
;;
-conf|--config)
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[@]}
return 0
;;
-o|--output)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
esac
fi

ARGUMENTS=
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
}

function _complete_astra_group_db_command_describeembeddingprovider() {
# Get completion data
COMPREPLY=()
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
COMMANDS=$1

FLAG_OPTS="--no-color --async -v --verbose"
ARG_OPTS="--token -cf --config-file -o -ep -conf --timeout --embedding-provider --env --config --output"

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
SAW_ARG=$?
if [[ ${SAW_ARG} -eq 0 ]]; then
ARG_VALUES=
ARG_GENERATED_VALUES=
case ${PREV_WORD} in
--token)
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
;;
-ep|--embedding-provider)
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
;;
--timeout)
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[@]}
return 0
;;
-o|--output)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
esac
fi

ARGUMENTS=
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
}

function _complete_astra_group_db_command_createregion() {
# Get completion data
COMPREPLY=()
Expand Down
37 changes: 28 additions & 9 deletions src/main/java/com/dtsx/astra/cli/AstraCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* #L%
*/

import com.datastax.astra.client.exception.AuthenticationException;
import com.datastax.astra.internal.utils.AnsiUtils;
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 @@ -60,14 +58,20 @@
import com.dtsx.astra.cli.db.collection.DbDescribeEmbeddingProviderCmd;
import com.dtsx.astra.cli.db.collection.DbListCollectionsCmd;
import com.dtsx.astra.cli.db.collection.DbListEmbeddingProvidersCmd;
import com.dtsx.astra.cli.db.collection.DbTruncateCollectionCmd;
import com.dtsx.astra.cli.db.cqlsh.DbCqlShellCmd;
import com.dtsx.astra.cli.db.dsbulk.DbCountCmd;
import com.dtsx.astra.cli.db.dsbulk.DbLoadCmd;
import com.dtsx.astra.cli.db.dsbulk.DbUnLoadCmd;
import com.dtsx.astra.cli.db.endpoint.DbGetEndpointApiCmd;
import com.dtsx.astra.cli.db.endpoint.DbGetEndpointPlaygroundCmd;
import com.dtsx.astra.cli.db.endpoint.DbGetEndpointSwaggerCmd;
import com.dtsx.astra.cli.db.exception.CollectionAlreadyExistException;
import com.dtsx.astra.cli.db.exception.CollectionNotFoundException;
import com.dtsx.astra.cli.db.exception.DatabaseAlreadyExistException;
import com.dtsx.astra.cli.db.exception.DatabaseNameNotUniqueException;
import com.dtsx.astra.cli.db.exception.InvalidDatabaseStateException;
import com.dtsx.astra.cli.db.exception.TableNotFoundException;
import com.dtsx.astra.cli.db.keyspace.DbCreateKeyspaceCmd;
import com.dtsx.astra.cli.db.keyspace.DbDeleteKeyspaceCmd;
import com.dtsx.astra.cli.db.keyspace.DbListKeyspacesCmd;
Expand All @@ -79,8 +83,10 @@
import com.dtsx.astra.cli.db.region.DbCreateRegionCmd;
import com.dtsx.astra.cli.db.region.DbDeleteRegionCmd;
import com.dtsx.astra.cli.db.region.DbListRegionsCmd;
import com.dtsx.astra.cli.db.endpoint.DbGetEndpointPlaygroundCmd;
import com.dtsx.astra.cli.db.endpoint.DbGetEndpointSwaggerCmd;
import com.dtsx.astra.cli.db.table.DbDeleteTableCmd;
import com.dtsx.astra.cli.db.table.DbDescribeTableCmd;
import com.dtsx.astra.cli.db.table.DbListTablesCmd;
import com.dtsx.astra.cli.db.table.DbTruncateTableCmd;
import com.dtsx.astra.cli.iam.role.RoleDescribeCmd;
import com.dtsx.astra.cli.iam.role.RoleGetCmd;
import com.dtsx.astra.cli.iam.role.RoleListCmd;
Expand Down Expand Up @@ -181,7 +187,9 @@
// Keyspaces
DbCreateKeyspaceCmd.class, DbDeleteKeyspaceCmd.class, DbListKeyspacesCmd.class,
// Collections
DbListCollectionsCmd.class, DbDeleteCollectionCmd.class, DbCreateCollectionCmd.class, DbDescribeCollectionCmd.class,
DbListCollectionsCmd.class, DbDeleteCollectionCmd.class, DbCreateCollectionCmd.class, DbDescribeCollectionCmd.class, DbTruncateCollectionCmd.class,
// Tables
DbListTablesCmd.class, DbDeleteTableCmd.class, DbDeleteTableCmd.class, DbTruncateTableCmd.class, DbDescribeTableCmd.class,
// Vectorize
DbListEmbeddingProvidersCmd.class, DbDescribeEmbeddingProviderCmd.class,
// Regions
Expand Down Expand Up @@ -314,39 +322,50 @@ public static ExitCode run(Class<?> clazz, String[] args) {
"astra streaming list-regions to list available regions.");
return ExitCode.INVALID_OPTION_VALUE;
} catch(InvalidCloudProviderException cloudException) {
cloudException.printStackTrace();
LoggerShell.exception(cloudException,null);
LoggerShell.info("Use " +
"astra db list-clouds or " +
"astra streaming list-clouds to list available cloud providers.");
return ExitCode.INVALID_OPTION_VALUE;
} catch(ParseException ex) {
ex.printStackTrace();
LoggerShell.exception(ex,"Command is not properly formatted.");
return ExitCode.UNRECOGNIZED_COMMAND;
} catch (InvalidTokenException | TokenNotFoundException | AuthenticationException | com.dtsx.astra.sdk.exception.AuthenticationException |
} catch (InvalidTokenException | TokenNotFoundException | com.dtsx.astra.sdk.exception.AuthenticationException |
FileSystemException | ConfigurationException e) {
e.printStackTrace();
AstraCliConsole.outputError(ExitCode.CONFIGURATION, e.getMessage());
return ExitCode.CONFIGURATION;
} catch (InvalidArgumentException | IllegalArgumentException dex) {
dex.printStackTrace();
AstraCliConsole.outputError(ExitCode.INVALID_ARGUMENT, dex.getMessage());
return ExitCode.INVALID_ARGUMENT;
} catch (DatabaseNotFoundException | KeyspaceNotFoundException |
TenantNotFoundException |
CollectionNotFoundException | TableNotFoundException |
RoleNotFoundException | ChangeDataCaptureNotFoundException |
UserNotFoundException | RegionNotFoundException ex) {
ex.printStackTrace();
AstraCliConsole.outputError(ExitCode.NOT_FOUND, ex.getMessage());
return ExitCode.NOT_FOUND;
} catch (DatabaseNameNotUniqueException name) {
name.printStackTrace();
AstraCliConsole.outputError(ExitCode.CONFLICT, name.getMessage());
return ExitCode.CONFLICT;
} catch (DatabaseAlreadyExistException | KeyspaceAlreadyExistException |
} catch (DatabaseAlreadyExistException | CollectionAlreadyExistException |
KeyspaceAlreadyExistException |
TenantAlreadyExistException | UserAlreadyExistException |
RegionAlreadyExistException e) {
AstraCliConsole.outputError(ExitCode.ALREADY_EXIST, e.getMessage());
e.printStackTrace();
AstraCliConsole.outputError(ExitCode.ALREADY_EXIST, e.getMessage());
return ExitCode.ALREADY_EXIST;
} catch(InvalidDatabaseStateException ex) {
ex.printStackTrace();
AstraCliConsole.outputError(ExitCode.UNAVAILABLE, ex.getMessage());
return ExitCode.UNAVAILABLE;
} catch (Exception ex) {
} catch (Exception ex) {
ex.printStackTrace();
AstraCliConsole.outputError(ExitCode.INTERNAL_ERROR, ex.getMessage());
return ExitCode.INTERNAL_ERROR;
}
Expand Down
Loading

0 comments on commit 2553042

Please sign in to comment.