Skip to content

Commit 8faf682

Browse files
authored
Vert.x config cleanup (#1446)
1 parent 04ede4a commit 8faf682

File tree

23 files changed

+619
-736
lines changed

23 files changed

+619
-736
lines changed

sqrl-cli/src/main/java/com/datasqrl/cli/DatasqrlRun.java

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
package com.datasqrl.cli;
1717

1818
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;
2119
import static com.datasqrl.env.EnvVariableNames.POSTGRES_JDBC_URL;
2220
import static com.datasqrl.env.EnvVariableNames.POSTGRES_PASSWORD;
23-
import static com.datasqrl.env.EnvVariableNames.POSTGRES_PORT;
2421
import static com.datasqrl.env.EnvVariableNames.POSTGRES_USERNAME;
2522

2623
import com.datasqrl.config.PackageJson;
@@ -32,15 +29,14 @@
3229
import com.datasqrl.graphql.config.ServerConfigUtil;
3330
import com.datasqrl.graphql.server.RootGraphqlModel;
3431
import com.datasqrl.util.ConfigLoaderUtils;
35-
import com.google.common.io.Resources;
32+
import com.fasterxml.jackson.databind.ObjectMapper;
3633
import io.micrometer.prometheusmetrics.PrometheusConfig;
3734
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
3835
import io.vertx.core.Vertx;
3936
import io.vertx.core.VertxOptions;
4037
import io.vertx.core.json.JsonObject;
4138
import io.vertx.micrometer.MicrometerMetricsFactory;
4239
import java.net.URI;
43-
import java.net.URL;
4440
import java.nio.file.Files;
4541
import java.nio.file.Path;
4642
import java.nio.file.Paths;
@@ -83,6 +79,7 @@ public class DatasqrlRun {
8379
private final Configuration flinkConfig;
8480
private final Map<String, String> env;
8581
private final boolean blocking;
82+
private final ObjectMapper mapper;
8683
@Nullable private final CountDownLatch shutdownLatch;
8784

8885
private Vertx vertx;
@@ -99,6 +96,7 @@ private DatasqrlRun(
9996
this.flinkConfig = flinkConfig;
10097
this.env = env;
10198
this.blocking = blocking;
99+
mapper = SqrlObjectMapper.getMapperWithEnvVarResolver(env);
102100
shutdownLatch = blocking ? new CountDownLatch(1) : null;
103101
}
104102

@@ -272,52 +270,34 @@ private String getenv(String key) {
272270

273271
@SneakyThrows
274272
private void startVertx() {
275-
if (!planDir.resolve("vertx.json").toFile().exists()) {
273+
var vertxJson = planDir.resolve("vertx.json").toFile();
274+
if (!vertxJson.exists()) {
276275
return;
277276
}
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;
282279
if (rootGraphqlModel == null) {
283280
return; // no graphql server queries
284281
}
285282

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));
307287
}
308288

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));
312291

292+
var serverConfig = ServerConfigUtil.mergeConfigs(baseServerConfig, vertxConfig());
293+
var serverVerticle = new HttpServerVerticle(serverConfig, rootGraphqlModel);
313294
var prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
314295
var metricsOptions =
315296
new MicrometerMetricsFactory(prometheusMeterRegistry).newOptions().setEnabled(true);
316297

317298
vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(metricsOptions));
318-
319299
vertx
320-
.deployVerticle(server)
300+
.deployVerticle(serverVerticle)
321301
.onComplete(
322302
res -> {
323303
if (res.succeeded()) {

sqrl-cli/src/main/resources/templates/server-config.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@
108108
"http2RstFloodWindowDuration" : 30,
109109
"http2RstFloodWindowDurationTimeUnit" : "SECONDS",
110110
"strictThreadMode" : false,
111-
"useAlpn" : false,
111+
"enabledSecureTransportProtocols" : [ "TLSv1", "TLSv1.1", "TLSv1.2" ],
112112
"keyCertOptions" : null,
113113
"trustOptions" : null,
114114
"clientAuth" : "NONE",
115-
"enabledSecureTransportProtocols" : [ "TLSv1", "TLSv1.1", "TLSv1.2" ],
116115
"sslHandshakeTimeout" : 10,
117116
"sslHandshakeTimeoutUnit" : "SECONDS",
118-
"sni" : false,
119-
"fileRegionEnabled" : true
117+
"fileRegionEnabled" : true,
118+
"useAlpn" : false,
119+
"sni" : false
120120
},
121121
"pgConnectOptions" : {
122122
"host" : "${POSTGRES_HOST}",
@@ -184,5 +184,16 @@
184184
"contactEmail" : "[email protected]",
185185
"license" : "Apache License 2.0",
186186
"licenseUrl" : "https://www.apache.org/licenses/LICENSE-2.0"
187+
},
188+
"kafkaMutationConfig" : {
189+
"value.serializer" : "com.datasqrl.graphql.kafka.JsonSerializer",
190+
"bootstrap.servers" : "${KAFKA_BOOTSTRAP_SERVERS}",
191+
"key.serializer" : "com.datasqrl.graphql.kafka.JsonSerializer"
192+
},
193+
"kafkaSubscriptionConfig" : {
194+
"key.deserializer" : "com.datasqrl.graphql.kafka.JsonDeserializer",
195+
"value.deserializer" : "com.datasqrl.graphql.kafka.JsonDeserializer",
196+
"bootstrap.servers" : "${KAFKA_BOOTSTRAP_SERVERS}",
197+
"auto.offset.reset" : "latest"
187198
}
188199
}

sqrl-planner/src/main/resources/server-config.json

Lines changed: 0 additions & 193 deletions
This file was deleted.

sqrl-server/sqrl-server-vertx-base/src/main/java/com/datasqrl/graphql/JsonEnvVarDeserializer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.fasterxml.jackson.core.JsonParser;
2020
import com.fasterxml.jackson.databind.DeserializationContext;
2121
import com.fasterxml.jackson.databind.JsonDeserializer;
22+
import jakarta.annotation.Nullable;
2223
import java.io.IOException;
2324
import java.util.Map;
2425
import java.util.regex.Matcher;
@@ -27,14 +28,14 @@
2728
/** Custom deserializer to replace environment variables in JSON strings. */
2829
public class JsonEnvVarDeserializer extends JsonDeserializer<String> {
2930

30-
private Map<String, String> env;
31+
private final Map<String, String> env;
3132

3233
public JsonEnvVarDeserializer() {
33-
env = GlobalEnvironmentStore.getAll();
34+
this(null);
3435
}
3536

36-
public JsonEnvVarDeserializer(Map<String, String> env) {
37-
this.env = env;
37+
public JsonEnvVarDeserializer(@Nullable Map<String, String> env) {
38+
this.env = env != null ? env : GlobalEnvironmentStore.getAll();
3839
}
3940

4041
@Override

0 commit comments

Comments
 (0)