use of fish.payara.internal.notification.PayaraNotifier in project Payara by payara.
the class GetJMXMonitoringConfiguration method execute.
/**
* Method that is invoked when the asadmin command is performed. Pretty
* prints the Monitoring Service Configuration values.
*
* @param context
*/
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config name: " + targetUtil);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
ActionReport actionReport = context.getActionReport();
ActionReport jmxMonitoringReport = actionReport.addSubActionsReport();
ActionReport notifiersReport = actionReport.addSubActionsReport();
ActionReport attributeReport = actionReport.addSubActionsReport();
ColumnFormatter jmxMonitoringColumnFormatter = new ColumnFormatter(JMX_MONITORING_HEADERS);
ColumnFormatter attributeColumnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS);
ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS);
MonitoringServiceConfiguration monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
List<ServiceHandle<PayaraNotifier>> allNotifierServiceHandles = habitat.getAllServiceHandles(PayaraNotifier.class);
jmxMonitoringColumnFormatter.addRow(new Object[] { monitoringConfig.getEnabled(), monitoringConfig.getLogFrequency(), monitoringConfig.getLogFrequencyUnit() });
Map<String, Object> map = new HashMap<>();
map.put("enabled", monitoringConfig.getEnabled());
map.put("logfrequency", monitoringConfig.getLogFrequency());
map.put("logfrequencyunit", monitoringConfig.getLogFrequencyUnit());
Properties extraProps = new Properties();
extraProps.put("jmxmonitoringConfiguration", map);
List<Map<String, String>> monitoredAttributes = new ArrayList<>();
for (MonitoredAttribute monitoredBean : monitoringConfig.getMonitoredAttributes()) {
Object[] values = new Object[3];
values[0] = monitoredBean.getObjectName();
values[1] = monitoredBean.getAttributeName();
values[2] = monitoredBean.getDescription();
Map<String, String> monitoredAttribute = new HashMap<>();
monitoredAttribute.put(monitoredBean.getObjectName(), monitoredBean.getAttributeName());
monitoredAttributes.add(monitoredAttribute);
attributeColumnFormatter.addRow(values);
}
// Cannot change key in line below - required for admingui propertyDescTable.inc
extraProps.put("monitored-beans", monitoredAttributes);
actionReport.setExtraProperties(extraProps);
if (!monitoringConfig.getNotifierList().isEmpty()) {
List<String> notifiers = monitoringConfig.getNotifierList();
Properties notifierProps = new Properties();
for (ServiceHandle<PayaraNotifier> serviceHandle : allNotifierServiceHandles) {
final String notifierClassName = serviceHandle.getActiveDescriptor().getImplementationClass().getSimpleName();
final String notifierName = NotifierUtils.getNotifierName(serviceHandle.getActiveDescriptor());
Object[] values = new Object[2];
values[0] = notifierName;
values[1] = notifiers.contains(notifierName);
notifiersColumnFormatter.addRow(values);
Map<String, Object> mapNotifiers = new HashMap<>(2);
mapNotifiers.put("notifierName", values[0]);
mapNotifiers.put("notifierEnabled", values[1]);
notifierProps.put("notifierList" + notifierClassName, mapNotifiers);
}
actionReport.getExtraProperties().putAll(notifierProps);
}
jmxMonitoringReport.setMessage(jmxMonitoringColumnFormatter.toString());
jmxMonitoringReport.appendMessage(StringUtils.EOL);
notifiersReport.setMessage(notifiersColumnFormatter.toString());
notifiersReport.appendMessage(StringUtils.EOL);
attributeReport.setMessage(attributeColumnFormatter.toString());
attributeReport.appendMessage(StringUtils.EOL);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations