use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.
the class ListHazelcastClusterMembersCommand method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
// Check if the DAS is in a Hazelcast cluster
if (payaraInstance.isClustered()) {
// Get the instance descriptors of the cluster members
Set<InstanceDescriptor> instances = payaraInstance.getClusteredPayaras();
// Create the table headers
String[] headers = { "Instance Name", "Instance Group", "Instance Type", "Host Name", "HTTP Ports", "HTTPS Ports", "Admin Port", "Hazelcast Port", "Lite Member", "Deployed Applications", "Last Heartbeat" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
List members = new ArrayList();
Properties extraProps = new Properties();
// list
for (InstanceDescriptor instance : instances) {
if (type != null && type.equals("micro")) {
if (instance.isMicroInstance()) {
populateMembers(members, instance, columnFormatter);
}
} else if (type != null && type.equals("server")) {
if (instance.isPayaraInstance()) {
populateMembers(members, instance, columnFormatter);
}
} else {
populateMembers(members, instance, columnFormatter);
}
}
// Return the instance information as both a String for console output, and in the action report for REST
extraProps.put("members", members);
actionReport.setExtraProperties(extraProps);
actionReport.setMessage(columnFormatter.toString());
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} else {
// If hazelcast is not enabled, just return a String stating as such
Properties extraProps = new Properties();
extraProps.put("members", "Hazelcast is not enabled");
actionReport.setExtraProperties(extraProps);
actionReport.setMessage("Hazelcast is not enabled");
}
}
use of com.sun.enterprise.util.ColumnFormatter 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 com.sun.enterprise.util.ColumnFormatter in project Payara by payara.
the class GetHazelcastConfiguration 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;
}
HazelcastConfigSpecificConfiguration nodeConfiguration = config.getExtensionByType(HazelcastConfigSpecificConfiguration.class);
HazelcastRuntimeConfiguration runtimeConfiguration = domain.getExtensionByType(HazelcastRuntimeConfiguration.class);
final ActionReport actionReport = context.getActionReport();
if (checkEncrypted) {
if (!Boolean.parseBoolean(runtimeConfiguration.getDatagridEncryptionEnabled())) {
actionReport.setMessage("Data Grid Not Encrypted");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
} else {
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
return;
}
String[] headers = { "Property Name", "PropertyValue", "Scope" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
columnFormatter.addRow(new Object[] { "Configuration File", runtimeConfiguration.getHazelcastConfigurationFile(), "Domain" });
columnFormatter.addRow(new Object[] { "Interfaces", runtimeConfiguration.getInterface(), "Domain" });
columnFormatter.addRow(new Object[] { "Auto Increment Port", runtimeConfiguration.getAutoIncrementPort(), "Domain" });
columnFormatter.addRow(new Object[] { "Start Port", runtimeConfiguration.getStartPort(), "Domain" });
columnFormatter.addRow(new Object[] { "Cluster Name", runtimeConfiguration.getClusterGroupName(), "Domain" });
columnFormatter.addRow(new Object[] { "License Key", runtimeConfiguration.getLicenseKey(), "Domain" });
columnFormatter.addRow(new Object[] { "Host Aware Partitioning", runtimeConfiguration.getHostAwarePartitioning(), "Domain" });
columnFormatter.addRow(new Object[] { "DAS Public Address", runtimeConfiguration.getDASPublicAddress(), "Domain" });
columnFormatter.addRow(new Object[] { "DAS Bind Address", runtimeConfiguration.getDASBindAddress(), "Domain" });
columnFormatter.addRow(new Object[] { "DAS Port", runtimeConfiguration.getDasPort(), "Domain" });
columnFormatter.addRow(new Object[] { "Cluster Mode", runtimeConfiguration.getDiscoveryMode(), "Domain" });
columnFormatter.addRow(new Object[] { "Tcpip Members", runtimeConfiguration.getTcpipMembers(), "Domain" });
columnFormatter.addRow(new Object[] { "DNS Members", runtimeConfiguration.getDnsMembers(), "Domain" });
columnFormatter.addRow(new Object[] { "MulticastGroup", runtimeConfiguration.getMulticastGroup(), "Domain" });
columnFormatter.addRow(new Object[] { "MulticastPort", runtimeConfiguration.getMulticastPort(), "Domain" });
columnFormatter.addRow(new Object[] { "Kubernetes Namespace", runtimeConfiguration.getKubernetesNamespace(), "Domain" });
columnFormatter.addRow(new Object[] { "Kubernetes Service Name", runtimeConfiguration.getKubernetesServiceName(), "Domain" });
columnFormatter.addRow(new Object[] { "Encrypt Datagrid", runtimeConfiguration.getDatagridEncryptionEnabled(), "Domain" });
columnFormatter.addRow(new Object[] { "Enabled", nodeConfiguration.getEnabled(), "Config" });
columnFormatter.addRow(new Object[] { "JNDIName", nodeConfiguration.getJNDIName(), "Config" });
columnFormatter.addRow(new Object[] { "Cache Manager JNDI Name", nodeConfiguration.getCacheManagerJNDIName(), "Config" });
columnFormatter.addRow(new Object[] { "Caching Provider JNDI Name", nodeConfiguration.getCachingProviderJNDIName(), "Config" });
columnFormatter.addRow(new Object[] { "Lite Member", nodeConfiguration.getLite(), "Config" });
columnFormatter.addRow(new Object[] { "Member Name", nodeConfiguration.getMemberName(), "Config" });
columnFormatter.addRow(new Object[] { "Member Group", nodeConfiguration.getMemberGroup(), "Config" });
columnFormatter.addRow(new Object[] { "Executor Pool Size", nodeConfiguration.getExecutorPoolSize(), "Config" });
columnFormatter.addRow(new Object[] { "Executor Queue Capacity", nodeConfiguration.getExecutorQueueCapacity(), "Config" });
columnFormatter.addRow(new Object[] { "Scheduled Executor Pool Size", nodeConfiguration.getScheduledExecutorPoolSize(), "Config" });
columnFormatter.addRow(new Object[] { "Scheduled Executor Queue Capacity", nodeConfiguration.getScheduledExecutorQueueCapacity(), "Config" });
columnFormatter.addRow(new Object[] { "Public Address", nodeConfiguration.getPublicAddress(), "Config" });
columnFormatter.addRow(new Object[] { "Config Specific Data Grid Start Port", nodeConfiguration.getConfigSpecificDataGridStartPort(), "Config" });
Map<String, Object> map = new HashMap<>(26);
Properties extraProps = new Properties();
map.put("hazelcastConfigurationFile", runtimeConfiguration.getHazelcastConfigurationFile());
map.put("enabled", nodeConfiguration.getEnabled());
map.put("autoIncrementPort", runtimeConfiguration.getAutoIncrementPort());
map.put("startPort", runtimeConfiguration.getStartPort());
map.put("multicastGroup", runtimeConfiguration.getMulticastGroup());
map.put("multicastPort", runtimeConfiguration.getMulticastPort());
map.put("jndiName", nodeConfiguration.getJNDIName());
map.put("lite", nodeConfiguration.getLite());
map.put("clusterName", runtimeConfiguration.getClusterGroupName());
map.put("licenseKey", runtimeConfiguration.getLicenseKey());
map.put("hostAwarePartitioning", runtimeConfiguration.getHostAwarePartitioning());
map.put("dasPublicAddress", runtimeConfiguration.getDASPublicAddress());
map.put("dasBindAddress", runtimeConfiguration.getDASBindAddress());
map.put("dasPort", runtimeConfiguration.getDasPort());
map.put("tcpipMembers", runtimeConfiguration.getTcpipMembers());
map.put("dnsMembers", runtimeConfiguration.getDnsMembers());
map.put("clusterMode", runtimeConfiguration.getDiscoveryMode());
map.put("memberName", nodeConfiguration.getMemberName());
map.put("memberGroup", nodeConfiguration.getMemberGroup());
map.put("interfaces", runtimeConfiguration.getInterface());
map.put("cacheManagerJndiName", nodeConfiguration.getCacheManagerJNDIName());
map.put("cachingProviderJndiName", nodeConfiguration.getCachingProviderJNDIName());
map.put("executorPoolSize", nodeConfiguration.getExecutorPoolSize());
map.put("executorQueueCapacity", nodeConfiguration.getExecutorQueueCapacity());
map.put("scheduledExecutorPoolSize", nodeConfiguration.getScheduledExecutorPoolSize());
map.put("scheduledExecutorQueueCapacity", nodeConfiguration.getScheduledExecutorQueueCapacity());
map.put("publicAddress", nodeConfiguration.getPublicAddress());
map.put("kubernetesNamespace", runtimeConfiguration.getKubernetesNamespace());
map.put("kubernetesServiceName", runtimeConfiguration.getKubernetesServiceName());
map.put("configSpecificDataGridStartPort", nodeConfiguration.getConfigSpecificDataGridStartPort());
map.put("encryptDatagrid", runtimeConfiguration.getDatagridEncryptionEnabled());
extraProps.put("getHazelcastConfiguration", map);
actionReport.setExtraProperties(extraProps);
actionReport.setMessage(columnFormatter.toString());
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.
the class BaseGetConfigSourceConfigurationCommand method listConfiguration.
/**
* @param configuration the configuration to print
* @return A column formatted string representing the configuration
* @see #getConfigSourceConfiguration(PayaraConfigSourceConfiguration)
*/
protected String listConfiguration(C configuration) {
Map<String, Object> configMap = getConfigSourceConfiguration(configuration);
Iterator<Entry<String, Object>> configIterator = configMap.entrySet().iterator();
List<String> headers = new ArrayList<>(2);
List<Object> values = new ArrayList<>(2);
while (configIterator.hasNext()) {
Entry<String, Object> entry = configIterator.next();
headers.add(entry.getKey());
values.add(entry.getValue());
}
ColumnFormatter columnFormatter = new ColumnFormatter(headers.toArray(new String[0]));
columnFormatter.addRow(values.toArray());
return columnFormatter.toString();
}
use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.
the class GetPayaraExecutorServiceConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext acc) {
Config configNode = targetUtil.getConfig(target);
PayaraExecutorServiceConfiguration payaraExecutorServiceConfiguration = configNode.getExtensionByType(PayaraExecutorServiceConfiguration.class);
ColumnFormatter columnFormatter = new ColumnFormatter(HEADERS);
Object[] values = { payaraExecutorServiceConfiguration.getThreadPoolExecutorCorePoolSize(), payaraExecutorServiceConfiguration.getThreadPoolExecutorMaxPoolSize(), payaraExecutorServiceConfiguration.getThreadPoolExecutorKeepAliveTime(), payaraExecutorServiceConfiguration.getThreadPoolExecutorKeepAliveTimeUnit(), payaraExecutorServiceConfiguration.getThreadPoolExecutorQueueSize(), payaraExecutorServiceConfiguration.getScheduledThreadPoolExecutorCorePoolSize() };
columnFormatter.addRow(values);
Map<String, Object> map = new HashMap<>();
Properties extraProps = new Properties();
map.put("threadPoolExecutorCorePoolSize", values[0]);
map.put("threadPoolExecutorMaxPoolSize", values[1]);
map.put("threadPoolExecutorKeepAliveTime", values[2]);
map.put("threadPoolExecutorKeepAliveTimeUnit", values[3]);
map.put("threadPoolExecutorQueueSize", values[4]);
map.put("scheduledThreadPoolExecutorCorePoolSize", values[5]);
extraProps.put("payaraExecutorServiceConfiguration", map);
acc.getActionReport().setExtraProperties(extraProps);
acc.getActionReport().setMessage(columnFormatter.toString());
}
Aggregations