Search in sources :

Example 6 with SSHLauncher

use of org.glassfish.cluster.ssh.launcher.SSHLauncher in project Payara by payara.

the class StopInstanceCommand method execute.

public void execute(AdminCommandContext context) {
    report = context.getActionReport();
    logger = context.getLogger();
    SSHLauncher launcher;
    if (env.isDas()) {
        if (kill) {
            errorMessage = killInstance(context);
        } else {
            errorMessage = callInstance();
        }
    } else {
        errorMessage = Strings.get("stop.instance.notDas", env.getRuntimeType().toString());
    }
    if (errorMessage == null && !kill) {
        errorMessage = pollForDeath();
    }
    if (errorMessage != null) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(errorMessage);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    report.setMessage(Strings.get("stop.instance.success", instanceName));
    if (kill) {
        // If we killed then stop-local-instance already waited for death
        return;
    }
    // we think the instance is down but it might not be completely down so do further checking
    // get the node name and then the node
    // if localhost check if files exists
    // else if SSH check if file exists  on remote system
    // else can't check anything else.
    String nodeName = instance.getNodeRef();
    Node node = nodes.getNode(nodeName);
    InstanceDirUtils insDU = new InstanceDirUtils(node, serverContext);
    // this should be replaced with method from Node config bean.
    if (node.isLocal()) {
        try {
            pidFile = new File(insDU.getLocalInstanceDir(instance.getName()), "config/pid");
        } catch (java.io.IOException eio) {
            // could not get the file name so can't see if it still exists.  Need to exit
            return;
        }
        if (pidFile.exists()) {
            // server still not down completely, do we poll?
            errorMessage = pollForRealDeath("local");
        }
    } else if (node.getType().equals("SSH")) {
        try {
            pidFile = new File(insDU.getLocalInstanceDir(instance.getName()), "config/pid");
        } catch (java.io.IOException eio) {
            // could not get the file name so can't see if it still exists.  Need to exit
            return;
        }
        // use SFTPClient to see if file exists.
        launcher = habitat.getService(SSHLauncher.class);
        launcher.init(node, logger);
        try {
            ftpClient = launcher.getSFTPClient();
            if (ftpClient.exists(pidFile.toString())) {
                // server still not down, do we poll?
                errorMessage = pollForRealDeath("SSH");
            }
        } catch (IOException ex) {
        // could not get to other host
        } finally {
            if (ftpClient != null) {
                ftpClient.close();
            }
        }
    } else if (node.getType().equals("DCOM")) {
        DcomInfo info;
        try {
            info = new DcomInfo(node);
            String path = info.getRemoteNodeRootDirectory() + "\\config\\pid";
            wrf = new WindowsRemoteFile(info.getCredentials(), path);
            if (wrf.exists())
                errorMessage = pollForRealDeath("DCOM");
        } catch (WindowsException ex) {
        // could not get to other host
        }
    }
    if (errorMessage != null) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(errorMessage);
    }
}
Also used : WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) SSHLauncher(org.glassfish.cluster.ssh.launcher.SSHLauncher) IOException(java.io.IOException) IOException(java.io.IOException) WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) File(java.io.File) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException) DcomInfo(org.glassfish.cluster.ssh.util.DcomInfo)

Aggregations

SSHLauncher (org.glassfish.cluster.ssh.launcher.SSHLauncher)6 WindowsRemoteFile (com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile)4 WindowsException (com.sun.enterprise.util.cluster.windows.process.WindowsException)4 DcomInfo (org.glassfish.cluster.ssh.util.DcomInfo)4 Node (com.sun.enterprise.config.serverbeans.Node)3 WindowsRemoteFileSystem (com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem)3 SFTPv3DirectoryEntry (com.trilead.ssh2.SFTPv3DirectoryEntry)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 SFTPClient (org.glassfish.cluster.ssh.sftp.SFTPClient)3 Nodes (com.sun.enterprise.config.serverbeans.Nodes)2 PasswordAdapter (com.sun.enterprise.security.store.PasswordAdapter)1 SCPClient (com.trilead.ssh2.SCPClient)1 SFTPv3FileAttributes (com.trilead.ssh2.SFTPv3FileAttributes)1 File (java.io.File)1 IOException (java.io.IOException)1