use of org.glassfish.cluster.ssh.launcher.SSHLauncher 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