Search in sources :

Example 71 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class GrizzlyService method postConstruct.

/**
 * The component has been injected with any dependency and
 * will be placed into commission by the subsystem.
 */
@Override
public void postConstruct() {
    events.register(this);
    final NetworkConfig networkConfig = config.getNetworkConfig();
    configListener = new DynamicConfigListener(config, LOGGER);
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(networkConfig.getNetworkListeners());
    bean.addListener(configListener);
    bean = (ObservableBean) ConfigSupport.getImpl(config.getHttpService());
    bean.addListener(configListener);
    transactions.addListenerForType(SystemProperty.class, configListener);
    configListener.setGrizzlyService(this);
    try {
        boolean isAtLeastOneProxyStarted = false;
        futures = new ArrayList<Future<Result<Thread>>>();
        // Record how long it took for the listeners to start up
        final long startTime = System.currentTimeMillis();
        // Keep a list of successfully started listeners
        List<NetworkListener> startedListeners = new ArrayList<>();
        for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
            if (createNetworkProxy(listener) != null) {
                isAtLeastOneProxyStarted = true;
                startedListeners.add(listener);
            }
        }
        if (isAtLeastOneProxyStarted) {
            // Get the startup time
            final long startupTime = System.currentTimeMillis() - startTime;
            // Log the listeners which started.
            String boundAddresses = Arrays.toString(startedListeners.stream().map(listener -> listener.getAddress() + ":" + listener.getPort()).collect(Collectors.toList()).toArray());
            LOGGER.log(Level.INFO, KernelLoggerInfo.grizzlyStarted, new Object[] { Grizzly.getDotedVersion(), startupTime, boundAddresses });
            registerContainerAdapters();
        }
    } catch (RuntimeException e) {
        // So far postConstruct can not throw any other exception type
        LOGGER.log(Level.SEVERE, KernelLoggerInfo.grizzlyCantStart, e);
        for (NetworkProxy proxy : proxies) {
            try {
                proxy.stop();
            } catch (Exception proxyStopException) {
                LOGGER.log(Level.SEVERE, KernelLoggerInfo.grizzlyCloseException, new Object[] { proxy.getPort(), proxyStopException });
            }
        }
        throw e;
    }
    registerMonitoringStatsProviders();
}
Also used : Arrays(java.util.Arrays) RestrictTo(org.glassfish.api.event.RestrictTo) KernelLoggerInfo(org.glassfish.kernel.KernelLoggerInfo) Events(org.glassfish.api.event.Events) TimeoutException(java.util.concurrent.TimeoutException) RequestDispatcher(org.glassfish.api.container.RequestDispatcher) InetAddress(java.net.InetAddress) Protocol(org.glassfish.grizzly.config.dom.Protocol) Future(java.util.concurrent.Future) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) Map(java.util.Map) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) Futures(org.glassfish.grizzly.utils.Futures) GenericGrizzlyListener(org.glassfish.grizzly.config.GenericGrizzlyListener) Method(java.lang.reflect.Method) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Logger(java.util.logging.Logger) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) List(java.util.List) HttpCodecFilter(org.glassfish.grizzly.http.HttpCodecFilter) StartupRunLevel(org.glassfish.api.StartupRunLevel) Service(org.jvnet.hk2.annotations.Service) Transactions(org.jvnet.hk2.config.Transactions) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Queue(java.util.Queue) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Result(com.sun.enterprise.util.Result) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) FutureImpl(org.glassfish.grizzly.impl.FutureImpl) ObservableBean(org.jvnet.hk2.config.ObservableBean) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Constants(org.glassfish.common.util.Constants) GrizzlyMonitoring(com.sun.enterprise.v3.services.impl.monitor.GrizzlyMonitoring) Rank(org.glassfish.hk2.api.Rank) EventTypes(org.glassfish.api.event.EventTypes) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) HttpProbe(org.glassfish.grizzly.http.HttpProbe) StringUtils(com.sun.enterprise.util.StringUtils) FutureProvider(org.glassfish.api.FutureProvider) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Named(javax.inject.Named) EventListener(org.glassfish.api.event.EventListener) PreDestroy(org.glassfish.hk2.api.PreDestroy) RunLevel(org.glassfish.hk2.runlevel.RunLevel) Mapper(org.glassfish.grizzly.http.server.util.Mapper) HttpHandler(org.glassfish.grizzly.http.server.HttpHandler) IOException(java.io.IOException) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) ApplicationContainer(org.glassfish.api.deployment.ApplicationContainer) UnknownHostException(java.net.UnknownHostException) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Grizzly(org.glassfish.grizzly.Grizzly) PostConstruct(org.glassfish.hk2.api.PostConstruct) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) InvocationHandler(java.lang.reflect.InvocationHandler) Config(com.sun.enterprise.config.serverbeans.Config) Collections(java.util.Collections) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) Future(java.util.concurrent.Future) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 72 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class DeleteSystemProperty 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();
    Property domainProp = domain.getProperty("administrative.domain.name");
    String domainName = domainProp.getValue();
    if (!spb.containsProperty(propName)) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        String msg = localStrings.getLocalString("no.such.property", "System Property named {0} does not exist at the given target {1}", propName, target);
        report.setMessage(msg);
        return;
    }
    if (definitions(propName) == 1) {
        // implying user is deleting the "last" definition of this property
        List<String> refs = new ArrayList<String>();
        List<Dom> doms = new ArrayList<Dom>();
        if ("domain".equals(target) || target.equals(domainName)) {
            for (Server s : domain.getServers().getServer()) {
                Config config = s.getConfig();
                Cluster cluster = s.getCluster();
                if (!s.containsProperty(propName) && !config.containsProperty(propName)) {
                    if (cluster != null) {
                        if (!cluster.containsProperty(propName)) {
                            doms.add(Dom.unwrap(s));
                        }
                    } else {
                        doms.add(Dom.unwrap(s));
                    }
                }
            }
        } else {
            Config config = domain.getConfigNamed(target);
            if (config != null) {
                doms.add(Dom.unwrap(config));
                String configName = config.getName();
                for (Server s : domain.getServers().getServer()) {
                    String configRef = s.getConfigRef();
                    if (configRef.equals(configName)) {
                        if (!s.containsProperty(propName)) {
                            doms.add(Dom.unwrap(s));
                        }
                    }
                }
                for (Cluster c : domain.getClusters().getCluster()) {
                    String configRef = c.getConfigRef();
                    if (configRef.equals(configName)) {
                        if (!c.containsProperty(propName)) {
                            doms.add(Dom.unwrap(c));
                        }
                    }
                }
            } else {
                Cluster cluster = domain.getClusterNamed(target);
                if (cluster != null) {
                    doms.add(Dom.unwrap(cluster));
                    Config clusterConfig = domain.getConfigNamed(cluster.getConfigRef());
                    doms.add(Dom.unwrap(clusterConfig));
                    for (Server s : cluster.getInstances()) {
                        if (!s.containsProperty(propName)) {
                            doms.add(Dom.unwrap(s));
                        }
                    }
                } else {
                    Server server = domain.getServerNamed(target);
                    doms.add(Dom.unwrap(server));
                    doms.add(Dom.unwrap(domain.getConfigNamed(server.getConfigRef())));
                }
            }
        }
        String sysPropName = SystemPropertyConstants.getPropertyAsValue(propName);
        for (Dom d : doms) {
            listRefs(d, sysPropName, refs);
        }
        if (!refs.isEmpty()) {
            // there are some references
            String msg = localStrings.getLocalString("cant.delete.referenced.property", "System Property {0} is referenced by {1} in the configuration. Please remove the references first.", propName, Arrays.toString(refs.toArray()));
            report.setMessage(msg);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // now we are sure that the target exits in the config, just remove the given property
    try {
        ConfigSupport.apply(new SingleConfigCode<SystemPropertyBag>() {

            public Object run(SystemPropertyBag param) throws PropertyVetoException, TransactionFailure {
                param.getSystemProperty().remove(param.getSystemProperty(propName));
                return param;
            }
        }, spb);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        String msg = localStrings.getLocalString("delete.sysprops.ok", "System Property named {0} deleted from given target {1}. Make sure you check its references.", propName, target);
        report.setMessage(msg);
    } catch (TransactionFailure tf) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tf);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Dom(org.jvnet.hk2.config.Dom) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) Property(org.jvnet.hk2.config.types.Property)

