Search in sources :

Example 1 with RequestTracingServiceConfiguration

use of fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration in project Payara by payara.

the class BaseRequestTracingNotifierConfigurer method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    Config config = targetUtil.getConfig(target);
    final RequestTracingServiceConfiguration configuration = config.getExtensionByType(RequestTracingServiceConfiguration.class);
    ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
    notifierClass = (Class<C>) genericSuperclass.getActualTypeArguments()[0];
    C c = configuration.getNotifierByType(notifierClass);
    try {
        if (c == null) {
            ConfigSupport.apply(new SingleConfigCode<RequestTracingServiceConfiguration>() {

                @Override
                public Object run(final RequestTracingServiceConfiguration configurationProxy) throws PropertyVetoException, TransactionFailure {
                    C c = configurationProxy.createChild(notifierClass);
                    applyValues(c);
                    configurationProxy.getNotifierList().add(c);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return configurationProxy;
                }
            }, configuration);
        } else {
            ConfigSupport.apply(new SingleConfigCode<C>() {

                public Object run(C cProxy) throws PropertyVetoException, TransactionFailure {
                    applyValues(cProxy);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return cProxy;
                }
            }, c);
        }
        if (dynamic) {
            if (server.isDas()) {
                if (targetUtil.getConfig(target).isDas()) {
                    configureDynamically();
                }
            } else {
                configureDynamically();
            }
        }
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Exception during command ", ex);
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) RequestTracingServiceConfiguration(fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration)

Example 2 with RequestTracingServiceConfiguration

use of fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration 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 3 with RequestTracingServiceConfiguration

use of fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration in project Payara by payara.

the class SetRequestTracingConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    Config config = targetUtil.getConfig(target);
    final RequestTracingServiceConfiguration requestTracingServiceConfiguration = config.getExtensionByType(RequestTracingServiceConfiguration.class);
    if (requestTracingServiceConfiguration != null) {
        final Set<String> notifierNames = NotifierUtils.getNotifierNames(serviceLocator);
        try {
            ConfigSupport.apply(new SingleConfigCode<RequestTracingServiceConfiguration>() {

                @Override
                public Object run(final RequestTracingServiceConfiguration proxy) throws PropertyVetoException, TransactionFailure {
                    boolean warn = false;
                    if (enabled != null) {
                        proxy.enabled(enabled.toString());
                    }
                    if (sampleRate != null) {
                        proxy.setSampleRate(sampleRate);
                    }
                    if (adaptiveSamplingEnabled != null) {
                        proxy.setAdaptiveSamplingEnabled(adaptiveSamplingEnabled.toString());
                    }
                    if (adaptiveSamplingTargetCount != null) {
                        proxy.setAdaptiveSamplingTargetCount(adaptiveSamplingTargetCount);
                    }
                    if (adaptiveSamplingTimeValue != null) {
                        proxy.setAdaptiveSamplingTimeValue(adaptiveSamplingTimeValue.toString());
                    }
                    if (adaptiveSamplingTimeUnit != null) {
                        proxy.setAdaptiveSamplingTimeUnit(adaptiveSamplingTimeUnit);
                    }
                    if (applicationsOnlyEnabled != null) {
                        proxy.setApplicationsOnlyEnabled(applicationsOnlyEnabled.toString());
                    }
                    if (thresholdValue != null) {
                        proxy.setThresholdValue(thresholdValue);
                    }
                    if (thresholdUnit != null) {
                        proxy.setThresholdUnit(thresholdUnit);
                    }
                    if (sampleRateFirstEnabled != null) {
                        proxy.setSampleRateFirstEnabled(sampleRateFirstEnabled.toString());
                    }
                    if (traceStoreSize != null) {
                        warn = !traceStoreSize.toString().equals(proxy.getTraceStoreSize());
                        proxy.setTraceStoreSize(traceStoreSize.toString());
                    }
                    if (traceStoreTimeout != null) {
                        warn = !traceStoreTimeout.equals(proxy.getTraceStoreTimeout());
                        proxy.setTraceStoreTimeout(traceStoreTimeout);
                    }
                    if (reservoirSamplingEnabled != null) {
                        proxy.setReservoirSamplingEnabled(reservoirSamplingEnabled.toString());
                    }
                    if (historicTraceStoreEnabled != null) {
                        proxy.setHistoricTraceStoreEnabled(historicTraceStoreEnabled.toString());
                    }
                    if (historicTraceStoreSize != null) {
                        warn = !historicTraceStoreSize.toString().equals(proxy.getHistoricTraceStoreSize());
                        proxy.setHistoricTraceStoreSize(historicTraceStoreSize.toString());
                    }
                    if (historicTraceStoreTimeout != null) {
                        warn = !historicTraceStoreTimeout.equals(proxy.getHistoricTraceStoreTimeout());
                        proxy.setHistoricTraceStoreTimeout(historicTraceStoreTimeout);
                    }
                    List<String> notifiers = proxy.getNotifierList();
                    if (enableNotifiers != null) {
                        for (String notifier : enableNotifiers) {
                            if (notifierNames.contains(notifier)) {
                                if (!notifiers.contains(notifier)) {
                                    notifiers.add(notifier);
                                }
                            } else {
                                throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
                            }
                        }
                    }
                    if (disableNotifiers != null) {
                        for (String notifier : disableNotifiers) {
                            if (notifierNames.contains(notifier)) {
                                notifiers.remove(notifier);
                            } else {
                                throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
                            }
                        }
                    }
                    if (setNotifiers != null) {
                        notifiers.clear();
                        for (String notifier : setNotifiers) {
                            if (notifierNames.contains(notifier)) {
                                if (!notifiers.contains(notifier)) {
                                    notifiers.add(notifier);
                                }
                            } else {
                                throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
                            }
                        }
                    }
                    actionReport.setActionExitCode(ExitCode.SUCCESS);
                    if (warn) {
                        actionReport.setMessage(STRINGS.get("requesttracing.configure.store.size.warning"));
                    }
                    return proxy;
                }
            }, requestTracingServiceConfiguration);
        } catch (TransactionFailure ex) {
            actionReport.failure(logger, ex.getCause().getMessage());
            return;
        }
    }
    if (dynamic) {
        if (server.isDas()) {
            if (targetUtil.getConfig(target).isDas()) {
                configureDynamically(actionReport);
            }
        } else {
            configureDynamically(actionReport);
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyChangeEvent(java.beans.PropertyChangeEvent) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) PropertyVetoException(java.beans.PropertyVetoException) List(java.util.List) RequestTracingServiceConfiguration(fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)3 RequestTracingServiceConfiguration (fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration)3 Properties (java.util.Properties)3 ActionReport (org.glassfish.api.ActionReport)3 PropertyVetoException (java.beans.PropertyVetoException)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 PayaraNotifier (fish.payara.internal.notification.PayaraNotifier)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)1