Skip to content

Commit 2553042

Browse files
committed
delete-table, truncate-table, list-tables, reflection-config for data api 2.0
1 parent 7cd151b commit 2553042

37 files changed

+1521
-155
lines changed

pom.xml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<description>Command Line Interface for DataStax Astra</description>
88
<packaging>jar</packaging>
99
<inceptionYear>2022</inceptionYear>
10-
<version>0.5</version>
10+
<version>0.6</version>
1111
<url>https://github.com/datastax/astra-cli</url>
1212
<properties>
1313

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

22-
<astra-sdk.version>1.2.8</astra-sdk.version>
23-
<astra-db-java.version>1.4.5</astra-db-java.version>
22+
<astra-sdk.version>1.2.9</astra-sdk.version>
23+
<astra-db-java.version>2.0.0-PREVIEW</astra-db-java.version>
2424
<jansi.version>2.4.1</jansi.version>
2525
<airline.version>3.0.0</airline.version>
2626
<slf4j.version>2.0.16</slf4j.version>
2727
<httpclient.version>5.1.2</httpclient.version>
28-
<jackson-datatype.version>2.17.2</jackson-datatype.version>
28+
<jackson.version>2.18.2</jackson.version>
2929
<commons-compress.version>1.27.1</commons-compress.version>
3030
<!-- TEST -->
31-
<junit-jupiter.version>5.10.2</junit-jupiter.version>
31+
<junit-jupiter.version>5.11.4</junit-jupiter.version>
3232
<awaitibility.version>4.2.2</awaitibility.version>
3333
<!-- Java -->
3434
<maven.plugin.compiler.source>17</maven.plugin.compiler.source>
@@ -45,7 +45,7 @@
4545
<version.maven.plugin.javadoc>3.6.0</version.maven.plugin.javadoc>
4646
<version.maven.plugin.jar>3.4.2</version.maven.plugin.jar>
4747
<version.maven.plugin.license>2.4.0</version.maven.plugin.license>
48-
<version.maven.plugin.native>0.10.3</version.maven.plugin.native>
48+
<version.maven.plugin.native>0.10.4</version.maven.plugin.native>
4949
<version.maven.plugin.release>3.1.1</version.maven.plugin.release>
5050
<version.maven.plugin.resources>3.3.1</version.maven.plugin.resources>
5151
<version.maven.plugin.shade>3.6.0</version.maven.plugin.shade>
@@ -94,7 +94,22 @@
9494
<dependency>
9595
<groupId>com.fasterxml.jackson.datatype</groupId>
9696
<artifactId>jackson-datatype-jsr310</artifactId>
97-
<version>${jackson-datatype.version}</version>
97+
<version>${jackson.version}</version>
98+
</dependency>
99+
<dependency>
100+
<groupId>com.fasterxml.jackson.core</groupId>
101+
<artifactId>jackson-core</artifactId>
102+
<version>${jackson.version}</version>
103+
</dependency>
104+
<dependency>
105+
<groupId>com.fasterxml.jackson.core</groupId>
106+
<artifactId>jackson-databind</artifactId>
107+
<version>${jackson.version}</version>
108+
</dependency>
109+
<dependency>
110+
<groupId>com.fasterxml.jackson.core</groupId>
111+
<artifactId>jackson-annotations</artifactId>
112+
<version>${jackson.version}</version>
98113
</dependency>
99114

100115
<dependency>

src/main/dist/astra-init.sh

