Search in sources :

Example 1 with MonitoringService

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

the class GetMonitoringConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    ActionReport monitoringServiceReport = actionReport.addSubActionsReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        actionReport.setMessage("No such config named: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    MonitoringService monitoringService = config.getMonitoringService();
    AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
    CommandRunner.CommandInvocation commandInvocation = commandRunner.getCommandInvocation("get-rest-monitoring-configuration", actionReport, context.getSubject());
    commandInvocation.execute();
    commandInvocation = commandRunner.getCommandInvocation("get-jmx-monitoring-configuration", actionReport, context.getSubject());
    commandInvocation.execute();
    final String[] headers = { "Monitoring Enabled", "AMX Enabled", "MBeans Enabled", "DTrace Enabled" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    columnFormatter.addRow(new Object[] { monitoringService.getMonitoringEnabled(), amxConfiguration.getEnabled(), monitoringService.getMbeanEnabled(), monitoringService.getDtraceEnabled() });
    Map<String, Object> extraPropertiesMap = new HashMap<>();
    extraPropertiesMap.put("monitoringEnabled", monitoringService.getMonitoringEnabled());
    extraPropertiesMap.put("mbeanEnabled", monitoringService.getMbeanEnabled());
    extraPropertiesMap.put("dtraceEnabled", monitoringService.getDtraceEnabled());
    extraPropertiesMap.put("amxEnabled", amxConfiguration.getEnabled());
    Properties extraProperties = new Properties();
    extraProperties.put("getMonitoringConfiguration", extraPropertiesMap);
    actionReport.setExtraProperties(extraProperties);
    monitoringServiceReport.setMessage(columnFormatter.toString());
    monitoringServiceReport.appendMessage(StringUtils.EOL);
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) AMXConfiguration(fish.payara.admin.amx.config.AMXConfiguration) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) CommandRunner(org.glassfish.api.admin.CommandRunner) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 2 with MonitoringService

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

