use of com.sun.enterprise.util.cluster.windows.process.WindowsException 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");
}
}
}
Aggregations