Skip to content

Commit

Permalink
Add 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
clun committed Nov 11, 2022
1 parent cd48d6a commit dda1dfc
Show file tree
Hide file tree
Showing 80 changed files with 1,926 additions and 629 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<app.main.class>com.dtsx.astra.cli.AstraCli</app.main.class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<astra-sdk.version>0.3.5</astra-sdk.version>
<astra-sdk.version>0.3.6-SNAPSHOT</astra-sdk.version>
<jansi.version>2.4.0</jansi.version>
<airline.version>2.9.0</airline.version>
<slf4j.version>2.0.3</slf4j.version>
Expand Down
43 changes: 34 additions & 9 deletions src/main/java/com/dtsx/astra/cli/AstraCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@
import com.dtsx.astra.cli.db.exception.KeyspaceAlreadyExistException;
import com.dtsx.astra.cli.db.keyspace.DbCreateKeyspaceCmd;
import com.dtsx.astra.cli.db.keyspace.DbListKeyspacesCmd;
import com.dtsx.astra.cli.iam.*;
import com.dtsx.astra.cli.iam.exception.RoleNotFoundException;
import com.dtsx.astra.cli.iam.exception.UserAlreadyExistException;
import com.dtsx.astra.cli.iam.exception.UserNotFoundException;
import com.dtsx.astra.cli.db.region.*;
import com.dtsx.astra.cli.db.tool.DbGraphqlPlaygroundCmd;
import com.dtsx.astra.cli.db.tool.DbSwaggerUICmd;
import com.dtsx.astra.cli.iam.role.exception.RoleNotFoundException;
import com.dtsx.astra.cli.iam.user.exception.UserAlreadyExistException;
import com.dtsx.astra.cli.iam.user.exception.UserNotFoundException;
import com.dtsx.astra.cli.iam.role.RoleGetCmd;
import com.dtsx.astra.cli.iam.role.RoleListCmd;
import com.dtsx.astra.cli.iam.token.TokenCreateCmd;
import com.dtsx.astra.cli.iam.token.TokenDeleteCmd;
import com.dtsx.astra.cli.iam.token.TokenListCmd;
import com.dtsx.astra.cli.iam.user.UserDeleteCmd;
import com.dtsx.astra.cli.iam.user.UserGetCmd;
import com.dtsx.astra.cli.iam.user.UserInviteCmd;
import com.dtsx.astra.cli.iam.user.UserListCmd;
import com.dtsx.astra.cli.org.*;
import com.dtsx.astra.cli.streaming.*;
import com.dtsx.astra.cli.streaming.cdc.StreamingCreateCdcCmd;
Expand Down Expand Up @@ -103,14 +114,18 @@
DbListCmd.class, DbGetCmd.class, DbStatusCmd.class,
// Operation
DbResumeCmd.class, DbDownloadScbCmd.class, DbCreateDotEnvCmd.class,
// Keyspaces
DbCreateKeyspaceCmd.class, DbListKeyspacesCmd.class,
// DsBulk
DbCountCmd.class, DbLoadCmd.class, DbUnLoadCmd.class,
// Cqlshell
DbCqlShellCmd.class,
// List Regions
DbListRegionsClassicCmd.class, DbListRegionsServerlessCmd.class
// Work with Keyspaces
DbCreateKeyspaceCmd.class, DbListKeyspacesCmd.class,
// Work with Regions
DbCreateRegionCmd.class, DbListRegionsCmd.class, DbDeleteRegionCmd.class,
// List Region
DbListRegionsClassicCmd.class, DbListRegionsServerlessCmd.class,
// External Tools
DbSwaggerUICmd.class, DbGraphqlPlaygroundCmd.class
}),

@Group(
Expand All @@ -124,10 +139,11 @@
StreamingListCmd.class, StreamingGetCmd.class,
StreamingExistCmd.class, StreamingStatusCmd.class,
StreamingPulsarTokenCmd.class, StreamingCreateDotEnvCmd.class,
// list Regions
StreamingListRegionsCmd.class,
// Pulsar Shell
PulsarShellCmd.class,
// Create CDC
// Change Data Capture
StreamingCreateCdcCmd.class, StreamingDeleteCdcCmd.class, StreamingGetCdcCmd.class
}),

