use of fish.payara.jmx.monitoring.JMXMonitoringService in project Payara by payara.
the class SetJMXMonitoringConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
Config config = targetUtil.getConfig(target);
if (config == null) {
actionReport.setMessage("Cound not find target: " + target);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
final JMXMonitoringService jmxMonitoringService = serviceLocator.getService(JMXMonitoringService.class);
if (jmxMonitoringService == null) {
actionReport.appendMessage("Could not find a monitoring service.");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
jmxMonitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
try {
ConfigSupport.apply(new SingleConfigCode<MonitoringServiceConfiguration>() {
@Override
public Object run(final MonitoringServiceConfiguration monitoringConfigProxy) throws PropertyVetoException, TransactionFailure {
updateConfiguration(monitoringConfigProxy);
updateAttributes(monitoringConfigProxy, actionReport);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return monitoringConfigProxy;
}
}, jmxMonitoringConfig);
if (dynamic) {
enableOnTarget(actionReport, context, enabled);
}
// If the JMX Monitoring is enabled, enable Mbeans too as without it you have nothing to monitor
if (enabled != null && enabled) {
MonitoringService monitoringService = config.getMonitoringService();
ConfigSupport.apply(new SingleConfigCode<MonitoringService>() {
@Override
public Object run(final MonitoringService monitoringServiceProxy) throws PropertyVetoException, TransactionFailure {
monitoringServiceProxy.setMbeanEnabled((String.valueOf(enabled)));
return monitoringServiceProxy;
}
}, monitoringService);
}
} catch (TransactionFailure ex) {
logger.log(Level.WARNING, "Falied to excute the command " + "set-jmx-monitoring-configuration: " + ex.getCause().getMessage());
actionReport.setMessage(ex.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
Aggregations