use of org.glassfish.api.ActionReport in project Payara by payara.
the class BaseRequestTracingNotifierConfigurer 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 RequestTracingServiceConfiguration configuration = config.getExtensionByType(RequestTracingServiceConfiguration.class);
ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
notifierClass = (Class<C>) genericSuperclass.getActualTypeArguments()[0];
C c = configuration.getNotifierByType(notifierClass);
try {
if (c == null) {
ConfigSupport.apply(new SingleConfigCode<RequestTracingServiceConfiguration>() {
@Override
public Object run(final RequestTracingServiceConfiguration configurationProxy) throws PropertyVetoException, TransactionFailure {
C c = configurationProxy.createChild(notifierClass);
applyValues(c);
configurationProxy.getNotifierList().add(c);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return configurationProxy;
}
}, configuration);
} 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 org.glassfish.api.ActionReport in project Payara by payara.
the class HealthCheckConfigurer method enableLogNotifier.
private void enableLogNotifier(AdminCommandContext context) {
CommandRunner runner = serviceLocator.getService(CommandRunner.class);
ActionReport subReport = context.getActionReport().addSubActionsReport();
CommandRunner.CommandInvocation inv = runner.getCommandInvocation("healthcheck-log-notifier-configure", subReport, context.getSubject());
ParameterMap params = new ParameterMap();
params.add("dynamic", dynamic.toString());
params.add("target", target);
if (notifierEnabled != null) {
params.add("enabled", notifierEnabled.toString());
}
if (notifierEnabled == null && enabled != null) {
params.add("enabled", enabled.toString());
}
inv.parameters(params);
inv.execute();
// swallow the offline warning as it is not a problem
if (subReport.hasWarnings()) {
subReport.setMessage("");
}
}
use of org.glassfish.api.ActionReport 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 org.glassfish.api.ActionReport 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 org.glassfish.api.ActionReport in project Payara by payara.
the class TestLogNotifier method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport actionReport = context.getActionReport();
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config named: " + target);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
LogNotifierConfiguration logConfig = config.getExtensionByType(LogNotifierConfiguration.class);
if (useSeparateLogFile == null) {
useSeparateLogFile = Boolean.parseBoolean(logConfig.getUseSeparateLogFile());
}
// prepare log message
LogNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
LogNotifierConfigurationExecutionOptions options = new LogNotifierConfigurationExecutionOptions();
options.setUseSeparateLogFile(useSeparateLogFile);
// set up logger to store result
LogNotifierService service = new LogNotifierService();
Logger logger = Logger.getLogger(LogNotifierService.class.getCanonicalName());
BlockingQueueHandler bqh = new BlockingQueueHandler(10);
bqh.setLevel(Level.FINE);
Level oldLevel = logger.getLevel();
logger.setLevel(Level.FINE);
logger.addHandler(bqh);
service.handleNotification(event);
logger.setLevel(oldLevel);
LogRecord message = bqh.poll();
logger.removeHandler(bqh);
if (message == null) {
// something's gone wrong
Logger.getLogger(TestLogNotifier.class.getCanonicalName()).log(Level.SEVERE, "Failed to send Log message");
actionReport.setMessage("Failed to send Log message");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
} else {
;
actionReport.setMessage(message.getMessage());
if (message.getLevel() == Level.FINE) {
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} else {
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
}
Aggregations