use of fish.payara.nucleus.notification.configuration.NotifierConfiguration in project Payara by payara.
the class NotificationService method bootstrapNotificationService.
public void bootstrapNotificationService() {
if (configuration != null) {
executionOptions = new NotificationExecutionOptions();
executionOptions.setEnabled(Boolean.parseBoolean(configuration.getEnabled()));
for (NotifierConfiguration notifierConfiguration : configuration.getNotifierConfigurationList()) {
NotifierType type = null;
try {
ConfigView view = ConfigSupport.getImpl(notifierConfiguration);
NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
type = annotation.type();
executionOptions.addNotifierConfigurationExecutionOption(factoryStore.get(type).build(notifierConfiguration));
} catch (UnsupportedEncodingException e) {
logger.log(Level.SEVERE, "Notifier configuration with type " + type + " cannot be configured due to encoding problems in configuration parameters", e);
}
}
if (executionOptions.isEnabled()) {
logger.info("Payara Notification Service bootstrapped with configuration: " + executionOptions);
}
}
}
use of fish.payara.nucleus.notification.configuration.NotifierConfiguration 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);
}
Aggregations