Search in sources :

Example 6 with WindowsRemoteFile

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

the class LogFilterForInstance method downloadAllInstanceLogFiles.

public void downloadAllInstanceLogFiles(ServiceLocator habitat, Server targetServer, Domain domain, Logger logger, String instanceName, String tempDirectoryOnServer, String instanceLogFileDirectory) throws IOException {
    // method is used from collect-log-files command
    // for Instance it's going through this loop. This will use ssh utility to get file from instance machine(remote machine) and
    // store in  tempDirectoryOnServer which is used to create zip file.
    // Right now user needs to go through this URL to setup and configure ssh http://wikis.sun.com/display/GlassFish/3.1SSHSetup
    SSHLauncher sshL = getSSHL(habitat);
    String sNode = targetServer.getNodeRef();
    Nodes nodes = domain.getNodes();
    Node node = nodes.getNode(sNode);
    if (node.getType().equals("SSH")) {
        sshL.init(node, logger);
        List<String> allInstanceLogFileName = getInstanceLogFileNames(habitat, targetServer, domain, logger, instanceName, instanceLogFileDirectory);
        boolean noFileFound = true;
        String sourceDir = getLoggingDirectoryForNode(instanceLogFileDirectory, node, sNode, instanceName);
        SFTPClient sftpClient = sshL.getSFTPClient();
        try {
            List instanceLogFileNames = sftpClient.ls(sourceDir);
            for (int i = 0; i < instanceLogFileNames.size(); i++) {
                SFTPv3DirectoryEntry file = (SFTPv3DirectoryEntry) instanceLogFileNames.get(i);
                String fileName = file.filename;
                // code to remove . and .. file which is return from sftpclient ls method
                if (!file.attributes.isDirectory() && !fileName.equals(".") && !fileName.equals("..") && fileName.contains(".log") && !fileName.contains(".log.")) {
                    noFileFound = false;
                    break;
                }
            }
        } catch (Exception e) {
            // if directory doesn't present or missing on remote machine. It happens due to bug 16451
            noFileFound = true;
        }
        if (noFileFound) {
            // this loop is used when user has changed value for server.log but not restarted the server.
            sourceDir = getLoggingDirectoryForNodeWhenNoFilesFound(instanceLogFileDirectory, node, sNode, instanceName);
        }
        String[] remoteFileNames = new String[allInstanceLogFileName.size()];
        for (int i = 0; i < allInstanceLogFileName.size(); i++) {
            remoteFileNames[i] = sourceDir + File.separator + allInstanceLogFileName.get(i);
        }
        sftpClient.close();
        SCPClient scpClient = sshL.getSCPClient();
        scpClient.get(remoteFileNames, tempDirectoryOnServer);
    } else if (node.getType().equals("DCOM")) {
        List instanceLogFileNames = getInstanceLogFileNames(habitat, targetServer, domain, logger, instanceName, instanceLogFileDirectory);
        String sourceDir = getLoggingDirectoryForNode(instanceLogFileDirectory, node, sNode, instanceName);
        try {
            DcomInfo info = new DcomInfo(node);
            WindowsRemoteFileSystem wrfs = new WindowsRemoteFileSystem(info.getHost(), info.getUser(), info.getPassword());
            for (int i = 0; i < instanceLogFileNames.size(); i++) {
                String logFileName = (String) instanceLogFileNames.get(i);
                WindowsRemoteFile wrf = new WindowsRemoteFile(wrfs, sourceDir + File.separator + logFileName);
                File instanceLogFile = new File(tempDirectoryOnServer + File.separator + logFileName);
                wrf.copyTo(instanceLogFile);
            }
        } catch (WindowsException ex) {
            throw new IOException("Unable to download instance log file from DCOM Instance Node");
        }
    }
}
Also used : SCPClient(com.trilead.ssh2.SCPClient) SSHLauncher(org.glassfish.cluster.ssh.launcher.SSHLauncher) Node(com.sun.enterprise.config.serverbeans.Node) SFTPClient(org.glassfish.cluster.ssh.sftp.SFTPClient) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException) Nodes(com.sun.enterprise.config.serverbeans.Nodes) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException) DcomInfo(org.glassfish.cluster.ssh.util.DcomInfo) SFTPv3DirectoryEntry(com.trilead.ssh2.SFTPv3DirectoryEntry) WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsRemoteFileSystem(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem) ArrayList(java.util.ArrayList) List(java.util.List) WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile)

Example 7 with WindowsRemoteFile

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

the class LogFilterForInstance method getInstanceLogFileNames.

