From 1007159be9d8e05297273b2c712ce7b6596fbee0 Mon Sep 17 00:00:00 2001 From: Steve Hu Date: Thu, 1 Feb 2024 14:19:39 -0500 Subject: [PATCH] fixes #2095 use the environment from the startup.yml if light-env environemnt variable is not set (#2096) --- .../com/networknt/server/DefaultConfigLoader.java | 15 ++++++++++++--- server/src/main/resources/config/startup.yml | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/networknt/server/DefaultConfigLoader.java b/server/src/main/java/com/networknt/server/DefaultConfigLoader.java index d1e4634a8b..72a62774f5 100644 --- a/server/src/main/java/com/networknt/server/DefaultConfigLoader.java +++ b/server/src/main/java/com/networknt/server/DefaultConfigLoader.java @@ -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(); } @@ -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; } diff --git a/server/src/main/resources/config/startup.yml b/server/src/main/resources/config/startup.yml index 34d511fa46..65027fbf5d 100644 --- a/server/src/main/resources/config/startup.yml +++ b/server/src/main/resources/config/startup.yml @@ -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