Search in sources :

Example 1 with PayaraNotifier

use of fish.payara.internal.notification.PayaraNotifier in project Payara by payara.

the class NotificationService method initialize.

@PostConstruct
void initialize() {
    // Get the config if it's not been injected
    if (configuration == null) {
        configuration = serviceLocator.getService(NotificationServiceConfiguration.class);
    }
    // Register an event listener
    if (events != null) {
        events.register(this);
    }
    // Is this service running on an instance?
    final ServerEnvironment env = serviceLocator.getService(ServerEnvironment.class);
    isInstance = env.isInstance();
    // Find and register all notifier services
    final List<ServiceHandle<PayaraNotifier>> notifierHandles = serviceLocator.getAllServiceHandles(PayaraNotifier.class);
    for (ServiceHandle<PayaraNotifier> handle : notifierHandles) {
        NotifierHandler handler;
        final boolean isNotifierConfigurable = handle.getActiveDescriptor().getAdvertisedContracts().contains(PayaraConfiguredNotifier.class.getName());
        if (isNotifierConfigurable) {
            PayaraNotifierConfiguration notifierConfig = getOrCreateNotifierConfiguration(handle);
            handler = new NotifierHandler(handle, notifierConfig);
        } else {
            handler = new NotifierHandler(handle);
        }
        notifiers.add(handler);
    }
}
Also used : PayaraNotifier(fish.payara.internal.notification.PayaraNotifier) NotificationServiceConfiguration(fish.payara.internal.notification.admin.NotificationServiceConfiguration) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) PayaraConfiguredNotifier(fish.payara.internal.notification.PayaraConfiguredNotifier) PayaraNotifierConfiguration(fish.payara.internal.notification.PayaraNotifierConfiguration) PostConstruct(javax.annotation.PostConstruct)

Example 2 with PayaraNotifier

use of fish.payara.internal.notification.PayaraNotifier 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 3 with PayaraNotifier

use of fish.payara.internal.notification.PayaraNotifier in project Payara by payara.

