From 0b962b80c12b3d573c4e5d93d2993bda2b60428b Mon Sep 17 00:00:00 2001 From: Oliver Bertuch Date: Tue, 16 Feb 2021 16:38:48 +0100 Subject: [PATCH 1/4] feature(config-api): Make MPCONFIG in TranslatedConfigView debugable 1. When no value can be found and no default has been given, a warning should be printed, so we have a useful error message. Important e. g. to track causes when DB connections fail, etc. 2. When a value has been found, it might be the wrong one due to wrong ordinal config, human mistake, etc etc. Enabling debugging with the TranslatedConfigView will reveal the origin of a value. Closes #5126 --- .../config/support/TranslatedConfigView.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java b/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java index 0fbd109cefd..19420ba20c5 100644 --- a/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java +++ b/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java @@ -43,6 +43,7 @@ import com.sun.enterprise.security.store.DomainScopedPasswordAliasStore; import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigValue; import org.eclipse.microprofile.config.spi.ConfigProviderResolver; import org.glassfish.hk2.api.ServiceLocator; import org.jvnet.hk2.config.ConfigBeanProxy; @@ -146,13 +147,17 @@ private static Object getTranslatedValue(Object value) { String matchValue = envValue[0]; String defaultValue = envValue.length > 1 ? envValue[1] : null; Config config = configResolver().getConfig(); - Optional newValue = config.getOptionalValue(matchValue, String.class); - if (newValue != null && newValue.isPresent()) { - stringValue = m3.replaceFirst(Matcher.quoteReplacement(m3.group(1) + newValue.get() + m3.group(3))); + ConfigValue cValue = config.getConfigValue(matchValue); + String newValue = cValue.getValue(); + if (newValue != null && ! newValue.isEmpty()) { + stringValue = m3.replaceFirst(Matcher.quoteReplacement(m3.group(1) + newValue + m3.group(3))); m3.reset(stringValue); + Logger.getAnonymousLogger().fine("Found property '"+matchValue+"' in source '"+cValue.getSourceName()+"' with ordinal '"+cValue.getSourceOrdinal()+"'"); } else if (defaultValue != null) { stringValue = defaultValue; break; + } else { + Logger.getAnonymousLogger().warning("MicroProfile Config: property '"+matchValue+"': no value found, no default given."); } i++; } From cb58c63976e952ff709ab39f2697f1057e99295e Mon Sep 17 00:00:00 2001 From: Andrew Pielage Date: Tue, 23 Feb 2021 11:44:59 +0000 Subject: [PATCH 2/4] Apply suggestions from code review Rename variable Co-authored-by: Alan --- .../org/glassfish/config/support/TranslatedConfigView.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java b/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java index 19420ba20c5..24f4b1adc60 100644 --- a/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java +++ b/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java @@ -147,12 +147,12 @@ private static Object getTranslatedValue(Object value) { String matchValue = envValue[0]; String defaultValue = envValue.length > 1 ? envValue[1] : null; Config config = configResolver().getConfig(); - ConfigValue cValue = config.getConfigValue(matchValue); - String newValue = cValue.getValue(); + ConfigValue configValue = config.getConfigValue(matchValue); + String newValue = configValue.getValue(); if (newValue != null && ! newValue.isEmpty()) { stringValue = m3.replaceFirst(Matcher.quoteReplacement(m3.group(1) + newValue + m3.group(3))); m3.reset(stringValue); - Logger.getAnonymousLogger().fine("Found property '"+matchValue+"' in source '"+cValue.getSourceName()+"' with ordinal '"+cValue.getSourceOrdinal()+"'"); + Logger.getAnonymousLogger().fine("Found property '"+matchValue+"' in source '"+configValue.getSourceName()+"' with ordinal '"+configValue.getSourceOrdinal()+"'"); } else if (defaultValue != null) { stringValue = defaultValue; break; From e94fef25e657682b6a23d1f66f5ff29a29595585 Mon Sep 17 00:00:00 2001 From: Andrew Pielage Date: Tue, 23 Feb 2021 11:48:32 +0000 Subject: [PATCH 3/4] Apply suggestions from code review Spacing --- .../org/glassfish/config/support/TranslatedConfigView.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java b/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java index 24f4b1adc60..8b6ae96a415 100644 --- a/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java +++ b/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java @@ -149,7 +149,7 @@ private static Object getTranslatedValue(Object value) { Config config = configResolver().getConfig(); ConfigValue configValue = config.getConfigValue(matchValue); String newValue = configValue.getValue(); - if (newValue != null && ! newValue.isEmpty()) { + if (newValue != null && !newValue.isEmpty()) { stringValue = m3.replaceFirst(Matcher.quoteReplacement(m3.group(1) + newValue + m3.group(3))); m3.reset(stringValue); Logger.getAnonymousLogger().fine("Found property '"+matchValue+"' in source '"+configValue.getSourceName()+"' with ordinal '"+configValue.getSourceOrdinal()+"'"); @@ -157,7 +157,7 @@ private static Object getTranslatedValue(Object value) { stringValue = defaultValue; break; } else { - Logger.getAnonymousLogger().warning("MicroProfile Config: property '"+matchValue+"': no value found, no default given."); + Logger.getAnonymousLogger().warning("MicroProfile Config: property '" + matchValue + "': no value found, no default given."); } i++; } From 86f733211650d6f3ab8512e7aa7060dcdba668ab Mon Sep 17 00:00:00 2001 From: Andrew Pielage Date: Tue, 23 Feb 2021 11:49:13 +0000 Subject: [PATCH 4/4] Update nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java Spacing --- .../java/org/glassfish/config/support/TranslatedConfigView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java b/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java index 8b6ae96a415..0f60f4fac1d 100644 --- a/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java +++ b/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/TranslatedConfigView.java @@ -152,7 +152,7 @@ private static Object getTranslatedValue(Object value) { if (newValue != null && !newValue.isEmpty()) { stringValue = m3.replaceFirst(Matcher.quoteReplacement(m3.group(1) + newValue + m3.group(3))); m3.reset(stringValue); - Logger.getAnonymousLogger().fine("Found property '"+matchValue+"' in source '"+configValue.getSourceName()+"' with ordinal '"+configValue.getSourceOrdinal()+"'"); + Logger.getAnonymousLogger().fine("Found property '" + matchValue + "' in source '" + configValue.getSourceName() + "' with ordinal '" + configValue.getSourceOrdinal() + "'"); } else if (defaultValue != null) { stringValue = defaultValue; break;