Search in sources :

Example 6 with CommandInvocation

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

the class DeleteInstanceCommand method execute.

@Override
public void execute(AdminCommandContext ctx) {
    ActionReport report = ctx.getActionReport();
    logger = ctx.getLogger();
    String msg = "";
    boolean fsfailure = false;
    boolean configfailure = false;
    // We are going to delete a server instance. Get the instance
    instance = servers.getServer(instanceName);
    if (instance == null) {
        msg = Strings.get("start.instance.noSuchInstance", instanceName);
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    instanceHost = instance.getAdminHost();
    // make sure instance is not running.
    if (instance.isRunning()) {
        msg = Strings.get("instance.shutdown", instanceName);
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    // We attempt to delete the instance filesystem first by running
    // _delete-instance-filesystem. We then remove the instance
    // from the config no matter if we could delete the files or not.
    // Get the name of the node from the instance's node-ref field
    noderef = instance.getNodeRef();
    if (!StringUtils.ok(noderef)) {
        msg = Strings.get("missingNodeRef", instanceName);
        fsfailure = true;
    } else {
        theNode = nodes.getNode(noderef);
        if (theNode == null) {
            msg = Strings.get("noSuchNode", noderef);
            fsfailure = true;
        }
    }
    if (!fsfailure) {
        nodedir = theNode.getNodeDirAbsolute();
        deleteInstanceFilesystem(ctx);
        report = ctx.getActionReport();
        if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
            fsfailure = true;
        }
        msg = report.getMessage();
    }
    // Now remove the instance from domain.xml.
    CommandInvocation ci = cr.getCommandInvocation("_unregister-instance", report, ctx.getSubject());
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", instanceName);
    ci.parameters(map);
    ci.execute();
    if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS && report.getActionExitCode() != ActionReport.ExitCode.WARNING) {
        // Failed to delete from domain.xml
        configfailure = true;
        if (fsfailure) {
            // Failed to delete instance from fs too
            msg = msg + NL + report.getMessage();
        } else {
            msg = report.getMessage();
        }
    }
    // OK, try to give a helpful message depending on the failure
    if (configfailure && fsfailure) {
        msg = msg + NL + NL + Strings.get("delete.instance.failed", instanceName, instanceHost);
    } else if (configfailure && !fsfailure) {
        msg = msg + NL + NL + Strings.get("delete.instance.config.failed", instanceName, instanceHost);
    } else if (!configfailure && fsfailure) {
        report.setActionExitCode(ActionReport.ExitCode.WARNING);
    // leave msg as is
    }
    if (configfailure) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 7 with CommandInvocation

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

the class ResourceUtil method runCommand.

/**
 * Executes the specified __asadmin command.
 * @param commandName
 * @param parameters
 * @param subject
 * @param managedJob
 * @return
 */
public static RestActionReporter runCommand(String commandName, ParameterMap parameters, Subject subject, boolean managedJob) {
    AsadminRecorderService asadminRecorderService = Globals.getDefaultHabitat().getService(AsadminRecorderService.class);
    if (asadminRecorderService.isEnabled()) {
        asadminRecorderService.recordAsadminCommand(commandName, parameters);
    }
    CommandRunner cr = Globals.getDefaultHabitat().getService(CommandRunner.class);
    RestActionReporter ar = new RestActionReporter();
    final CommandInvocation commandInvocation = cr.getCommandInvocation(commandName, ar, subject);
    if (managedJob) {
        commandInvocation.managedJob();
    }
    commandInvocation.parameters(parameters).execute();
    addCommandLog(ar, commandName, parameters);
    return ar;
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) AsadminRecorderService(fish.payara.asadmin.recorder.AsadminRecorderService) CommandRunner(org.glassfish.api.admin.CommandRunner) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 8 with CommandInvocation

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

the class CreateHTTPLoadBalancerCommand method createLBConfig.

private void createLBConfig(String config, final Subject subject) throws CommandException {
    CommandInvocation ci = runner.getCommandInvocation("create-http-lb-config", report, subject);
    ParameterMap map = new ParameterMap();
    // map.add("target", target);
    map.add("responsetimeout", responsetimeout);
    map.add("httpsrouting", httpsrouting == null ? null : httpsrouting.toString());
    map.add("reloadinterval", reloadinterval);
    map.add("monitor", monitor == null ? null : monitor.toString());
    map.add("routecookie", routecookie == null ? null : routecookie.toString());
    map.add("name", config);
    ci.parameters(map);
    ci.execute();
}
Also used : CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 9 with CommandInvocation

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

the class SetRestMonitoringConfigurationCommand method createRequiredMessageSecurityProvider.

private void createRequiredMessageSecurityProvider(ActionReport subActionReport, Subject subject) {
    CommandInvocation invocation = commandRunner.getCommandInvocation("create-message-security-provider", subActionReport, subject, false);
    ParameterMap parameters = new ParameterMap();
    parameters.add("classname", RestMonitoringAuthModule.class.getName());
    parameters.add("isdefaultprovider", "false");
    parameters.add("layer", "HttpServlet");
    parameters.add("providertype", "server");
    parameters.add("target", target);
    parameters.add("requestauthsource", "sender");
    parameters.add("DEFAULT", AUTH_MODULE_NAME);
    invocation.parameters(parameters).execute();
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation) RestMonitoringAuthModule(fish.payara.appserver.monitoring.rest.service.security.RestMonitoringAuthModule)

Example 10 with CommandInvocation

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

the class SetRestMonitoringConfigurationCommand method defaultRestMonitoringUserExists.

private boolean defaultRestMonitoringUserExists(ActionReport subActionReport, Subject subject) {
    boolean exists = false;
    CommandInvocation invocation = commandRunner.getCommandInvocation("list-file-users", subActionReport, subject, false);
    ParameterMap parameters = new ParameterMap();
    parameters.add("authrealmname", "file");
    invocation.parameters(parameters).execute();
    for (MessagePart message : subActionReport.getTopMessagePart().getChildren()) {
        if (message.getMessage().equals(DEFAULT_USER_NAME)) {
            exists = true;
            break;
        }
    }
    return exists;
}
Also used : MessagePart(org.glassfish.api.ActionReport.MessagePart) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Aggregations

CommandInvocation (org.glassfish.api.admin.CommandRunner.CommandInvocation)20 ActionReport (org.glassfish.api.ActionReport)13 ParameterMap (org.glassfish.api.admin.ParameterMap)6 Logger (java.util.logging.Logger)3 Node (com.sun.enterprise.config.serverbeans.Node)2 Server (com.sun.enterprise.config.serverbeans.Server)2 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)2 MessagePart (org.glassfish.api.ActionReport.MessagePart)2 CommandRunner (org.glassfish.api.admin.CommandRunner)2 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)1 TokenResolver (com.sun.enterprise.universal.glassfish.TokenResolver)1 RestMonitoringAuthModule (fish.payara.appserver.monitoring.rest.service.security.RestMonitoringAuthModule)1 AsadminRecorderService (fish.payara.asadmin.recorder.AsadminRecorderService)1 DGServerRef (fish.payara.enterprise.config.serverbeans.DGServerRef)1