Skip to content

Commit ceb3c39

Browse files
committed
create-keyspace
1 parent da42290 commit ceb3c39

File tree

13 files changed

+240
-60
lines changed

13 files changed

+240
-60
lines changed

astra-shell/src/main/java/com/datastax/astra/shell/AstraCli.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.fusesource.jansi.AnsiConsole;
66

77
import com.datastax.astra.shell.cmd.HelpCommand;
8+
import com.datastax.astra.shell.cmd.config.BaseConfigCommand;
89
import com.datastax.astra.shell.cmd.config.ConfigCreate;
910
import com.datastax.astra.shell.cmd.config.ConfigDefault;
1011
import com.datastax.astra.shell.cmd.config.ConfigDelete;
@@ -13,11 +14,13 @@
1314
import com.datastax.astra.shell.cmd.config.ConfigSetup;
1415
import com.datastax.astra.shell.cmd.db.DbCqlShellCli;
1516
import com.datastax.astra.shell.cmd.db.DbCreateCli;
17+
import com.datastax.astra.shell.cmd.db.DbCreateKeyspaceCli;
1618
import com.datastax.astra.shell.cmd.db.DbDeleteCli;
1719
import com.datastax.astra.shell.cmd.db.DbListCli;
1820
import com.datastax.astra.shell.cmd.db.DbGetCli;
1921
import com.datastax.astra.shell.cmd.db.OperationsDb;
2022
import com.datastax.astra.shell.cmd.iam.RoleListCli;
23+
import com.datastax.astra.shell.cmd.iam.OperationIam;
2124
import com.datastax.astra.shell.cmd.iam.RoleGetCli;
2225
import com.datastax.astra.shell.cmd.iam.UserDeleteCli;
2326
import com.datastax.astra.shell.cmd.iam.UserInviteCli;
@@ -50,19 +53,20 @@
5053
DbDeleteCli.class,
5154
DbGetCli.class,
5255
DbListCli.class,
56+
DbCreateKeyspaceCli.class
5357
}),
54-
@Group(name = "config", description = "Manage configuration file", commands = {
58+
@Group(name = BaseConfigCommand.COMMAND_CONFIG, description = "Manage configuration file", commands = {
5559
ConfigCreate.class,
5660
ConfigDefault.class,
5761
ConfigDelete.class,
5862
ConfigGet.class,
5963
ConfigList.class
6064
}),
61-
@Group(name= "role", description = "Manage roles (RBAC)", commands = {
65+
@Group(name= OperationIam.COMMAND_ROLE, description = "Manage roles (RBAC)", commands = {
6266
RoleListCli.class,
6367
RoleGetCli.class
6468
}),
65-
@Group(name= "user", description = "Manage users", commands = {
69+
@Group(name= OperationIam.COMMAND_USER, description = "Manage users", commands = {
6670
UserListCli.class,
6771
UserGetCli.class,
6872
UserInviteCli.class,

astra-shell/src/main/java/com/datastax/astra/shell/AstraShell.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
import com.datastax.astra.shell.cmd.db.DbListShell;
1010
import com.datastax.astra.shell.cmd.db.DbUseShell;
1111
import com.datastax.astra.shell.cmd.db.OperationsDb;
12-
import com.datastax.astra.shell.cmd.iam.RoleListShell;
12+
import com.datastax.astra.shell.cmd.iam.OperationIam;
1313
import com.datastax.astra.shell.cmd.iam.RoleGetCli;
14+
import com.datastax.astra.shell.cmd.iam.RoleListShell;
1415
import com.datastax.astra.shell.cmd.iam.UserDeleteShell;
16+
import com.datastax.astra.shell.cmd.iam.UserGetShell;
1517
import com.datastax.astra.shell.cmd.iam.UserInviteShell;
1618
import com.datastax.astra.shell.cmd.iam.UserListShell;
17-
import com.datastax.astra.shell.cmd.iam.UserGetShell;
1819
import com.datastax.astra.shell.cmd.shell.ConnectCommand;
1920
import com.datastax.astra.shell.cmd.shell.EmptyCommand;
2021
import com.datastax.astra.shell.out.LoggerShell;
@@ -47,11 +48,11 @@
4748
DbGetShell.class,
4849
DbUseShell.class
4950
}),
50-
@Group(name= "role", description = "Manage the roles (RBAC)", commands = {
51+
@Group(name= OperationIam.COMMAND_ROLE, description = "Manage the roles (RBAC)", commands = {
5152
RoleListShell.class,
5253
RoleGetCli.class
5354
}),
54-
@Group(name= "user", description = "Manage the users permission", commands = {
55+
@Group(name= OperationIam.COMMAND_USER, description = "Manage the users permission", commands = {
5556
UserListShell.class,
5657
UserGetShell.class,
5758
UserInviteShell.class,

astra-shell/src/main/java/com/datastax/astra/shell/cmd/config/BaseConfigCommand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
*/
1212
public abstract class BaseConfigCommand extends BaseCommand {
1313

14+
/** worki with roles. */
15+
public static final String COMMAND_CONFIG = "config";
16+
1417
/**
1518
* File on disk to reuse configuration.
1619
*/

astra-shell/src/main/java/com/datastax/astra/shell/cmd/db/DbCreateCli.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
@Command(name = BaseCommand.CREATE, description = "Create a database with cli")
1919
public class DbCreateCli extends BaseCliCommand {
2020

21+
/** Cqlsh Options. */
22+
@Option(name = { "--if-not-exist" },
23+
description = "will create a new DB only if none with same name")
24+
protected boolean ifNotExist = false;
25+
2126
/**
2227
* Database name or identifier
2328
*/
@@ -35,14 +40,14 @@ public class DbCreateCli extends BaseCliCommand {
3540
/**
3641
* Default keyspace created with the Db
3742
*/
38-
@Option(name = { "-ks", "--keyspace" }, title = "KEYSPACE", arity = 1,
43+
@Option(name = { "-k", "--keyspace" }, title = "KEYSPACE", arity = 1,
3944
description = "Default keyspace created with the Db")
4045
protected String defaultKeyspace;
4146

4247
/** {@inheritDoc} */
4348
@Override
4449
public ExitCode execute() {
45-
return OperationsDb.createDb(databaseName, databaseRegion, defaultKeyspace);
50+
return OperationsDb.createDb(databaseName, databaseRegion, defaultKeyspace, ifNotExist);
4651
}
4752

4853
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.datastax.astra.shell.cmd.db;
2+
3+
import com.datastax.astra.shell.ExitCode;
4+
import com.datastax.astra.shell.cmd.BaseCliCommand;
5+
import com.github.rvesse.airline.annotations.Arguments;
6+
import com.github.rvesse.airline.annotations.Command;
7+
import com.github.rvesse.airline.annotations.Option;
8+
import com.github.rvesse.airline.annotations.restrictions.Required;
9+
10+
/**
11+
* Delete a DB is exist
12+
*
13+
* @author Cedrick LUNVEN (@clunven)
14+
*/
15+
@Command(name = OperationsDb.CMD_CREATE_KEYSPACE, description = "Create a new keyspace")
16+
public class DbCreateKeyspaceCli extends BaseCliCommand {
17+
18+
/**
19+
* Database name or identifier
20+
*/
21+
@Required
22+
@Arguments(title = "DB", description = "Database name or identifier")
23+
public String database;
24+
25+
/** Provide a keyspace Name. */
26+
@Required
27+
@Option(name = {"-k", "--keyspace" },
28+
title = "KEYSPACE",
29+
arity = 1,
30+
description = "Name of the keyspace to create")
31+
public String keyspace;
32+
33+
/** Cqlsh Options. */
34+
@Option(name = { "--if-not-exist" },
35+
description = "will create a new DB only if none with same name")
36+
protected boolean ifNotExist = false;
37+
38+
/** {@inheritDoc} */
39+
public ExitCode execute() {
40+
return OperationsDb.createKeyspace(database, keyspace, ifNotExist);
41+
}
42+
43+
}

astra-shell/src/main/java/com/datastax/astra/shell/cmd/db/DbCreateShell.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
@Command(name = BaseCommand.CREATE, description = "Create a database with shell")
1919
public class DbCreateShell extends BaseShellCommand {
2020

21+
/** Cqlsh Options. */
22+
@Option(name = { "--if-not-exist" },
23+
description = "will create a new DB only if none with same name")
24+
protected boolean ifNotExist = false;
25+
2126
/**
2227
* Database name or identifier
2328
*/
@@ -42,7 +47,7 @@ public class DbCreateShell extends BaseShellCommand {
4247
/** {@inheritDoc} */
4348
@Override
4449
public ExitCode execute() {
45-
return OperationsDb.createDb(databaseName, databaseRegion, defaultKeyspace);
50+
return OperationsDb.createDb(databaseName, databaseRegion, defaultKeyspace, ifNotExist);
4651
}
4752

4853
}

astra-shell/src/main/java/com/datastax/astra/shell/cmd/db/DbGetCli.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public class DbGetCli extends BaseCliCommand {
1818
/** name of the DB. */
1919
@Required
2020
@Arguments(title = "DB", description = "Database name or identifier")
21-
public String databaseId;
21+
public String database;
2222

2323
/** {@inheritDoc} */
2424
public ExitCode execute() {
25-
return OperationsDb.showDb(databaseId);
25+
return OperationsDb.showDb(database);
2626
}
2727

2828
}

0 commit comments

Comments
 (0)