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;
}
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);
}
}
Aggregations