public List<String> getInstanceLogFileNames(ServiceLocator habitat, Server targetServer, Domain domain, Logger logger, String instanceName, String instanceLogFileDetails) throws IOException {
    // helper method to get all log file names for given instance
    String sNode = targetServer.getNodeRef();
    Node node = domain.getNodes().getNode(sNode);
    List instanceLogFileNames = null;
    List<String> instanceLogFileNamesAsString = new ArrayList();
    // this code is used when DAS and instances are running on the same machine
    if (node.isLocal()) {
        String loggingDir = getLoggingDirectoryForNode(instanceLogFileDetails, node, sNode, instanceName);
        File logsDir = new File(loggingDir);
        File[] allLogFileNames = logsDir.listFiles();
        boolean noFileFound = true;
        if (allLogFileNames != null) {
            // This check for,  if directory doesn't present or missing on machine. It happens due to bug 16451
            for (File file : allLogFileNames) {
                String fileName = file.getName();
                // code to remove . and .. file which is return
                if (file.isFile() && !fileName.equals(".") && !fileName.equals("..") && fileName.contains(".log") && !fileName.contains(".log.")) {
                    instanceLogFileNamesAsString.add(fileName);
                    noFileFound = false;
                }
            }
        }
        if (noFileFound) {
            // this loop is used when user has changed value for server.log but not restarted the server.
            loggingDir = getLoggingDirectoryForNodeWhenNoFilesFound(instanceLogFileDetails, node, sNode, instanceName);
            logsDir = new File(loggingDir);
            allLogFileNames = logsDir.listFiles();
            for (File file : allLogFileNames) {
                String fileName = file.getName();
                // code to remove . and .. file which is return
                if (file.isFile() && !fileName.equals(".") && !fileName.equals("..") && fileName.contains(".log") && !fileName.contains(".log.")) {
                    instanceLogFileNamesAsString.add(fileName);
                }
            }
        }
    } else if (node.getType().equals("SSH")) {
        // this code is used if DAS and instance are running on different machine
        SSHLauncher sshL = getSSHL(habitat);
        sshL.init(node, logger);
        SFTPClient sftpClient = sshL.getSFTPClient();
        boolean noFileFound = true;
        String loggingDir = getLoggingDirectoryForNode(instanceLogFileDetails, node, sNode, instanceName);
        try {
            instanceLogFileNames = sftpClient.ls(loggingDir);
            for (int i = 0; i < instanceLogFileNames.size(); i++) {
                SFTPv3DirectoryEntry file = (SFTPv3DirectoryEntry) instanceLogFileNames.get(i);
                String fileName = file.filename;
                // code to remove . and .. file which is return from sftpclient ls method
                if (!file.attributes.isDirectory() && !fileName.equals(".") && !fileName.equals("..") && fileName.contains(".log") && !fileName.contains(".log.")) {
                    instanceLogFileNamesAsString.add(fileName);
                    noFileFound = false;
                }
            }
        } catch (Exception ex) {
            // if directory doesn't present or missing on remote machine. It happens due to bug 16451
            noFileFound = true;
        }
        if (noFileFound) {
            // this loop is used when user has changed value for server.log but not restarted the server.
            loggingDir = getLoggingDirectoryForNodeWhenNoFilesFound(instanceLogFileDetails, node, sNode, instanceName);
            instanceLogFileNames = sftpClient.ls(loggingDir);
            for (int i = 0; i < instanceLogFileNames.size(); i++) {
                SFTPv3DirectoryEntry file = (SFTPv3DirectoryEntry) instanceLogFileNames.get(i);
                String fileName = file.filename;
                // code to remove . and .. file which is return from sftpclient ls method
                if (!file.attributes.isDirectory() && !fileName.equals(".") && !fileName.equals("..") && fileName.contains(".log") && !fileName.contains(".log.")) {
                    instanceLogFileNamesAsString.add(fileName);
                }
            }
        }
        sftpClient.close();
    } else if (node.getType().equals("DCOM")) {
        String loggingDir = getLoggingDirectoryForNode(instanceLogFileDetails, node, sNode, instanceName);
        try {
            DcomInfo info = new DcomInfo(node);
            WindowsRemoteFileSystem wrfs = new WindowsRemoteFileSystem(info.getHost(), info.getUser(), info.getPassword());
            WindowsRemoteFile wrf = new WindowsRemoteFile(wrfs, loggingDir);
            String[] allLogFileNames = wrf.list();
            for (int i = 0; i < allLogFileNames.length; i++) {
                File file = new File(allLogFileNames[i]);
                String fileName = file.getName();
                // code to remove . and .. file which is return
                if (!fileName.equals(".") && !fileName.equals("..") && fileName.contains(".log") && !fileName.contains(".log.")) {
                    instanceLogFileNamesAsString.add(fileName);
                }
            }
        } catch (WindowsException ex) {
            throw new IOException("Unable to get instance log file names from DCOM Instance Node");
        }
    }
    return instanceLogFileNamesAsString;
}
Also used : SSHLauncher(org.glassfish.cluster.ssh.launcher.SSHLauncher) Node(com.sun.enterprise.config.serverbeans.Node) ArrayList(java.util.ArrayList) SFTPClient(org.glassfish.cluster.ssh.sftp.SFTPClient) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException) DcomInfo(org.glassfish.cluster.ssh.util.DcomInfo) SFTPv3DirectoryEntry(com.trilead.ssh2.SFTPv3DirectoryEntry) WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsRemoteFileSystem(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem) ArrayList(java.util.ArrayList) List(java.util.List) WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile)

