-
Notifications
You must be signed in to change notification settings - Fork 18
Runtime config application #1225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
eb9577c
Added ConfigService interface and concrete class. Added required cons…
c985841
Add config to RoutingContext and implement ConfigService injection
83fe8d7
Updated ConfigService getConfig method to use ConfigRetriever getCach…
6c8aefb
Updated UIDOperatorVerticle to use ConfigService, Mocked ConfigServic…
c7a788f
Updated UIDOperatorService to get "identity_v3" config from UIDOperat…
cfd6a6a
Added ConfigValidatorUtil, Added configValidationHandler method to Co…
975f6ab
Updated UIDOperatorService to take config as method parameters, Updat…
491025b
Removed setMaxSharingLifetimeSeconds metho from ExtendedUIDOperatorVe…
8018196
Added ConfigValidatorUtilTest, Removed unused imports in UIDOperatorV…
cd23998
Updated ConfigValidatorUtil to handle null values, Updated ConfigVali…
bde83a5
Fixed httpStore in ConfigService
8478fd2
Added ConfigServiceTest
8aee5a3
Added ConfigRetrieverFactory to create vert.x ConfigRetriever
8f40ba2
Updated ConfigService, Main
c1fd6df
Updated ConfigServiceTest
fc1147a
Merge branch 'refs/heads/main' into bmz-UID2-4632-runtime-config-appl…
ab30054
Updated ConfigRetrieverFactory
7d2a16d
Updated ConfigService
67b05b1
Added ConfigServiceManager, StaticConfigService
25ad265
Update UIDOperatorVerticle, Main
6bd4a35
Update UIDOperatorVerticle
80b6b19
Add DelegatingConfigService
7ef6af6
Update ConfigServiceManager, Main
ed3141a
Update UIDOperatorVerticleTest
5cde2b2
Add static config to UIDOperatorVerticle constructor
91ecc1d
Update ConfigServiceTest to combine futures using compose
41e7489
Update feature flag functionality
272ac08
Add ConfigServiceManager tests
68530b4
Update ConfigServiceTest to remove unnecessary use of mock server
1dfdea3
Add authorisation header to config retriever
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/com/uid2/operator/service/ConfigRetrieverFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.uid2.operator.service; | ||
|
|
||
| import io.vertx.config.ConfigRetriever; | ||
| import io.vertx.config.ConfigRetrieverOptions; | ||
| import io.vertx.config.ConfigStoreOptions; | ||
| import io.vertx.core.Vertx; | ||
| import io.vertx.core.json.JsonObject; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
|
|
||
| import static com.uid2.operator.Const.Config.ConfigScanPeriodMs; | ||
| import static com.uid2.operator.Const.Config.CoreConfigPath; | ||
|
|
||
| public class ConfigRetrieverFactory { | ||
| public ConfigRetriever createRemoteConfigRetriever(Vertx vertx, JsonObject bootstrapConfig, String operatorKey) throws URISyntaxException { | ||
| String configPath = bootstrapConfig.getString(CoreConfigPath); | ||
| URI uri = new URI(configPath); | ||
|
|
||
| ConfigStoreOptions httpStore = new ConfigStoreOptions() | ||
| .setType("http") | ||
| .setOptional(true) | ||
| .setConfig(new JsonObject() | ||
| .put("host", uri.getHost()) | ||
| .put("port", uri.getPort()) | ||
| .put("path", uri.getPath()) | ||
| .put("headers", new JsonObject() | ||
| .put("Authorization", "Bearer " + operatorKey))); | ||
|
|
||
| ConfigRetrieverOptions retrieverOptions = new ConfigRetrieverOptions() | ||
| .setScanPeriod(bootstrapConfig.getLong(ConfigScanPeriodMs)) | ||
| .addStore(httpStore); | ||
|
|
||
| return ConfigRetriever.create(vertx, retrieverOptions); | ||
| } | ||
|
|
||
| public ConfigRetriever createJsonRetriever(Vertx vertx, JsonObject config) { | ||
| ConfigStoreOptions jsonStore = new ConfigStoreOptions() | ||
| .setType("json") | ||
| .setConfig(config); | ||
|
|
||
| ConfigRetrieverOptions retrieverOptions = new ConfigRetrieverOptions() | ||
| .setScanPeriod(-1) | ||
| .addStore(jsonStore); | ||
|
|
||
|
|
||
| return ConfigRetriever.create(vertx, retrieverOptions); | ||
| } | ||
|
|
||
| public ConfigRetriever createFileRetriever(Vertx vertx, String path) { | ||
| ConfigStoreOptions fileStore = new ConfigStoreOptions() | ||
| .setType("file") | ||
| .setConfig(new JsonObject() | ||
| .put("path", path) | ||
| .put("format", "json")); | ||
|
|
||
| ConfigRetrieverOptions retrieverOptions = new ConfigRetrieverOptions() | ||
| .addStore(fileStore); | ||
|
|
||
| return ConfigRetriever.create(vertx, retrieverOptions); | ||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
src/main/java/com/uid2/operator/service/ConfigService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package com.uid2.operator.service; | ||
|
|
||
| import com.uid2.operator.Const; | ||
| import io.vertx.config.ConfigRetriever; | ||
| import io.vertx.core.Future; | ||
| import io.vertx.core.Promise; | ||
| import io.vertx.core.json.JsonObject; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import static com.uid2.operator.service.ConfigValidatorUtil.*; | ||
| import static com.uid2.operator.service.UIDOperatorService.*; | ||
|
|
||
| public class ConfigService implements IConfigService { | ||
|
|
||
| private final ConfigRetriever configRetriever; | ||
| private static final Logger logger = LoggerFactory.getLogger(ConfigService.class); | ||
|
|
||
| private ConfigService(ConfigRetriever configRetriever) { | ||
| this.configRetriever = configRetriever; | ||
| this.configRetriever.setConfigurationProcessor(this::configValidationHandler); | ||
| } | ||
|
|
||
| public static Future<ConfigService> create(ConfigRetriever configRetriever) { | ||
| Promise<ConfigService> promise = Promise.promise(); | ||
|
|
||
| ConfigService instance = new ConfigService(configRetriever); | ||
|
|
||
| configRetriever.getConfig(ar -> { | ||
| if (ar.succeeded()) { | ||
| System.out.println("Successfully loaded config"); | ||
| promise.complete(instance); | ||
| } else { | ||
| System.err.println("Failed to load config: " + ar.cause().getMessage()); | ||
| logger.error("Failed to load config: {}", ar.cause().getMessage()); | ||
| promise.fail(ar.cause()); | ||
| } | ||
| }); | ||
|
|
||
| return promise.future(); | ||
| } | ||
|
|
||
| @Override | ||
| public JsonObject getConfig() { | ||
| return configRetriever.getCachedConfig(); | ||
| } | ||
|
|
||
| private JsonObject configValidationHandler(JsonObject config) { | ||
| boolean isValid = true; | ||
| Integer identityExpiresAfter = config.getInteger(IDENTITY_TOKEN_EXPIRES_AFTER_SECONDS); | ||
| Integer refreshExpiresAfter = config.getInteger(REFRESH_TOKEN_EXPIRES_AFTER_SECONDS); | ||
| Integer refreshIdentityAfter = config.getInteger(REFRESH_IDENTITY_TOKEN_AFTER_SECONDS); | ||
| Integer maxBidstreamLifetimeSeconds = config.getInteger(Const.Config.MaxBidstreamLifetimeSecondsProp, identityExpiresAfter); | ||
|
|
||
| isValid &= validateIdentityRefreshTokens(identityExpiresAfter, refreshExpiresAfter, refreshIdentityAfter); | ||
|
|
||
| isValid &= validateBidstreamLifetime(maxBidstreamLifetimeSeconds, identityExpiresAfter); | ||
|
|
||
| if (!isValid) { | ||
| logger.error("Failed to update config"); | ||
| JsonObject lastConfig = this.getConfig(); | ||
| if (lastConfig == null || lastConfig.isEmpty()) { | ||
| throw new RuntimeException("Invalid config retrieved and no previous config to revert to"); | ||
| } | ||
| return lastConfig; | ||
| } | ||
|
|
||
| return config; | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/uid2/operator/service/ConfigServiceManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.uid2.operator.service; | ||
|
|
||
| import io.vertx.core.Future; | ||
| import io.vertx.core.Promise; | ||
| import io.vertx.core.Vertx; | ||
| import io.vertx.core.shareddata.Lock; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class ConfigServiceManager { | ||
| private final Vertx vertx; | ||
| private final DelegatingConfigService delegatingConfigService; | ||
| private final IConfigService dynamicConfigService; | ||
| private final IConfigService staticConfigService; | ||
| private static final Logger logger = LoggerFactory.getLogger(ConfigServiceManager.class); | ||
|
|
||
| public ConfigServiceManager(Vertx vertx, IConfigService dynamicConfigService, IConfigService staticConfigService, boolean useDynamicConfig) { | ||
| this.vertx = vertx; | ||
| this.dynamicConfigService = dynamicConfigService; | ||
| this.staticConfigService = staticConfigService; | ||
| this.delegatingConfigService = new DelegatingConfigService(useDynamicConfig ? dynamicConfigService : staticConfigService); | ||
| } | ||
|
|
||
| public Future<Void> updateConfigService(boolean useDynamicConfig) { | ||
| Promise<Void> promise = Promise.promise(); | ||
| vertx.sharedData().getLocalLock("updateConfigServiceLock", lockAsyncResult -> { | ||
| if (lockAsyncResult.succeeded()) { | ||
| Lock lock = lockAsyncResult.result(); | ||
| try { | ||
| if (useDynamicConfig) { | ||
| logger.info("Switching to DynamicConfigService"); | ||
| delegatingConfigService.updateConfigService(dynamicConfigService); | ||
| } else { | ||
| logger.info("Switching to StaticConfigService"); | ||
| delegatingConfigService.updateConfigService(staticConfigService); | ||
| } | ||
| promise.complete(); | ||
| } catch (Exception e) { | ||
| promise.fail(e); | ||
| } finally { | ||
| lock.release(); | ||
| } | ||
| } else { | ||
| logger.error("Failed to acquire lock for updating active ConfigService", lockAsyncResult.cause()); | ||
| promise.fail(lockAsyncResult.cause()); | ||
| } | ||
| }); | ||
|
|
||
| return promise.future(); | ||
| } | ||
|
|
||
| public IConfigService getDelegatingConfigService() { | ||
| return delegatingConfigService; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undo