Search in sources :

Example 1 with SshConnector

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

the class UpdateNodeRemoteCommand method initFromConfig.

/**
 * Initialize any parameters not provided by the user from the
 * configuration.
 */
private void initFromConfig(Node node) {
    if (nodehost == null) {
        nodehost = node.getNodeHost();
    }
    if (installdir == null) {
        installdir = node.getInstallDir();
    }
    if (nodedir == null) {
        nodedir = node.getNodeDir();
    }
    if (windowsdomain == null) {
        windowsdomain = node.getWindowsDomain();
        if (windowsdomain == null) {
            windowsdomain = node.getNodeHost();
        }
    }
    SshConnector sshc = node.getSshConnector();
    if (sshc == null) {
        return;
    }
    if (remotePort == null) {
        remotePort = sshc.getSshPort();
    }
    SshAuth ssha = sshc.getSshAuth();
    if (ssha == null) {
        return;
    }
    if (remoteUser == null) {
        remoteUser = ssha.getUserName();
    }
    if (sshkeyfile == null) {
        sshkeyfile = ssha.getKeyfile();
    }
    if (remotepassword == null) {
        remotepassword = ssha.getPassword();
    }
    if (sshkeypassphrase == null) {
        sshkeypassphrase = ssha.getPassword();
    }
}
Also used : SshConnector(com.sun.enterprise.config.serverbeans.SshConnector) SshAuth(com.sun.enterprise.config.serverbeans.SshAuth)

Example 2 with SshConnector

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

the class NodeUtils method validate.

void validate(Node node) throws CommandValidationException {
    // Put node values into parameter map and validate
    ParameterMap map = new ParameterMap();
    map.add("DEFAULT", node.getName());
    map.add(NodeUtils.PARAM_INSTALLDIR, node.getInstallDir());
    map.add(NodeUtils.PARAM_NODEHOST, node.getNodeHost());
    map.add(NodeUtils.PARAM_NODEDIR, node.getNodeDirAbsolute());
    SshConnector sshc = node.getSshConnector();
    if (sshc != null) {
        map.add(NodeUtils.PARAM_REMOTEPORT, sshc.getSshPort());
        SshAuth ssha = sshc.getSshAuth();
        map.add(NodeUtils.PARAM_REMOTEUSER, ssha.getUserName());
        map.add(NodeUtils.PARAM_SSHKEYFILE, ssha.getKeyfile());
        map.add(NodeUtils.PARAM_SSHPASSWORD, ssha.getPassword());
        map.add(NodeUtils.PARAM_SSHKEYPASSPHRASE, ssha.getKeyPassphrase());
        map.add(NodeUtils.PARAM_TYPE, node.getType());
    }
    validate(map);
}
Also used : SshConnector(com.sun.enterprise.config.serverbeans.SshConnector) SshAuth(com.sun.enterprise.config.serverbeans.SshAuth)

Example 3 with SshConnector

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

the class SSHLauncher method init.

/**
 * Initialize the SSHLauncher use a Node config object
 * @param node
 * @param logger
 */
public void init(Node node, Logger logger) {
    this.logger = logger;
    int port;
    String host;
    SshConnector connector = node.getSshConnector();
    host = connector.getSshHost();
    if (SSHUtil.checkString(host) != null) {
        this.host = host;
    } else {
        this.host = node.getNodeHost();
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Connecting to host " + host);
    }
    // XXX Why do we need this again?  This is already done above and set to host
    String sshHost = connector.getSshHost();
    if (sshHost != null)
        this.host = sshHost;
    SshAuth sshAuth = connector.getSshAuth();
    String userName = null;
    if (sshAuth != null) {
        userName = sshAuth.getUserName();
        this.keyFile = sshAuth.getKeyfile();
        this.rawPassword = sshAuth.getPassword();
        this.rawKeyPassPhrase = sshAuth.getKeyPassphrase();
    }
    try {
        port = Integer.parseInt(connector.getSshPort());
    } catch (NumberFormatException nfe) {
        port = 22;
    }
    init(userName, this.host, port, this.rawPassword, keyFile, this.rawKeyPassPhrase, logger);
}
Also used : SshConnector(com.sun.enterprise.config.serverbeans.SshConnector) SshAuth(com.sun.enterprise.config.serverbeans.SshAuth)

Example 4 with SshConnector

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

the class UpdateNodeCommand method updateNodeElement.

