Skip to content

Commit

Permalink
fixes #2019 do not overwrite the values.yml if config server is not a…
Browse files Browse the repository at this point in the history
…vailable (#2020)
  • Loading branch information
stevehu authored Nov 25, 2023
1 parent b8f1158 commit 05f0f73
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions server/src/main/java/com/networknt/server/DefaultConfigLoader.java
Original file line number Diff line number Diff line change
@@ -198,6 +198,10 @@ private synchronized void loadConfigs(String queryParameters) {
String configServerConfigsPath = CONFIG_SERVER_CONFIGS_CONTEXT_ROOT + queryParameters;
//get service configs and put them in config cache
Map<String, Object> serviceConfigs = getServiceConfigs(configServerConfigsPath);
if(serviceConfigs == null) {
logger.error("Failed to load configs from config server. Please check the logs for more details.");
return;
}
if(logger.isDebugEnabled()) logger.debug("serviceConfigs received from Config Server: " + JsonMapper.toJson(serviceConfigs));

// pass serviceConfigs through Config.yaml's load method so that it can decrypt any encrypted values
@@ -235,6 +239,10 @@ private void loadFiles(String configPath, String contextRoot) {
String configServerFilesPath = contextRoot + configPath;
//get service files and put them in config dir
Map<String, Object> serviceFiles = getServiceConfigs(configServerFilesPath);
if(serviceFiles == null) {
logger.error("Failed to load files from config server. Please check the logs for more details.");
return;
}
if(logger.isDebugEnabled()) logger.debug("loadFiles: " + JsonMapper.toJson(serviceFiles));
try {
Path filePath = Paths.get(targetConfigsDirectory);
@@ -249,7 +257,7 @@ private void loadFiles(String configPath, String contextRoot) {
Files.write(filePath, ba);
}
} catch (IOException e) {
logger.error("Exception while creating {} dir or creating files there:{}",targetConfigsDirectory, e);
logger.error("Exception while creating {} dir or creating files there", targetConfigsDirectory, e);
}
}

@@ -293,7 +301,8 @@ private Map<String, Object> getServiceConfigs(String configServerPath) {
String body = response.body();
if(statusCode >= 300) {
logger.error("Failed to load configs from config server" + statusCode + ":" + body);
throw new Exception("Failed to load configs from config server: " + statusCode);
// return null, so that the values.yml won't be overwritten and the server can still be started with it.
return null;
} else {
// validate the headers against the product id and version. If they are not matched, throw an exception.
// this validation call is commented out for now as it is not ready on the config server side.
6 changes: 3 additions & 3 deletions status/src/main/java/com/networknt/status/Status.java
Original file line number Diff line number Diff line change
@@ -232,15 +232,15 @@ public void setMetadata(Map<String, Object> metadata) {
}

public static boolean shouldShowMetadata() {
return config.get(SHOW_METADATA) == null ? false : (boolean)config.get(SHOW_METADATA);
return config.get(SHOW_METADATA) == null ? false : Config.loadBooleanValue(SHOW_METADATA, config.get(SHOW_METADATA));
}

public static boolean shouldShowMessage() {
return config.get(SHOW_MESSAGE) == null ? true : (boolean)config.get(SHOW_MESSAGE);
return config.get(SHOW_MESSAGE) == null ? true : Config.loadBooleanValue(SHOW_MESSAGE, config.get(SHOW_MESSAGE));
}

public static boolean shouldShowDescription() {
return config.get(SHOW_DESCRIPTION) == null ? true : (boolean)config.get(SHOW_DESCRIPTION);
return config.get(SHOW_DESCRIPTION) == null ? true : Config.loadBooleanValue(SHOW_DESCRIPTION, config.get(SHOW_DESCRIPTION));
}

/**

0 comments on commit 05f0f73

Please sign in to comment.