Search in sources :

Example 11 with CommandRunner

use of org.glassfish.api.admin.CommandRunner in project Payara by payara.

the class FlushInstancesConnectionPool method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Resources resources = domain.getResources();
    String scope = "";
    if (moduleName != null) {
        if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
            report.setMessage("Modulename is not that of a valid module: " + moduleName);
            report.setActionExitCode(ActionReport.ExitCode.WARNING);
            return;
        }
        Application application = applications.getApplication(applicationName);
        Module module = application.getModule(moduleName);
        resources = module.getResources();
        scope = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX;
    } else if (applicationName != null) {
        if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
            report.setMessage("ApplicationName is not that of a valid module: " + applicationName);
            report.setActionExitCode(ActionReport.ExitCode.WARNING);
            return;
        }
        Application application = applications.getApplication(applicationName);
        resources = application.getResources();
        scope = ConnectorConstants.JAVA_APP_SCOPE_PREFIX;
    }
    if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
        report.setMessage("Connection Pool is not valid");
        report.setActionExitCode(ActionReport.ExitCode.WARNING);
        return;
    }
    List<Future> instanceFlushes = new ArrayList<>();
    for (Server server : domain.getServers().getServer()) {
        instanceFlushes.add(executor.submit(new Runnable() {

            @Override
            public void run() {
                ActionReport subReport = report.addSubActionsReport();
                try {
                    if (!server.isRunning()) {
                        // skip servers that are stopped
                        return;
                    }
                    String host = server.getAdminHost();
                    int port = server.getAdminPort();
                    ParameterMap map = new ParameterMap();
                    map.add("poolName", poolName);
                    if (applicationName != null) {
                        map.add("appname", applicationName);
                    }
                    if (moduleName != null) {
                        map.add("modulename", moduleName);
                    }
                    if (server.isDas()) {
                        CommandRunner runner = habitat.getService(CommandRunner.class);
                        CommandRunner.CommandInvocation invocation = runner.getCommandInvocation("_flush-connection-pool", subReport, context.getSubject());
                        invocation.parameters(map);
                        invocation.execute();
                    } else {
                        RemoteRestAdminCommand rac = new ServerRemoteRestAdminCommand(habitat, "_flush-connection-pool", host, port, false, "admin", null, LOGGER);
                        rac.executeCommand(map);
                        ActionReport result = rac.getActionReport();
                        subReport.setActionExitCode(result.getActionExitCode());
                        subReport.setMessage(result.getMessage());
                    }
                } catch (CommandException ex) {
                    subReport.failure(Logger.getLogger("CONNECTORS-ADMIN"), ex.getLocalizedMessage(), ex);
                    subReport.appendMessage(server.getName());
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                }
            }
        }));
    }
    for (Future future : instanceFlushes) {
        try {
            future.get();
        } catch (InterruptedException | ExecutionException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }
    }
    if (report.hasFailures()) {
        report.setActionExitCode(ActionReport.ExitCode.WARNING);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandException(org.glassfish.api.admin.CommandException) ActionReport(org.glassfish.api.ActionReport) RestEndpoint(org.glassfish.api.admin.RestEndpoint) Future(java.util.concurrent.Future) Resources(com.sun.enterprise.config.serverbeans.Resources) Module(com.sun.enterprise.config.serverbeans.Module) ExecutionException(java.util.concurrent.ExecutionException) Application(com.sun.enterprise.config.serverbeans.Application) CommandRunner(org.glassfish.api.admin.CommandRunner) RemoteRestAdminCommand(com.sun.enterprise.admin.remote.RemoteRestAdminCommand) ServerRemoteRestAdminCommand(com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand) ServerRemoteRestAdminCommand(com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand)

Example 12 with CommandRunner

use of org.glassfish.api.admin.CommandRunner in project Payara by payara.

the class SetJMXMonitoringConfiguration method enableOnTarget.

/**
 * @param actionReport
 * @param context
 * @param enabled
 */
private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) {
    CommandRunner runner = serviceLocator.getService(CommandRunner.class);
    ActionReport subReport = context.getActionReport().addSubActionsReport();
    CommandRunner.CommandInvocation invocation;
    if (target.equals("server-config")) {
        invocation = runner.getCommandInvocation("__enable-jmx-monitoring-service-on-das", subReport, context.getSubject());
    } else {
        invocation = runner.getCommandInvocation("__enable-jmx-monitoring-service-on-instance", subReport, context.getSubject());
    }
    // Build the parameters
    ParameterMap params = new ParameterMap();
    enabled = Boolean.valueOf(jmxMonitoringConfig.getEnabled());
    params.add("enabled", enabled.toString());
    params.add("target", target);
    invocation.parameters(params);
    invocation.execute();
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 13 with CommandRunner

use of org.glassfish.api.admin.CommandRunner in project Payara by payara.

the class CreateDockerContainerCommand method unregisterInstance.

/**
 * Lifecycle helper method that attempts to remove an instance registry if we failed to create the corresponding
 * Docker container
 *
 * @param adminCommandContext
 * @param actionReport
 */
private void unregisterInstance(AdminCommandContext adminCommandContext, ActionReport actionReport) {
    if (commandRunner != null) {
        actionReport.appendMessage("\n\nWill attempt to unregister instance...");
        ActionReport subActionReport = actionReport.addSubActionsReport();
        CommandRunner.CommandInvocation commandInvocation = commandRunner.getCommandInvocation("_unregister-instance", subActionReport, adminCommandContext.getSubject());
        ParameterMap commandParameters = new ParameterMap();
        commandParameters.add("DEFAULT", instanceName);
        commandInvocation.parameters(commandParameters);
        commandInvocation.execute();
        // give a more useful message
        if (subActionReport.getActionExitCode() == SUCCESS) {
            actionReport.appendMessage("\nSuccessfully unregistered instance");
        } else {
            actionReport.appendMessage("\nFailed to unregister instance, user intervention will be required");
        }
    }
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 14 with CommandRunner

use of org.glassfish.api.admin.CommandRunner in project Payara by payara.

the class SetMonitoringConfiguration method enableOnTarget.

/**
 * @param actionReport
 * @param context
 * @param enabled
 */
private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) {
    CommandRunner runner = serviceLocator.getService(CommandRunner.class);
    ActionReport subReport = context.getActionReport().addSubActionsReport();
    CommandRunner.CommandInvocation invocation;
    if (target.equals("server-config")) {
        invocation = runner.getCommandInvocation("__enable-monitoring-service-on-das", subReport, context.getSubject());
    } else {
        invocation = runner.getCommandInvocation("__enable-monitoring-service-on-instance", subReport, context.getSubject());
    }
    // Build the parameters
    ParameterMap params = new ParameterMap();
    enabled = Boolean.valueOf(monitoringConfig.getEnabled());
    params.add("enabled", enabled.toString());
    params.add("target", target);
    invocation.parameters(params);
    invocation.execute();
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 15 with CommandRunner

use of org.glassfish.api.admin.CommandRunner in project Payara by payara.

the class SetNotificationConfiguration method enableNotificationConfigureOnTarget.

private void enableNotificationConfigureOnTarget(ActionReport actionReport, AdminCommandContext context) {
    CommandRunner runner = serviceLocator.getService(CommandRunner.class);
    ActionReport subReport = context.getActionReport().addSubActionsReport();
    inv = runner.getCommandInvocation("notification-configure", subReport, context.getSubject());
    ParameterMap params = new ParameterMap();
    params.add("enabled", enabled.toString());
    params.add("target", target);
    params.add("dynamic", dynamic.toString());
    inv.parameters(params);
    inv.execute();
    // swallow the offline warning as it is not a problem
    if (subReport.hasWarnings()) {
        subReport.setMessage("");
    }
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

Aggregations

CommandRunner (org.glassfish.api.admin.CommandRunner)26 ParameterMap (org.glassfish.api.admin.ParameterMap)14 ActionReport (org.glassfish.api.ActionReport)12 ArrayList (java.util.ArrayList)8 Properties (java.util.Properties)5 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)4 IOException (java.io.IOException)3 RemoteRestAdminCommand (com.sun.enterprise.admin.remote.RemoteRestAdminCommand)2 Server (com.sun.enterprise.config.serverbeans.Server)2 File (java.io.File)2 AdminCommand (org.glassfish.api.admin.AdminCommand)2 CommandException (org.glassfish.api.admin.CommandException)2 CommandModel (org.glassfish.api.admin.CommandModel)2 CommandInvocation (org.glassfish.api.admin.CommandRunner.CommandInvocation)2 InternalSystemAdministrator (org.glassfish.internal.api.InternalSystemAdministrator)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 ServerRemoteRestAdminCommand (com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand)1 DoNothingActionReporter (com.sun.enterprise.admin.report.DoNothingActionReporter)1 PlainTextActionReporter (com.sun.enterprise.admin.report.PlainTextActionReporter)1 Application (com.sun.enterprise.config.serverbeans.Application)1