Skip to content

Commit 420f536

Browse files
committed
Adding logs
1 parent bea7d92 commit 420f536

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

astra-db-client/src/main/java/com/dtsx/astra/sdk/AstraDB.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.dtsx.astra.sdk.db.AstraDBOpsClient;
66
import com.dtsx.astra.sdk.db.domain.Database;
77
import com.dtsx.astra.sdk.db.exception.DatabaseNotFoundException;
8+
import com.dtsx.astra.sdk.utils.ApiLocator;
89
import com.dtsx.astra.sdk.utils.AstraEnvironment;
910
import io.stargate.sdk.ServiceDeployment;
1011
import io.stargate.sdk.api.SimpleTokenProvider;
@@ -44,6 +45,10 @@ public class AstraDB {
4445
*/
4546
private final NamespaceClient nsClient;
4647

48+
/**
49+
* Url to access the API
50+
*/
51+
private final String apiEndpoint;
4752

4853
/**
4954
* Initialization with endpoint and apikey.
@@ -60,6 +65,7 @@ public AstraDB(String token, String apiEndpoint) {
6065
if (apiEndpoint.endsWith("com")) {
6166
apiEndpoint = apiEndpoint + "/api/json";
6267
}
68+
this.apiEndpoint = apiEndpoint;
6369
// Finding Environment based on apiEndpoint (looping to devops)
6470
if (apiEndpoint.contains(AstraEnvironment.PROD.getAppsSuffix())) {
6571
this.env = AstraEnvironment.PROD;
@@ -122,18 +128,27 @@ public AstraDB(@NonNull String token, @NonNull UUID databaseId, String region, @
122128
.findById(databaseId.toString())
123129
.orElseThrow(() -> new DatabaseNotFoundException(databaseId.toString()));
124130

125-
this.apiClient = AstraClient.builder()
126-
.env(env)
127-
.withDatabaseRegion(region == null ? region : db.getInfo().getRegion())
128-
.withDatabaseId(databaseId.toString())
129-
.disableCrossRegionFailOver()
130-
.build()
131-
.apiStargateJson();
131+
this.apiEndpoint = ApiLocator
132+
.getApiJsonEndpoint(env, databaseId.toString(), region != null ? region : db.getInfo().getRegion());
133+
// Create Json Api Client without AstraDB
134+
ServiceDeployment<ServiceHttp> jsonDeploy = new ServiceDeployment<>();
135+
jsonDeploy.addDatacenterTokenProvider("default", new SimpleTokenProvider(token));
136+
jsonDeploy.addDatacenterServices("default", new ServiceHttp("json", apiEndpoint, apiEndpoint));
137+
this.apiClient = new ApiClient(jsonDeploy);
132138

133139
// will inherit 'default_keyspace' from the database
134140
this.nsClient = apiClient.namespace(db.getInfo().getKeyspace());
135141
}
136142

143+
/**
144+
* Gets apiEndpoint
145+
*
146+
* @return value of apiEndpoint
147+
*/
148+
public String getApiEndpoint() {
149+
return apiEndpoint;
150+
}
151+
137152
// --------------------------
138153
// --- Find, FindAll ----
139154
// --------------------------

astra-sdk-devops/src/main/java/com/dtsx/astra/sdk/utils/ApiLocator.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ public static String getApiJsonEndpoint(String dbId, String dbRegion) {
8989
return getApiJsonEndpoint(AstraEnvironment.PROD, dbId, dbRegion);
9090
}
9191

92+
/**
93+
* END Point for the Json API
94+
*
95+
* @param dbId
96+
* database identifier
97+
* @param dbRegion
98+
* region identifier
99+
* @return
100+
* the url to invoke
101+
*/
102+
public static String getApiEndpoint(String dbId, String dbRegion) {
103+
return getApiEndpoint(AstraEnvironment.PROD, dbId, dbRegion);
104+
}
105+
92106
/**
93107
* END Point for the Json API
94108
*
@@ -102,10 +116,25 @@ public static String getApiJsonEndpoint(String dbId, String dbRegion) {
102116
* the url to invoke
103117
*/
104118
public static String getApiJsonEndpoint(AstraEnvironment env, String dbId, String dbRegion) {
119+
return getApiEndpoint(env, dbId, dbRegion) + "/api/json";
120+
}
121+
122+
/**
123+
* END Point for the Json API
124+
*
125+
* @param env
126+
* target environment
127+
* @param dbId
128+
* database identifier
129+
* @param dbRegion
130+
* region identifier
131+
* @return
132+
* the url to invoke
133+
*/
134+
public static String getApiEndpoint(AstraEnvironment env, String dbId, String dbRegion) {
105135
Assert.hasLength(dbId, "dbId");
106136
Assert.hasLength(dbRegion, "dbRegion");
107-
String val = HTTPS + dbId + "-" + dbRegion + env.getAppsSuffix() + "/api/json";
108-
return val;
137+
return HTTPS + dbId + "-" + dbRegion + env.getAppsSuffix();
109138
}
110139

111140
/**

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<lombok.version>1.18.30</lombok.version>
3939

4040
<!-- Stargate -->
41-
<stargate-sdk.version>2.1.3</stargate-sdk.version>
41+
<stargate-sdk.version>2.1.4-SNAPSHOT</stargate-sdk.version>
4242
<stargate-grpc.version>2.0.17</stargate-grpc.version>
4343
<grpc-netty.version>1.56.1</grpc-netty.version>
4444

0 commit comments

Comments
 (0)