the class GetMonitoringServiceConfiguration 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;
    }
    MonitoringService monitoringService = config.getMonitoringService();
    AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
    final ActionReport actionReport = context.getActionReport();
    final String[] headers = { "Monitoring Enabled", "AMX Enabled", "MBeans Enabled", "DTrace Enabled" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    columnFormatter.addRow(new Object[] { monitoringService.getMonitoringEnabled(), amxConfiguration.getEnabled(), monitoringService.getMbeanEnabled(), monitoringService.getDtraceEnabled() });
    actionReport.appendMessage(columnFormatter.toString());
    Map<String, Object> extraPropertiesMap = new HashMap<>();
    extraPropertiesMap.put("monitoringEnabled", monitoringService.getMonitoringEnabled());
    extraPropertiesMap.put("amxEnabled", amxConfiguration.getEnabled());
    extraPropertiesMap.put("mbeanEnabled", monitoringService.getMbeanEnabled());
    extraPropertiesMap.put("dtraceEnabled", monitoringService.getDtraceEnabled());
    Properties extraProperties = new Properties();
    extraProperties.put("getMonitoringServiceConfiguration", extraPropertiesMap);
    actionReport.setExtraProperties(extraProperties);
    actionReport.setMessage(columnFormatter.toString());
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : AMXConfiguration(fish.payara.admin.amx.config.AMXConfiguration) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 3 with MonitoringService

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

the class SetMonitoringConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    // obtain the correct configuration
    Config config = targetUtil.getConfig(target);
    MonitoringService monitorServiceConfig = config.getExtensionByType(MonitoringService.class);
    if (monitorServiceConfig != null) {
        try {
            ConfigSupport.apply((monitorServiceConfigProxy) -> {
                if (monitoringServiceEnabled != null) {
                    monitorServiceConfigProxy.setMonitoringEnabled(String.valueOf(monitoringServiceEnabled));
                }
                if (mbeansEnabled != null) {
                    monitorServiceConfigProxy.setMbeanEnabled(String.valueOf(mbeansEnabled));
                }
                if (dTraceEnabled != null) {
                    monitorServiceConfigProxy.setMbeanEnabled(String.valueOf(dTraceEnabled));
                }
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return monitorServiceConfigProxy;
            }, monitorServiceConfig);
        } catch (TransactionFailure ex) {
            logger.log(Level.WARNING, "Exception during command ", ex);
            actionReport.setMessage(ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    CommandInvocation commandInvocation = commandRunner.getCommandInvocation("set-jmx-monitoring-configuration", actionReport, context.getSubject());
    ParameterMap commandParameters = new ParameterMap();
    if (jmxLogEnabled != null) {
        commandParameters.add("enabled", jmxLogEnabled.toString());
    }
    if (jmxLogFrequency != null) {
        commandParameters.add("logfrequency", jmxLogFrequency);
    }
    if (jmxLogFrequencyUnit != null) {
        commandParameters.add("logfrequencyunit", jmxLogFrequencyUnit);
    }
    if (attributesToAdd != null) {
        for (String attributeToAdd : attributesToAdd) {
            commandParameters.add("addattribute", attributeToAdd);
        }
    }
    if (attributesToRemove != null) {
        for (String attributeToRemove : attributesToRemove) {
            commandParameters.add("delattribute", attributeToRemove);
        }
    }
    if (dynamic) {
        commandParameters.add("dynamic", dynamic.toString());
    }
    commandParameters.add("target", target);
    commandInvocation.parameters(commandParameters);
    commandInvocation.execute();
    if (actionReport.getActionExitCode() != SUCCESS && actionReport.getActionExitCode() != WARNING) {
        // Command couldn't be execute
        failureMessage(actionReport);
        return;
    }
    if (amxEnabled != null) {
        commandInvocation = commandRunner.getCommandInvocation("set-amx-enabled", actionReport, context.getSubject());
        commandParameters = new ParameterMap();
        commandParameters.add("enabled", amxEnabled.toString());
        commandParameters.add("dynamic", dynamic.toString());
        commandParameters.add("target", target);
        commandInvocation.parameters(commandParameters);
        commandInvocation.execute();
        if (actionReport.getActionExitCode() != SUCCESS && actionReport.getActionExitCode() != WARNING) {
            // Command couldn't be execute
            failureMessage(actionReport);
            return;
        }
    }
    commandInvocation = commandRunner.getCommandInvocation("set-rest-monitoring-configuration", actionReport, context.getSubject());
    commandParameters = new ParameterMap();
    if (restMonitoringEnabled != null) {
        commandParameters.add("enabled", restMonitoringEnabled.toString());
    }
    if (restMonitoringContextRoot != null) {
        commandParameters.add("contextroot", restMonitoringContextRoot);
    }
    if (restMonitoringApplicationName != null) {
        commandParameters.add("applicationname", restMonitoringApplicationName);
    }
    if (restMonitoringSecurityEnabled != null) {
        commandParameters.add("securityenabled", restMonitoringSecurityEnabled.toString());
    }
    commandParameters.add("target", target);
    commandInvocation.parameters(commandParameters);
    commandInvocation.execute();
    if (actionReport.getActionExitCode() != SUCCESS && actionReport.getActionExitCode() != WARNING) {
        // Command couldn't be execute
        failureMessage(actionReport);
        return;
    }
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 4 with MonitoringService

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

the class SetMonitoringServiceConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    config = targetUtil.getConfig(target);
    if (config != null) {
        monitoringService = config.getMonitoringService();
    } else {
        actionReport.setMessage("Cound not find target: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<MonitoringService>() {

            @Override
            public Object run(final MonitoringService monitoringServiceProxy) throws PropertyVetoException, TransactionFailure {
                if (monitoringEnabled != null) {
                    monitoringServiceProxy.setMonitoringEnabled(String.valueOf(monitoringEnabled));
                }
                if (mbeanEnabled != null) {
                    monitoringServiceProxy.setMbeanEnabled(String.valueOf(mbeanEnabled));
                }
                if (dtraceEnabled != null) {
                    monitoringServiceProxy.setDtraceEnabled(String.valueOf(dtraceEnabled));
                }
                if (amxEnabled != null) {
                    AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
                    ConfigSupport.apply(new SingleConfigCode<AMXConfiguration>() {

                        @Override
                        public Object run(final AMXConfiguration amxConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                            amxConfigurationProxy.setEnabled((String.valueOf(amxEnabled)));
                            return amxConfigurationProxy;
                        }
                    }, amxConfiguration);
                }
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return monitoringServiceProxy;
            }
        }, monitoringService);
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Failed to execute the command set-monitoring-service-configuration: {0}", 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) AMXConfiguration(fish.payara.admin.amx.config.AMXConfiguration) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ActionReport(org.glassfish.api.ActionReport) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService)

Example 5 with MonitoringService

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

the class GetMonitoringLevel 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;
    }
    MonitoringService monitoringService = config.getMonitoringService();
    final ActionReport actionReport = context.getActionReport();
    final String[] headers = { "Module", "Monitoring Level" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    Map<String, Object> extraPropertiesMap = new HashMap<>();
    List<String> validModuleList = new ArrayList<>(Arrays.asList(Constants.validModuleNames));
    // their monitoring levels
    if (moduleName == null) {
        for (String validModule : validModuleList) {
            columnFormatter.addRow(new Object[] { validModule, monitoringService.getMonitoringLevel(validModule) });
            extraPropertiesMap.put(validModule, monitoringService.getMonitoringLevel(validModule));
        }
    }
    if (moduleName != null) {
        List<String> moduleNameList = Arrays.asList(moduleName.split(","));
        for (String module : moduleNameList) {
            boolean isValidMoudle = false;
            String selectedModule = module.trim().toLowerCase();
            for (String validModule : validModuleList) {
                if (validModule.trim().equals(selectedModule)) {
                    columnFormatter.addRow(new Object[] { selectedModule, monitoringService.getMonitoringLevel(selectedModule) });
                    extraPropertiesMap.put(selectedModule, monitoringService.getMonitoringLevel(selectedModule));
                    isValidMoudle = true;
                    break;
                }
            }
            if (!isValidMoudle) {
                actionReport.setMessage(selectedModule + " isn't a valid Module name");
                actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    Properties extraProperties = new Properties();
    extraProperties.put("getMonitoringLevel", extraPropertiesMap);
    actionReport.setExtraProperties(extraProperties);
    actionReport.setMessage(columnFormatter.toString());
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

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