private void updateNodeElement(final String nodeName) throws TransactionFailure {
    LOG.fine(() -> String.format("updateNodeElement(nodeName=%s)", nodeName));
    ConfigSupport.apply(new SingleConfigCode() {

        @Override
        public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
            Transaction t = Transaction.getTransaction(param);
            if (t != null) {
                Nodes nodes = ((Domain) param).getNodes();
                Node node = nodes.getNode(nodeName);
                Node writeableNode = t.enroll(node);
                if (windowsdomain != null) {
                    writeableNode.setWindowsDomain(windowsdomain);
                }
                if (nodedir != null) {
                    writeableNode.setNodeDir(nodedir);
                }
                if (nodehost != null) {
                    writeableNode.setNodeHost(nodehost);
                }
                if (installdir != null) {
                    writeableNode.setInstallDir(installdir);
                }
                if (type != null) {
                    writeableNode.setType(type);
                }
                if (RemoteType.SSH.name().equals(type) || RemoteType.DCOM.name().equals(type)) {
                    SshConnector sshConnector = writeableNode.getSshConnector();
                    if (sshConnector == null) {
                        sshConnector = writeableNode.createChild(SshConnector.class);
                    } else {
                        sshConnector = t.enroll(sshConnector);
                    }
                    if (sshport != null) {
                        sshConnector.setSshPort(sshport);
                    }
                    if (sshnodehost != null) {
                        sshConnector.setSshHost(sshnodehost);
                    }
                    writeableNode.setSshConnector(sshConnector);
                    if (// 
                    sshAuthType != null || sshuser != null || sshkeyfile != null || sshpassword != null || sshkeypassphrase != null) {
                        SshAuth sshAuth = sshConnector.getSshAuth();
                        if (sshAuth == null) {
                            sshAuth = sshConnector.createChild(SshAuth.class);
                        } else {
                            sshAuth = t.enroll(sshAuth);
                        }
                        if (sshuser != null) {
                            sshAuth.setUserName(sshuser);
                        }
                        if (sshkeypassphrase != null) {
                            sshAuth.setKeyPassphrase(sshkeypassphrase);
                        }
                        if (sshAuthType == null) {
                            // if both set, keyfile wins
                            if (sshpassword != null) {
                                sshAuth.setKeyfile(null);
                                sshAuth.setPassword(sshpassword);
                            }
                            if (sshkeyfile != null) {
                                sshAuth.setKeyfile(sshkeyfile);
                                sshAuth.setPassword(null);
                            }
                        } else {
                            if (SshAuthType.KEY.name().equals(sshAuthType)) {
                                // keyfile is set even if null, it would not be possible to
                                // return to default from UI otherwise
                                sshAuth.setKeyfile(sshkeyfile);
                                sshAuth.setPassword(null);
                            } else if (SshAuthType.PASSWORD.name().equals(sshAuthType)) {
                                sshAuth.setKeyfile(null);
                                sshAuth.setKeyPassphrase(null);
                                if (sshpassword != null) {
                                    sshAuth.setPassword(sshpassword);
                                }
                            }
                        }
                        sshConnector.setSshAuth(sshAuth);
                    }
                }
                if (dockerImage != null) {
                    writeableNode.setDockerImage(dockerImage);
                }
                if (dockerPasswordFile != null) {
                    writeableNode.setDockerPasswordFile(dockerPasswordFile);
                }
                if (dockerPort != null) {
                    writeableNode.setDockerPort(Integer.toString(dockerPort));
                }
                if (useTls != null) {
                    writeableNode.setUseTls(useTls);
                }
            }
            return Boolean.TRUE;
        }
    }, domain);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) SshConnector(com.sun.enterprise.config.serverbeans.SshConnector) Transaction(org.jvnet.hk2.config.Transaction) Node(com.sun.enterprise.config.serverbeans.Node) SshAuth(com.sun.enterprise.config.serverbeans.SshAuth) Nodes(com.sun.enterprise.config.serverbeans.Nodes)

Example 5 with SshConnector

use of com.sun.enterprise.config.serverbeans.SshConnector 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(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(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(PARAM_SSHPASSWORD, sshAuth.getPassword());
        }
        if (sshAuth.getKeyPassphrase() != null) {
            info.add(PARAM_SSHKEYPASSPHRASE, sshAuth.getKeyPassphrase());
        }
        if (sshAuth.getKeyfile() != null) {
            info.add(PARAM_SSHKEYFILE, sshAuth.getKeyfile());
        }
        info.add(PARAM_INSTALLDIR, node.getInstallDir());
        info.add(PARAM_REMOTEPORT, sshC.getSshPort());
        info.add(PARAM_REMOTEUSER, sshAuth.getUserName());
        info.add(PARAM_NODEHOST, node.getNodeHost());
        info.add(PARAM_WINDOWS_DOMAIN, node.getWindowsDomain());
    }
    CommandInvocation commandInvocation = commandRunner.getCommandInvocation("_delete-node", report, context.getSubject());
    ParameterMap commandParameters = new ParameterMap();
    commandParameters.add("DEFAULT", name);
    commandInvocation.parameters(commandParameters);
    commandInvocation.execute();
    // Uninstall Payara after deleting the node
    if (uninstall) {
        if (!uninstallNode(context, info, node) && !force) {
            report.setActionExitCode(FAILURE);
            return;
        }
    }
}
Also used : SshConnector(com.sun.enterprise.config.serverbeans.SshConnector) Node(com.sun.enterprise.config.serverbeans.Node) ParameterMap(org.glassfish.api.admin.ParameterMap) SshAuth(com.sun.enterprise.config.serverbeans.SshAuth) ActionReport(org.glassfish.api.ActionReport) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Aggregations

SshAuth (com.sun.enterprise.config.serverbeans.SshAuth)7 SshConnector (com.sun.enterprise.config.serverbeans.SshConnector)7 Node (com.sun.enterprise.config.serverbeans.Node)2 ParameterMap (org.glassfish.api.admin.ParameterMap)2 Nodes (com.sun.enterprise.config.serverbeans.Nodes)1 ProcessManagerException (com.sun.enterprise.universal.process.ProcessManagerException)1 PropertyVetoException (java.beans.PropertyVetoException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 ActionReport (org.glassfish.api.ActionReport)1 CommandInvocation (org.glassfish.api.admin.CommandRunner.CommandInvocation)1 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)1 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)1 Transaction (org.jvnet.hk2.config.Transaction)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1