use of org.glassfish.api.ActionReport 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 org.glassfish.api.ActionReport 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 org.glassfish.api.ActionReport in project Payara by payara.
the class ListManagedThreadFactories method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
try {
Collection<ManagedThreadFactory> managedThreadFactories = domain.getResources().getResources(ManagedThreadFactory.class);
List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
for (ManagedThreadFactory managedThreadFactory : managedThreadFactories) {
String jndiName = managedThreadFactory.getJndiName();
if (bindableResourcesHelper.resourceExists(jndiName, target)) {
ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(jndiName);
Map<String, String> resourceNameMap = new HashMap<String, String>();
String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
if (logicalName != null) {
resourceNameMap.put("logical-jndi-name", logicalName);
}
resourceNameMap.put("name", jndiName);
resourcesList.add(resourceNameMap);
}
}
Properties extraProperties = new Properties();
extraProperties.put("managedThreadFactories", resourcesList);
report.setExtraProperties(extraProperties);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("list.managed.thread.factory.failed", "List managed thread factories failed"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class ListContextServices method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
try {
Collection<ContextService> contextServices = domain.getResources().getResources(ContextService.class);
List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
for (ContextService contextService : contextServices) {
String jndiName = contextService.getJndiName();
if (bindableResourcesHelper.resourceExists(jndiName, target)) {
ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(jndiName);
Map<String, String> resourceNameMap = new HashMap<String, String>();
String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
if (logicalName != null) {
resourceNameMap.put("logical-jndi-name", logicalName);
}
resourceNameMap.put("name", jndiName);
resourcesList.add(resourceNameMap);
}
}
Properties extraProperties = new Properties();
extraProperties.put("contextServices", resourcesList);
report.setExtraProperties(extraProperties);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("list.context.service.failed", "List context services failed"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class CreateConnectorConnectionPool method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
HashMap attrList = new HashMap();
attrList.put(ResourceConstants.RES_ADAPTER_NAME, raname);
attrList.put(ResourceConstants.CONN_DEF_NAME, connectiondefinition);
attrList.put(ServerTags.DESCRIPTION, description);
attrList.put(ResourceConstants.STEADY_POOL_SIZE, steadypoolsize);
attrList.put(ResourceConstants.MAX_POOL_SIZE, maxpoolsize);
attrList.put(ResourceConstants.MAX_WAIT_TIME_IN_MILLIS, maxwait);
attrList.put(ResourceConstants.POOL_SIZE_QUANTITY, poolresize);
attrList.put(ResourceConstants.IDLE_TIME_OUT_IN_SECONDS, idletimeout);
attrList.put(ResourceConstants.IS_CONNECTION_VALIDATION_REQUIRED, isconnectvalidatereq.toString());
attrList.put(ResourceConstants.CONN_FAIL_ALL_CONNECTIONS, failconnection.toString());
attrList.put(ResourceConstants.VALIDATE_ATMOST_ONCE_PERIOD_IN_SECONDS, validateatmostonceperiod);
attrList.put(ResourceConstants.CONNECTION_LEAK_TIMEOUT_IN_SECONDS, leaktimeout);
attrList.put(ResourceConstants.CONNECTION_LEAK_RECLAIM, leakreclaim.toString());
attrList.put(ResourceConstants.CONNECTION_CREATION_RETRY_ATTEMPTS, creationretryattempts);
attrList.put(ResourceConstants.CONNECTION_CREATION_RETRY_INTERVAL_IN_SECONDS, creationretryinterval);
attrList.put(ResourceConstants.LAZY_CONNECTION_ASSOCIATION, lazyconnectionassociation.toString());
attrList.put(ResourceConstants.LAZY_CONNECTION_ENLISTMENT, lazyconnectionenlistment.toString());
attrList.put(ResourceConstants.ASSOCIATE_WITH_THREAD, associatewiththread.toString());
attrList.put(ResourceConstants.MATCH_CONNECTIONS, matchconnections.toString());
attrList.put(ResourceConstants.MAX_CONNECTION_USAGE_COUNT, maxconnectionusagecount);
attrList.put(ResourceConstants.CONNECTOR_CONNECTION_POOL_NAME, poolname);
attrList.put(ResourceConstants.CONN_TRANSACTION_SUPPORT, transactionsupport);
attrList.put(ResourceConstants.PING, ping.toString());
attrList.put(ResourceConstants.POOLING, pooling.toString());
ResourceStatus rs;
try {
ConnectorConnectionPoolManager connPoolMgr = connectorConnectionPoolManagerProvider.get();
rs = connPoolMgr.create(domain.getResources(), attrList, properties, target);
} catch (Exception e) {
Logger.getLogger(CreateConnectorConnectionPool.class.getName()).log(Level.SEVERE, "Unable to create connector connection pool " + poolname, e);
String def = "Connector connection pool: {0} could not be created, reason: {1}";
report.setMessage(localStrings.getLocalString("create.connector.connection.pool.fail", def, poolname) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
if (rs.getStatus() == ResourceStatus.FAILURE) {
ec = ActionReport.ExitCode.FAILURE;
if (rs.getMessage() != null) {
report.setMessage(rs.getMessage());
} else {
report.setMessage(localStrings.getLocalString("create.connector.connection.pool.fail", "Connector connection pool {0} creation failed.", poolname));
}
if (rs.getException() != null)
report.setFailureCause(rs.getException());
} else {
// TODO only for DAS ?
if ("true".equalsIgnoreCase(ping.toString())) {
ActionReport subReport = report.addSubActionsReport();
ParameterMap parameters = new ParameterMap();
parameters.set("pool_name", poolname);
commandRunner.getCommandInvocation("ping-connection-pool", subReport, context.getSubject()).parameters(parameters).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
subReport.setMessage(localStrings.getLocalString("ping.create.connector.connection.pool.fail", "\nAttempting to ping during Connector Connection " + "Pool Creation : {0} - Failed.", poolname));
subReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
} else {
subReport.setMessage(localStrings.getLocalString("ping.create.connector.connection.pool.success", "\nAttempting to ping during Connector Connection " + "Pool Creation : {0} - Succeeded.", poolname));
}
}
}
if (rs.getMessage() != null) {
report.setMessage(rs.getMessage());
}
report.setActionExitCode(ec);
}
Aggregations