the class GetHealthCheckConfiguration 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();
    // subReport(0)
    ActionReport baseActionReport = mainActionReport.addSubActionsReport();
    // subReport(1)
    ActionReport hoggingThreadsActionReport = mainActionReport.addSubActionsReport();
    // subReport(2)
    ActionReport thresholdDiagnosticsActionReport = mainActionReport.addSubActionsReport();
    // subReport(3)
    ActionReport stuckThreadsActionReport = mainActionReport.addSubActionsReport();
    // subReport(4)
    ActionReport mpHealthcheckCheckerActionReport = mainActionReport.addSubActionsReport();
    // subReport(5)
    ActionReport microProfileMetricsActionReport = mainActionReport.addSubActionsReport();
    // subReport(6)
    ActionReport monitoredMicroProfileMetricsActionReport = mainActionReport.addSubActionsReport();
    ColumnFormatter baseColumnFormatter = new ColumnFormatter(baseHeaders);
    ColumnFormatter hoggingThreadsColumnFormatter = new ColumnFormatter(hoggingThreadsHeaders);
    ColumnFormatter stuckThreadsColumnFormatter = new ColumnFormatter(stuckThreadsHeaders);
    ColumnFormatter thresholdDiagnosticsColumnFormatter = new ColumnFormatter(thresholdDiagnosticsHeaders);
    ColumnFormatter mpHealthCheckColumnFormatter = new ColumnFormatter(MPHealthCheckHeaders);
    ColumnFormatter microProfileMetricsColumnFormatter = new ColumnFormatter(microProfileMetricsCheckHeaders);
    ColumnFormatter monitoredMicroProfileMetricsColumnFormatter = new ColumnFormatter(monitoredMicroProfileMetricHeaders);
    ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(notifierHeaders);
    HealthCheckServiceConfiguration configuration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
    List<ServiceHandle<BaseHealthCheck>> allServiceHandles = habitat.getAllServiceHandles(BaseHealthCheck.class);
    List<ServiceHandle<PayaraNotifier>> allNotifierServiceHandles = habitat.getAllServiceHandles(PayaraNotifier.class);
    mainActionReport.appendMessage("Health Check Service Configuration is enabled?: " + configuration.getEnabled() + "\n");
    if (Boolean.parseBoolean(configuration.getEnabled())) {
        mainActionReport.appendMessage("Historical Tracing Enabled?: " + configuration.getHistoricalTraceEnabled() + "\n");
        if (Boolean.parseBoolean(configuration.getHistoricalTraceEnabled())) {
            mainActionReport.appendMessage("Historical Tracing Store Size: " + configuration.getHistoricalTraceStoreSize() + "\n");
        }
        if (StringUtils.ok(configuration.getHistoricalTraceStoreTimeout())) {
            mainActionReport.appendMessage("Health Check Historical Tracing Store Timeout in Seconds: " + configuration.getHistoricalTraceStoreTimeout() + "\n");
        }
    }
    // Create the extraProps map for the general healthcheck configuration
    Properties mainExtraProps = new Properties();
    Map<String, Object> mainExtraPropsMap = new HashMap<>();
    mainExtraPropsMap.put("enabled", configuration.getEnabled());
    mainExtraPropsMap.put("historicalTraceEnabled", configuration.getHistoricalTraceEnabled());
    mainExtraPropsMap.put("historicalTraceStoreSize", configuration.getHistoricalTraceStoreSize());
    mainExtraPropsMap.put("historicalTraceStoreTimeout", configuration.getHistoricalTraceStoreTimeout());
    mainExtraProps.put("healthcheckConfiguration", mainExtraPropsMap);
    mainActionReport.setExtraProperties(mainExtraProps);
    final List<String> notifiers = configuration.getNotifierList();
    if (!notifiers.isEmpty()) {
        Properties extraProps = new Properties();
        for (ServiceHandle<PayaraNotifier> serviceHandle : allNotifierServiceHandles) {
            final String notifierClassName = serviceHandle.getActiveDescriptor().getImplementationClass().getSimpleName();
            final String notifierName = NotifierUtils.getNotifierName(serviceHandle.getActiveDescriptor());
            Object[] values = new Object[2];
            values[0] = notifierName;
            values[1] = notifiers.contains(notifierName);
            notifiersColumnFormatter.addRow(values);
            Map<String, Object> map = new HashMap<>(2);
            map.put("notifierName", values[0]);
            map.put("notifierEnabled", values[1]);
            extraProps.put("notifierList" + notifierClassName, map);
        }
        mainActionReport.getExtraProperties().putAll(extraProps);
        mainActionReport.appendMessage(notifiersColumnFormatter.toString());
        mainActionReport.appendMessage(StringUtils.EOL);
    }
    mainActionReport.appendMessage("Below are the list of configuration details of each checker listed by its name.");
    mainActionReport.appendMessage(StringUtils.EOL);
    Properties baseExtraProps = new Properties();
    Properties hoggingThreadsExtraProps = new Properties();
    Properties stuckThreadsExtrasProps = new Properties();
    Properties thresholdDiagnosticsExtraProps = new Properties();
    Properties mpHealthcheckExtrasProps = new Properties();
    Properties microProfileMetricsExtrasProps = new Properties();
    Properties monitoredMicroProfileMetricsExtrasProps = new Properties();
    for (ServiceHandle<BaseHealthCheck> serviceHandle : allServiceHandles) {
        Checker checker = configuration.getCheckerByType(serviceHandle.getService().getCheckerType());
        if (checker instanceof HoggingThreadsChecker) {
            HoggingThreadsChecker hoggingThreadsChecker = (HoggingThreadsChecker) checker;
            Object[] values = new Object[7];
            values[0] = hoggingThreadsChecker.getName();
            values[1] = hoggingThreadsChecker.getEnabled();
            values[2] = hoggingThreadsChecker.getTime();
            values[3] = hoggingThreadsChecker.getUnit();
            values[4] = hoggingThreadsChecker.getAddToMicroProfileHealth();
            values[5] = hoggingThreadsChecker.getThresholdPercentage();
            values[6] = hoggingThreadsChecker.getRetryCount();
            hoggingThreadsColumnFormatter.addRow(values);
            // Create the extra props map for a hogging thread checker
            addHoggingThreadsCheckerExtraProps(hoggingThreadsExtraProps, hoggingThreadsChecker);
        } else if (checker instanceof ThresholdDiagnosticsChecker) {
            ThresholdDiagnosticsChecker thresholdDiagnosticsChecker = (ThresholdDiagnosticsChecker) checker;
            Object[] values = new Object[8];
            values[0] = thresholdDiagnosticsChecker.getName();
            values[1] = thresholdDiagnosticsChecker.getEnabled();
            values[2] = thresholdDiagnosticsChecker.getTime();
            values[3] = thresholdDiagnosticsChecker.getUnit();
            values[4] = thresholdDiagnosticsChecker.getAddToMicroProfileHealth();
            Property thresholdCriticalProperty = thresholdDiagnosticsChecker.getProperty(THRESHOLD_CRITICAL);
            values[5] = thresholdCriticalProperty != null ? thresholdCriticalProperty.getValue() : "-";
            Property thresholdWarningProperty = thresholdDiagnosticsChecker.getProperty(THRESHOLD_WARNING);
            values[6] = thresholdWarningProperty != null ? thresholdWarningProperty.getValue() : "-";
            Property thresholdGoodProperty = thresholdDiagnosticsChecker.getProperty(THRESHOLD_GOOD);
            values[7] = thresholdGoodProperty != null ? thresholdGoodProperty.getValue() : "-";
            thresholdDiagnosticsColumnFormatter.addRow(values);
            // Create the extra props map for a checker with thresholds
            addThresholdDiagnosticsCheckerExtraProps(thresholdDiagnosticsExtraProps, thresholdDiagnosticsChecker);
        } else if (checker instanceof StuckThreadsChecker) {
            StuckThreadsChecker stuckThreadsChecker = (StuckThreadsChecker) checker;
            Object[] values = new Object[7];
            values[0] = stuckThreadsChecker.getName();
            values[1] = stuckThreadsChecker.getEnabled();
            values[2] = stuckThreadsChecker.getTime();
            values[3] = stuckThreadsChecker.getUnit();
            values[4] = stuckThreadsChecker.getAddToMicroProfileHealth();
            values[5] = stuckThreadsChecker.getThreshold();
            values[6] = stuckThreadsChecker.getThresholdTimeUnit();
            stuckThreadsColumnFormatter.addRow(values);
            addStuckThreadsCheckerExtrasProps(stuckThreadsExtrasProps, stuckThreadsChecker);
        } else if (checker instanceof MicroProfileHealthCheckerConfiguration) {
            MicroProfileHealthCheckerConfiguration mpHealthcheckChecker = (MicroProfileHealthCheckerConfiguration) checker;
            Object[] values = new Object[6];
            values[0] = mpHealthcheckChecker.getName();
            values[1] = mpHealthcheckChecker.getEnabled();
            values[2] = mpHealthcheckChecker.getTime();
            values[3] = mpHealthcheckChecker.getUnit();
            values[4] = mpHealthcheckChecker.getAddToMicroProfileHealth();
            values[5] = mpHealthcheckChecker.getTimeout();
            mpHealthCheckColumnFormatter.addRow(values);
            addMPHealthcheckCheckerExtrasProps(mpHealthcheckExtrasProps, mpHealthcheckChecker);
        } else if (checker instanceof MicroProfileMetricsChecker) {
            MicroProfileMetricsChecker microProfileMetricsChecker = (MicroProfileMetricsChecker) checker;
            Object[] values = new Object[5];
            values[0] = microProfileMetricsChecker.getName();
            values[1] = microProfileMetricsChecker.getEnabled();
            values[2] = microProfileMetricsChecker.getTime();
            values[3] = microProfileMetricsChecker.getUnit();
            values[4] = microProfileMetricsChecker.getAddToMicroProfileHealth();
            microProfileMetricsColumnFormatter.addRow(values);
            addMicroProfileMetricsCheckerExtrasProps(microProfileMetricsExtrasProps, microProfileMetricsChecker);
            Map<String, String> monitoredAttributes = new HashMap<>();
            List<MonitoredMetric> metrics = microProfileMetricsChecker.getMonitoredMetrics();
            if (!metrics.isEmpty()) {
                for (MonitoredMetric monitoredBean : metrics) {
                    Object[] metricValues = new Object[2];
                    metricValues[0] = monitoredBean.getMetricName();
                    metricValues[1] = monitoredBean.getDescription();
                    monitoredMicroProfileMetricsColumnFormatter.addRow(metricValues);
                    monitoredAttributes.put("MetricsName", monitoredBean.getMetricName());
                }
                monitoredMicroProfileMetricsExtrasProps.put("monitoredMetrics", monitoredAttributes);
            }
        } else if (checker != null) {
            Object[] values = new Object[5];
            values[0] = checker.getName();
            values[1] = checker.getEnabled();
            values[2] = checker.getTime();
            values[3] = checker.getUnit();
            values[4] = checker.getAddToMicroProfileHealth();
            baseColumnFormatter.addRow(values);
            // Create the extra props map for a base checker
            addBaseCheckerExtraProps(baseExtraProps, checker);
        }
    }
    if (!baseColumnFormatter.getContent().isEmpty()) {
        baseActionReport.setMessage(baseColumnFormatter.toString());
        baseActionReport.appendMessage(StringUtils.EOL);
    }
    if (!hoggingThreadsColumnFormatter.getContent().isEmpty()) {
        hoggingThreadsActionReport.setMessage(hoggingThreadsColumnFormatter.toString());
        hoggingThreadsActionReport.appendMessage(StringUtils.EOL);
    }
    if (!thresholdDiagnosticsColumnFormatter.getContent().isEmpty()) {
        thresholdDiagnosticsActionReport.setMessage(thresholdDiagnosticsColumnFormatter.toString());
        thresholdDiagnosticsActionReport.appendMessage(StringUtils.EOL);
    }
    if (!stuckThreadsColumnFormatter.getContent().isEmpty()) {
        stuckThreadsActionReport.setMessage(stuckThreadsColumnFormatter.toString());
        stuckThreadsActionReport.appendMessage(StringUtils.EOL);
    }
    if (!mpHealthCheckColumnFormatter.getContent().isEmpty()) {
        mpHealthcheckCheckerActionReport.setMessage(mpHealthCheckColumnFormatter.toString());
        mpHealthcheckCheckerActionReport.appendMessage(StringUtils.EOL);
    }
    if (!microProfileMetricsColumnFormatter.getContent().isEmpty()) {
        microProfileMetricsActionReport.setMessage(microProfileMetricsColumnFormatter.toString());
        microProfileMetricsActionReport.appendMessage(StringUtils.EOL);
    }
    if (!monitoredMicroProfileMetricsColumnFormatter.getContent().isEmpty()) {
        monitoredMicroProfileMetricsActionReport.setMessage(monitoredMicroProfileMetricsColumnFormatter.toString());
        monitoredMicroProfileMetricsActionReport.appendMessage(StringUtils.EOL);
    }
    // Populate the extraProps with defaults for any checker that isn't present
    baseExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, garbageCollectorPropertyName);
    hoggingThreadsExtraProps = checkCheckerPropertyPresence(hoggingThreadsExtraProps, hoggingThreadsPropertyName);
    stuckThreadsExtrasProps = checkCheckerPropertyPresence(stuckThreadsExtrasProps, stuckThreadsPropertyName);
    thresholdDiagnosticsExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, cpuUsagePropertyName);
    thresholdDiagnosticsExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, connectionPoolPropertyName);
    thresholdDiagnosticsExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, heapMemoryUsagePropertyName);
    thresholdDiagnosticsExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, machineMemoryUsagePropertyName);
    mpHealthcheckExtrasProps = checkCheckerPropertyPresence(mpHealthcheckExtrasProps, mpHealthcheckPropertyName);
    microProfileMetricsExtrasProps = checkCheckerPropertyPresence(microProfileMetricsExtrasProps, microProfileMetricsPropertyName);
    // Add the extra props to their respective action reports
    baseActionReport.setExtraProperties(baseExtraProps);
    hoggingThreadsActionReport.setExtraProperties(hoggingThreadsExtraProps);
    thresholdDiagnosticsActionReport.setExtraProperties(thresholdDiagnosticsExtraProps);
    stuckThreadsActionReport.setExtraProperties(stuckThreadsExtrasProps);
    mpHealthcheckCheckerActionReport.setExtraProperties(mpHealthcheckExtrasProps);
    microProfileMetricsActionReport.setExtraProperties(microProfileMetricsExtrasProps);
    monitoredMicroProfileMetricsActionReport.setExtraProperties(monitoredMicroProfileMetricsExtrasProps);
    mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PayaraNotifier(fish.payara.internal.notification.PayaraNotifier) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) MicroProfileMetricsChecker(fish.payara.nucleus.healthcheck.configuration.MicroProfileMetricsChecker) HealthCheckServiceConfiguration(fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) Property(org.jvnet.hk2.config.types.Property) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) MicroProfileHealthCheckerConfiguration(fish.payara.nucleus.healthcheck.configuration.MicroProfileHealthCheckerConfiguration) MonitoredMetric(fish.payara.nucleus.healthcheck.configuration.MonitoredMetric) HoggingThreadsChecker(fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker) StuckThreadsChecker(fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker) MicroProfileMetricsChecker(fish.payara.nucleus.healthcheck.configuration.MicroProfileMetricsChecker) Checker(fish.payara.nucleus.healthcheck.configuration.Checker) ThresholdDiagnosticsChecker(fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker) BaseHealthCheck(fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck) ThresholdDiagnosticsChecker(fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker) HoggingThreadsChecker(fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker) StuckThreadsChecker(fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker) ServiceHandle(org.glassfish.hk2.api.ServiceHandle)

