Skip to content

Commit 280a7db

Browse files
committed
Fix path, Fix Db status
1 parent 339acab commit 280a7db

File tree

20 files changed

+109
-50
lines changed

20 files changed

+109
-50
lines changed

astra-sdk/src/main/java/com/datastax/astra/sdk/AstraClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public AstraClient(String dbId, String dbRegion, String token) {
105105
.withDatabaseRegion(dbRegion));
106106
}
107107

108-
109108
/**
110109
* Initialization through builder.
111110
*

astra-sdk/src/main/java/com/datastax/astra/sdk/config/AstraClientConfig.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public class AstraClientConfig implements Serializable {
3636

3737
/** Logger for our Client. */
3838
private static final Logger LOGGER = LoggerFactory.getLogger(AstraClientConfig.class);
39+
40+
/** User home folder. */
41+
public static final String ENV_USER_HOME = "user.home";
42+
43+
/** Where yo download cloud secure bundles. */
44+
public static final String DEFAULT_SCB_FOLDER = System.getProperty(ENV_USER_HOME) + File.separator + ".astra" + File.separator + "scb";
3945

4046
/** Initialize parameters from Environment variables. */
4147
public static final String ASTRA_DB_ID = "ASTRA_DB_ID";
@@ -51,9 +57,7 @@ public class AstraClientConfig implements Serializable {
5157
public static final String ASTRA_DB_KEYSPACE = "ASTRA_DB_KEYSPACE";
5258
/** SECURE BUNDLE FOR EACH RECGIONS. */
5359
public static final String ASTRA_DB_SCB_FOLDER = "ASTRA_DB_SCB_FOLDER";
54-
/** User home folder. */
55-
public static final String ENV_USER_HOME = "user.home";
56-
60+
5761
/** Port for grpc in Astra. */
5862
public static final int GRPC_PORT = 443;
5963

@@ -290,7 +294,7 @@ public AstraClientConfig enableGrpc() {
290294
private boolean downloadSecureConnectBundle = true;
291295

292296
/** Folder to load secure connect bundle with formated names scb_dbid_region.zip */
293-
private String secureConnectBundleFolder = System.getProperty(ENV_USER_HOME) + File.separator + ".astra";
297+
private String secureConnectBundleFolder = DEFAULT_SCB_FOLDER;
294298

295299
/**
296300
* Getter accessor for attribute 'secureConnectBundleFolder'.

astra-sdk/src/main/java/com/datastax/astra/sdk/databases/DatabaseClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void downloadAllSecureConnectBundles(String destination) {
167167
Utils.downloadFile(dc.getSecureBundleUrl(), fileName);
168168
LOGGER.info("+ Downloading file: {}", fileName);
169169
} else {
170-
LOGGER.info("+ SecureBundle found : {}", buildScbFileName(odb.get().getId(), dc.getRegion()));
170+
LOGGER.info("+ {} available (no download)", buildScbFileName(odb.get().getId(), dc.getRegion()));
171171
}
172172
});
173173
}

astra-sdk/src/main/java/com/datastax/astra/sdk/databases/domain/DatabaseStatusType.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
23
* Copyright DataStax, Inc.
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,6 +28,8 @@ public enum DatabaseStatusType {
2728
/** */
2829
ERROR,
2930
/** */
31+
DEGRADED,
32+
/** */
3033
HIBERNATED,
3134
/** */
3235
HIBERNATING,

astra-sdk/src/main/java/com/datastax/astra/sdk/utils/AstraRc.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ public String renderSections() {
304304
public String renderSection(String sectionName) {
305305
StringBuilder sb = new StringBuilder();
306306
if (sectionName!= null && sections.containsKey(sectionName)) {
307-
sb.append(LINE_SEPARATOR + "[" + sectionName + "]"+ LINE_SEPARATOR);
308307
sections.get(sectionName).entrySet().forEach(line -> {
309308
sb.append(line.getKey() + "=" + line.getValue() + LINE_SEPARATOR);
310309
});

astra-sdk/src/test/java/com/datastax/astra/sdk/AstraRcTest.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616

1717
package com.datastax.astra.sdk;
1818

19+
import java.io.File;
20+
1921
import org.junit.Ignore;
22+
import org.junit.jupiter.api.Assertions;
23+
import org.junit.jupiter.api.DisplayName;
24+
import org.junit.jupiter.api.Test;
25+
26+
import com.datastax.astra.sdk.utils.AstraRc;
2027

2128
/**
2229
* Create Astrarc to execute test locally.
@@ -26,20 +33,25 @@
2633
@Ignore
2734
public class AstraRcTest {
2835

29-
/*
36+
/** Could be reused for tests. */
37+
public File tmpAstraRC = new File(System.getProperty("java.io.tmpdir") + File.separator + ".astrarc");
38+
3039
@Test
3140
@DisplayName("Create .astraRC without clientId/clientSecret")
3241
public void should_create_astraRc_File() {
42+
tmpAstraRC.delete();
3343
// Given
34-
new File(System.getProperty("user.home") + "/.astrarc").delete();
35-
Assertions.assertFalse(new File(System.getProperty("user.home") + "/.astrarc").exists());
44+
Assertions.assertFalse(tmpAstraRC.exists());
3645
// When
37-
AstraRc.create(AstraClient.builder().build().getToken().get());
38-
// Then
39-
Assertions.assertTrue(new File(System.getProperty("user.home") + "/.astrarc").exists());
40-
// Then we should be able to load the file
41-
AstraRc.load().print();
46+
AstraRc arc = new AstraRc(tmpAstraRC.getAbsolutePath());
47+
48+
arc.createSectionWithToken("default", "ABC");
49+
arc.save();
50+
//Then
51+
Assertions.assertTrue(tmpAstraRC.exists());
52+
System.out.println(arc.getSections());
4253
}
43-
*/
54+
55+
4456

4557
}

astra-shell/NOTES.MD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ mvn clean install -Dmaven.test.skip=true
4444
4545
(2) mvn clean install -Dmaven.test.skip=true -Pnative
4646
47+
# Clean the ZIP
48+
zip -d 0.3.2-alpha2.zip __MACOSX/\*
49+
zip -d 0.3.2-alpha2.zip \*/.DS_Store
50+
51+
4752
4853
4954

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ public static void main(String[] args) {
114114
.run(); // Run the command
115115

116116
} catch(ParseArgumentsUnexpectedException ex) {
117+
LoggerShell.error("Invalid command\n - try 'astra help' to get general help\n - try 'astra help <cmd>' to get help on a particular command (eg: astra help db create)\n - [TAB][TAB] help you with autocompletion." );
117118

118-
LoggerShell.error("Invalid command: " + ex.getMessage());
119-
//ex.printStackTrace();
120119
} catch(Exception e) {
121120
LoggerShell.error("Execution error:" + e.getMessage());
122121
//e.printStackTrace();

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.datastax.astra.shell.cmd.config;
22

3+
import java.util.Optional;
4+
35
import com.datastax.astra.shell.ExitCode;
46
import com.datastax.astra.shell.cmd.BaseCommand;
57
import com.datastax.astra.shell.out.ShellPrinter;
68
import com.github.rvesse.airline.annotations.Arguments;
79
import com.github.rvesse.airline.annotations.Command;
10+
import com.github.rvesse.airline.annotations.Option;
811
import com.github.rvesse.airline.annotations.restrictions.Required;
912

1013
/**
@@ -25,11 +28,24 @@ public class ConfigGet extends BaseConfigCommand implements Runnable {
2528
description = "Section in configuration file to as as defulat.")
2629
protected String sectionName;
2730

31+
/** Authentication token used if not provided in config. */
32+
@Option(name = { "-k", "--key" }, title = "Key in the section", description = "If provided return only value for a key.")
33+
protected String key;
34+
2835
/** {@inheritDoc} */
2936
public void run() {
3037
if (!getAstraRc().isSectionExists(sectionName)) {
3138
ShellPrinter.outputError(ExitCode.INVALID_PARAMETER, "Section '" + sectionName + "' has not been found in config.");
3239
ExitCode.INVALID_PARAMETER.exit();
40+
} else if (key != null) {
41+
Optional<String> optKey = getAstraRc().getSectionKey(sectionName, key);
42+
if (!optKey.isPresent()) {
43+
ShellPrinter.outputError(ExitCode.INVALID_PARAMETER,
44+
"Key '" + key + "' has not been found in config section '" + sectionName + "'");
45+
ExitCode.INVALID_PARAMETER.exit();
46+
} else {
47+
System.out.print(optKey.get());
48+
}
3349
} else {
3450
System.out.print(getAstraRc().renderSection(sectionName));
3551
}

astra-shell/src/test/java/com/datastax/astra/DatabasesCommandsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,11 @@ public void createKeyspace() throws Exception {
3434
astraCli("db", "create-keyspace", "foo", "-k", "ks3", "-v");
3535
}
3636

37+
@Test
38+
public void errorMessages() throws Exception {
39+
astraCli("xxx");
40+
}
41+
42+
3743

3844
}

0 commit comments

Comments
 (0)