Skip to content

Commit b51440d

Browse files
pravinbhatmsmygit
andauthored
Feat/scb autodownload (#365)
* Auto-download Astra DB SCB * add more unit test coverage * Reuse CONNECT_PASSWORD as opposed to new Astra token properties * simplify * File path fix * Improved error reporting --------- Co-authored-by: Madhavan Sridharan <[email protected]>
1 parent 3dd9939 commit b51440d

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

src/main/java/com/datastax/cdm/data/AstraDevOpsClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ public AstraDevOpsClient(IPropertyHelper propertyHelper) {
7272
* @throws IOException
7373
* If an error occurs during the download process
7474
*/
75-
public String downloadSecureBundle(PKFactory.Side side) throws IOException {
75+
public String downloadSecureBundle(PKFactory.Side side) throws Exception {
7676
String token = getAstraToken(side);
7777
String databaseId = getAstraDatabaseId(side);
7878
String dbRegion = getRegion(side);
7979
String scbType = getScbType(side);
8080

8181
if (token == null || token.isEmpty() || databaseId == null || databaseId.isEmpty()) {
82-
logger.warn("Missing required Astra parameters for {} (token or database ID)", side);
83-
return null;
82+
logger.error("Missing required Astra parameters for {} (token or database ID)", side);
83+
throw new Exception("Failed to download secure bundle");
8484
}
8585

8686
logger.info("Auto-downloading secure connect bundle for {} database ID: {}, type: {}, region: {}", side,
@@ -91,14 +91,14 @@ public String downloadSecureBundle(PKFactory.Side side) throws IOException {
9191

9292
if (jsonResponse == null) {
9393
logger.error("Failed to fetch secure bundle URL info for {}", side);
94-
return null;
94+
throw new Exception("Failed to download secure bundle");
9595
}
9696

9797
String downloadUrl = extractDownloadUrl(jsonResponse, scbType, side, dbRegion);
9898

9999
if (downloadUrl == null) {
100100
logger.error("Could not extract download URL for {} bundle type: {}", side, scbType);
101-
return null;
101+
throw new Exception("Failed to download secure bundle");
102102
}
103103

104104
return downloadBundleFile(downloadUrl, side);

src/main/scala/com/datastax/cdm/job/ConnectionFetcher.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class ConnectionFetcher(propertyHelper: IPropertyHelper, testAstraClient: AstraD
5555
}
5656
} catch {
5757
case e: Exception =>
58-
logger.warn(s"Failed to auto-download secure bundle for $side: ${e.getMessage}")
59-
logger.debug("Auto-download failure details", e)
58+
logger.error(s"Failed to auto-download secure bundle for $side: ${e.getMessage}")
59+
logger.error("Auto-download failure details", e)
6060
}
6161
}
6262

src/test/java/com/datastax/cdm/data/AstraDevOpsClientTest.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import com.datastax.cdm.properties.IPropertyHelper;
4040
import com.datastax.cdm.properties.KnownProperties;
41-
import com.fasterxml.jackson.databind.ObjectMapper;
4241

4342
@ExtendWith(MockitoExtension.class)
4443
class AstraDevOpsClientTest {
@@ -69,42 +68,39 @@ void setUp() throws Exception {
6968
}
7069

7170
@Test
72-
void testDownloadSecureBundleWithNullToken() throws IOException {
71+
void testDownloadSecureBundleWithNullToken() throws Exception {
7372
// Setup
7473
when(propertyHelper.getAsString(KnownProperties.CONNECT_ORIGIN_PASSWORD)).thenReturn(null);
7574

7675
// Test
77-
String result = client.downloadSecureBundle(PKFactory.Side.ORIGIN);
76+
assertThrows(Exception.class, () -> client.downloadSecureBundle(PKFactory.Side.ORIGIN));
7877

7978
// Verify
80-
assertNull(result);
8179
verify(propertyHelper).getAsString(KnownProperties.CONNECT_ORIGIN_PASSWORD);
8280
}
8381

8482
@Test
85-
void testDownloadSecureBundleWithEmptyToken() throws IOException {
83+
void testDownloadSecureBundleWithEmptyToken() throws Exception {
8684
// Setup
8785
when(propertyHelper.getAsString(KnownProperties.CONNECT_ORIGIN_PASSWORD)).thenReturn("");
8886

8987
// Test
90-
String result = client.downloadSecureBundle(PKFactory.Side.ORIGIN);
88+
assertThrows(Exception.class, () -> client.downloadSecureBundle(PKFactory.Side.ORIGIN));
9189

9290
// Verify
93-
assertNull(result);
9491
verify(propertyHelper).getAsString(KnownProperties.CONNECT_ORIGIN_PASSWORD);
9592
}
9693

9794
@Test
98-
void testDownloadSecureBundleWithNullDatabaseId() throws IOException {
95+
void testDownloadSecureBundleWithNullDatabaseId() throws Exception {
9996
// Setup
10097
when(propertyHelper.getAsString(KnownProperties.CONNECT_ORIGIN_PASSWORD)).thenReturn("test-token");
10198
when(propertyHelper.getAsString(KnownProperties.ORIGIN_ASTRA_DATABASE_ID)).thenReturn(null);
10299

103100
// Test
104-
String result = client.downloadSecureBundle(PKFactory.Side.ORIGIN);
101+
assertThrows(Exception.class, () -> client.downloadSecureBundle(PKFactory.Side.ORIGIN));
105102

106103
// Verify
107-
assertNull(result);
108104
verify(propertyHelper).getAsString(KnownProperties.CONNECT_ORIGIN_PASSWORD);
109105
verify(propertyHelper).getAsString(KnownProperties.ORIGIN_ASTRA_DATABASE_ID);
110106
}
@@ -527,10 +523,7 @@ void testDownloadSecureBundleWithEmptyJsonResponse() throws Exception {
527523
when(propertyHelper.getAsString(KnownProperties.ORIGIN_ASTRA_SCB_REGION)).thenReturn(null);
528524

529525
// Test
530-
String result = client.downloadSecureBundle(PKFactory.Side.ORIGIN);
531-
532-
// Verify
533-
assertNull(result);
526+
assertThrows(Exception.class, () -> client.downloadSecureBundle(PKFactory.Side.ORIGIN));
534527
}
535528

536529
@Test

0 commit comments

Comments
 (0)