Example 4 with PayaraNotifier

use of fish.payara.internal.notification.PayaraNotifier in project Payara by payara.

the class GetRequestTracingConfiguration 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();
    RequestTracingServiceConfiguration configuration = config.getExtensionByType(RequestTracingServiceConfiguration.class);
    writeVariableToActionReport(mainActionReport, "Enabled?", configuration.getEnabled());
    if (Boolean.parseBoolean(configuration.getEnabled())) {
        writeVariableToActionReport(mainActionReport, "Sample Rate", configuration.getSampleRate());
        // Print adaptive sampling details
        writeVariableToActionReport(mainActionReport, "Adaptive Sampling Enabled?", configuration.getAdaptiveSamplingEnabled());
        if (Boolean.parseBoolean(configuration.getAdaptiveSamplingEnabled())) {
            writeVariableToActionReport(mainActionReport, "Adaptive Sampling Target Count", configuration.getAdaptiveSamplingTargetCount());
            writeVariableToActionReport(mainActionReport, "Adaptive Sampling Time Value", configuration.getAdaptiveSamplingTimeValue());
            writeVariableToActionReport(mainActionReport, "Adaptive Sampling Time Unit", configuration.getAdaptiveSamplingTimeUnit());
        }
        // Print filter details
        writeVariableToActionReport(mainActionReport, "Application Only?", configuration.getApplicationsOnlyEnabled());
        writeVariableToActionReport(mainActionReport, "Threshold Value", configuration.getThresholdValue());
        writeVariableToActionReport(mainActionReport, "Threshold Unit", configuration.getThresholdUnit());
        writeVariableToActionReport(mainActionReport, "Sample Rate First?", configuration.getSampleRateFirstEnabled());
        // Print trace store details
        writeVariableToActionReport(mainActionReport, "Reservoir Sampling Enabled?", configuration.getReservoirSamplingEnabled());
        writeVariableToActionReport(mainActionReport, "Trace Store Size", configuration.getTraceStoreSize());
        if (StringUtils.ok(configuration.getTraceStoreTimeout())) {
            writeVariableToActionReport(mainActionReport, "Trace Store Timeout (secs)", configuration.getTraceStoreTimeout());
        }
        // Print historic trace store details
        writeVariableToActionReport(mainActionReport, "Historic Trace Store Enabled?", configuration.getHistoricTraceStoreEnabled());
        if (Boolean.parseBoolean(configuration.getHistoricTraceStoreEnabled())) {
            writeVariableToActionReport(mainActionReport, "Historic Trace Store Size", configuration.getHistoricTraceStoreSize());
            if (StringUtils.ok(configuration.getHistoricTraceStoreTimeout())) {
                writeVariableToActionReport(mainActionReport, "Historic Trace Store Timeout (secs)", configuration.getHistoricTraceStoreTimeout());
            }
        }
    }
    // Create the extraProps for the general request tracing configuration
    Properties mainExtraProps = new Properties();
    Map<String, Object> mainExtraPropsMap = new HashMap<>();
    mainExtraPropsMap.put("enabled", configuration.getEnabled());
    mainExtraPropsMap.put("sampleRate", configuration.getSampleRate());
    mainExtraPropsMap.put("adaptiveSamplingEnabled", configuration.getAdaptiveSamplingEnabled());
    mainExtraPropsMap.put("adaptiveSamplingTargetCount", configuration.getAdaptiveSamplingTargetCount());
    mainExtraPropsMap.put("adaptiveSamplingTimeValue", configuration.getAdaptiveSamplingTimeValue());
    mainExtraPropsMap.put("adaptiveSamplingTimeUnit", configuration.getAdaptiveSamplingTimeUnit());
    mainExtraPropsMap.put("applicationsOnlyEnabled", configuration.getApplicationsOnlyEnabled());
    mainExtraPropsMap.put("thresholdValue", configuration.getThresholdValue());
    mainExtraPropsMap.put("thresholdUnit", configuration.getThresholdUnit());
    mainExtraPropsMap.put("sampleRateFirstEnabled", configuration.getSampleRateFirstEnabled());
    mainExtraPropsMap.put("traceStoreSize", configuration.getTraceStoreSize());
    mainExtraPropsMap.put("traceStoreTimeout", configuration.getTraceStoreTimeout());
    mainExtraPropsMap.put("reservoirSamplingEnabled", configuration.getReservoirSamplingEnabled());
    mainExtraPropsMap.put("historicTraceStoreEnabled", configuration.getHistoricTraceStoreEnabled());
    mainExtraPropsMap.put("historicTraceStoreSize", configuration.getHistoricTraceStoreSize());
    mainExtraPropsMap.put("historicTraceStoreTimeout", configuration.getHistoricTraceStoreTimeout());
    mainExtraProps.put("requestTracingConfiguration", mainExtraPropsMap);
    mainActionReport.setExtraProperties(mainExtraProps);
    mainActionReport.appendMessage("Below are the configuration details of each notifier listed by its name.");
    mainActionReport.appendMessage(StringUtils.EOL);
    ActionReport notifiersActionReport = mainActionReport.addSubActionsReport();
    List<ServiceHandle<PayaraNotifier>> allServiceHandles = habitat.getAllServiceHandles(PayaraNotifier.class);
    if (configuration.getNotifierList().isEmpty()) {
        notifiersActionReport.setMessage("No notifier defined");
    } else {
        String[] headers = { "Notifier Name", "Notifier Enabled" };
        ColumnFormatter columnFormatter = new ColumnFormatter(headers);
        List<String> notifiers = configuration.getNotifierList();
        Properties notifierExtraProps = new Properties();
        for (ServiceHandle<PayaraNotifier> serviceHandle : allServiceHandles) {
            final String notifierClassName = serviceHandle.getActiveDescriptor().getImplementationClass().getSimpleName();
            final String notifierName = NotifierUtils.getNotifierName(serviceHandle.getActiveDescriptor());
            Object[] values = new Object[2];
            values[0] = notifierName;
            values[1] = notifiers.contains(notifierName);
            columnFormatter.addRow(values);
            Map<String, Object> notifierExtraPropsMap = new HashMap<>();
            notifierExtraPropsMap.put("notifierName", values[0]);
            notifierExtraPropsMap.put("notifierEnabled", values[1]);
            notifierExtraProps.put("getRequesttracingConfiguration" + notifierClassName, notifierExtraPropsMap);
            notifiersActionReport.setExtraProperties(notifierExtraProps);
        }
        notifiersActionReport.setMessage(columnFormatter.toString());
    }
    mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PayaraNotifier(fish.payara.internal.notification.PayaraNotifier) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) RequestTracingServiceConfiguration(fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 5 with PayaraNotifier

use of fish.payara.internal.notification.PayaraNotifier in project Payara by payara.

the class GetAdminAuditServiceConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    ColumnFormatter columnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS);
    ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS);
    targetConfig = targetUtil.getConfig(target);
    AdminAuditConfiguration config = targetConfig.getExtensionByType(AdminAuditConfiguration.class);
    Object[] configValues = { config.getEnabled(), config.getAuditLevel() };
    columnFormatter.addRow(configValues);
    Map<String, Object> map = new HashMap<>();
    Properties extraProperties = new Properties();
    map.put("enabled", config.getEnabled());
    map.put("auditLevel", config.getAuditLevel());
    extraProperties.put("adminauditConfiguration", map);
    ActionReport notifiersReport = actionReport.addSubActionsReport();
    List<ServiceHandle<PayaraNotifier>> allNotifierServiceHandles = serviceLocator.getAllServiceHandles(PayaraNotifier.class);
    Properties notifierProps = new Properties();
    if (!config.getNotifierList().isEmpty()) {
        List<String> notifiers = config.getNotifierList();
        for (ServiceHandle<PayaraNotifier> serviceHandle : allNotifierServiceHandles) {
            final String notifierClassName = serviceHandle.getActiveDescriptor().getImplementationClass().getSimpleName();
            final String notifierName = NotifierUtils.getNotifierName(serviceHandle.getActiveDescriptor());
            Object[] values = new Object[2];
            values[0] = notifierName;
            values[1] = notifiers.contains(notifierName);
            notifiersColumnFormatter.addRow(values);
            Map<String, Object> mapNotifiers = new HashMap<>(2);
            mapNotifiers.put("notifierName", values[0]);
            mapNotifiers.put("notifierEnabled", values[1]);
            notifierProps.put("notifierList" + notifierClassName, mapNotifiers);
        }
    }
    notifiersReport.setMessage(notifiersColumnFormatter.toString());
    extraProperties.putAll(notifierProps);
    actionReport.setExtraProperties(extraProperties);
    actionReport.setMessage(columnFormatter.toString());
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PayaraNotifier(fish.payara.internal.notification.PayaraNotifier) HashMap(java.util.HashMap) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) AdminAuditConfiguration(fish.payara.audit.AdminAuditConfiguration) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Aggregations

