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

APPSERV-124 Monitoring-Console: Adds server side page configuration #4666

Merged
merged 3 commits into from
Jun 1, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -155,30 +167,18 @@ public Object run(MonitoringConsoleConfiguration configProxy) throws PropertyVet
configProxy.getDisabledWatchNames().remove(_enableWatch);
}
if (isDefined(_addWatchName) && isDefined(_addWatchJson)) {
List<String> customWatchNames = configProxy.getCustomWatchNames();
List<String> 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<String> customWatchNames = configProxy.getCustomWatchNames();
int index = customWatchNames.indexOf(_removeWatch);
if (index >= 0) {
customWatchNames.remove(index);
List<String> 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);
Expand All @@ -187,6 +187,28 @@ public Object run(MonitoringConsoleConfiguration configProxy) throws PropertyVet
}
}

static void add(String name, String value, List<String> names, List<String> 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<String> names, List<String> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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)
Expand All @@ -86,4 +86,16 @@ public interface MonitoringConsoleConfiguration extends DomainExtension {
@Element
List<String> getCustomWatchValues();

/**
* @return Names of MC (client) pages
*/
@Element
List<String> getPageNames();

/**
* @return JSON values of the MC (client) pages (index is same in {@link #getPageNames()})
*/
@Element
List<String> getPageValues();

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@

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;
import java.util.ArrayList;
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;
Expand Down Expand Up @@ -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;
Expand All @@ -102,22 +105,23 @@
/**
* 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
* registers itself as an {@link EventListener} so that it can run its actual {@link #init()} bootstrapping as soon as
* 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");

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

Expand All @@ -266,7 +270,48 @@ public void remove(String name) {

@Override
public Iterable<String> list() {
return config.getCustomWatchValues();
return unmodifiableList(config.getCustomWatchValues());
}

@Override
public MonitoringConsolePageConfig getPageConfig() {
return this;
}

@Override
public String getPage(String name) {
List<String> values = config.getPageValues();
List<String> 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<String> listPages() {
return unmodifiableList(config.getPageNames());
}

private void runCommand(String name, String... params) {
Expand Down Expand Up @@ -322,13 +367,13 @@ public Collection<GroupData> 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
}
}
7 changes: 3 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,9 @@
<concurrent-api.version>1.1.2</concurrent-api.version>
<concurrent.version>1.0.payara-p2</concurrent.version>
<asm.version>7.3.1</asm.version>
<monitoring-console-api.version>1.0</monitoring-console-api.version>
<monitoring-console-process.version>1.1</monitoring-console-process.version>
<monitoring-console-webapp.version>1.1</monitoring-console-webapp.version>

<monitoring-console-api.version>1.1</monitoring-console-api.version>
<monitoring-console-process.version>1.2</monitoring-console-process.version>
<monitoring-console-webapp.version>1.2</monitoring-console-webapp.version>
<validation.xml.root>${project.build.outputDirectory}</validation.xml.root>
</properties>

Expand Down