Example 8 with WindowsRemoteFile

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

the class InstallNodeDcomCommand method precopy.

/**
 * bnevins: This is exclusively a "user-performance" enhancement.
 * We are forcing the failure
 * to happen before the very very slow zipfile creation.
 * FAIL FAST principle
 * This adds a bit of extra overhead to the command...
 * Note that allowing multiple hosts makes things MUCH more complicated.
 * @throws WindowsException
 */
@Override
final void precopy() throws CommandException {
    remoteInstallDirString = getInstallDir().replace('/', '\\');
    try {
        for (String host : hosts) {
            String remotePassword = getWindowsPassword(host);
            passwords.add(new HostAndPassword(host, remotePassword));
            if (!getForce()) {
                WindowsRemoteFileSystem wrfs = new WindowsRemoteFileSystem(host, getRemoteUser(), remotePassword);
                WindowsRemoteFile remoteInstallDir = new WindowsRemoteFile(wrfs, remoteInstallDirString);
                if (remoteInstallDir.exists())
                    throw new CommandException(Strings.get("install.dir.exists", remoteInstallDir));
            }
        }
    } catch (WindowsException ex) {
        throw new CommandException(ex);
    }
}
Also used : WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsRemoteFileSystem(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem) CommandException(org.glassfish.api.admin.CommandException) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException)

Example 9 with WindowsRemoteFile

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

the class InstallNodeDcomCommand method copyToHostsInternal.

private void copyToHostsInternal(File zipFile, ArrayList<String> binDirFiles) throws CommandException, WindowsException {
    final String zipFileName = "glassfish_install.zip";
    final String unpackScriptName = "unpack.bat";
    for (String host : hosts) {
        String remotePassword = getPassword(host);
        WindowsRemoteFileSystem wrfs = new WindowsRemoteFileSystem(host, getRemoteUser(), remotePassword);
        WindowsRemoteFile remoteInstallDir = new WindowsRemoteFile(wrfs, remoteInstallDirString);
        remoteInstallDir.mkdirs(getForce());
        WindowsRemoteFile remoteZip = new WindowsRemoteFile(remoteInstallDir, zipFileName);
        WindowsRemoteFile unpackScript = new WindowsRemoteFile(remoteInstallDir, unpackScriptName);
        // createUnpackScript
        System.out.printf("Copying %d bytes", zipFile.length());
        remoteZip.copyFrom(zipFile, new RemoteFileCopyProgress() {

            @Override
            public void callback(long numcopied, long numtotal) {
                // final int percent = (int)((double)numcopied / (double)numtotal * 100.0);
                System.out.print(".");
            }

            @Override
            public int getChunkSize() {
                return 1048576;
            }
        });
        System.out.println("");
        String fullZipFileName = remoteInstallDirString + "\\" + zipFileName;
        String fullUnpackScriptPath = remoteInstallDirString + "\\" + unpackScriptName;
        unpackScript.copyFrom(makeScriptString(remoteInstallDirString, zipFileName));
        if (logger.isLoggable(Level.FINE))
            logger.fine("WROTE FILE TO REMOTE SYSTEM: " + fullZipFileName + " and " + fullUnpackScriptPath);
        unpackOnHosts(host, remotePassword, fullUnpackScriptPath.replace('/', '\\'));
    }
}
Also used : WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsRemoteFileSystem(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem) RemoteFileCopyProgress(com.sun.enterprise.util.cluster.windows.io.RemoteFileCopyProgress)

Example 10 with WindowsRemoteFile

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

the class UninstallNodeDcomCommand method deleteFromHosts.

@Override
final void deleteFromHosts() throws CommandException {
    for (String host : hosts) {
        try {
            String pw = getWindowsPassword(host);
            WindowsRemoteFileSystem wrfs = new WindowsRemoteFileSystem(host, getRemoteUser(), pw);
            WindowsRemoteFile remoteInstallDir = new WindowsRemoteFile(wrfs, getInstallDir());
            if (!remoteInstallDir.exists()) {
                throw new CommandException(Strings.get("remote.install.dir.already.gone", getInstallDir()));
            }
            remoteInstallDir.delete();
            // make sure it's gone now...
            if (remoteInstallDir.exists()) {
                throw new CommandException(Strings.get("remote.install.dir.cant.delete", getInstallDir()));
            }
        } catch (CommandException ce) {
            throw ce;
        } catch (Exception e) {
            throw new CommandException(e);
        }
    }
}
Also used : WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsRemoteFileSystem(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem) CommandException(org.glassfish.api.admin.CommandException) CommandException(org.glassfish.api.admin.CommandException)

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