Expand All @@ -147,6 +163,14 @@
UserGetCmd.class, UserInviteCmd.class, UserDeleteCmd.class,
UserListCmd.class
}),

@Group(
name= "token",
description = "Manage tokens",
defaultCommand = TokenListCmd.class,
commands = {
TokenListCmd.class, TokenCreateCmd.class, TokenDeleteCmd.class
})
})
public class AstraCli {

Expand Down Expand Up @@ -239,6 +263,7 @@ public static ExitCode run(Class<?> clazz, String[] args) {
AstraCliConsole.outputError(ExitCode.UNAVAILABLE, ex.getMessage());
return ExitCode.UNAVAILABLE;
} catch (Exception ex) {
ex.printStackTrace();
AstraCliConsole.outputError(ExitCode.INTERNAL_ERROR, ex.getMessage());
return ExitCode.INTERNAL_ERROR;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/dtsx/astra/cli/config/ConfigCreateCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import com.dtsx.astra.cli.core.exception.InvalidTokenException;
import com.dtsx.astra.cli.core.exception.TokenNotFoundException;
import com.dtsx.astra.cli.core.out.AstraCliConsole;
import com.dtsx.astra.sdk.organizations.OrganizationsClient;
import com.dtsx.astra.sdk.organizations.domain.Organization;
import com.dtsx.astra.sdk.org.OrganizationsClient;
import com.dtsx.astra.sdk.org.domain.Organization;
import com.github.rvesse.airline.annotations.Arguments;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ConfigDeleteCmd extends AbstractCmd {
/** {@inheritDoc} */
@Override
public void execute() {
OperationsConfig.assertSectionExist(sectionName);
ServiceConfig.assertSectionExist(sectionName);
ctx().getConfiguration().deleteSection(sectionName);
ctx().getConfiguration().save();
AstraCliConsole.outputSuccess("Section '" + sectionName + "' has been deleted.");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/dtsx/astra/cli/config/ConfigGetCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ConfigGetCmd extends AbstractCmd {
/** {@inheritDoc} */
@Override
public void execute() throws ConfigurationException {
OperationsConfig.assertSectionExist(sectionName);
ServiceConfig.assertSectionExist(sectionName);
if (key != null) {
Optional<String> optKey = ctx().getConfiguration().getSectionKey(sectionName, key);
if (optKey.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/dtsx/astra/cli/config/ConfigListCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ConfigListCmd extends AbstractCmd {
/** {@inheritDoc} */
@Override
public void execute() {
OperationsConfig.listConfigurations();
ServiceConfig.listConfigurations();
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/dtsx/astra/cli/config/ConfigUseCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ConfigUseCmd extends AbstractCmd {
/** {@inheritDoc} */
@Override
public void execute() {
OperationsConfig.assertSectionExist(sectionName);
ServiceConfig.assertSectionExist(sectionName);
ctx().getConfiguration().copySection(sectionName, AstraConfiguration.ASTRARC_DEFAULT);
ctx().getConfiguration().save();
AstraCliConsole.outputSuccess("Section '" + sectionName + "' is set as default.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @author Cedrick LUNVEN (@clunven)
*/
public class OperationsConfig {
public class ServiceConfig {

/**
* Title of the table.
Expand All @@ -45,7 +45,7 @@ public class OperationsConfig {
/**
* Hide default constructor
*/
private OperationsConfig() {}
private ServiceConfig() {}

/**
* Syntax sugar.
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/dtsx/astra/cli/config/SetupCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.dtsx.astra.cli.core.exception.InvalidTokenException;
import com.dtsx.astra.cli.core.out.AstraCliConsole;
import com.dtsx.astra.cli.core.out.LoggerShell;
import com.dtsx.astra.sdk.organizations.OrganizationsClient;
import com.dtsx.astra.sdk.org.OrganizationsClient;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;
import org.fusesource.jansi.Ansi;
Expand Down Expand Up @@ -94,7 +94,9 @@ private void createDefaultSection(String token)
ccc.sectionName = new OrganizationsClient(token).organization().getName();
ccc.run();
} catch(Exception e) {
LoggerShell.error("Token provided is invalid. Please enter a valid token or quit with CTRL+C");
LoggerShell.warning("Invalid token: It must be start with 'AstraCS:..' and have Organization Administrator privileges.");
LoggerShell.warning("Generated token at database creation cannot be used.");
LoggerShell.warning("Please enter a valid token or quit with CTRL+C.");
throw new InvalidTokenException(token, e);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/dtsx/astra/cli/core/CliContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import com.dtsx.astra.cli.core.out.AstraCliConsole;
import com.dtsx.astra.cli.core.out.LoggerShell;
import com.dtsx.astra.cli.core.out.OutputFormat;
import com.dtsx.astra.sdk.databases.DatabasesClient;
import com.dtsx.astra.sdk.organizations.OrganizationsClient;
import com.dtsx.astra.sdk.db.DatabasesClient;
import com.dtsx.astra.sdk.org.OrganizationsClient;
import com.dtsx.astra.sdk.org.OrganizationsClient;
import com.dtsx.astra.sdk.streaming.StreamingClient;
import com.dtsx.astra.sdk.utils.AstraRc;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -183,7 +184,7 @@ private void validateToken() {
*/
public String getToken()
throws TokenNotFoundException {
if (StringUtils.isEmpty(tokenOptions.token())) {
if (tokenOptions == null || StringUtils.isEmpty(tokenOptions.token())) {
throw new TokenNotFoundException();
}
return tokenOptions.token();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ public TokenNotFoundException() {
super("Token has not been found.");
}

/**
* Default constructor
*/
public TokenNotFoundException(String tokenId) {
super("Token "+ tokenId + " has not been found.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public abstract class AbstractDatabaseCmd extends AbstractConnectedCmd {

/** Access to sdb Services. */
protected DatabaseService dbServices = DatabaseService.getInstance();
protected ServiceDatabase dbServices = ServiceDatabase.getInstance();

/**
* Database name or identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import com.dtsx.astra.cli.db.exception.DatabaseNotFoundException;
import com.dtsx.astra.cli.utils.AstraCliUtils;
import com.dtsx.astra.cli.utils.FileUtils;
import com.dtsx.astra.sdk.databases.DatabaseClient;
import com.dtsx.astra.sdk.databases.DatabasesClient;
import com.dtsx.astra.sdk.databases.domain.Database;
import com.dtsx.astra.sdk.databases.domain.Datacenter;
import com.dtsx.astra.sdk.db.DatabaseClient;
import com.dtsx.astra.sdk.db.DatabasesClient;
import com.dtsx.astra.sdk.db.domain.Database;
import com.dtsx.astra.sdk.db.domain.Datacenter;

import java.io.File;
import java.util.List;
Expand All @@ -42,30 +42,30 @@
*
* @author Cedrick LUNVEN (@clunven)
*/
public class DatabaseDao {
public class DaoDatabase {

/**
* Singleton Pattern
*/
private static DatabaseDao instance;
private static DaoDatabase instance;

/**
* Singleton Pattern.
*
* @return
* instance of the service.
*/
public static synchronized DatabaseDao getInstance() {
public static synchronized DaoDatabase getInstance() {
if (null == instance) {
instance = new DatabaseDao();
instance = new DaoDatabase();
}
return instance;
}

/**
* Default Constructor.
*/
private DatabaseDao() {
private DaoDatabase() {
}


Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/dtsx/astra/cli/db/DbCreateCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.dtsx.astra.cli.db.exception.DatabaseNotFoundException;
import com.dtsx.astra.cli.db.exception.InvalidDatabaseStateException;
import com.dtsx.astra.cli.db.exception.KeyspaceAlreadyExistException;
import com.dtsx.astra.sdk.databases.domain.DatabaseStatusType;
import com.dtsx.astra.sdk.db.domain.DatabaseStatusType;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;

Expand All @@ -52,7 +52,7 @@ public class DbCreateCmd extends AbstractDatabaseCmd {
*/
@Option(name = { "-r", "--region" }, title = "DB_REGION", arity = 1,
description = "Cloud provider region to provision")
protected String region = DatabaseService.DEFAULT_REGION;
protected String region = ServiceDatabase.DEFAULT_REGION;

/**
* Default keyspace created with the Db
Expand All @@ -66,22 +66,28 @@ public class DbCreateCmd extends AbstractDatabaseCmd {
*/
@Option(name = { "--wait" },
description = "Will wait until the database become ACTIVE")
protected boolean wait = false;
protected boolean wait = true;

/**
* Will not wait for the database become available.
*/
@Option(name = { "--async" }, description = "Will not wait for the resource to become available")
protected boolean async = false;

/**
* Provide a limit to the wait period in seconds, default is 180s.
*/
@Option(name = { "--timeout" },
description = "Provide a limit to the wait period in seconds, default is 300s.")
protected int timeout = DatabaseService.DEFAULT_TIMEOUT_SECONDS;
protected int timeout = ServiceDatabase.DEFAULT_TIMEOUT_SECONDS;

/** {@inheritDoc} */
@Override
public void execute()
throws DatabaseNameNotUniqueException, DatabaseNotFoundException,
InvalidDatabaseStateException, InvalidArgumentException, KeyspaceAlreadyExistException {
dbServices.createDb(db, region, keyspace, ifNotExist);
if (wait) {
if (!async) {
switch (dbServices.waitForDbStatus(db, DatabaseStatusType.ACTIVE, timeout)) {
case NOT_FOUND -> throw new DatabaseNotFoundException(db);
case UNAVAILABLE -> throw new InvalidDatabaseStateException(db, DatabaseStatusType.ACTIVE, DatabaseStatusType.PENDING);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/dtsx/astra/cli/db/DbCreateDotEnvCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
public class DbCreateDotEnvCmd extends AbstractDatabaseCmd {

/**
* Cloud provider region to provision
* Specified a region explicitly
*/
@Option(name = { "-r", "--region" }, title = "DB_REGION", arity = 1,
description = "Cloud provider region to provision")
protected String region = DatabaseService.DEFAULT_REGION;
description = "Cloud provider region")
protected String region;

/**
* Default keyspace created with the Db
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/dtsx/astra/cli/db/DbDeleteCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import com.dtsx.astra.cli.core.out.AstraCliConsole;
import com.dtsx.astra.cli.db.exception.InvalidDatabaseStateException;
import com.dtsx.astra.sdk.databases.domain.DatabaseStatusType;
import com.dtsx.astra.sdk.db.domain.DatabaseStatusType;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;

Expand All @@ -39,7 +39,7 @@ public class DbDeleteCmd extends AbstractDatabaseCmd {
*/
@Option(name = { "--wait" },
description = "Will wait until the database become ACTIVE")
protected boolean wait = false;
protected boolean wait = true;

/**
* Provide a limit to the wait period in seconds, default is 180s.
Expand All @@ -48,10 +48,16 @@ public class DbDeleteCmd extends AbstractDatabaseCmd {
description = "Provide a limit to the wait period in seconds, default is 300s.")
protected int timeout = 300;

/**
* Will not wait for the database become available.
*/
@Option(name = { "--async" }, description = "Will not wait for the resource to become available")
protected boolean async = false;

/** {@inheritDoc} */
public void execute() {
dbServices.deleteDb(db);
if (wait) {
if (!async) {
if (dbServices.retryUntilDbDeleted(db, timeout) >= timeout) {
throw new InvalidDatabaseStateException(db, DatabaseStatusType.TERMINATED,
DatabaseStatusType.TERMINATING);
Expand Down
Loading

0 comments on commit dda1dfc

Please sign in to comment.