Skip to content

Commit

Permalink
fixes networknt#2095 use the environment from the startup.yml if ligh…
Browse files Browse the repository at this point in the history
…t-env environemnt variable is not set (networknt#2096)
  • Loading branch information
stevehu authored Feb 1, 2024
1 parent c708b9d commit 1007159
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions server/src/main/java/com/networknt/server/DefaultConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,16 @@ private static String getConfigServerQueryParameters() {
if(startupConfig.get(PRODUCT_VERSION) != null) qs.append("&").append(PRODUCT_VERSION).append("=").append(startupConfig.get(PRODUCT_VERSION));
if(startupConfig.get(API_ID) != null) qs.append("&").append(API_ID).append("=").append(startupConfig.get(API_ID));
if(startupConfig.get(API_VERSION) != null) qs.append("&").append(API_VERSION).append("=").append(startupConfig.get(API_VERSION));
if(lightEnv != null) qs.append("&").append(ENV_TAG).append("=").append(lightEnv);
if(lightEnv != null) {
qs.append("&").append(ENV_TAG).append("=").append(lightEnv);
} else if(startupConfig.get(ENV_TAG) != null) {
// light-env is not set in the environment. Use the envTag from the startup config
qs.append("&").append(ENV_TAG).append("=").append(startupConfig.get(ENV_TAG));
} else {
// light-env is not set in the environment and the startup config. Use the default value.
logger.warn("light-env is not set in the environment and envTag is not set in the startup config. Use the default value: " + DEFAULT_ENV);
qs.append("&").append(ENV_TAG).append("=").append(DEFAULT_ENV);
}
if(logger.isDebugEnabled()) logger.debug("configParameters: {}", qs);
return qs.toString();
}
Expand Down Expand Up @@ -495,12 +504,12 @@ private static boolean isHeadersMatchedJar(HttpHeaders headers) {
// the above headers are sent to the config server except productVersion that might be current/default version.
// as the productId and productVersion are embedded in the jar file, we need to retrieve them from the jar.
if(productId != null && productVersion != null && apiId != null && apiVersion != null && envTag != null) {
if(logger.isInfoEnabled()) logger.trace("jar productId = " + Server.getLight4jProduct() + " productVersion = " + Server.getLight4jVersion() + " startup apiId = " + startupConfig.get(API_ID) + " apiVersion = " + startupConfig.get(API_VERSION) + " envTag = " + lightEnv);
if(logger.isInfoEnabled()) logger.trace("jar productId = " + Server.getLight4jProduct() + " productVersion = " + Server.getLight4jVersion() + " startup apiId = " + startupConfig.get(API_ID) + " apiVersion = " + startupConfig.get(API_VERSION) + " envTag = " + (lightEnv == null ? startupConfig.get(ENV_TAG) : lightEnv)) ;
return productId.equals(Server.getLight4jProduct()) &&
productVersion.equals(Server.getLight4jVersion()) &&
apiId.equals(startupConfig.get(API_ID)) &&
apiVersion.equals(startupConfig.get(API_VERSION)) &&
envTag.equals(lightEnv);
(lightEnv != null ? envTag.equals(lightEnv) : envTag.equals(startupConfig.get(ENV_TAG)));
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/resources/config/startup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ dummy: dummyEntry
# productVersion: 2.0.0
# apiId: com.networknt.petstore-1.0.0
# apiVersion: 1.0.0
# environment: dev
# envTag: dev

0 comments on commit 1007159

Please sign in to comment.