Search in sources :

Example 1 with WindowsRemoteFile

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

the class NodeUtils method pingDcomConnection.

/**
 * Make sure GF is installed and available.
 *
 * @throws CommandValidationException
 */
void pingDcomConnection(String host, String domain, String username, String password, String installRoot) throws CommandValidationException {
    if (!StringUtils.ok(password)) {
        throw new CommandValidationException(Strings.get("dcom.nopassword"));
    }
    // resolve password aliases
    password = DcomUtils.resolvePassword(resolver.resolve(password));
    if (NetUtils.isThisHostLocal(host)) {
        throw new CommandValidationException(Strings.get("dcom.yes.local", host));
    }
    try {
        installRoot = installRoot.replace('/', '\\');
        WindowsRemoteFileSystem wrfs = new WindowsRemoteFileSystem(host, username, password);
        WindowsRemoteFile wrf = new WindowsRemoteFile(wrfs, installRoot);
        WindowsCredentials creds = new WindowsCredentials(host, domain, username, password);
        // also looking for side-effect of Exception getting thrown...
        if (!wrf.exists()) {
            throw new CommandValidationException(Strings.get("dcom.no.remote.install", host, installRoot));
        }
        if (!WindowsRemotePinger.ping(installRoot, creds)) {
            throw new CommandValidationException(Strings.get("dcom.no.connection", host));
        }
    } catch (CommandValidationException cve) {
        throw cve;
    } catch (Exception ex) {
        throw new CommandValidationException(ex);
    }
}
Also used : WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsRemoteFileSystem(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem) WindowsCredentials(com.sun.enterprise.util.cluster.windows.process.WindowsCredentials) ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with WindowsRemoteFile

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

the class LogFilterForInstance method downloadGivenInstanceLogFile.

public File downloadGivenInstanceLogFile(ServiceLocator habitat, Server targetServer, Domain domain, Logger logger, String instanceName, String domainRoot, String logFileName, String instanceLogFileName) throws IOException {
    File instanceLogFile = null;
    // method is used from logviewer back end code logfilter.
    // for Instance it's going through this loop. This will use ssh utility to get file from instance machine(remote machine) and
    // store in domains/domain1/logs/<instance name> which is used to get LogFile object.
    // 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);
        SFTPClient sftpClient = sshL.getSFTPClient();
        File logFileDirectoryOnServer = makingDirectory(domainRoot + File.separator + "logs" + File.separator + instanceName);
        boolean noFileFound = true;
        String loggingDir = getLoggingDirectoryForNode(instanceLogFileName, node, sNode, instanceName);
        try {
            List 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.")) {
                    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.
            loggingDir = getLoggingDirectoryForNodeWhenNoFilesFound(instanceLogFileName, node, sNode, instanceName);
        }
        String loggingFile = loggingDir + File.separator + logFileName;
        if (!sftpClient.exists(loggingFile)) {
            loggingFile = loggingDir + File.separator + "server.log";
        } else if (!sftpClient.exists(loggingFile)) {
            loggingFile = instanceLogFileName;
        }
        // creating local file name on DAS
        long instanceLogFileSize = 0;
        instanceLogFile = new File(logFileDirectoryOnServer.getAbsolutePath() + File.separator + loggingFile.substring(loggingFile.lastIndexOf(File.separator), loggingFile.length()));
        // getting size of the file on DAS
        if (instanceLogFile.exists()) {
            instanceLogFileSize = instanceLogFile.length();
        }
        SFTPv3FileAttributes sftPv3FileAttributes = sftpClient._stat(loggingFile);
        // getting size of the file on instance machine
        long fileSizeOnNode = sftPv3FileAttributes.size;
        // if differ both size then downloading
        if (instanceLogFileSize != fileSizeOnNode) {
            try (BufferedInputStream in = new BufferedInputStream(sftpClient.read(loggingFile));
                BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(instanceLogFile))) {
                int i;
                while ((i = in.read()) != -1) {
                    out.write(i);
                }
                out.flush();
            }
        }
        sftpClient.close();
    } else if (node.getType().equals("DCOM")) {
        File logFileDirectoryOnServer = makingDirectory(domainRoot + File.separator + "logs" + File.separator + instanceName);
        String loggingDir = getLoggingDirectoryForNode(instanceLogFileName, node, sNode, instanceName);
        try {
            DcomInfo info = new DcomInfo(node);
            WindowsRemoteFileSystem wrfs = new WindowsRemoteFileSystem(info.getHost(), info.getUser(), info.getPassword());
            if (logFileName == null || logFileName.equals("")) {
                logFileName = "server.log";
            }
            WindowsRemoteFile wrf = new WindowsRemoteFile(wrfs, loggingDir + File.separator + logFileName);
            instanceLogFile = new File(logFileDirectoryOnServer + File.separator + logFileName);
            wrf.copyTo(instanceLogFile);
        } catch (WindowsException ex) {
            throw new IOException("Unable to download instance log file from DCOM Instance Node");
        }
    }
    return instanceLogFile;
}
Also used : SSHLauncher(org.glassfish.cluster.ssh.launcher.SSHLauncher) Node(com.sun.enterprise.config.serverbeans.Node) SFTPClient(org.glassfish.cluster.ssh.sftp.SFTPClient) IOException(java.io.IOException) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException) Nodes(com.sun.enterprise.config.serverbeans.Nodes) IOException(java.io.IOException) 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) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) WindowsRemoteFileSystem(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem) ArrayList(java.util.ArrayList) List(java.util.List) SFTPv3FileAttributes(com.trilead.ssh2.SFTPv3FileAttributes) WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with WindowsRemoteFile

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

