Skip to content

Commit

Permalink
Release new version
Browse files Browse the repository at this point in the history
  • Loading branch information
clun committed Jan 23, 2024
1 parent 2a7aa6e commit 6e29dc7
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 119 deletions.
2 changes: 1 addition & 1 deletion astra-db-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>astra-db-client</artifactId>
<name> + astra-db-client</name>
<name>Java Client for Astra DB</name>

<parent>
<groupId>com.datastax.astra</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.stream.Stream;

/**
* Hiding top level Json Api and skip interaction with namespaces
* Client for AstraDB at database level (crud for collections).
*/
@Slf4j @Getter
public class AstraDB {
Expand Down
129 changes: 58 additions & 71 deletions astra-db-client/src/main/java/com/dtsx/astra/sdk/AstraDBAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,62 +33,44 @@
import static io.stargate.sdk.utils.Utils.readEnvVariable;

/**
* Astra Vector Client, Native experience for Vector Database.
* Client for AstraDB at organization level (crud for databases).
*/
@Slf4j
public class AstraDBAdmin {

/** Default timeout for connection. */
/** Default timeout for initiating connection. */
public static final int CONNECT_TIMEOUT_SECONDS = 20;

/**
* Free tier.
*/
/** Default cloud provider if not provided by user. (free-tier) */
public static final CloudProviderType FREE_TIER_CLOUD = CloudProviderType.GCP;

/**
* Free tier.
*/
/** Default region if not provided by user. (free-tier) */
public static final String FREE_TIER_CLOUD_REGION = "us-east1";

/**
* Token header param
*/
/** Header name used to hold the Astra Token. */
public static final String TOKEN_HEADER_PARAM = "X-Token";

/**
* Technical Keyspace name.
*/
/** Default keyspace name if not provided by user. */
public static final String DEFAULT_KEYSPACE = "default_keyspace";

/**
* First Level of the API will
*/
/** Client for the Astra Devops Api. (crud on databases) */
final AstraDBOpsClient devopsDbClient;

/**
* Environment
*/
/** Target Astra Environment, default is PROD. */
final AstraEnvironment env;

/**
* Token required to initialize the clients
*/
/** Astra Token used as credentials. */
@Getter
final String token;

/**
* JDK HttpClient
*/
/** JDK11 HttpClient to interact with apis. */
final HttpClient httpClient;

/**
* Configuration token
*/
/** Token value read for environment variable. */
static String astraConfigToken;

/*
* Load from environment.
* Load token values from environment variables and ~/.astrarc.
*/
static {
new AstraRc().getSectionKey(
Expand All @@ -99,29 +81,30 @@ public class AstraDBAdmin {
}

/**
* Load with token from environment
* Default initialization, the token is retrieved from environment variable <code>ASTRA_DB_APPLICATION_TOKEN</code> or from
* file <code>~/.astrarc</code>, section <code>default</code>, key <code>ASTRA_DB_APPLICATION_TOKEN</code>.
*/
public AstraDBAdmin() {
this(astraConfigToken);
}

/**
* Default constructor.
* Initialization with an authentification token, defaulting to production environment.
*
* @param token
* a token is all you need
* authentication token
*/
public AstraDBAdmin(String token) {
this(token, AstraEnvironment.PROD);
}

/**
* Second constructor for non-production environments.
* Initialization with an authentification token and target environment, Use this constructor for testing purpose.
*
* @param token
* token
* authentication token
* @param env
* target environments
* target Astra environment
*/
public AstraDBAdmin(String token, AstraEnvironment env) {
this.env = env;
Expand All @@ -134,10 +117,10 @@ public AstraDBAdmin(String token, AstraEnvironment env) {
}

/**
* List active vector databases.
* List active databases with vector enabled in current organization.
*
* @return
* active devops databases.
* active databases list
*/
public Stream<Database> findAllDatabases() {
return devopsDbClient
Expand All @@ -146,7 +129,7 @@ public Stream<Database> findAllDatabases() {
}

/**
* Create Db in free Tier.
* Create new database with a name on free tier. The database name should not exist in the tenant.
*
* @param name
* database name
Expand All @@ -158,37 +141,9 @@ public UUID createDatabase(@NonNull String name) {
}

/**
* Delete a Database if exists from its name
*
* @param name
* database name
* @return
* if the db has been deleted
*/
public boolean deleteDatabaseByName(@NonNull String name) {
Optional<Database> opDb = findDatabaseByName(name).findFirst();
opDb.ifPresent(db -> devopsDbClient.database(db.getId()).delete());
return opDb.isPresent();
}

/**
* Delete a Database if exists from its name
*
* @param databaseId
* database identifier
* @return
* if the db has been deleted
*/
public boolean deleteDatabaseById(@NonNull UUID databaseId) {
if (findDatabaseById(databaseId).isPresent()) {
devopsDbClient.database(databaseId.toString()).delete();
return true;
}
return false;
}

/**
* Create a database with the full definition.
* Create new database with a name on the specified cloud provider and region.
* If the database with same name already exists it will be resumed if not active.
* The method will wait for the database to be active.
*
* @param name
* database name
Expand All @@ -197,7 +152,7 @@ public boolean deleteDatabaseById(@NonNull UUID databaseId) {
* @param cloudRegion
* cloud region
* @return
* database uid
* database identifier
*/
public UUID createDatabase(@NonNull String name, @NonNull CloudProviderType cloud, @NonNull String cloudRegion) {
Optional<Database> optDb = findDatabaseByName(name).findFirst();
Expand Down Expand Up @@ -236,6 +191,38 @@ public UUID createDatabase(@NonNull String name, @NonNull CloudProviderType clou
return newDbId;
}

/**
* Delete a Database if exists from its name
*
* @param name
* database name
* @return
* if the db has been deleted
*/
public boolean deleteDatabaseByName(@NonNull String name) {
Optional<Database> opDb = findDatabaseByName(name).findFirst();
opDb.ifPresent(db -> devopsDbClient.database(db.getId()).delete());
return opDb.isPresent();
}

/**
* Delete a Database if exists from its name
*
* @param databaseId
* database identifier
* @return
* if the db has been deleted
*/
public boolean deleteDatabaseById(@NonNull UUID databaseId) {
if (findDatabaseById(databaseId).isPresent()) {
devopsDbClient.database(databaseId.toString()).delete();
return true;
}
return false;
}




/**
* Retrieve list of all Databases of the account and filter on name
Expand Down
Loading

0 comments on commit 6e29dc7

Please sign in to comment.