|
39 | 39 | import io.micrometer.prometheus.PrometheusRenameFilter; |
40 | 40 | import io.vertx.config.ConfigRetriever; |
41 | 41 | import io.vertx.config.ConfigRetrieverOptions; |
| 42 | +import io.vertx.config.ConfigStoreOptions; |
42 | 43 | import io.vertx.core.*; |
43 | 44 | import io.vertx.core.http.HttpServerOptions; |
44 | | -import io.vertx.core.json.JsonArray; |
45 | 45 | import io.vertx.core.json.JsonObject; |
46 | 46 | import io.vertx.micrometer.*; |
47 | 47 | import io.vertx.micrometer.backends.BackendRegistries; |
|
59 | 59 | import java.util.*; |
60 | 60 | import java.util.function.Supplier; |
61 | 61 |
|
62 | | -import static com.uid2.operator.Const.Config.ConfigScanPeriodMsProp; |
63 | 62 | import static io.micrometer.core.instrument.Metrics.globalRegistry; |
64 | 63 |
|
65 | 64 | public class Main { |
@@ -269,68 +268,20 @@ private ICloudStorage wrapCloudStorageForOptOut(ICloudStorage cloudStorage) { |
269 | 268 | } |
270 | 269 | } |
271 | 270 |
|
272 | | - private Future<IConfigService> initialiseConfigService() throws Exception { |
273 | | - Promise<IConfigService> promise = Promise.promise(); |
274 | | - |
275 | | - ConfigRetriever dynamicConfigRetriever = ConfigRetrieverFactory.create( |
276 | | - vertx, |
277 | | - config.getJsonObject("runtime_config_store"), |
278 | | - this.createOperatorKeyRetriever().retrieve() |
279 | | - ); |
280 | | - Future<ConfigService> dynamicConfigFuture = ConfigService.create(dynamicConfigRetriever); |
281 | | - |
282 | | - ConfigRetriever staticConfigRetriever = ConfigRetrieverFactory.create( |
283 | | - vertx, |
284 | | - new JsonObject() |
285 | | - .put("type", "json") |
286 | | - .put("config", config) |
287 | | - .put(ConfigScanPeriodMsProp, -1), |
288 | | - "" |
289 | | - ); |
290 | | - |
291 | | - Future<ConfigService> staticConfigFuture = ConfigService.create(staticConfigRetriever); |
292 | | - |
293 | | - // Create ConfigRetriever with options specified in JsonObject. |
294 | | - // Includes an optional file store and scan period of 10000 ms (10 sec). |
295 | | - // See https://vertx.io/docs/vertx-config/java/#_file for Vertx file store docs. |
296 | | - ConfigRetriever featureFlagConfigRetriever = ConfigRetriever.create( |
297 | | - vertx, |
298 | | - new ConfigRetrieverOptions( |
299 | | - new JsonObject() |
300 | | - .put("stores", new JsonArray() |
301 | | - .add(new JsonObject() |
302 | | - .put("type", "file") |
303 | | - .put("optional", true) |
304 | | - .put("config", new JsonObject() |
305 | | - .put("path", "conf/feat-flag/feat-flag.json")))) |
306 | | - .put("scanPeriod", 10000)) |
307 | | - ); |
308 | | - |
309 | | - Future.all(dynamicConfigFuture, staticConfigFuture, featureFlagConfigRetriever.getConfig()) |
310 | | - .onComplete(ar -> { |
311 | | - if (ar.succeeded()) { |
312 | | - CompositeFuture configServiceManagerCompositeFuture = ar.result(); |
313 | | - IConfigService dynamicConfigService = configServiceManagerCompositeFuture.resultAt(0); |
314 | | - IConfigService staticConfigService = configServiceManagerCompositeFuture.resultAt(1); |
315 | | - JsonObject featureFlagConfig = configServiceManagerCompositeFuture.resultAt(2); |
316 | | - |
317 | | - boolean remoteConfigFeatureFlag = featureFlagConfig |
318 | | - .getJsonObject("remote_config") |
319 | | - .getBoolean("enabled", false); |
320 | | - |
321 | | - ConfigServiceManager configServiceManager = new ConfigServiceManager( |
322 | | - vertx, dynamicConfigService, staticConfigService, remoteConfigFeatureFlag); |
323 | | - |
324 | | - setupFeatureFlagListener(configServiceManager, featureFlagConfigRetriever); |
325 | | - |
326 | | - IConfigService configService = configServiceManager.getDelegatingConfigService(); |
327 | | - promise.complete(configService); |
328 | | - } else { |
329 | | - LOGGER.error("Failed to initialise ConfigService: ", ar.cause()); |
330 | | - promise.fail(ar.cause()); |
331 | | - } |
332 | | - }); |
333 | | - return promise.future(); |
| 271 | + private Future<IConfigService> initialiseConfigService() { |
| 272 | + // Read runtime config values from this.config. |
| 273 | + final ConfigStoreOptions configStoreOptions = new ConfigStoreOptions() |
| 274 | + .setType("json") |
| 275 | + .setConfig(config); |
| 276 | + |
| 277 | + final ConfigRetrieverOptions configRetrieverOptions = new ConfigRetrieverOptions() |
| 278 | + .addStore(configStoreOptions) |
| 279 | + // Don't scan as config values won't change. |
| 280 | + .setScanPeriod(-1); |
| 281 | + |
| 282 | + final ConfigRetriever configRetriever = ConfigRetriever.create(vertx, configRetrieverOptions); |
| 283 | + |
| 284 | + return ConfigService.create(configRetriever).map(x -> (IConfigService) x); |
334 | 285 | } |
335 | 286 |
|
336 | 287 | private void run() throws Exception { |
|
0 commit comments