use of fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration in project Payara by payara.
the class BaseGetNotifierConfiguration 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();
ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
notifierConfigurationClass = (Class<NC>) genericSuperclass.getActualTypeArguments()[0];
NotificationServiceConfiguration configuration = config.getExtensionByType(NotificationServiceConfiguration.class);
NC nc = configuration.getNotifierConfigurationByType(notifierConfigurationClass);
String message;
Properties extraProps = new Properties();
Map<String, Object> configMap = getNotifierConfiguration(nc);
if (nc == null) {
message = "Notifier Configuration is not defined";
} else {
message = listConfiguration(nc);
}
mainActionReport.setMessage(message);
extraProps.put("notifierConfiguration", configMap);
mainActionReport.setExtraProperties(extraProps);
mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration in project Payara by payara.
the class BaseNotificationConfigurer method execute.
@Override
public void execute(final AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
Properties extraProperties = actionReport.getExtraProperties();
if (extraProperties == null) {
extraProperties = new Properties();
actionReport.setExtraProperties(extraProperties);
}
Config configuration = targetUtil.getConfig(target);
final NotificationServiceConfiguration notificationServiceConfiguration = configuration.getExtensionByType(NotificationServiceConfiguration.class);
ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
notifierConfigurationClass = (Class<C>) genericSuperclass.getActualTypeArguments()[0];
C c = notificationServiceConfiguration.getNotifierConfigurationByType(notifierConfigurationClass);
try {
if (c == null) {
ConfigSupport.apply(new SingleConfigCode<NotificationServiceConfiguration>() {
@Override
public Object run(final NotificationServiceConfiguration notificationServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure {
C c = notificationServiceConfigurationProxy.createChild(notifierConfigurationClass);
applyValues(c);
notificationServiceConfigurationProxy.getNotifierConfigurationList().add(c);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ParameterMap params = new ParameterMap();
params.add("enabled", Boolean.TRUE.toString());
params.add("dynamic", Boolean.TRUE.toString());
params.add("target", target);
ActionReport healthCheckSubReport = actionReport.addSubActionsReport();
CommandRunner.CommandInvocation healthCheckCommandInvocation = commandRunner.getCommandInvocation(getHealthCheckNotifierCommandName(), healthCheckSubReport, context.getSubject());
healthCheckCommandInvocation.parameters(params);
healthCheckCommandInvocation.execute();
if (healthCheckSubReport.hasFailures()) {
logger.log(Level.SEVERE, "Error occurred while configuring notifier with command: " + getHealthCheckNotifierCommandName());
}
ActionReport requestTracingSubReport = actionReport.addSubActionsReport();
CommandRunner.CommandInvocation requestTracingCommandInvocation = commandRunner.getCommandInvocation(getRequestTracingNotifierCommandName(), requestTracingSubReport, context.getSubject());
requestTracingCommandInvocation.parameters(params);
requestTracingCommandInvocation.execute();
if (requestTracingSubReport.hasFailures()) {
logger.log(Level.SEVERE, "Error occurred while configuring notifier with command: " + getRequestTracingNotifierCommandName());
}
return notificationServiceConfigurationProxy;
}
}, notificationServiceConfiguration);
} else {
ConfigSupport.apply(new SingleConfigCode<C>() {
public Object run(C cProxy) throws PropertyVetoException, TransactionFailure {
applyValues(cProxy);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return cProxy;
}
}, c);
}
if (dynamic) {
if (server.isDas()) {
if (targetUtil.getConfig(target).isDas()) {
configureDynamically();
}
} else {
configureDynamically();
}
}
} catch (TransactionFailure ex) {
logger.log(Level.WARNING, "Exception during command ", ex);
actionReport.setMessage(ex.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
use of fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration 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.configuration.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