16
16
package com .datasqrl .cli ;
17
17
18
18
import static com .datasqrl .env .EnvVariableNames .KAFKA_BOOTSTRAP_SERVERS ;
19
- import static com .datasqrl .env .EnvVariableNames .POSTGRES_DATABASE ;
20
- import static com .datasqrl .env .EnvVariableNames .POSTGRES_HOST ;
21
19
import static com .datasqrl .env .EnvVariableNames .POSTGRES_JDBC_URL ;
22
20
import static com .datasqrl .env .EnvVariableNames .POSTGRES_PASSWORD ;
23
- import static com .datasqrl .env .EnvVariableNames .POSTGRES_PORT ;
24
21
import static com .datasqrl .env .EnvVariableNames .POSTGRES_USERNAME ;
25
22
26
23
import com .datasqrl .config .PackageJson ;
32
29
import com .datasqrl .graphql .config .ServerConfigUtil ;
33
30
import com .datasqrl .graphql .server .RootGraphqlModel ;
34
31
import com .datasqrl .util .ConfigLoaderUtils ;
35
- import com .google . common . io . Resources ;
32
+ import com .fasterxml . jackson . databind . ObjectMapper ;
36
33
import io .micrometer .prometheusmetrics .PrometheusConfig ;
37
34
import io .micrometer .prometheusmetrics .PrometheusMeterRegistry ;
38
35
import io .vertx .core .Vertx ;
39
36
import io .vertx .core .VertxOptions ;
40
37
import io .vertx .core .json .JsonObject ;
41
38
import io .vertx .micrometer .MicrometerMetricsFactory ;
42
39
import java .net .URI ;
43
- import java .net .URL ;
44
40
import java .nio .file .Files ;
45
41
import java .nio .file .Path ;
46
42
import java .nio .file .Paths ;
@@ -83,6 +79,7 @@ public class DatasqrlRun {
83
79
private final Configuration flinkConfig ;
84
80
private final Map <String , String > env ;
85
81
private final boolean blocking ;
82
+ private final ObjectMapper mapper ;
86
83
@ Nullable private final CountDownLatch shutdownLatch ;
87
84
88
85
private Vertx vertx ;
@@ -99,6 +96,7 @@ private DatasqrlRun(
99
96
this .flinkConfig = flinkConfig ;
100
97
this .env = env ;
101
98
this .blocking = blocking ;
99
+ mapper = SqrlObjectMapper .getMapperWithEnvVarResolver (env );
102
100
shutdownLatch = blocking ? new CountDownLatch (1 ) : null ;
103
101
}
104
102
@@ -272,52 +270,34 @@ private String getenv(String key) {
272
270
273
271
@ SneakyThrows
274
272
private void startVertx () {
275
- if (!planDir .resolve ("vertx.json" ).toFile ().exists ()) {
273
+ var vertxJson = planDir .resolve ("vertx.json" ).toFile ();
274
+ if (!vertxJson .exists ()) {
276
275
return ;
277
276
}
278
- RootGraphqlModel rootGraphqlModel =
279
- SqrlObjectMapper .MAPPER .readValue (
280
- planDir .resolve ("vertx.json" ).toFile (), ModelContainer .class )
281
- .model ;
277
+
278
+ RootGraphqlModel rootGraphqlModel = mapper .readValue (vertxJson , ModelContainer .class ).model ;
282
279
if (rootGraphqlModel == null ) {
283
280
return ; // no graphql server queries
284
281
}
285
282
286
- URL resource = Resources .getResource ("server-config.json" );
287
- Map <String , Object > json = SqrlObjectMapper .MAPPER .readValue (resource , Map .class );
288
- JsonObject config = new JsonObject (json );
289
-
290
- ServerConfig serverConfig =
291
- new ServerConfig (config ) {
292
- @ Override
293
- public String getEnvironmentVariable (String envVar ) {
294
- return getenv (envVar );
295
- }
296
- };
297
-
298
- // Set Postgres connection options from environment variables
299
- if (planDir .resolve ("postgres.json" ).toFile ().exists ()) {
300
- serverConfig
301
- .getPgConnectOptions ()
302
- .setHost (getenv (POSTGRES_HOST ))
303
- .setPort (Integer .parseInt (getenv (POSTGRES_PORT )))
304
- .setUser (getenv (POSTGRES_USERNAME ))
305
- .setPassword (getenv (POSTGRES_PASSWORD ))
306
- .setDatabase (getenv (POSTGRES_DATABASE ));
283
+ var vertxConfigJson = planDir .resolve ("vertx-config.json" ).toFile ();
284
+ if (!vertxConfigJson .exists ()) {
285
+ throw new IllegalStateException (
286
+ "Server config JSON '%s' does not exist" .formatted (vertxConfigJson ));
307
287
}
308
288
309
- serverConfig = ServerConfigUtil .mergeConfigs (serverConfig , vertxConfig ());
310
-
311
- var server = new HttpServerVerticle (serverConfig , rootGraphqlModel );
289
+ Map <String , Object > json = mapper .readValue (vertxConfigJson , Map .class );
290
+ var baseServerConfig = new ServerConfig (new JsonObject (json ));
312
291
292
+ var serverConfig = ServerConfigUtil .mergeConfigs (baseServerConfig , vertxConfig ());
293
+ var serverVerticle = new HttpServerVerticle (serverConfig , rootGraphqlModel );
313
294
var prometheusMeterRegistry = new PrometheusMeterRegistry (PrometheusConfig .DEFAULT );
314
295
var metricsOptions =
315
296
new MicrometerMetricsFactory (prometheusMeterRegistry ).newOptions ().setEnabled (true );
316
297
317
298
vertx = Vertx .vertx (new VertxOptions ().setMetricsOptions (metricsOptions ));
318
-
319
299
vertx
320
- .deployVerticle (server )
300
+ .deployVerticle (serverVerticle )
321
301
.onComplete (
322
302
res -> {
323
303
if (res .succeeded ()) {
0 commit comments