1818
1919import com .datastax .astra .sdk .config .AstraClientConfig ;
2020import com .datastax .oss .driver .api .core .CqlSession ;
21+ import com .dtsx .astra .sdk .utils .ApiLocator ;
2122import io .stargate .sdk .StargateClient ;
23+ import io .stargate .sdk .api .SimpleTokenProvider ;
2224import io .stargate .sdk .doc .StargateDocumentApiClient ;
2325import io .stargate .sdk .gql .StargateGraphQLApiClient ;
26+ import io .stargate .sdk .grpc .ServiceGrpc ;
2427import io .stargate .sdk .grpc .StargateGrpcApiClient ;
28+ import io .stargate .sdk .http .ServiceHttp ;
2529import io .stargate .sdk .rest .StargateRestApiClient ;
2630import io .stargate .sdk .utils .AnsiUtils ;
2731import io .stargate .sdk .utils .Utils ;
@@ -114,7 +118,6 @@ public AstraClient(AstraClientConfig config) {
114118 // ---------------------------------------------------
115119 // Devops APIS
116120 // ---------------------------------------------------
117-
118121 if (Utils .hasLength (config .getToken ())) {
119122 apiDevopsOrganizations = new OrganizationsClient (config .getToken ());
120123 apiDevopsDatabases = new DatabasesClient (config .getToken ());
@@ -157,7 +160,6 @@ public AstraClient(AstraClientConfig config) {
157160 } else {
158161 config .getStargateConfig ().withAuthCredentials ("token" , config .getToken ());
159162 }
160-
161163 }
162164
163165 // ---------------------------------------------------
@@ -170,52 +172,82 @@ public AstraClient(AstraClientConfig config) {
170172 throw new IllegalArgumentException ("Cannot retrieve db with id " + config .getDatabaseId ());
171173 }
172174
173- /* Loop on regions
175+ /* Loop on regions. for each region a DC. */
174176 db .get ().getInfo ().getDatacenters ().stream ().forEach (dc -> {
175- config.getStargateConfig().withApiNodeDC(dc.getRegion(),
176- new StargateNodeConfig(
177- // node name = region, we got a single per region LB is done by Astra
178- dc.getRegion(),
179- // url or rest api
180- ApiLocator.getApiRestEndpoint(config.getDatabaseId(), dc.getRegion()),
181- // url of graphql API
177+ // Rest Api
178+ config .getStargateConfig ().addServiceRest (dc .getRegion (),
179+ new ServiceHttp (dc .getRegion () + "-rest" ,
180+ ApiLocator .getApiRestEndpoint (config .getDatabaseId (), dc .getRegion ()),
181+ ApiLocator .getEndpointHealthCheck (config .getDatabaseId (), dc .getRegion ())));
182+ // Document API
183+ config .getStargateConfig ().addDocumentService (dc .getRegion (),
184+ new ServiceHttp (dc .getRegion () + "-doc" ,
185+ ApiLocator .getApiDocumentEndpoint (config .getDatabaseId (), dc .getRegion ()),
186+ ApiLocator .getEndpointHealthCheck (config .getDatabaseId (), dc .getRegion ())));
187+ // GraphQL
188+ config .getStargateConfig ().addGraphQLService (dc .getRegion (),
189+ new ServiceHttp (dc .getRegion () + "-gql" ,
182190 ApiLocator .getApiGraphQLEndPoint (config .getDatabaseId (), dc .getRegion ()),
183- // host for grpc
184- ApiLocator.getApiGrpcEndPoint(config.getDatabaseId(), dc.getRegion()),
185- // port for grpc
186- AstraClientConfig.GRPC_PORT));
187-
188- config.getStargateConfig()
189- .withCqlCloudSecureConnectBundleDC(dc.getRegion(),
190- config.getSecureConnectBundleFolder()
191- + File.separator
192- + AstraClientConfig.buildScbFileName(config.getDatabaseId(), dc.getRegion()));
193- }
194- );*/
191+ ApiLocator .getEndpointHealthCheck (config .getDatabaseId (), dc .getRegion ())));
192+
193+ if (config .getStargateConfig ().isEnabledGrpc ()) {
194+ // Grpc
195+ config .getStargateConfig ().addGrpcService (dc .getRegion (), new ServiceGrpc (dc .getRegion () + "-grpc" ,
196+ ApiLocator .getApiGrpcEndPoint (config .getDatabaseId (), dc .getRegion ()) + ":" + AstraClientConfig .GRPC_PORT ,
197+ ApiLocator .getEndpointHealthCheck (config .getDatabaseId (), dc .getRegion ()), true ));
198+ }
199+
200+ if (config .getStargateConfig ().isEnabledCql ()) {
201+ // Cloud Secure Bundle
202+ config .getStargateConfig ().withCqlCloudSecureConnectBundleDC (dc .getRegion (),
203+ config .getSecureConnectBundleFolder ()
204+ + File .separator
205+ + AstraClientConfig .buildScbFileName (config .getDatabaseId (), dc .getRegion ()));
206+ }
207+
208+ config .getStargateConfig ().withApiTokenProviderDC (dc .getRegion (),
209+ new SimpleTokenProvider (config .getToken ()));
210+
211+ });
195212
196213 } else {
197- /*
214+
198215 LOGGER .info ("+ Cross-region failback is disabled." );
199- config.getStargateConfig().withApiNodeDC(currentDatabaseRegion,
200- new StargateNodeConfig(
201- // node name = region, we got a single per region LB is done by Astra
202- this.currentDatabaseRegion,
203- // url or rest api
204- ApiLocator.getApiRestEndpoint(config.getDatabaseId(), currentDatabaseRegion),
205- // url of graphql API
206- ApiLocator.getApiGraphQLEndPoint(config.getDatabaseId(), currentDatabaseRegion),
207- // host for grpc
208- ApiLocator.getApiGrpcEndPoint(config.getDatabaseId(), currentDatabaseRegion),
209- // port for grpc
210- AstraClientConfig.GRPC_PORT));
211- config.getStargateConfig()
212- .withCqlCloudSecureConnectBundleDC(currentDatabaseRegion,
213- config.getSecureConnectBundleFolder()
214- + File.separator
215- + AstraClientConfig.buildScbFileName(config.getDatabaseId(), currentDatabaseRegion));
216- */
216+ // Authentication for the DB
217+ config .getStargateConfig ().withApiTokenProviderDC (currentDatabaseRegion ,
218+ new SimpleTokenProvider (config .getToken ()));
219+ // Rest Api
220+ config .getStargateConfig ().addServiceRest (currentDatabaseRegion ,
221+ new ServiceHttp (currentDatabaseRegion + "-rest" ,
222+ ApiLocator .getApiRestEndpoint (config .getDatabaseId (), currentDatabaseRegion ),
223+ ApiLocator .getEndpointHealthCheck (config .getDatabaseId (), currentDatabaseRegion )));
224+ // Document API
225+ config .getStargateConfig ().addDocumentService (currentDatabaseRegion ,
226+ new ServiceHttp (currentDatabaseRegion + "-doc" ,
227+ ApiLocator .getApiDocumentEndpoint (config .getDatabaseId (), currentDatabaseRegion ),
228+ ApiLocator .getEndpointHealthCheck (config .getDatabaseId (), currentDatabaseRegion )));
229+ // GraphQL
230+ config .getStargateConfig ().addGraphQLService (currentDatabaseRegion ,
231+ new ServiceHttp (currentDatabaseRegion + "-gql" ,
232+ ApiLocator .getApiGraphQLEndPoint (config .getDatabaseId (), currentDatabaseRegion ),
233+ ApiLocator .getEndpointHealthCheck (config .getDatabaseId (),currentDatabaseRegion )));
234+ // Grpc
235+ if (config .getStargateConfig ().isEnabledGrpc ()) {
236+ config .getStargateConfig ().addGrpcService (currentDatabaseRegion , new ServiceGrpc (currentDatabaseRegion + "-grpc" ,
237+ ApiLocator .getApiGrpcEndPoint (config .getDatabaseId (), currentDatabaseRegion ) + ":" + AstraClientConfig .GRPC_PORT ,
238+ ApiLocator .getEndpointHealthCheck (config .getDatabaseId (), currentDatabaseRegion ), true ));
239+ }
240+
241+ // CQL
242+ if (config .getStargateConfig ().isEnabledCql ()) {
243+ config .getStargateConfig ()
244+ .withCqlCloudSecureConnectBundleDC (currentDatabaseRegion ,
245+ config .getSecureConnectBundleFolder ()
246+ + File .separator
247+ + AstraClientConfig .buildScbFileName (config .getDatabaseId (), currentDatabaseRegion ));
248+ }
217249 }
218- this .stargateClient = config .getStargateConfig ().build ();
250+ this .stargateClient = config .getStargateConfig ().build ();
219251
220252 } else {
221253 LOGGER .info ("+ API(s) CqlSession [" + AnsiUtils .red ("DISABLED" )+ "]" );
@@ -226,7 +258,6 @@ public AstraClient(AstraClientConfig config) {
226258 LOGGER .info ("[" + AnsiUtils .yellow ("AstraClient" ) + "] has been initialized." );
227259 }
228260
229-
230261 /**
231262 * Download the secure connect bundle files
232263 * @param config
0 commit comments