PayaraNotifier (fish.payara.internal.notification.PayaraNotifier)6 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)6 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)5 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 ActionReport (org.glassfish.api.ActionReport)5 Config (com.sun.enterprise.config.serverbeans.Config)4 PayaraConfiguredNotifier (fish.payara.internal.notification.PayaraConfiguredNotifier)2 PayaraNotifierConfiguration (fish.payara.internal.notification.PayaraNotifierConfiguration)2 NotificationServiceConfiguration (fish.payara.internal.notification.admin.NotificationServiceConfiguration)2 AdminAuditConfiguration (fish.payara.audit.AdminAuditConfiguration)1 MonitoredAttribute (fish.payara.jmx.monitoring.configuration.MonitoredAttribute)1 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)1 Checker (fish.payara.nucleus.healthcheck.configuration.Checker)1 HealthCheckServiceConfiguration (fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration)1 HoggingThreadsChecker (fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker)1 MicroProfileHealthCheckerConfiguration (fish.payara.nucleus.healthcheck.configuration.MicroProfileHealthCheckerConfiguration)1 MicroProfileMetricsChecker (fish.payara.nucleus.healthcheck.configuration.MicroProfileMetricsChecker)1 MonitoredMetric (fish.payara.nucleus.healthcheck.configuration.MonitoredMetric)1 StuckThreadsChecker (fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker)1