the class NodeRunnerDcom method setupAuthTokenFile.

/*
     * BE CAREFUL -- Don't introduce "Distributed Concurrency Bugs"
     * e.g. you have to make sure the filename is unique.
     * 1. create a remote file
     * 2. copy the token/auth stuff into it
     * 3. add the correct args to the remote commandline
     *    Put the file in the same directory that nadmin lives in (lib)
     */
private void setupAuthTokenFile(List<String> cmd, List<String> stdin) throws WindowsException {
    WindowsRemoteFileSystem wrfs = new WindowsRemoteFileSystem(dcomInfo.getCredentials());
    authTokenFilePath = dcomInfo.getNadminParentPath() + "\\token_" + System.nanoTime() + new SecureRandom().nextInt(1000);
    authTokenFilePath = createUniqueFilename(dcomInfo.getNadminParentPath());
    authTokenFile = new WindowsRemoteFile(wrfs, authTokenFilePath);
    authTokenFile.copyFrom(stdin);
    cmd.add(AsadminInput.CLI_INPUT_OPTION);
    cmd.add(authTokenFilePath);
}
Also used : WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsRemoteFileSystem(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem) SecureRandom(java.security.SecureRandom)

Example 4 with WindowsRemoteFile

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

the class ValidateDcom method testDcomFileWrite.

private boolean testDcomFileWrite() {
    try {
        script = new WindowsRemoteFile(wrf, SCRIPT_NAME);
        script.copyFrom("dir " + testdir + "\\\n");
        out.append(Strings.get("dcom.write.ok", SCRIPT_NAME, testdir, host)).append('\n');
    } catch (WindowsException ex) {
        setError(ex, Strings.get("dcom.no.write", SCRIPT_NAME, testdir, host));
        return false;
    }
    return true;
}
Also used : WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException)

Example 5 with WindowsRemoteFile

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

the class ValidateDcom method testJdkAvailable.

private boolean testJdkAvailable() {
    try {
        script = new WindowsRemoteFile(wrf, SCRIPT_NAME);
        script.copyFrom("javac -version \r\n");
        WindowsRemoteScripter scripter = new WindowsRemoteScripter(creds);
        // javac and jar write to stderr NOT stdout
        scripter.wantStdErr();
        String scriptOut = scripter.run(scriptFullPath);
        script.delete();
        out.append(Strings.get("dcom.yes.jdk", host, scriptOut));
        out.append('\n');
        return true;
    } catch (WindowsException ex) {
        setError(ex, Strings.get("dcom.no.jdk", host));
        return false;
    }
}
Also used : WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsRemoteScripter(com.sun.enterprise.util.cluster.windows.process.WindowsRemoteScripter) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException)

Aggregations

WindowsRemoteFile (com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile)12 WindowsRemoteFileSystem (com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem)8 WindowsException (com.sun.enterprise.util.cluster.windows.process.WindowsException)8 IOException (java.io.IOException)5 File (java.io.File)4 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 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