Lines changed: 183 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ function _complete_astra_group_db() {
495495
CURR_CMD=${COMP_WORDS[2]}
496496
fi
497497

498-
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"
498+
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"
499499
if [[ ${COMP_CWORD} -eq 2 ]]; then
500500
COMPREPLY=( $(_complete_astra_group_db_command_list "${COMMANDS}" ) )
501501
DEFAULT_GROUP_COMMAND_COMPLETIONS=(${COMPREPLY[@]})
@@ -585,6 +585,21 @@ function _complete_astra_group_db() {
585585
echo ${COMPREPLY[@]}
586586
return $?
587587
;;
588+
list-tables)
589+
COMPREPLY=( $(_complete_astra_group_db_command_listtables "${COMMANDS}" ) )
590+
echo ${COMPREPLY[@]}
591+
return $?
592+
;;
593+
list-embedding-providers)
594+
COMPREPLY=( $(_complete_astra_group_db_command_listembeddingproviders "${COMMANDS}" ) )
595+
echo ${COMPREPLY[@]}
596+
return $?
597+
;;
598+
describe-embedding-provider)
599+
COMPREPLY=( $(_complete_astra_group_db_command_describeembeddingprovider "${COMMANDS}" ) )
600+
echo ${COMPREPLY[@]}
601+
return $?
602+
;;
588603
create-region)
589604
COMPREPLY=( $(_complete_astra_group_db_command_createregion "${COMMANDS}" ) )
590605
echo ${COMPREPLY[@]}
@@ -1430,7 +1445,7 @@ function _complete_astra_group_db_command_deletecollection() {
14301445
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
14311446
COMMANDS=$1
14321447

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

14361451
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
@@ -1495,7 +1510,7 @@ function _complete_astra_group_db_command_createcollection() {
14951510
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
14961511
COMMANDS=$1
14971512

1498-
FLAG_OPTS="--no-color --async -v --verbose"
1513+
FLAG_OPTS="--no-color --async -v --verbose --if-not-exists"
14991514
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"
15001515

15011516
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
@@ -1658,6 +1673,171 @@ function _complete_astra_group_db_command_describecollection() {
16581673
return 0
16591674
}
16601675

1676+
function _complete_astra_group_db_command_listtables() {
1677+
# Get completion data
1678+
COMPREPLY=()
1679+
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
1680+
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
1681+
COMMANDS=$1
1682+
1683+
FLAG_OPTS="--no-color -v --verbose"
1684+
ARG_OPTS="--token -cf --config-file --keyspace -o -conf --env -k --config --output"
1685+
1686+
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
1687+
SAW_ARG=$?
1688+
if [[ ${SAW_ARG} -eq 0 ]]; then
1689+
ARG_VALUES=
1690+
ARG_GENERATED_VALUES=
1691+
case ${PREV_WORD} in
1692+
--token)
1693+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1694+
echo ${COMPREPLY[@]}
1695+
return 0
1696+
;;
1697+
-cf|--config-file)
1698+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1699+
echo ${COMPREPLY[@]}
1700+
return 0
1701+
;;
1702+
-k|--keyspace)
1703+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1704+
echo ${COMPREPLY[@]}
1705+
return 0
1706+
;;
1707+
-conf|--config)
1708+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1709+
echo ${COMPREPLY[@]}
1710+
return 0
1711+
;;
1712+
--env)
1713+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1714+
echo ${COMPREPLY[@]}
1715+
return 0
1716+
;;
1717+
-o|--output)
1718+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1719+
echo ${COMPREPLY[@]}
1720+
return 0
1721+
;;
1722+
esac
1723+
fi
1724+
1725+
ARGUMENTS=
1726+
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
1727+
echo ${COMPREPLY[@]}
1728+
return 0
1729+
}
1730+
1731+
function _complete_astra_group_db_command_listembeddingproviders() {
1732+
# Get completion data
1733+
COMPREPLY=()
1734+
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
1735+
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
1736+
COMMANDS=$1
1737+
1738+
FLAG_OPTS="--no-color -v --verbose"
1739+
ARG_OPTS="--token -cf --config-file -o -conf --env --config --output"
1740+
1741+
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
1742+
SAW_ARG=$?
1743+
if [[ ${SAW_ARG} -eq 0 ]]; then
1744+
ARG_VALUES=
1745+
ARG_GENERATED_VALUES=
1746+
case ${PREV_WORD} in
1747+
--token)
1748+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1749+
echo ${COMPREPLY[@]}
1750+
return 0
1751+
;;
1752+
-cf|--config-file)
1753+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1754+
echo ${COMPREPLY[@]}
1755+
return 0
1756+
;;
1757+
-conf|--config)
1758+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1759+
echo ${COMPREPLY[@]}
1760+
return 0
1761+
;;
1762+
--env)
1763+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1764+
echo ${COMPREPLY[@]}
1765+
return 0
1766+
;;
1767+
-o|--output)
1768+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1769+
echo ${COMPREPLY[@]}
1770+
return 0
1771+
;;
1772+
esac
1773+
fi
1774+
1775+
ARGUMENTS=
1776+
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
1777+
echo ${COMPREPLY[@]}
1778+
return 0
1779+
}
1780+
1781+
function _complete_astra_group_db_command_describeembeddingprovider() {
1782+
# Get completion data
1783+
COMPREPLY=()
1784+
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
1785+
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
1786+
COMMANDS=$1
1787+
1788+
FLAG_OPTS="--no-color --async -v --verbose"
1789+
ARG_OPTS="--token -cf --config-file -o -ep -conf --timeout --embedding-provider --env --config --output"
1790+
1791+
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
1792+
SAW_ARG=$?
1793+
if [[ ${SAW_ARG} -eq 0 ]]; then
1794+
ARG_VALUES=
1795+
ARG_GENERATED_VALUES=
1796+
case ${PREV_WORD} in
1797+
--token)
1798+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1799+
echo ${COMPREPLY[@]}
1800+
return 0
1801+
;;
1802+
-cf|--config-file)
1803+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1804+
echo ${COMPREPLY[@]}
1805+
return 0
1806+
;;
1807+
-ep|--embedding-provider)
1808+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1809+
echo ${COMPREPLY[@]}
1810+
return 0
1811+
;;
1812+
-conf|--config)
1813+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1814+
echo ${COMPREPLY[@]}
1815+
return 0
1816+
;;
1817+
--timeout)
1818+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1819+
echo ${COMPREPLY[@]}
1820+
return 0
1821+
;;
1822+
--env)
1823+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1824+
echo ${COMPREPLY[@]}
1825+
return 0
1826+
;;
1827+
-o|--output)
1828+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1829+
echo ${COMPREPLY[@]}
1830+
return 0
1831+
;;
1832+
esac
1833+
fi
1834+
1835+
ARGUMENTS=
1836+
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
1837+
echo ${COMPREPLY[@]}
1838+
return 0
1839+
}
1840+
16611841
function _complete_astra_group_db_command_createregion() {
16621842
# Get completion data
16631843
COMPREPLY=()

src/main/java/com/dtsx/astra/cli/AstraCli.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
* #L%
2121
*/
2222

23-
import com.datastax.astra.client.exception.AuthenticationException;
24-
import com.datastax.astra.internal.utils.AnsiUtils;
2523
import com.dtsx.astra.cli.config.ConfigCreateCmd;
2624
import com.dtsx.astra.cli.config.ConfigDeleteCmd;
2725
import com.dtsx.astra.cli.config.ConfigDescribeCmd;
@@ -60,14 +58,20 @@
6058
import com.dtsx.astra.cli.db.collection.DbDescribeEmbeddingProviderCmd;
6159
import com.dtsx.astra.cli.db.collection.DbListCollectionsCmd;
6260
import com.dtsx.astra.cli.db.collection.DbListEmbeddingProvidersCmd;
61+
import com.dtsx.astra.cli.db.collection.DbTruncateCollectionCmd;
6362
import com.dtsx.astra.cli.db.cqlsh.DbCqlShellCmd;
6463
import com.dtsx.astra.cli.db.dsbulk.DbCountCmd;
6564
import com.dtsx.astra.cli.db.dsbulk.DbLoadCmd;
6665
import com.dtsx.astra.cli.db.dsbulk.DbUnLoadCmd;
6766
import com.dtsx.astra.cli.db.endpoint.DbGetEndpointApiCmd;
67+
import com.dtsx.astra.cli.db.endpoint.DbGetEndpointPlaygroundCmd;
68+
import com.dtsx.astra.cli.db.endpoint.DbGetEndpointSwaggerCmd;
69+
import com.dtsx.astra.cli.db.exception.CollectionAlreadyExistException;
70+
import com.dtsx.astra.cli.db.exception.CollectionNotFoundException;
6871
import com.dtsx.astra.cli.db.exception.DatabaseAlreadyExistException;
6972
import com.dtsx.astra.cli.db.exception.DatabaseNameNotUniqueException;
7073
import com.dtsx.astra.cli.db.exception.InvalidDatabaseStateException;
74+
import com.dtsx.astra.cli.db.exception.TableNotFoundException;
7175
import com.dtsx.astra.cli.db.keyspace.DbCreateKeyspaceCmd;
7276
import com.dtsx.astra.cli.db.keyspace.DbDeleteKeyspaceCmd;
7377
import com.dtsx.astra.cli.db.keyspace.DbListKeyspacesCmd;
@@ -79,8 +83,10 @@
7983
import com.dtsx.astra.cli.db.region.DbCreateRegionCmd;
8084
import com.dtsx.astra.cli.db.region.DbDeleteRegionCmd;
8185
import com.dtsx.astra.cli.db.region.DbListRegionsCmd;
82-
import com.dtsx.astra.cli.db.endpoint.DbGetEndpointPlaygroundCmd;
83-
import com.dtsx.astra.cli.db.endpoint.DbGetEndpointSwaggerCmd;
86+
import com.dtsx.astra.cli.db.table.DbDeleteTableCmd;
87+
import com.dtsx.astra.cli.db.table.DbDescribeTableCmd;
88+
import com.dtsx.astra.cli.db.table.DbListTablesCmd;
89+
import com.dtsx.astra.cli.db.table.DbTruncateTableCmd;
8490
import com.dtsx.astra.cli.iam.role.RoleDescribeCmd;
8591
import com.dtsx.astra.cli.iam.role.RoleGetCmd;
8692
import com.dtsx.astra.cli.iam.role.RoleListCmd;
@@ -181,7 +187,9 @@
181187
// Keyspaces
182188
DbCreateKeyspaceCmd.class, DbDeleteKeyspaceCmd.class, DbListKeyspacesCmd.class,
183189
// Collections
184-
DbListCollectionsCmd.class, DbDeleteCollectionCmd.class, DbCreateCollectionCmd.class, DbDescribeCollectionCmd.class,
190+
DbListCollectionsCmd.class, DbDeleteCollectionCmd.class, DbCreateCollectionCmd.class, DbDescribeCollectionCmd.class, DbTruncateCollectionCmd.class,
191+
// Tables
192+
DbListTablesCmd.class, DbDeleteTableCmd.class, DbDeleteTableCmd.class, DbTruncateTableCmd.class, DbDescribeTableCmd.class,
185193
// Vectorize
186194
DbListEmbeddingProvidersCmd.class, DbDescribeEmbeddingProviderCmd.class,
187195
// Regions
@@ -314,39 +322,50 @@ public static ExitCode run(Class<?> clazz, String[] args) {
314322
"astra streaming list-regions to list available regions.");
315323
return ExitCode.INVALID_OPTION_VALUE;
316324
} catch(InvalidCloudProviderException cloudException) {
325+
cloudException.printStackTrace();
317326
LoggerShell.exception(cloudException,null);
318327
LoggerShell.info("Use " +
319328
"astra db list-clouds or " +
320329
"astra streaming list-clouds to list available cloud providers.");
321330
return ExitCode.INVALID_OPTION_VALUE;
322331
} catch(ParseException ex) {
332+
ex.printStackTrace();
323333
LoggerShell.exception(ex,"Command is not properly formatted.");
324334
return ExitCode.UNRECOGNIZED_COMMAND;
325-
} catch (InvalidTokenException | TokenNotFoundException | AuthenticationException | com.dtsx.astra.sdk.exception.AuthenticationException |
335+
} catch (InvalidTokenException | TokenNotFoundException | com.dtsx.astra.sdk.exception.AuthenticationException |
326336
FileSystemException | ConfigurationException e) {
337+
e.printStackTrace();
327338
AstraCliConsole.outputError(ExitCode.CONFIGURATION, e.getMessage());
328339
return ExitCode.CONFIGURATION;
329340
} catch (InvalidArgumentException | IllegalArgumentException dex) {
341+
dex.printStackTrace();
330342
AstraCliConsole.outputError(ExitCode.INVALID_ARGUMENT, dex.getMessage());
331343
return ExitCode.INVALID_ARGUMENT;
332344
} catch (DatabaseNotFoundException | KeyspaceNotFoundException |
333345
TenantNotFoundException |
346+
CollectionNotFoundException | TableNotFoundException |
334347
RoleNotFoundException | ChangeDataCaptureNotFoundException |
335348
UserNotFoundException | RegionNotFoundException ex) {
349+
ex.printStackTrace();
336350
AstraCliConsole.outputError(ExitCode.NOT_FOUND, ex.getMessage());
337351
return ExitCode.NOT_FOUND;
338352
} catch (DatabaseNameNotUniqueException name) {
353+
name.printStackTrace();
339354
AstraCliConsole.outputError(ExitCode.CONFLICT, name.getMessage());
340355
return ExitCode.CONFLICT;
341-
} catch (DatabaseAlreadyExistException | KeyspaceAlreadyExistException |
356+
} catch (DatabaseAlreadyExistException | CollectionAlreadyExistException |
357+
KeyspaceAlreadyExistException |
342358
TenantAlreadyExistException | UserAlreadyExistException |
343359
RegionAlreadyExistException e) {
344-
AstraCliConsole.outputError(ExitCode.ALREADY_EXIST, e.getMessage());
360+
e.printStackTrace();
361+
AstraCliConsole.outputError(ExitCode.ALREADY_EXIST, e.getMessage());
345362
return ExitCode.ALREADY_EXIST;
346363
} catch(InvalidDatabaseStateException ex) {
364+
ex.printStackTrace();
347365
AstraCliConsole.outputError(ExitCode.UNAVAILABLE, ex.getMessage());
348366
return ExitCode.UNAVAILABLE;
349-
} catch (Exception ex) {
367+
} catch (Exception ex) {
368+
ex.printStackTrace();
350369
AstraCliConsole.outputError(ExitCode.INTERNAL_ERROR, ex.getMessage());
351370
return ExitCode.INTERNAL_ERROR;
352371
}

0 commit comments

Comments
 (0)