3333import static io .stargate .sdk .utils .Utils .readEnvVariable ;
3434
3535/**
36- * Astra Vector Client, Native experience for Vector Database .
36+ * Client for AstraDB at organization level (crud for databases) .
3737 */
3838@ Slf4j
3939public class AstraDBAdmin {
4040
41- /** Default timeout for connection. */
41+ /** Default timeout for initiating connection. */
4242 public static final int CONNECT_TIMEOUT_SECONDS = 20 ;
4343
44- /**
45- * Free tier.
46- */
44+ /** Default cloud provider if not provided by user. (free-tier) */
4745 public static final CloudProviderType FREE_TIER_CLOUD = CloudProviderType .GCP ;
4846
49- /**
50- * Free tier.
51- */
47+ /** Default region if not provided by user. (free-tier) */
5248 public static final String FREE_TIER_CLOUD_REGION = "us-east1" ;
5349
54- /**
55- * Token header param
56- */
50+ /** Header name used to hold the Astra Token. */
5751 public static final String TOKEN_HEADER_PARAM = "X-Token" ;
5852
59- /**
60- * Technical Keyspace name.
61- */
53+ /** Default keyspace name if not provided by user. */
6254 public static final String DEFAULT_KEYSPACE = "default_keyspace" ;
6355
64- /**
65- * First Level of the API will
66- */
56+ /** Client for the Astra Devops Api. (crud on databases) */
6757 final AstraDBOpsClient devopsDbClient ;
6858
69- /**
70- * Environment
71- */
59+ /** Target Astra Environment, default is PROD. */
7260 final AstraEnvironment env ;
7361
74- /**
75- * Token required to initialize the clients
76- */
62+ /** Astra Token used as credentials. */
7763 @ Getter
7864 final String token ;
7965
80- /**
81- * JDK HttpClient
82- */
66+ /** JDK11 HttpClient to interact with apis. */
8367 final HttpClient httpClient ;
8468
85- /**
86- * Configuration token
87- */
69+ /** Token value read for environment variable. */
8870 static String astraConfigToken ;
8971
9072 /*
91- * Load from environment.
73+ * Load token values from environment variables and ~/.astrarc .
9274 */
9375 static {
9476 new AstraRc ().getSectionKey (
@@ -99,29 +81,30 @@ public class AstraDBAdmin {
9981 }
10082
10183 /**
102- * Load with token from environment
84+ * Default initialization, the token is retrieved from environment variable <code>ASTRA_DB_APPLICATION_TOKEN</code> or from
85+ * file <code>~/.astrarc</code>, section <code>default</code>, key <code>ASTRA_DB_APPLICATION_TOKEN</code>.
10386 */
10487 public AstraDBAdmin () {
10588 this (astraConfigToken );
10689 }
10790
10891 /**
109- * Default constructor .
92+ * Initialization with an authentification token, defaulting to production environment .
11093 *
11194 * @param token
112- * a token is all you need
95+ * authentication token
11396 */
11497 public AstraDBAdmin (String token ) {
11598 this (token , AstraEnvironment .PROD );
11699 }
117100
118101 /**
119- * Second constructor for non-production environments .
102+ * Initialization with an authentification token and target environment, Use this constructor for testing purpose .
120103 *
121104 * @param token
122- * token
105+ * authentication token
123106 * @param env
124- * target environments
107+ * target Astra environment
125108 */
126109 public AstraDBAdmin (String token , AstraEnvironment env ) {
127110 this .env = env ;
@@ -134,10 +117,10 @@ public AstraDBAdmin(String token, AstraEnvironment env) {
134117 }
135118
136119 /**
137- * List active vector databases .
120+ * List active databases with vector enabled in current organization .
138121 *
139122 * @return
140- * active devops databases.
123+ * active databases list
141124 */
142125 public Stream <Database > findAllDatabases () {
143126 return devopsDbClient
@@ -146,7 +129,7 @@ public Stream<Database> findAllDatabases() {
146129 }
147130
148131 /**
149- * Create Db in free Tier .
132+ * Create new database with a name on free tier. The database name should not exist in the tenant .
150133 *
151134 * @param name
152135 * database name
@@ -158,37 +141,9 @@ public UUID createDatabase(@NonNull String name) {
158141 }
159142
160143 /**
161- * Delete a Database if exists from its name
162- *
163- * @param name
164- * database name
165- * @return
166- * if the db has been deleted
167- */
168- public boolean deleteDatabaseByName (@ NonNull String name ) {
169- Optional <Database > opDb = findDatabaseByName (name ).findFirst ();
170- opDb .ifPresent (db -> devopsDbClient .database (db .getId ()).delete ());
171- return opDb .isPresent ();
172- }
173-
174- /**
175- * Delete a Database if exists from its name
176- *
177- * @param databaseId
178- * database identifier
179- * @return
180- * if the db has been deleted
181- */
182- public boolean deleteDatabaseById (@ NonNull UUID databaseId ) {
183- if (findDatabaseById (databaseId ).isPresent ()) {
184- devopsDbClient .database (databaseId .toString ()).delete ();
185- return true ;
186- }
187- return false ;
188- }
189-
190- /**
191- * Create a database with the full definition.
144+ * Create new database with a name on the specified cloud provider and region.
145+ * If the database with same name already exists it will be resumed if not active.
146+ * The method will wait for the database to be active.
192147 *
193148 * @param name
194149 * database name
@@ -197,7 +152,7 @@ public boolean deleteDatabaseById(@NonNull UUID databaseId) {
197152 * @param cloudRegion
198153 * cloud region
199154 * @return
200- * database uid
155+ * database identifier
201156 */
202157 public UUID createDatabase (@ NonNull String name , @ NonNull CloudProviderType cloud , @ NonNull String cloudRegion ) {
203158 Optional <Database > optDb = findDatabaseByName (name ).findFirst ();
@@ -236,6 +191,38 @@ public UUID createDatabase(@NonNull String name, @NonNull CloudProviderType clou
236191 return newDbId ;
237192 }
238193
194+ /**
195+ * Delete a Database if exists from its name
196+ *
197+ * @param name
198+ * database name
199+ * @return
200+ * if the db has been deleted
201+ */
202+ public boolean deleteDatabaseByName (@ NonNull String name ) {
203+ Optional <Database > opDb = findDatabaseByName (name ).findFirst ();
204+ opDb .ifPresent (db -> devopsDbClient .database (db .getId ()).delete ());
205+ return opDb .isPresent ();
206+ }
207+
208+ /**
209+ * Delete a Database if exists from its name
210+ *
211+ * @param databaseId
212+ * database identifier
213+ * @return
214+ * if the db has been deleted
215+ */
216+ public boolean deleteDatabaseById (@ NonNull UUID databaseId ) {
217+ if (findDatabaseById (databaseId ).isPresent ()) {
218+ devopsDbClient .database (databaseId .toString ()).delete ();
219+ return true ;
220+ }
221+ return false ;
222+ }
223+
224+
225+
239226
240227 /**
241228 * Retrieve list of all Databases of the account and filter on name
0 commit comments