Search in sources :

Example 1 with CommandInvocation

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

the class SetRestMonitoringConfigurationCommand method messageSecurityProviderExists.

private boolean messageSecurityProviderExists(ActionReport subActionReport, Subject subject) {
    boolean exists = false;
    CommandInvocation invocation = commandRunner.getCommandInvocation("list-message-security-providers", subActionReport, subject, false);
    ParameterMap parameters = new ParameterMap();
    parameters.add("layer", "HttpServlet");
    invocation.parameters(parameters).execute();
    for (MessagePart message : subActionReport.getTopMessagePart().getChildren()) {
        if (message.getMessage().equals(AUTH_MODULE_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)

Example 2 with CommandInvocation

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

the class UpdateNodeConfigCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    StringBuilder msg = new StringBuilder();
    Node node = null;
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    logger = context.getLogger();
    // Make sure Node is valid
    node = nodes.getNode(name);
    if (node == null) {
        String m = Strings.get("noSuchNode", name);
        logger.warning(m);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(m);
        return;
    }
    if (node.isDefaultLocalNode()) {
        String m = Strings.get("update.node.config.defaultnode", name);
        logger.warning(m);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(m);
        return;
    }
    // After updating the config node it needs to have a host
    if (!StringUtils.ok(nodehost) && !StringUtils.ok(node.getNodeHost())) {
        String m = Strings.get("update.node.config.missing.attribute", node.getName(), NodeUtils.PARAM_NODEHOST);
        logger.warning(m);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(m);
        return;
    }
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", name);
    if (installdir != null) {
        map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
    }
    if (nodehost != null) {
        map.add(NodeUtils.PARAM_NODEHOST, nodehost);
    }
    if (nodedir != null) {
        map.add(NodeUtils.PARAM_NODEDIR, nodedir);
    }
    map.add(NodeUtils.PARAM_TYPE, "CONFIG");
    if (map.size() > 1) {
        CommandInvocation ci = cr.getCommandInvocation("_update-node", report, context.getSubject());
        ci.parameters(map);
        ci.execute();
        if (StringUtils.ok(report.getMessage())) {
            if (msg.length() > 0) {
                msg.append(NL);
            }
            msg.append(report.getMessage());
        }
        report.setMessage(msg.toString());
    }
}
Also used : Node(com.sun.enterprise.config.serverbeans.Node) ActionReport(org.glassfish.api.ActionReport) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 3 with CommandInvocation

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

the class UpdateNodeRemoteCommand method executeInternal.

protected final void executeInternal(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    StringBuilder msg = new StringBuilder();
    Node node = null;
    logger = context.getLogger();
    // Make sure Node is valid
    node = nodes.getNode(name);
    if (node == null) {
        String m = Strings.get("noSuchNode", name);
        logger.warning(m);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(m);
        return;
    }
    if (node.isDefaultLocalNode()) {
        String m = Strings.get("update.node.config.defaultnode", name);
        logger.warning(m);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(m);
        return;
    }
    // Ah the problems caused by hard-coding ssh into parameter names!
    populateParameters();
    // First create a map that holds the parameters and reflects what
    // the user passed on the command line.
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", name);
    map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
    map.add(NodeUtils.PARAM_NODEHOST, nodehost);
    map.add(NodeUtils.PARAM_NODEDIR, nodedir);
    map.add(NodeUtils.PARAM_REMOTEPORT, remotePort);
    map.add(NodeUtils.PARAM_REMOTEUSER, remoteUser);
    map.add(NodeUtils.PARAM_SSHKEYFILE, sshkeyfile);
    map.add(NodeUtils.PARAM_REMOTEPASSWORD, remotepassword);
    map.add(NodeUtils.PARAM_SSHKEYPASSPHRASE, sshkeypassphrase);
    map.add(NodeUtils.PARAM_WINDOWSDOMAINNAME, windowsdomain);
    map.add(NodeUtils.PARAM_TYPE, getType().toString());
    // Now init any parameters that weren't passed into the command
    // using the values from the config
    initFromConfig(node);
    // Finally, anything that still isn't set, use the defaults.
    // These should likely come from config -- but they don't
    // as of now
    setDefaults();
    // validateMap holds the union of what the user passed and what was
    // in the config so we have all the settings needed to validate what
    // the node will look like after we update it.
    ParameterMap validateMap = new ParameterMap();
    validateMap.add(NodeUtils.PARAM_INSTALLDIR, installdir);
    validateMap.add(NodeUtils.PARAM_NODEHOST, nodehost);
    validateMap.add(NodeUtils.PARAM_NODEDIR, nodedir);
    validateMap.add(NodeUtils.PARAM_REMOTEPORT, remotePort);
    validateMap.add(NodeUtils.PARAM_REMOTEUSER, remoteUser);
    validateMap.add(NodeUtils.PARAM_SSHKEYFILE, sshkeyfile);
    validateMap.add(NodeUtils.PARAM_REMOTEPASSWORD, remotepassword);
    validateMap.add(NodeUtils.PARAM_SSHKEYPASSPHRASE, sshkeypassphrase);
    validateMap.add(NodeUtils.PARAM_WINDOWSDOMAINNAME, windowsdomain);
    validateMap.add(NodeUtils.PARAM_TYPE, getType().toString());
    // Validate the settings
    try {
        NodeUtils nodeUtils = new NodeUtils(habitat, logger);
        nodeUtils.validate(validateMap);
    } catch (CommandValidationException e) {
        String m1 = Strings.get("node.ssh.invalid.params");
        if (!force) {
            String m2 = Strings.get("update.node.ssh.not.updated");
            msg.append(StringUtils.cat(NL, m1, m2, e.getMessage()));
            report.setMessage(msg.toString());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        } else {
            String m2 = Strings.get("update.node.ssh.continue.force");
            msg.append(StringUtils.cat(NL, m1, e.getMessage(), m2));
        }
    }
    // Settings are valid. Now use the generic update-node command to
    // update the node.
    CommandInvocation ci = cr.getCommandInvocation("_update-node", report, context.getSubject());
    ci.parameters(map);
    ci.execute();
    if (StringUtils.ok(report.getMessage())) {
        if (msg.length() > 0) {
            msg.append(NL);
        }
        msg.append(report.getMessage());
    }
    report.setMessage(msg.toString());
}
Also used : Node(com.sun.enterprise.config.serverbeans.Node) ActionReport(org.glassfish.api.ActionReport) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 4 with CommandInvocation

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

the class ValidateNodeCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Logger logger = context.getLogger();
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    if (logger.isLoggable(Level.FINE))
        logger.fine(Strings.get("Validating node {0}", name));
    Node node = nodes.getNode(name);
    if (node == null) {
        // node doesn't exist
        String msg = Strings.get("noSuchNode", name);
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    try {
        validateNode(node);
    } catch (CommandValidationException e) {
        logger.warning(e.getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(e.getMessage());
        return;
    }
    if (logger.isLoggable(Level.FINE))
        logger.fine(Strings.get("Node {0} is valid. Updating if needed", name));
    // What is there in the node is valid. Now go update anything that
    // was not there.
    CommandInvocation ci = cr.getCommandInvocation("_update-node", report, context.getSubject());
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", name);
    if (!excludeFromUpdate.contains("installdir"))
        map.add("installdir", installdir);
    if (!excludeFromUpdate.contains("nodehost"))
        map.add("nodehost", nodehost);
    if (!excludeFromUpdate.contains("nodedir"))
        map.add("nodedir", nodedir);
    if (!excludeFromUpdate.contains("sshport"))
        map.add("sshport", sshport);
    if (!excludeFromUpdate.contains("sshuser"))
        map.add("sshuser", sshuser);
    if (!excludeFromUpdate.contains("sshkeyfile"))
        map.add("sshkeyfile", sshkeyfile);
    // Only update if there is something to do
    if (map.size() > 1) {
        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 5 with CommandInvocation

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

the class CreateInstanceCommand method validateInstanceDirUnique.

private void validateInstanceDirUnique(ActionReport report, AdminCommandContext context) {
    CommandInvocation listInstances = cr.getCommandInvocation("list-instances", report, context.getSubject());
    ParameterMap map = new ParameterMap();
    map.add("whichTarget", theNode.getName());
    listInstances.parameters(map);
    listInstances.execute();
    Properties pro = listInstances.report().getExtraProperties();
    if (pro != null) {
        List<HashMap> instanceList = (List<HashMap>) pro.get("instanceList");
        if (instanceList == null)
            return;
        for (HashMap instanceMap : instanceList) {
            final File nodeDirFile = (nodeDir != null ? new File(nodeDir) : defaultLocalNodeDirFile());
            File instanceDir = new File(new File(nodeDirFile.toString(), theNode.getName()), instance);
            String instanceName = (String) instanceMap.get("name");
            File instanceListDir = new File(new File(nodeDirFile.toString(), theNode.getName()), instance);
            if (instance.equalsIgnoreCase(instanceName) && instanceDir.equals(instanceListDir)) {
                String msg = Strings.get("Instance.duplicateInstanceDir", instance, instanceName);
                logger.warning(msg);
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                report.setMessage(msg);
                return;
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties) File(java.io.File) 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