Example 73 with org.jvnet.hk2.config

use of org.jvnet.hk2.config 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();
    ColumnFormatter baseColumnFormatter = new ColumnFormatter(baseHeaders);
    ColumnFormatter hoggingThreadsColumnFormatter = new ColumnFormatter(hoggingThreadsHeaders);
    ColumnFormatter stuckThreadsColumnFormatter = new ColumnFormatter(stuckThreadsHeaders);
    ColumnFormatter thresholdDiagnosticsColumnFormatter = new ColumnFormatter(thresholdDiagnosticsHeaders);
    ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(notifierHeaders);
    HealthCheckServiceConfiguration configuration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
    List<ServiceHandle<BaseHealthCheck>> allServiceHandles = habitat.getAllServiceHandles(BaseHealthCheck.class);
    List<ServiceHandle<BaseNotifierService>> allNotifierServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.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 (!Strings.isNullOrEmpty(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);
    if (!configuration.getNotifierList().isEmpty()) {
        List<Class<Notifier>> notifierClassList = Lists.transform(configuration.getNotifierList(), new Function<Notifier, Class<Notifier>>() {

            @Override
            public Class<Notifier> apply(Notifier input) {
                return resolveNotifierClass(input);
            }
        });
        Properties extraProps = new Properties();
        for (ServiceHandle<BaseNotifierService> serviceHandle : allNotifierServiceHandles) {
            Notifier notifier = configuration.getNotifierByType(serviceHandle.getService().getNotifierType());
            if (notifier != null) {
                ConfigView view = ConfigSupport.getImpl(notifier);
                NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
                if (notifierClassList.contains(view.<Notifier>getProxyType())) {
                    Object[] values = new Object[2];
                    values[0] = annotation.type();
                    values[1] = notifier.getEnabled();
                    notifiersColumnFormatter.addRow(values);
                    Map<String, Object> map = new HashMap<>(2);
                    map.put("notifierName", values[0]);
                    map.put("notifierEnabled", values[1]);
                    extraProps.put("notifierList" + annotation.type(), 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();
    for (ServiceHandle<BaseHealthCheck> serviceHandle : allServiceHandles) {
        Checker checker = configuration.getCheckerByType(serviceHandle.getService().getCheckerType());
        if (checker instanceof HoggingThreadsChecker) {
            HoggingThreadsChecker hoggingThreadsChecker = (HoggingThreadsChecker) checker;
            Object[] values = new Object[6];
            values[0] = hoggingThreadsChecker.getName();
            values[1] = hoggingThreadsChecker.getEnabled();
            values[2] = hoggingThreadsChecker.getTime();
            values[3] = hoggingThreadsChecker.getUnit();
            values[4] = hoggingThreadsChecker.getThresholdPercentage();
            values[5] = 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[7];
            values[0] = thresholdDiagnosticsChecker.getName();
            values[1] = thresholdDiagnosticsChecker.getEnabled();
            values[2] = thresholdDiagnosticsChecker.getTime();
            values[3] = thresholdDiagnosticsChecker.getUnit();
            Property thresholdCriticalProperty = thresholdDiagnosticsChecker.getProperty(THRESHOLD_CRITICAL);
            values[4] = thresholdCriticalProperty != null ? thresholdCriticalProperty.getValue() : "-";
            Property thresholdWarningProperty = thresholdDiagnosticsChecker.getProperty(THRESHOLD_WARNING);
            values[5] = thresholdWarningProperty != null ? thresholdWarningProperty.getValue() : "-";
            Property thresholdGoodProperty = thresholdDiagnosticsChecker.getProperty(THRESHOLD_GOOD);
            values[6] = 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[6];
            values[0] = stuckThreadsChecker.getName();
            values[1] = stuckThreadsChecker.getEnabled();
            values[2] = stuckThreadsChecker.getTime();
            values[3] = stuckThreadsChecker.getUnit();
            values[4] = stuckThreadsChecker.getThreshold();
            values[5] = stuckThreadsChecker.getThresholdTimeUnit();
            stuckThreadsColumnFormatter.addRow(values);
            addStuckThreadsCheckerExtrasProps(stuckThreadsExtrasProps, stuckThreadsChecker);
        } else if (checker != null) {
            Object[] values = new Object[4];
            values[0] = checker.getName();
            values[1] = checker.getEnabled();
            values[2] = checker.getTime();
            values[3] = checker.getUnit();
            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);
    }
    // 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);
    // Add the extra props to their respective action reports
    baseActionReport.setExtraProperties(baseExtraProps);
    hoggingThreadsActionReport.setExtraProperties(hoggingThreadsExtraProps);
    thresholdDiagnosticsActionReport.setExtraProperties(thresholdDiagnosticsExtraProps);
    stuckThreadsActionReport.setExtraProperties(stuckThreadsExtrasProps);
    mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : HashMap(java.util.HashMap) ConfigView(org.jvnet.hk2.config.ConfigView) Config(com.sun.enterprise.config.serverbeans.Config) 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) Notifier(fish.payara.nucleus.notification.configuration.Notifier) HoggingThreadsChecker(fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker) StuckThreadsChecker(fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker) Checker(fish.payara.nucleus.healthcheck.configuration.Checker) ThresholdDiagnosticsChecker(fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker) NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) BaseHealthCheck(fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck) ThresholdDiagnosticsChecker(fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker) BaseNotifierService(fish.payara.nucleus.notification.service.BaseNotifierService) HoggingThreadsChecker(fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker) StuckThreadsChecker(fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker) ServiceHandle(org.glassfish.hk2.api.ServiceHandle)

Example 74 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class HealthCheckServiceThresholdConfigurer method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    final AdminCommandContext theContext = context;
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    final BaseThresholdHealthCheck service = habitat.getService(BaseThresholdHealthCheck.class, serviceName);
    Config config = targetUtil.getConfig(target);
    if (service == null) {
        actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.status.error", "Service with name {0} could not be found.", serviceName));
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    HealthCheckServiceConfiguration healthCheckServiceConfiguration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
    final ThresholdDiagnosticsChecker checker = healthCheckServiceConfiguration.<ThresholdDiagnosticsChecker>getCheckerByType(service.getCheckerType());
    if (checker == null) {
        actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.threshold.checker.not.exists", "Health Check Service Checker Configuration with name {0} could not be found.", serviceName));
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        evaluateThresholdProp(actionReport, checker, HealthCheckConstants.THRESHOLD_CRITICAL, thresholdCritical);
        evaluateThresholdProp(actionReport, checker, HealthCheckConstants.THRESHOLD_WARNING, thresholdWarning);
        evaluateThresholdProp(actionReport, checker, HealthCheckConstants.THRESHOLD_GOOD, thresholdGood);
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Exception during command ", ex);
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (dynamic) {
        if (service.getOptions() == null) {
            service.setOptions(service.constructOptions(checker));
        }
        if (server.isDas()) {
            if (targetUtil.getConfig(target).isDas()) {
                configureDynamically(actionReport, service);
                healthCheckService.reboot();
            }
        } else {
            // it implicitly targeted to us as we are not the DAS
            // restart the service
            configureDynamically(actionReport, service);
            healthCheckService.reboot();
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) HealthCheckServiceConfiguration(fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration) ThresholdDiagnosticsChecker(fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) BaseThresholdHealthCheck(fish.payara.nucleus.healthcheck.preliminary.BaseThresholdHealthCheck)

Example 75 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class HoggingThreadsConfigurer method execute.

@Override
public void execute(AdminCommandContext context) {
    Config config = targetUtil.getConfig(target);
    HoggingThreadsHealthCheck service = habitat.getService(HoggingThreadsHealthCheck.class);
    final ActionReport actionReport = context.getActionReport();
    if (service == null) {
        actionReport.appendMessage(strings.getLocalString("healthcheck.hoggingthreads.configure.status.error", "Hogging Threads Checker Service could not be found"));
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Warn about deprecated option
    if (name != null) {
        actionReport.appendMessage("\n--name parameter is decremented, please begin using the --checkerName option\n");
    }
    try {
        HealthCheckServiceConfiguration healthCheckServiceConfiguration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
        HoggingThreadsChecker hoggingThreadConfiguration = healthCheckServiceConfiguration.getCheckerByType(HoggingThreadsChecker.class);
        if (hoggingThreadConfiguration == null) {
            ConfigSupport.apply(new SingleConfigCode<HealthCheckServiceConfiguration>() {

                @Override
                public Object run(final HealthCheckServiceConfiguration healthCheckServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                    HoggingThreadsChecker checkerProxy = healthCheckServiceConfigurationProxy.createChild(HoggingThreadsChecker.class);
                    applyValues(checkerProxy);
                    healthCheckServiceConfigurationProxy.getCheckerList().add(checkerProxy);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return healthCheckServiceConfigurationProxy;
                }
            }, healthCheckServiceConfiguration);
        } else {
            ConfigSupport.apply(new SingleConfigCode<HoggingThreadsChecker>() {

                @Override
                public Object run(final HoggingThreadsChecker hoggingThreadConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                    applyValues(hoggingThreadConfigurationProxy);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return hoggingThreadConfigurationProxy;
                }
            }, hoggingThreadConfiguration);
        }
        if (dynamic) {
            if (server.isDas()) {
                if (targetUtil.getConfig(target).isDas()) {
                    HoggingThreadsChecker checkerByType = healthCheckServiceConfiguration.getCheckerByType(HoggingThreadsChecker.class);
                    service.setOptions(service.constructOptions(checkerByType));
                    healthCheckService.registerCheck(checkerByType.getName(), service);
                    healthCheckService.reboot();
                }
            } else {
                // it implicitly targetted to us as we are not the DAS
                // restart the service
                HoggingThreadsChecker checkerByType = healthCheckServiceConfiguration.getCheckerByType(HoggingThreadsChecker.class);
                service.setOptions(service.constructOptions(hoggingThreadConfiguration));
                healthCheckService.registerCheck(checkerByType.getName(), service);
                healthCheckService.reboot();
            }
        }
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Exception during command ", ex);
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) HoggingThreadsChecker(fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker) Config(com.sun.enterprise.config.serverbeans.Config) HoggingThreadsHealthCheck(fish.payara.nucleus.healthcheck.preliminary.HoggingThreadsHealthCheck) HealthCheckServiceConfiguration(fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration) ActionReport(org.glassfish.api.ActionReport)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)81 Config (com.sun.enterprise.config.serverbeans.Config)69 ActionReport (org.glassfish.api.ActionReport)60 PropertyVetoException (java.beans.PropertyVetoException)59 Property (org.jvnet.hk2.config.types.Property)50 CommandTarget (org.glassfish.config.support.CommandTarget)24 Target (org.glassfish.internal.api.Target)23 Properties (java.util.Properties)21 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)17 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)15 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 Server (com.sun.enterprise.config.serverbeans.Server)14 List (java.util.List)14 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)14 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 IOException (java.io.IOException)10 Map (java.util.Map)10 Cluster (com.sun.enterprise.config.serverbeans.Cluster)9