use of com.sun.enterprise.config.serverbeans.MonitoringService in project Payara by payara.
the class GetMonitoringConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport actionReport = context.getActionReport();
ActionReport monitoringServiceReport = actionReport.addSubActionsReport();
Config config = targetUtil.getConfig(target);
if (config == null) {
actionReport.setMessage("No such config named: " + target);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
MonitoringService monitoringService = config.getMonitoringService();
AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
CommandRunner.CommandInvocation commandInvocation = commandRunner.getCommandInvocation("get-rest-monitoring-configuration", actionReport, context.getSubject());
commandInvocation.execute();
commandInvocation = commandRunner.getCommandInvocation("get-jmx-monitoring-configuration", actionReport, context.getSubject());
commandInvocation.execute();
final String[] headers = { "Monitoring Enabled", "AMX Enabled", "MBeans Enabled", "DTrace Enabled" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
columnFormatter.addRow(new Object[] { monitoringService.getMonitoringEnabled(), amxConfiguration.getEnabled(), monitoringService.getMbeanEnabled(), monitoringService.getDtraceEnabled() });
Map<String, Object> extraPropertiesMap = new HashMap<>();
extraPropertiesMap.put("monitoringEnabled", monitoringService.getMonitoringEnabled());
extraPropertiesMap.put("mbeanEnabled", monitoringService.getMbeanEnabled());
extraPropertiesMap.put("dtraceEnabled", monitoringService.getDtraceEnabled());
extraPropertiesMap.put("amxEnabled", amxConfiguration.getEnabled());
Properties extraProperties = new Properties();
extraProperties.put("getMonitoringConfiguration", extraPropertiesMap);
actionReport.setExtraProperties(extraProperties);
monitoringServiceReport.setMessage(columnFormatter.toString());
monitoringServiceReport.appendMessage(StringUtils.EOL);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.MonitoringService in project Payara by payara.
the class GetMonitoringServiceConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config named: " + target);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
MonitoringService monitoringService = config.getMonitoringService();
AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
final ActionReport actionReport = context.getActionReport();
final String[] headers = { "Monitoring Enabled", "AMX Enabled", "MBeans Enabled", "DTrace Enabled" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
columnFormatter.addRow(new Object[] { monitoringService.getMonitoringEnabled(), amxConfiguration.getEnabled(), monitoringService.getMbeanEnabled(), monitoringService.getDtraceEnabled() });
actionReport.appendMessage(columnFormatter.toString());
Map<String, Object> extraPropertiesMap = new HashMap<>();
extraPropertiesMap.put("monitoringEnabled", monitoringService.getMonitoringEnabled());
extraPropertiesMap.put("amxEnabled", amxConfiguration.getEnabled());
extraPropertiesMap.put("mbeanEnabled", monitoringService.getMbeanEnabled());
extraPropertiesMap.put("dtraceEnabled", monitoringService.getDtraceEnabled());
Properties extraProperties = new Properties();
extraProperties.put("getMonitoringServiceConfiguration", extraPropertiesMap);
actionReport.setExtraProperties(extraProperties);
actionReport.setMessage(columnFormatter.toString());
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.MonitoringService in project Payara by payara.
the class SetMonitoringConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport actionReport = context.getActionReport();
// obtain the correct configuration
Config config = targetUtil.getConfig(target);
MonitoringService monitorServiceConfig = config.getExtensionByType(MonitoringService.class);
if (monitorServiceConfig != null) {
try {
ConfigSupport.apply((monitorServiceConfigProxy) -> {
if (monitoringServiceEnabled != null) {
monitorServiceConfigProxy.setMonitoringEnabled(String.valueOf(monitoringServiceEnabled));
}
if (mbeansEnabled != null) {
monitorServiceConfigProxy.setMbeanEnabled(String.valueOf(mbeansEnabled));
}
if (dTraceEnabled != null) {
monitorServiceConfigProxy.setMbeanEnabled(String.valueOf(dTraceEnabled));
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return monitorServiceConfigProxy;
}, monitorServiceConfig);
} catch (TransactionFailure ex) {
logger.log(Level.WARNING, "Exception during command ", ex);
actionReport.setMessage(ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
CommandInvocation commandInvocation = commandRunner.getCommandInvocation("set-jmx-monitoring-configuration", actionReport, context.getSubject());
ParameterMap commandParameters = new ParameterMap();
if (jmxLogEnabled != null) {
commandParameters.add("enabled", jmxLogEnabled.toString());
}
if (jmxLogFrequency != null) {
commandParameters.add("logfrequency", jmxLogFrequency);
}
if (jmxLogFrequencyUnit != null) {
commandParameters.add("logfrequencyunit", jmxLogFrequencyUnit);
}
if (attributesToAdd != null) {
for (String attributeToAdd : attributesToAdd) {
commandParameters.add("addattribute", attributeToAdd);
}
}
if (attributesToRemove != null) {
for (String attributeToRemove : attributesToRemove) {
commandParameters.add("delattribute", attributeToRemove);
}
}
if (dynamic) {
commandParameters.add("dynamic", dynamic.toString());
}
commandParameters.add("target", target);
commandInvocation.parameters(commandParameters);
commandInvocation.execute();
if (actionReport.getActionExitCode() != SUCCESS && actionReport.getActionExitCode() != WARNING) {
// Command couldn't be execute
failureMessage(actionReport);
return;
}
if (amxEnabled != null) {
commandInvocation = commandRunner.getCommandInvocation("set-amx-enabled", actionReport, context.getSubject());
commandParameters = new ParameterMap();
commandParameters.add("enabled", amxEnabled.toString());
commandParameters.add("dynamic", dynamic.toString());
commandParameters.add("target", target);
commandInvocation.parameters(commandParameters);
commandInvocation.execute();
if (actionReport.getActionExitCode() != SUCCESS && actionReport.getActionExitCode() != WARNING) {
// Command couldn't be execute
failureMessage(actionReport);
return;
}
}
commandInvocation = commandRunner.getCommandInvocation("set-rest-monitoring-configuration", actionReport, context.getSubject());
commandParameters = new ParameterMap();
if (restMonitoringEnabled != null) {
commandParameters.add("enabled", restMonitoringEnabled.toString());
}
if (restMonitoringContextRoot != null) {
commandParameters.add("contextroot", restMonitoringContextRoot);
}
if (restMonitoringApplicationName != null) {
commandParameters.add("applicationname", restMonitoringApplicationName);
}
if (restMonitoringSecurityEnabled != null) {
commandParameters.add("securityenabled", restMonitoringSecurityEnabled.toString());
}
commandParameters.add("target", target);
commandInvocation.parameters(commandParameters);
commandInvocation.execute();
if (actionReport.getActionExitCode() != SUCCESS && actionReport.getActionExitCode() != WARNING) {
// Command couldn't be execute
failureMessage(actionReport);
return;
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.MonitoringService in project Payara by payara.
the class SetMonitoringServiceConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
config = targetUtil.getConfig(target);
if (config != null) {
monitoringService = config.getMonitoringService();
} else {
actionReport.setMessage("Cound not find target: " + target);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
try {
ConfigSupport.apply(new SingleConfigCode<MonitoringService>() {
@Override
public Object run(final MonitoringService monitoringServiceProxy) throws PropertyVetoException, TransactionFailure {
if (monitoringEnabled != null) {
monitoringServiceProxy.setMonitoringEnabled(String.valueOf(monitoringEnabled));
}
if (mbeanEnabled != null) {
monitoringServiceProxy.setMbeanEnabled(String.valueOf(mbeanEnabled));
}
if (dtraceEnabled != null) {
monitoringServiceProxy.setDtraceEnabled(String.valueOf(dtraceEnabled));
}
if (amxEnabled != null) {
AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
ConfigSupport.apply(new SingleConfigCode<AMXConfiguration>() {
@Override
public Object run(final AMXConfiguration amxConfigurationProxy) throws PropertyVetoException, TransactionFailure {
amxConfigurationProxy.setEnabled((String.valueOf(amxEnabled)));
return amxConfigurationProxy;
}
}, amxConfiguration);
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return monitoringServiceProxy;
}
}, monitoringService);
} catch (TransactionFailure ex) {
logger.log(Level.WARNING, "Failed to execute the command set-monitoring-service-configuration: {0}", ex.getCause().getMessage());
actionReport.setMessage(ex.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
use of com.sun.enterprise.config.serverbeans.MonitoringService in project Payara by payara.
the class GetMonitoringLevel method execute.
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config named: " + target);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
MonitoringService monitoringService = config.getMonitoringService();
final ActionReport actionReport = context.getActionReport();
final String[] headers = { "Module", "Monitoring Level" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
Map<String, Object> extraPropertiesMap = new HashMap<>();
List<String> validModuleList = new ArrayList<>(Arrays.asList(Constants.validModuleNames));
// their monitoring levels
if (moduleName == null) {
for (String validModule : validModuleList) {
columnFormatter.addRow(new Object[] { validModule, monitoringService.getMonitoringLevel(validModule) });
extraPropertiesMap.put(validModule, monitoringService.getMonitoringLevel(validModule));
}
}
if (moduleName != null) {
List<String> moduleNameList = Arrays.asList(moduleName.split(","));
for (String module : moduleNameList) {
boolean isValidMoudle = false;
String selectedModule = module.trim().toLowerCase();
for (String validModule : validModuleList) {
if (validModule.trim().equals(selectedModule)) {
columnFormatter.addRow(new Object[] { selectedModule, monitoringService.getMonitoringLevel(selectedModule) });
extraPropertiesMap.put(selectedModule, monitoringService.getMonitoringLevel(selectedModule));
isValidMoudle = true;
break;
}
}
if (!isValidMoudle) {
actionReport.setMessage(selectedModule + " isn't a valid Module name");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
Properties extraProperties = new Properties();
extraProperties.put("getMonitoringLevel", extraPropertiesMap);
actionReport.setExtraProperties(extraProperties);
actionReport.setMessage(columnFormatter.toString());
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations