use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class SetFaultToleranceConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext acc) {
Config targetConfig = targetUtil.getConfig(target);
FaultToleranceServiceConfiguration faultToleranceServiceConfiguration = targetConfig.getExtensionByType(FaultToleranceServiceConfiguration.class);
try {
ConfigSupport.apply((FaultToleranceServiceConfiguration configProxy) -> {
if (managedExecutorServiceName != null) {
configProxy.setManagedExecutorService(managedExecutorServiceName);
}
if (managedScheduledExecutorServiceName != null) {
configProxy.setManagedScheduledExecutorService(managedScheduledExecutorServiceName);
}
return null;
}, faultToleranceServiceConfiguration);
} catch (TransactionFailure ex) {
acc.getActionReport().failure(logger, "Failed to update Fault Tolerance configuration", ex);
}
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class GetMetricsConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext adminCommandContext) {
Config targetConfig = targetUtil.getConfig(target);
if (targetConfig == null) {
adminCommandContext.getActionReport().setMessage("No such config name: " + targetUtil);
adminCommandContext.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
MetricsServiceConfiguration metricsConfiguration = targetConfig.getExtensionByType(MetricsServiceConfiguration.class);
ColumnFormatter columnFormatter = new ColumnFormatter(OUTPUT_HEADERS);
Object[] outputValues = { metricsConfiguration.getEnabled(), metricsConfiguration.getSecure() };
columnFormatter.addRow(outputValues);
adminCommandContext.getActionReport().appendMessage(columnFormatter.toString());
Map<String, Object> extraPropertiesMap = new HashMap<>();
extraPropertiesMap.put("enabled", metricsConfiguration.getEnabled());
extraPropertiesMap.put("secure", metricsConfiguration.getSecure());
Properties extraProperties = new Properties();
extraProperties.put("metricsConfiguration", extraPropertiesMap);
adminCommandContext.getActionReport().setExtraProperties(extraProperties);
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class GetZendeskSupportConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext acc) {
Config configNode = targetUtil.getConfig(config);
ZendeskSupportConfiguration zendeskSupportConfiguration = configNode.getExtensionByType(ZendeskSupportConfiguration.class);
ActionReport actionReport = acc.getActionReport();
final String[] outputHeaders = { "Enabled", "Email Address" };
ColumnFormatter columnFormatter = new ColumnFormatter(outputHeaders);
Object[] outputValues = { zendeskSupportConfiguration.getEnabled(), zendeskSupportConfiguration.getEmailAddress() };
columnFormatter.addRow(outputValues);
actionReport.appendMessage(columnFormatter.toString());
Map<String, Object> extraPropsMap = new HashMap<>();
extraPropsMap.put("enabled", zendeskSupportConfiguration.getEnabled());
extraPropsMap.put("emailAddress", zendeskSupportConfiguration.getEmailAddress());
Properties extraProps = new Properties();
extraProps.put("zendeskSupportConfiguration", extraPropsMap);
actionReport.setExtraProperties(extraProps);
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class TestEmailNotifier 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;
}
EmailNotifierConfiguration emailConfig = config.getExtensionByType(EmailNotifierConfiguration.class);
if (jndiName == null) {
jndiName = emailConfig.getJndiName();
}
if (to == null) {
to = emailConfig.getTo();
}
// prepare email
EmailNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
EmailMessageQueue queue = new EmailMessageQueue();
queue.addMessage(new EmailMessage(event, event.getSubject(), event.getMessage()));
EmailNotifierConfigurationExecutionOptions options = new EmailNotifierConfigurationExecutionOptions();
options.setJndiName(jndiName);
options.setTo(to);
Session session;
try {
InitialContext initialContext = new InitialContext();
session = (Session) initialContext.lookup(jndiName);
} catch (NamingException ex) {
Logger.getLogger(TestEmailNotifier.class.getName()).log(Level.SEVERE, "Unable to find session" + jndiName);
context.getActionReport().setMessage("Unable to find session: " + jndiName);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
EmailNotificationRunnable notifierRun = new EmailNotificationRunnable(queue, session, options);
// set up logger to store result
Logger logger = Logger.getLogger(EmailNotificationRunnable.class.getCanonicalName());
BlockingQueueHandler bqh = new BlockingQueueHandler(10);
bqh.setLevel(Level.FINE);
Level oldLevel = logger.getLevel();
logger.setLevel(Level.FINE);
logger.addHandler(bqh);
// send message, this occurs in its own thread
Thread notifierThread = new Thread(notifierRun, "test-email-notifier-thread");
notifierThread.start();
try {
notifierThread.join();
} catch (InterruptedException ex) {
Logger.getLogger(TestEmailNotifier.class.getName()).log(Level.SEVERE, null, ex);
} finally {
logger.setLevel(oldLevel);
}
LogRecord message = bqh.poll();
logger.removeHandler(bqh);
if (message == null) {
// something's gone wrong
Logger.getLogger(TestEmailNotifier.class.getName()).log(Level.SEVERE, "Failed to send email");
actionReport.setMessage("Failed to send email message");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
} else {
if (message.getLevel() == Level.FINE) {
actionReport.setMessage(message.getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} else {
actionReport.setMessage(message.getMessage() + message.getThrown().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class SetBatchRuntimeConfiguration 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);
}
if (dataSourceLookupName == null && executorServiceLookupName == null) {
actionReport.setMessage("Either dataSourceLookupName or executorServiceLookupName must be specified.");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
Config config = targetUtil.getConfig(target);
BatchRuntimeConfiguration batchRuntimeConfiguration = config.getExtensionByType(BatchRuntimeConfiguration.class);
if (batchRuntimeConfiguration != null) {
ConfigSupport.apply(new SingleConfigCode<BatchRuntimeConfiguration>() {
@Override
public Object run(final BatchRuntimeConfiguration batchRuntimeConfigurationProxy) throws PropertyVetoException, TransactionFailure {
boolean encounteredError = false;
int tableprefixlength = 0;
int tablesuffixlength = 0;
if (dataSourceLookupName != null) {
try {
validateDataSourceLookupName(context, target, dataSourceLookupName);
batchRuntimeConfigurationProxy.setDataSourceLookupName(dataSourceLookupName);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (GlassFishBatchValidationException ex) {
logger.log(Level.WARNING, ex.getMessage());
actionReport.setMessage(dataSourceLookupName + " is not mapped to a DataSource");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishBatchValidationException(dataSourceLookupName + " is not mapped to a DataSource");
}
}
if (executorServiceLookupName != null && !encounteredError) {
try {
validateExecutorServiceLookupName(context, target, executorServiceLookupName);
batchRuntimeConfigurationProxy.setExecutorServiceLookupName(executorServiceLookupName);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (GlassFishBatchValidationException ex) {
logger.log(Level.WARNING, ex.getMessage());
actionReport.setMessage("No executor service bound to name = " + executorServiceLookupName);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishBatchValidationException("No executor service bound to name = " + executorServiceLookupName);
}
}
if (schemaName != null && !encounteredError) {
batchRuntimeConfigurationProxy.setSchemaName(schemaName);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
if (tablePrefix != null && !encounteredError) {
tableprefixlength = tablePrefix.length();
batchRuntimeConfigurationProxy.setTablePrefix(tablePrefix);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
if (tableSuffix != null && !encounteredError) {
tablesuffixlength = tableSuffix.length();
batchRuntimeConfigurationProxy.setTableSuffix(tableSuffix);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
if (targetUtil.isThisDAS() && isOracle(dataSourceLookupName)) {
if (tablesuffixlength + tableprefixlength + MAX_TABLE_LENGTH > 30) {
actionReport.setMessage("The table name cannot be greater than 30 characters in Oracle, please amend the table prefix or suffix size ");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishBatchValidationException("The table name cannot be greater than 30 characters in Oracle, please amend the table prefix or suffix size ");
}
}
return null;
}
}, batchRuntimeConfiguration);
}
} catch (TransactionFailure txfEx) {
logger.log(Level.WARNING, "Exception during command ", txfEx);
actionReport.setMessage(txfEx.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
Aggregations