Skip to content
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

fixes #2019 do not overwrite the values.yml if config server is not a… #2020

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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.
Expand Down
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
Expand Up @@ -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));
}

/**
Expand Down