use of fish.payara.nucleus.notification.log.LogNotifierConfiguration 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);
}
use of fish.payara.nucleus.notification.log.LogNotifierConfiguration in project Payara by payara.
the class GetNotificationConfiguration 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;
}
ActionReport mainActionReport = context.getActionReport();
final NotificationServiceConfiguration notificationServiceConfiguration = config.getExtensionByType(NotificationServiceConfiguration.class);
NotificationServiceConfiguration configuration = config.getExtensionByType(NotificationServiceConfiguration.class);
List<ServiceHandle<BaseNotifierService>> allServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
String[] headers = { "Enabled", "Notifier Enabled" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
if (configuration.getNotifierConfigurationList().isEmpty()) {
mainActionReport.setMessage("No notifier defined");
} else {
List<Class<NotifierConfiguration>> notifierConfigurationClassList = Lists.transform(configuration.getNotifierConfigurationList(), new Function<NotifierConfiguration, Class<NotifierConfiguration>>() {
@Override
public Class<NotifierConfiguration> apply(NotifierConfiguration input) {
return resolveNotifierConfigurationClass(input);
}
});
Properties extraProps = new Properties();
for (ServiceHandle<BaseNotifierService> serviceHandle : allServiceHandles) {
NotifierConfiguration notifierConfiguration = configuration.getNotifierConfigurationByType(serviceHandle.getService().getNotifierConfigType());
if (notifierConfiguration != null) {
ConfigView view = ConfigSupport.getImpl(notifierConfiguration);
NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
if (notifierConfigurationClassList.contains(view.<NotifierConfiguration>getProxyType())) {
Object[] values = new Object[2];
values[0] = notificationServiceConfiguration.getEnabled();
values[1] = notifierConfiguration.getEnabled();
columnFormatter.addRow(values);
Map<String, Object> map;
if (NotifierType.LOG.equals(annotation.type())) {
map = new HashMap<>(3);
map.put("enabled", values[0]);
map.put("notifierEnabled", values[1]);
LogNotifierConfiguration logNotifierConfiguration = (LogNotifierConfiguration) notifierConfiguration;
map.put("useSeparateLogFile", logNotifierConfiguration.getUseSeparateLogFile());
} else {
map = new HashMap<>(2);
map.put("enabled", values[0]);
map.put("notifierEnabled", values[1]);
}
extraProps.put("getNotificationConfiguration" + annotation.type(), map);
}
}
}
mainActionReport.setExtraProperties(extraProps);
mainActionReport.setMessage(columnFormatter.toString());
}
mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of fish.payara.nucleus.notification.log.LogNotifierConfiguration in project Payara by payara.
the class LogNotifierConfigurationExecutionOptionsFactoryMock method notifierConfigurationExecutionOptionBuildsSuccessfullyForLog.
@Test
public void notifierConfigurationExecutionOptionBuildsSuccessfullyForLog() {
LogNotifierConfiguration logNotifierConfiguration = mock(LogNotifierConfiguration.class);
when(logNotifierConfiguration.getEnabled()).thenReturn("true");
LogNotifierConfigurationExecutionOptions executionOptions = factory.build(logNotifierConfiguration);
assertThat(executionOptions.getNotifierType(), is(NotifierType.LOG));
assertThat(executionOptions.isEnabled(), is(true));
}
Aggregations