Search in sources :

Example 16 with CommandInvocation

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

the class CreateNodeConfigCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    // validate installdir if passed and running on localhost
    if (StringUtils.ok(nodehost)) {
        if (NetUtils.isThisHostLocal(nodehost) && StringUtils.ok(installdir)) {
            TokenResolver resolver = null;
            // Create a resolver that can replace system properties in strings
            Map<String, String> systemPropsMap = new HashMap<String, String>((Map) (System.getProperties()));
            resolver = new TokenResolver(systemPropsMap);
            String resolvedInstallDir = resolver.resolve(installdir);
            File actualInstallDir = new File(resolvedInstallDir + "/" + NodeUtils.LANDMARK_FILE);
            if (!actualInstallDir.exists()) {
                report.setMessage(Strings.get("invalid.installdir", installdir));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    CommandInvocation ci = cr.getCommandInvocation("_create-node", report, context.getSubject());
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", name);
    if (StringUtils.ok(nodedir))
        map.add(NodeUtils.PARAM_NODEDIR, nodedir);
    if (StringUtils.ok(installdir))
        map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
    if (StringUtils.ok(nodehost))
        map.add(NodeUtils.PARAM_NODEHOST, nodehost);
    map.add(NodeUtils.PARAM_TYPE, "CONFIG");
    ci.parameters(map);
    ci.execute();
    NodeUtils.sanitizeReport(report);
}
Also used : TokenResolver(com.sun.enterprise.universal.glassfish.TokenResolver) HashMap(java.util.HashMap) ActionReport(org.glassfish.api.ActionReport) File(java.io.File) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 17 with CommandInvocation

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

the class CreateNodeImplicitCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    if (name == null)
        name = nodehost;
    if (nodes.getNode(name) != null) {
        // already created nothing to do here
        return;
    }
    CommandInvocation ci = cr.getCommandInvocation("_create-node", report, context.getSubject());
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", name);
    map.add(NodeUtils.PARAM_NODEDIR, nodedir);
    map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
    map.add(NodeUtils.PARAM_NODEHOST, nodehost);
    map.add(NodeUtils.PARAM_TYPE, "CONFIG");
    ci.parameters(map);
    ci.execute();
}
Also used : ActionReport(org.glassfish.api.ActionReport) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 18 with CommandInvocation

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

the class CreateRemoteNodeCommand method executeInternal.

public final void executeInternal(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    StringBuilder msg = new StringBuilder();
    logger = context.getLogger();
    initialize();
    populateBaseClass();
    checkDefaults();
    ParameterMap map = new ParameterMap();
    populateParametersInternal(map);
    try {
        validate();
    } catch (CommandValidationException ex) {
        report.setMessage(ex.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        nodeUtils = new NodeUtils(habitat, logger);
        nodeUtils.validate(map);
        if (install) {
            boolean s = installNode(context);
            if (!s && !force) {
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    } catch (CommandValidationException e) {
        String m1 = Strings.get("node.ssh.invalid.params");
        if (!force) {
            String m2 = Strings.get("create.node.ssh.or.dcom.not.created", getType().toString());
            msg.append(StringUtils.cat(NL, m1, m2, e.getMessage()));
            report.setMessage(msg.toString());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        } else {
            String m2 = Strings.get("create.node.ssh.continue.force");
            msg.append(StringUtils.cat(NL, m1, e.getMessage(), m2));
        }
    }
    map.remove(NodeUtils.PARAM_INSTALL);
    CommandInvocation ci = cr.getCommandInvocation("_create-node", report, context.getSubject());
    ci.parameters(map);
    ci.execute();
    NodeUtils.sanitizeReport(report);
    if (StringUtils.ok(report.getMessage())) {
        if (msg.length() > 0) {
            msg.append(NL);
        }
        msg.append(report.getMessage());
    }
    report.setMessage(msg.toString());
}
Also used : ActionReport(org.glassfish.api.ActionReport) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 19 with CommandInvocation

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

the class DeleteNodeConfigCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Logger logger = context.getLogger();
    Node node = nodes.getNode(name);
    if (node == null) {
        // no node to delete  nothing to do here
        String msg = Strings.get("noSuchNode", name);
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    if (!(node.getType().equals("CONFIG"))) {
        // no node to delete  nothing to do here
        String msg = Strings.get("notConfigNodeType", name);
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    CommandInvocation ci = cr.getCommandInvocation("_delete-node", report, context.getSubject());
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", name);
    ci.parameters(map);
    ci.execute();
}
Also used : ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 20 with CommandInvocation

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

the class DeleteNodeRemoteCommand method executeInternal.

protected final void executeInternal(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    logger = context.getLogger();
    Node node = nodes.getNode(name);
    if (node == null) {
        // no node to delete  nothing to do here
        String msg = Strings.get("noSuchNode", name);
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    String type = node.getType();
    if ((type == null) || (type.equals("CONFIG"))) {
        // no node to delete  nothing to do here
        String msg = Strings.get("notRemoteNodeType", name);
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    ParameterMap info = new ParameterMap();
    if (uninstall) {
        // store needed info for uninstall
        SshConnector sshC = node.getSshConnector();
        SshAuth sshAuth = sshC.getSshAuth();
        if (sshAuth.getPassword() != null)
            info.add(NodeUtils.PARAM_REMOTEPASSWORD, sshAuth.getPassword());
        if (sshAuth.getKeyPassphrase() != null)
            info.add(NodeUtils.PARAM_SSHKEYPASSPHRASE, sshAuth.getKeyPassphrase());
        if (sshAuth.getKeyfile() != null)
            info.add(NodeUtils.PARAM_SSHKEYFILE, sshAuth.getKeyfile());
        info.add(NodeUtils.PARAM_INSTALLDIR, node.getInstallDir());
        info.add(NodeUtils.PARAM_REMOTEPORT, sshC.getSshPort());
        info.add(NodeUtils.PARAM_REMOTEUSER, sshAuth.getUserName());
        info.add(NodeUtils.PARAM_NODEHOST, node.getNodeHost());
        info.add(NodeUtils.PARAM_WINDOWS_DOMAIN, node.getWindowsDomain());
    }
    CommandInvocation ci = cr.getCommandInvocation("_delete-node", report, context.getSubject());
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", name);
    ci.parameters(map);
    ci.execute();
    // uninstall GlassFish after deleting the node
    if (uninstall) {
        boolean s = uninstallNode(context, info, node);
        if (!s && !force) {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport) 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