From d60da013d8f51583a680e2eb23c33e16e00b80d9 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Tue, 12 May 2020 17:57:36 +0200 Subject: [PATCH 1/2] APPSERV-124 adds server side page configuration --- ...MonitoringConsoleConfigurationCommand.java | 62 +++++++++++++------ .../MonitoringConsoleConfiguration.java | 16 ++++- .../runtime/MonitoringConsoleRuntimeImpl.java | 61 +++++++++++++++--- pom.xml | 6 +- 4 files changed, 112 insertions(+), 33 deletions(-) diff --git a/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/admin/SetMonitoringConsoleConfigurationCommand.java b/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/admin/SetMonitoringConsoleConfigurationCommand.java index cb9c6b7acce..79c20bf0f63 100644 --- a/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/admin/SetMonitoringConsoleConfigurationCommand.java +++ b/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/admin/SetMonitoringConsoleConfigurationCommand.java @@ -115,6 +115,18 @@ public class SetMonitoringConsoleConfigurationCommand implements AdminCommand { @Param(optional = true, alias = "remove-watch") private String _removeWatch; + @SuppressWarnings("squid:S116") + @Param(optional = true, alias = "add-page-name") + private String _addPageName; + + @SuppressWarnings("squid:S116") + @Param(optional = true, alias = "add-page-json") + private String _addPageJson; + + @SuppressWarnings("squid:S116") + @Param(optional = true, alias = "remove-page") + private String _removePage; + @Inject protected CommandRunner commandRunner; @@ -155,30 +167,18 @@ public Object run(MonitoringConsoleConfiguration configProxy) throws PropertyVet configProxy.getDisabledWatchNames().remove(_enableWatch); } if (isDefined(_addWatchName) && isDefined(_addWatchJson)) { - List customWatchNames = configProxy.getCustomWatchNames(); - List customWatchValues = configProxy.getCustomWatchValues(); - int index = customWatchNames.indexOf(_addWatchName); - if (index >= 0) { - customWatchNames.remove(index); - if (index < customWatchValues.size()) { - customWatchValues.remove(index); - } - } - customWatchNames.add(_addWatchName); - customWatchValues.add(_addWatchJson); + add(_addWatchName, _addWatchJson, configProxy.getCustomWatchNames(), configProxy.getCustomWatchValues()); } if (isDefined(_removeWatch)) { - List customWatchNames = configProxy.getCustomWatchNames(); - int index = customWatchNames.indexOf(_removeWatch); - if (index >= 0) { - customWatchNames.remove(index); - List customWatchValues = configProxy.getCustomWatchValues(); - if (index < customWatchValues.size()) { - customWatchValues.remove(index); - } - } + remove(_removeWatch, configProxy.getCustomWatchNames(), configProxy.getCustomWatchValues()); configProxy.getDisabledWatchNames().remove(_removeWatch); } + if (isDefined(_addPageName) && isDefined(_addPageJson)) { + add(_addPageName, _addPageJson, configProxy.getPageNames(), configProxy.getPageValues()); + } + if (isDefined(_removePage)) { + remove(_removePage, configProxy.getPageNames(), configProxy.getPageValues()); + } return null; } }, config); @@ -187,6 +187,28 @@ public Object run(MonitoringConsoleConfiguration configProxy) throws PropertyVet } } + static void add(String name, String value, List names, List values) { + int index = names.indexOf(name); + if (index >= 0) { + names.remove(index); + if (index < values.size()) { + values.remove(index); + } + } + names.add(name); + values.add(value); + } + + static void remove(String name, List names, List values) { + int index = names.indexOf(name); + if (index >= 0) { + names.remove(index); + if (index < values.size()) { + values.remove(index); + } + } + } + static boolean isDefined(String value) { return value != null && !value.isEmpty(); } diff --git a/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/configuration/MonitoringConsoleConfiguration.java b/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/configuration/MonitoringConsoleConfiguration.java index c54e723b12b..198dff9fe32 100644 --- a/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/configuration/MonitoringConsoleConfiguration.java +++ b/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/configuration/MonitoringConsoleConfiguration.java @@ -51,7 +51,7 @@ /** * Configuration for the monitoring console core. * This is first of all the data and watch collection and evaluation. - * + * * @author Jan Bernitt * @since 5.201 */ @@ -61,7 +61,7 @@ public interface MonitoringConsoleConfiguration extends DomainExtension { /** * Note that this is not reflecting whether or not the monitoring data is collected. * This is controlled by the general monitoring configuration. - * + * * @return True, if monitoring console web-app is deployed, else false. */ @Attribute(defaultValue = "false", dataType = Boolean.class) @@ -86,4 +86,16 @@ public interface MonitoringConsoleConfiguration extends DomainExtension { @Element List getCustomWatchValues(); + /** + * @return Names of MC (client) pages + */ + @Element + List getPageNames(); + + /** + * @return JSON values of the MC (client) pages (index is same in {@link #getPageNames()}) + */ + @Element + List getPageValues(); + } diff --git a/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/runtime/MonitoringConsoleRuntimeImpl.java b/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/runtime/MonitoringConsoleRuntimeImpl.java index c1f64c973da..9c2983f873b 100644 --- a/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/runtime/MonitoringConsoleRuntimeImpl.java +++ b/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/runtime/MonitoringConsoleRuntimeImpl.java @@ -41,6 +41,7 @@ import static java.lang.Boolean.parseBoolean; import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.jvnet.hk2.config.Dom.unwrap; import java.beans.PropertyChangeEvent; @@ -48,6 +49,7 @@ import java.util.Collection; import java.util.List; import java.util.Map.Entry; +import java.util.NoSuchElementException; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -88,6 +90,7 @@ import fish.payara.monitoring.adapt.GroupDataRepository; import fish.payara.monitoring.adapt.MonitoringConsole; import fish.payara.monitoring.adapt.MonitoringConsoleFactory; +import fish.payara.monitoring.adapt.MonitoringConsolePageConfig; import fish.payara.monitoring.adapt.MonitoringConsoleRuntime; import fish.payara.monitoring.adapt.MonitoringConsoleWatchConfig; import fish.payara.monitoring.collect.MonitoringDataSource; @@ -102,7 +105,7 @@ /** * This implementation of the {@link MonitoringConsoleRuntime} connects the Payara independent parts of the monitoring * console with the Payara server. - * + * * The most complicated aspect about the implementation is the way it is bootstrapped. By implementing * {@link ApplicationLifecycleInterceptor} it forces the creation of an instance of this {@link Service} even though it * is not otherwise referenced within the HK2 context. As this happens fairly early in the bootstrapping it then @@ -110,14 +113,15 @@ * the {@link EventTypes#SERVER_READY} is received. This makes sure the bootstrapping of the console runtime does not * alter the order of services created by starting to collect data from services that implement * {@link MonitoringDataSource} or {@link MonitoringWatchSource}. - * + * * @author Jan Bernitt * @since 5.201 */ @Service public class MonitoringConsoleRuntimeImpl implements ConfigListener, ApplicationLifecycleInterceptor, EventListener, - MonitoringConsoleRuntime, MonitoringConsoleWatchConfig, GroupDataRepository { + MonitoringConsoleRuntime, MonitoringConsoleWatchConfig, MonitoringConsolePageConfig, + GroupDataRepository { private static final Logger LOGGER = Logger.getLogger("monitoring-console-core"); @@ -254,8 +258,8 @@ public void enable(String name) { @Override public void add(String name, String watchJson) { - runCommand(SET_MONITORING_CONSOLE_CONFIGURATION_COMMAND, - "add-watch-name", name, + runCommand(SET_MONITORING_CONSOLE_CONFIGURATION_COMMAND, + "add-watch-name", name, "add-watch-json", watchJson); } @@ -266,7 +270,48 @@ public void remove(String name) { @Override public Iterable list() { - return config.getCustomWatchValues(); + return unmodifiableList(config.getCustomWatchValues()); + } + + @Override + public MonitoringConsolePageConfig getPageConfig() { + return this; + } + + @Override + public String getPage(String name) { + List values = config.getPageValues(); + List names = config.getPageNames(); + int index = names.indexOf(name); + if (index < 0) { + throw new NoSuchElementException("Page does not exist: " + name); + } + String page = values.get(index); + checkPageId(name, page); // this should just protect against the mostly theoretical chance that names and values are not in sync when accessed + return page; + } + + @Override + public void putPage(String name, String pageJson) { + if (pageJson == null || pageJson.isEmpty() || "{}".equals(pageJson)) { + runCommand(SET_MONITORING_CONSOLE_CONFIGURATION_COMMAND, "remove-page", name); + } else { + checkPageId(name, pageJson); + runCommand(SET_MONITORING_CONSOLE_CONFIGURATION_COMMAND, + "add-page-name", name, + "add-page-json", pageJson); + } + } + + private static void checkPageId(String name, String pageJson) { + if (pageJson.indexOf("\"id\":\"" + name + "\"") < 0) { + throw new IllegalArgumentException("Page JSON id did not match given name."); + } + } + + @Override + public Iterable listPages() { + return unmodifiableList(config.getPageNames()); } private void runCommand(String name, String... params) { @@ -322,13 +367,13 @@ public Collection selectAll(String source, String group) { @Override public void before(Phase phase, ExtendedDeploymentContext context) { - // This is implemented as an ugly work-around to get the runtime service bootstrapped on startup + // This is implemented as an ugly work-around to get the runtime service bootstrapped on startup // even through it is not needed by any other service but we know all ApplicationLifecycleInterceptor are resolved } @Override public void after(Phase phase, ExtendedDeploymentContext context) { - // This is implemented as an ugly work-around to get the runtime service bootstrapped on startup + // This is implemented as an ugly work-around to get the runtime service bootstrapped on startup // even through it is not needed by any other service but we know all ApplicationLifecycleInterceptor are resolved } } diff --git a/pom.xml b/pom.xml index a5669b920c0..a1dcd42b622 100644 --- a/pom.xml +++ b/pom.xml @@ -205,9 +205,9 @@ 1.1.2 1.0.payara-p2 7.3.1 - 1.0 - 1.0 - 1.0 + 1.3 + 1.2-SNAPSHOT + 1.2-SNAPSHOT ${project.build.outputDirectory} From 246a0f5e32e20b84e6376e99c1d491037bdc5aaf Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Wed, 13 May 2020 13:58:35 +0200 Subject: [PATCH 2/2] APPSERV-124 use actual MC versions --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index a1dcd42b622..69abb4e396b 100644 --- a/pom.xml +++ b/pom.xml @@ -205,9 +205,9 @@ 1.1.2 1.0.payara-p2 7.3.1 - 1.3 - 1.2-SNAPSHOT - 1.2-SNAPSHOT + 1.1 + 1.2 + 1.2 ${project.build.outputDirectory}