use of com.sun.enterprise.util.cluster.windows.process.WindowsException in project Payara by payara.
the class WindowsRemoteFile method copyFrom.
/**
* If desired -- make this public sometime in the future. For now there is no
* reason to clog up the public namespace with it...
*/
private final void copyFrom(final BufferedInputStream sin, final RemoteFileCopyProgress progress, final long filelength) throws WindowsException {
OutputStream sout = null;
if (sin == null)
throw new NullPointerException("copyFrom stream arg is null");
try {
if (!exists())
createNewFile();
sout = new BufferedOutputStream(smbFile.getOutputStream());
byte[] buf = new byte[getChunkSize(progress, filelength)];
int numBytes = 0;
long totalBytesCopied = 0;
while ((numBytes = sin.read(buf)) >= 0) {
sout.write(buf, 0, numBytes);
totalBytesCopied += numBytes;
// It's OK to send in a null Progress object
if (progress != null)
progress.callback(totalBytesCopied, filelength);
}
} catch (Exception e) {
throw new WindowsException(e);
} finally {
try {
sin.close();
} catch (Exception e) {
// nothing can be done!
}
try {
sout.close();
} catch (Exception e) {
// nothing can be done!
}
}
}
use of com.sun.enterprise.util.cluster.windows.process.WindowsException 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;
}
use of com.sun.enterprise.util.cluster.windows.process.WindowsException in project Payara by payara.
the class ValidateDcom method init.
private boolean init(AdminCommandContext context) {
report = context.getActionReport();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
user = resolver.resolve(user);
password = DcomUtils.resolvePassword(resolver.resolve(password));
if (!ok(password)) {
setError(Strings.get("dcom.nopassword"));
return false;
}
// backslash does not actually matter but it's neater
testdir = resolver.resolve(testdir).replace('/', '\\');
if (testdir.endsWith("\\"))
testdir = testdir.substring(0, testdir.length() - 1);
if (!ok(windowsdomain))
windowsdomain = host;
creds = new WindowsCredentials(host, windowsdomain, user, password);
try {
wrfs = new WindowsRemoteFileSystem(creds);
} catch (WindowsException ex) {
// probably the j-interop-repackagted.jar is missing
setError(ex.getMessage());
return false;
}
scriptFullPath = testdir + "\\" + SCRIPT_NAME;
return true;
}
use of com.sun.enterprise.util.cluster.windows.process.WindowsException in project Payara by payara.
the class StopInstanceCommand method execute.
@Override
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;
}
String nodeName = instance.getNodeRef();
Node node = nodes.getNode(nodeName);
if (node.getType().equals("DOCKER")) {
stopDockerContainer(nodeName, instanceName, context);
}
if (node.getType().equals("TEMP")) {
deleteTempInstance(instanceName, context);
}
// If we've got any sub-command failures, log a warning
if (context.getActionReport().hasFailures()) {
report.setActionExitCode(ActionReport.ExitCode.WARNING);
report.setMessage(Strings.get("stop.instance.warning", instanceName));
} else {
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.
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);
}
}
use of com.sun.enterprise.util.cluster.windows.process.WindowsException 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();
if (allLogFileNames != null) {
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 (String allLogFileName : allLogFileNames) {
File file = new File(allLogFileName);
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;
}
Aggregations