use of fish.payara.internal.notification.PayaraConfiguredNotifier in project Payara by payara.
the class GetNotificationConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext context) {
// Get the command report
final ActionReport report = context.getActionReport();
// Get the target configuration
final Config targetConfig = targetUtil.getConfig(target);
if (targetConfig == null) {
report.setMessage("No such config named: " + target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
final NotificationServiceConfiguration configuration = targetConfig.getExtensionByType(NotificationServiceConfiguration.class);
final String notificationServiceEnabled = configuration.getEnabled();
final List<ServiceHandle<PayaraNotifier>> notifierHandles = habitat.getAllServiceHandles(PayaraNotifier.class);
if (notifierHandles.isEmpty()) {
report.setMessage("No notifiers defined");
report.setActionExitCode(ActionReport.ExitCode.WARNING);
return;
}
String[] headers = { "Notifier Name", "Enabled", "Notifier Enabled", "Notifier Noisy" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
Properties extraProps = new Properties();
for (ServiceHandle<PayaraNotifier> serviceHandle : notifierHandles) {
final Class<?> notifierClass = serviceHandle.getActiveDescriptor().getImplementationClass();
Object[] values = new Object[4];
values[0] = getNotifierName(serviceHandle.getActiveDescriptor());
values[1] = notificationServiceEnabled;
// Get the notifier config if applicable
PayaraNotifierConfiguration notifierConfig = null;
if (serviceHandle.getService() instanceof PayaraConfiguredNotifier) {
// Get the associated configuration
notifierConfig = configuration.getNotifierConfigurationByType(NotifierUtils.getConfigurationClass(notifierClass));
}
if (notifierConfig == null) {
values[2] = PayaraNotifierConfiguration.DEFAULT_ENABLED_VALUE;
values[3] = PayaraNotifierConfiguration.DEFAULT_NOISY_VALUE;
} else {
values[2] = notifierConfig.getEnabled();
values[3] = notifierConfig.getNoisy();
}
columnFormatter.addRow(values);
Map<String, Object> map = new HashMap<>(3);
map.put("enabled", values[1]);
map.put("notifierEnabled", values[2]);
map.put("noisy", values[3]);
if (notifierConfig != null && notifierConfig instanceof LogNotifierConfiguration) {
map.put("useSeparateLogFile", ((LogNotifierConfiguration) notifierConfig).getUseSeparateLogFile());
}
extraProps.put("getNotificationConfiguration" + notifierClass.getSimpleName(), map);
}
report.setMessage(columnFormatter.toString());
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
report.setExtraProperties(extraProps);
}
Aggregations