Search in sources :

Example 6 with MonitoringService

use of com.sun.enterprise.config.serverbeans.MonitoringService in project Payara by payara.

the class SetMonitoringLevel method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config != null) {
        monitoringService = config.getMonitoringService();
    } else {
        actionReport.setMessage("Cound not find target: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    if (moduleNames != null && moduleMonitoringLevels != null) {
        String modifiedModuleNames = moduleNames.replace(":", ",");
        String modifiedModuleMonitoringLevels = moduleMonitoringLevels.replace(":", ",");
        List<String> moduleNameList = Arrays.asList(modifiedModuleNames.split(","));
        List<String> moduleLevelList = Arrays.asList(modifiedModuleMonitoringLevels.split(","));
        if (moduleNameList.size() == moduleLevelList.size()) {
            for (int i = 0; i < moduleLevelList.size(); i++) {
                boolean isValidMoudle = false;
                List<String> validModuleList = new ArrayList<>(Arrays.asList(Constants.validModuleNames));
                String moduleName = moduleNameList.get(i).trim().toLowerCase();
                for (String module : validModuleList) {
                    if (module.trim().equalsIgnoreCase(moduleName)) {
                        String moduleLevel = moduleLevelList.get(i).trim().toUpperCase();
                        try {
                            ConfigSupport.apply(new SingleConfigCode<MonitoringService>() {

                                @Override
                                public Object run(final MonitoringService monitoringServiceProxy) throws PropertyVetoException, TransactionFailure {
                                    monitoringServiceProxy.setMonitoringLevel(moduleName, moduleLevel);
                                    return monitoringServiceProxy;
                                }
                            }, monitoringService);
                        } catch (TransactionFailure ex) {
                            logger.log(Level.WARNING, "Failed to execute the command set-monitoring-level: {0}", ex.getCause().getMessage());
                            actionReport.setMessage(ex.getCause().getMessage());
                            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
                        }
                        isValidMoudle = true;
                        break;
                    }
                }
                if (!isValidMoudle) {
                    actionReport.setMessage(moduleNameList.get(i) + " isn't a valid Module name");
                    actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    return;
                }
            }
        } else {
            actionReport.setMessage("Number of Module and Level entered doesn't match");
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) RestEndpoint(org.glassfish.api.admin.RestEndpoint) PropertyVetoException(java.beans.PropertyVetoException) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService)

Example 7 with MonitoringService

use of com.sun.enterprise.config.serverbeans.MonitoringService in project Payara by payara.

the class DynamicConfigListener method changed.

@Override
public synchronized UnprocessedChangeEvents changed(final PropertyChangeEvent[] events) {
    return ConfigSupport.sortAndDispatch(events, new Changed() {

        @Override
        public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "NetworkConfig changed {0} {1} {2}", new Object[] { type, tClass, t });
            }
            if (tClass == NetworkListener.class && t instanceof NetworkListener) {
                return processNetworkListener(type, (NetworkListener) t, events);
            } else if (tClass == Http.class && t instanceof Http) {
                return processProtocol(type, (Protocol) t.getParent(), events);
            } else if (tClass == FileCache.class && t instanceof FileCache) {
                return processProtocol(type, (Protocol) t.getParent().getParent(), null);
            } else if (tClass == Ssl.class && t instanceof Ssl) {
                /*
                         * Make sure the SSL parent is in fact a protocol.  It could
                         * be a jmx-connector.
                     */
                final ConfigBeanProxy parent = t.getParent();
                if (parent instanceof Protocol) {
                    return processProtocol(type, (Protocol) parent, null);
                }
            } else if (tClass == Protocol.class && t instanceof Protocol) {
                return processProtocol(type, (Protocol) t, null);
            } else if (tClass == ThreadPool.class && t instanceof ThreadPool) {
                NotProcessed notProcessed = null;
                ThreadPool threadPool = (ThreadPool) t;
                for (NetworkListener listener : threadPool.findNetworkListeners()) {
                    notProcessed = processNetworkListener(type, listener, null);
                }
                // Throw an unprocessed event change if one hasn't already if HTTP or ThreadPool monitoring is enabled.
                MonitoringService ms = config.getMonitoringService();
                String threadPoolLevel = ms.getModuleMonitoringLevels().getThreadPool();
                String httpServiceLevel = ms.getModuleMonitoringLevels().getHttpService();
                if (((threadPoolLevel != null && !threadPoolLevel.equals(OFF)) || (httpServiceLevel != null && !httpServiceLevel.equals(OFF))) && notProcessed == null) {
                    notProcessed = new NotProcessed("Monitoring statistics will be incorrect for " + threadPool.getName() + " until restart due to changed attribute(s).");
                }
                return notProcessed;
            } else if (tClass == Transport.class && t instanceof Transport) {
                NotProcessed notProcessed = null;
                for (NetworkListener listener : ((Transport) t).findNetworkListeners()) {
                    notProcessed = processNetworkListener(type, listener, null);
                }
                return notProcessed;
            } else if (tClass == VirtualServer.class && t instanceof VirtualServer && !grizzlyService.hasMapperUpdateListener()) {
                return processVirtualServer(type, (VirtualServer) t);
            } else if (tClass == SystemProperty.class && t instanceof SystemProperty) {
                NetworkConfig networkConfig = config.getNetworkConfig();
                if ((networkConfig != null) && ((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
                    for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
                        if (listener.getPort().equals(((SystemProperty) t).getValue())) {
                            return processNetworkListener(Changed.TYPE.CHANGE, listener, events);
                        }
                    }
                }
                return null;
            }
            return null;
        }
    }, logger);
}
Also used : ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) Ssl(org.glassfish.grizzly.config.dom.Ssl) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) FileCache(org.glassfish.grizzly.config.dom.FileCache) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Changed(org.jvnet.hk2.config.Changed) NotProcessed(org.jvnet.hk2.config.NotProcessed) Protocol(org.glassfish.grizzly.config.dom.Protocol) Transport(org.glassfish.grizzly.config.dom.Transport) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 8 with MonitoringService

