Search in sources :

Example 11 with ColumnFormatter

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");
    }
}
Also used : InstanceDescriptor(fish.payara.micro.data.InstanceDescriptor) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 12 with ColumnFormatter

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);
}
Also used : PayaraNotifier(fish.payara.internal.notification.PayaraNotifier) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) PayaraConfiguredNotifier(fish.payara.internal.notification.PayaraConfiguredNotifier) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) LogNotifierConfiguration(fish.payara.nucleus.notification.log.LogNotifierConfiguration) NotificationServiceConfiguration(fish.payara.internal.notification.admin.NotificationServiceConfiguration) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) PayaraNotifierConfiguration(fish.payara.internal.notification.PayaraNotifierConfiguration) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 13 with ColumnFormatter

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);
}
Also used : HazelcastRuntimeConfiguration(fish.payara.nucleus.hazelcast.HazelcastRuntimeConfiguration) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) HazelcastConfigSpecificConfiguration(fish.payara.nucleus.hazelcast.HazelcastConfigSpecificConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 14 with ColumnFormatter

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();
}
Also used : Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 15 with ColumnFormatter

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());
}
Also used : PayaraExecutorServiceConfiguration(fish.payara.nucleus.executorservice.PayaraExecutorServiceConfiguration) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Aggregations

ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)53 Properties (java.util.Properties)24 HashMap (java.util.HashMap)22 ActionReport (org.glassfish.api.ActionReport)22 Config (com.sun.enterprise.config.serverbeans.Config)21 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)8 ArrayList (java.util.ArrayList)7 PayaraNotifier (fish.payara.internal.notification.PayaraNotifier)5 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)3 AMXConfiguration (fish.payara.admin.amx.config.AMXConfiguration)2 MonitoredAttribute (fish.payara.jmx.monitoring.configuration.MonitoredAttribute)2 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)2 BaseHealthCheck (fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck)2 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)2 LogNotifierConfiguration (fish.payara.nucleus.notification.log.LogNotifierConfiguration)2 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)2 File (java.io.File)2 TaggedJobExecution (com.ibm.jbatch.spi.TaggedJobExecution)1 DomainConfig (com.sun.enterprise.admin.servermgmt.DomainConfig)1 DomainException (com.sun.enterprise.admin.servermgmt.DomainException)1