Search in sources :

Example 11 with WindowsRemoteFile

use of com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile in project Payara by payara.

the class NodeRunnerDcom method determineStatus.

/* hack TODO do not know how to get int status back from Windows
     * Stick in code that handles particular commands that we can figure out
     * the status.
     */
private int determineStatus(List<String> args) {
    if (args == null)
        throw new NullPointerException();
    if (args.size() < 2)
        return 0;
    String instanceName = args.get(args.size() - 1);
    if (isCommand(args, "_delete-instance-filesystem")) {
        try {
            String dir = Paths.getInstanceDirPath(node, instanceName);
            WindowsRemoteFile instanceDir = new WindowsRemoteFile(dcomInfo.getCredentials(), dir);
            return instanceDir.exists() ? 1 : 0;
        } catch (WindowsException ex) {
            return 0;
        }
    } else if (isCommand(args, "_create-instance-filesystem")) {
        try {
            String dir = Paths.getDasPropsPath(node);
            WindowsRemoteFile dasProps = new WindowsRemoteFile(dcomInfo.getCredentials(), dir);
            if (dasProps.exists())
                return 0;
            // uh-oh.  Wipe out the instance directory that was created
            dir = Paths.getInstanceDirPath(node, instanceName);
            WindowsRemoteFile instanceDir = new WindowsRemoteFile(dcomInfo.getCredentials(), dir);
            instanceDir.delete();
            return 1;
        } catch (WindowsException ex) {
            return 1;
        }
    }
    return 0;
}
Also used : WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException)

Example 12 with WindowsRemoteFile

use of com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile 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

WindowsRemoteFile (com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile)12 WindowsException (com.sun.enterprise.util.cluster.windows.process.WindowsException)9 WindowsRemoteFileSystem (com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem)8 SSHLauncher (org.glassfish.cluster.ssh.launcher.SSHLauncher)4 DcomInfo (org.glassfish.cluster.ssh.util.DcomInfo)4 Node (com.sun.enterprise.config.serverbeans.Node)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 IOException (java.io.IOException)2 CommandException (org.glassfish.api.admin.CommandException)2 ProcessManagerException (com.sun.enterprise.universal.process.ProcessManagerException)1 RemoteFileCopyProgress (com.sun.enterprise.util.cluster.windows.io.RemoteFileCopyProgress)1 WindowsCredentials (com.sun.enterprise.util.cluster.windows.process.WindowsCredentials)1 WindowsRemoteScripter (com.sun.enterprise.util.cluster.windows.process.WindowsRemoteScripter)1 SCPClient (com.trilead.ssh2.SCPClient)1 SFTPv3FileAttributes (com.trilead.ssh2.SFTPv3FileAttributes)1 File (java.io.File)1