use of com.sun.enterprise.config.serverbeans.MonitoringService in project Payara by payara.

the class SetJMXMonitoringConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        actionReport.setMessage("Cound not find target: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    final JMXMonitoringService jmxMonitoringService = serviceLocator.getService(JMXMonitoringService.class);
    if (jmxMonitoringService == null) {
        actionReport.appendMessage("Could not find a monitoring service.");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    jmxMonitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
    try {
        ConfigSupport.apply(new SingleConfigCode<MonitoringServiceConfiguration>() {

            @Override
            public Object run(final MonitoringServiceConfiguration monitoringConfigProxy) throws PropertyVetoException, TransactionFailure {
                updateConfiguration(monitoringConfigProxy);
                updateAttributes(monitoringConfigProxy, actionReport);
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return monitoringConfigProxy;
            }
        }, jmxMonitoringConfig);
        if (dynamic) {
            enableOnTarget(actionReport, context, enabled);
        }
        // If the JMX Monitoring is enabled, enable Mbeans too as without it you have nothing to monitor
        if (enabled != null && enabled) {
            MonitoringService monitoringService = config.getMonitoringService();
            ConfigSupport.apply(new SingleConfigCode<MonitoringService>() {

                @Override
                public Object run(final MonitoringService monitoringServiceProxy) throws PropertyVetoException, TransactionFailure {
                    monitoringServiceProxy.setMbeanEnabled((String.valueOf(enabled)));
                    return monitoringServiceProxy;
                }
            }, monitoringService);
        }
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Falied to excute the command " + "set-jmx-monitoring-configuration: " + ex.getCause().getMessage());
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JMXMonitoringService(fish.payara.jmx.monitoring.JMXMonitoringService) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ActionReport(org.glassfish.api.ActionReport) JMXMonitoringService(fish.payara.jmx.monitoring.JMXMonitoringService) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService)

Example 9 with MonitoringService

use of com.sun.enterprise.config.serverbeans.MonitoringService in project Payara by payara.

the class DynamicConfigListener method processNetworkListener.

private <T extends ConfigBeanProxy> NotProcessed processNetworkListener(Changed.TYPE type, NetworkListener listener, final PropertyChangeEvent[] changedProperties) {
    if (findConfigName(listener).equals(findConfigName(config))) {
        boolean isAdminListener = ADMIN_LISTENER.equals(listener.getName());
        Lock portLock = null;
        try {
            portLock = acquirePortLock(listener);
            switch(type) {
                case ADD:
                    final int[] ports = portLock.getPorts();
                    if (isAdminListener && ports[ports.length - 1] == -1) {
                        return null;
                    }
                    final Future future = grizzlyService.createNetworkProxy(listener);
                    if (future != null) {
                        future.get(RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS);
                        grizzlyService.registerContainerAdapters();
                    } else {
                        logger.log(Level.FINE, "Skipping proxy registration for the listener {0}", listener.getName());
                    }
                    break;
                case REMOVE:
                    if (!isAdminListener) {
                        grizzlyService.removeNetworkProxy(listener);
                    }
                    break;
                case CHANGE:
                    // If the listener is the admin listener
                    if (isAdminListener) {
                        return null;
                    }
                    // Only restart the network listener if something hasn't changed
                    if (!isRedundantChange(changedProperties)) {
                        MonitoringService ms = config.getMonitoringService();
                        String level = ms.getModuleMonitoringLevels().getHttpService();
                        // We only need to throw an unprocessed change event if monitoring is enabled for the HTTP service
                        if (level != null && (!level.equals(OFF))) {
                            String eventsMessage = "Monitoring statistics will be incorrect for " + listener.findHttpProtocolName() + " until restart due to changed attribute(s): ";
                            // so the for loop should only run once, but it's there just in case.
                            for (PropertyChangeEvent event : changedProperties) {
                                eventsMessage += ("\"" + event.getPropertyName() + "\" changed from \"" + event.getOldValue() + "\" to \"" + event.getNewValue() + "\".\n");
                            }
                            // Still restart the network listener, as it's only the monitoring that breaks.
                            grizzlyService.restartNetworkListener(listener, RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS);
                            return new NotProcessed(eventsMessage);
                        } else {
                            // Restart the network listener without throwing an unprocessed change
                            grizzlyService.restartNetworkListener(listener, RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS);
                        }
                    }
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Network listener configuration error. Type: " + type, e);
        } finally {
            if (portLock != null) {
                releaseListenerLock(portLock);
            }
        }
    }
    return null;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) Future(java.util.concurrent.Future) NotProcessed(org.jvnet.hk2.config.NotProcessed) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ReentrantLock(java.util.concurrent.locks.ReentrantLock)

Aggregations

MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)9 ActionReport (org.glassfish.api.ActionReport)7 Config (com.sun.enterprise.config.serverbeans.Config)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)3 AMXConfiguration (fish.payara.admin.amx.config.AMXConfiguration)3 PropertyVetoException (java.beans.PropertyVetoException)3 HashMap (java.util.HashMap)3 Properties (java.util.Properties)3 ArrayList (java.util.ArrayList)2 NotProcessed (org.jvnet.hk2.config.NotProcessed)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)1 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)1 JMXMonitoringService (fish.payara.jmx.monitoring.JMXMonitoringService)1 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1