private WindowsRemoteFile wrf;
public void execute(AdminCommandContext context) {
report = context.getActionReport();
logger = context.getLogger();
SSHLauncher launcher;
int dasPort;
String dasHost;
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);
String nodeHost = node.getNodeHost();
InstanceDirUtils insDU = new InstanceDirUtils(node, serverContext);
// this should be replaced with method from Node config bean.
dasPort = helper.getAdminPort(SystemPropertyConstants.DAS_SERVER_NAME);
dasHost = System.getProperty(SystemPropertyConstants.HOST_NAME_PROPERTY);
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")) {
// create the absolute path to the pid file on the remote host.
String nodeDir = node.getNodeDirAbsolute();
File nodeDirFile = (nodeDir != null ?
new File(nodeDir) :
insDU.defaultLocalNodeDirFile());
String nodeConfigDir = node.getName()+File.separator + instance.getName()+File.separator+"config";
File insDirFile= new File(nodeDirFile, nodeConfigDir);
//use SFTPClient to see if file exists.
launcher = habitat.getComponent(SSHLauncher.class);
launcher.init(node, logger);
try {
// should look for the parent to make sure we have the correct path first
ftpClient = launcher.getSFTPClient();
if (ftpClient.exists(insDirFile.toString())){
// check if file is there
pidFile = new File (insDirFile , "pid");
if (ftpClient.exists(pidFile.toString())){
// server still not down, do we poll?