use of fish.payara.internal.notification.admin.NotificationServiceConfiguration 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.internal.notification.admin.NotificationServiceConfiguration in project Payara by payara.
the class NotificationConfigurer method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
Properties extraProperties = actionReport.getExtraProperties();
if (extraProperties == null) {
extraProperties = new Properties();
actionReport.setExtraProperties(extraProperties);
}
Config config = targetUtil.getConfig(target);
final NotificationServiceConfiguration notificationServiceConfiguration = config.getExtensionByType(NotificationServiceConfiguration.class);
if (notificationServiceConfiguration != null) {
try {
ConfigSupport.apply(new SingleConfigCode<NotificationServiceConfiguration>() {
@Override
public Object run(final NotificationServiceConfiguration notificationServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure {
if (enabled != null) {
notificationServiceConfigurationProxy.enabled(enabled.toString());
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return notificationServiceConfigurationProxy;
}
}, notificationServiceConfiguration);
} catch (TransactionFailure ex) {
logger.log(Level.WARNING, "Exception during command ", ex);
actionReport.setMessage(ex.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
if (dynamic) {
if (server.isDas()) {
if (targetUtil.getConfig(target).isDas()) {
service.bootstrapNotificationService();
}
} else {
// apply as not the DAS so implicitly it is for us
service.bootstrapNotificationService();
}
}
}
Aggregations