try {
if (h.isQmasterHost() && h.getInstallTimeout() < 360000) {
//Qmaster installation can wait up to 5mins to qmaster to startup
h.setInstallTimeout(Util.DEF_INSTALL_TIMEOUT + 300000);
}
singleThreadPool.execute(new InstallTask(h, this, variablesCopy, localizedMessages));
} catch (RejectedExecutionException e) {
setHostState(h, State.CANCELED);
}
} else if (h.isFirstTask()) {
//This is a first execd/shadowd task and there were no other BDB or qmaster components
//Need to create a first task that will add all hosts as admin hosts
Properties vars = new Properties();
vars.putAll(idata.getVariables());
vars.put(VAR_ALL_ADMIN_HOSTS, Util.listToString(possibleAdminHosts));
vars.setProperty(VAR_ALL_CSPHOSTS, "");
vars.setProperty(VAR_ALL_COPYUSERS, "");
//Only for CSP mode
if (vars.getProperty("add.product.mode").equalsIgnoreCase("csp")) {
List<String> cspList = allHosts;
String allHostsButCurrent = "";
String allUsers = "";
// Construct a reverse odered list so the local host will be the last one
for (int i = cspList.size() - 1; i >= 0; i--) {
allHostsButCurrent += cspList.get(i).trim() + " ";
allUsers += allConnectUsers.get(i).trim() + " ";
}
vars.setProperty(VAR_ALL_CSPHOSTS, allHostsButCurrent.trim());
vars.setProperty(VAR_ALL_COPYUSERS, allUsers.trim());
} else if (vars.getProperty(VAR_SGE_JMX).equalsIgnoreCase("true") && vars.getProperty(VAR_JMX_SSL).equalsIgnoreCase("true")) {
//Copy certs to all shadow hosts (need the keystores to be able to start JMX thread)
String allHostsButCurrent = "";
String allUsers = "";
// Construct a reverse odered list so the local host will be the last one
for (int i = allShadowHosts.size() - 1; i >= 0; i--) {
allHostsButCurrent += allShadowHosts.get(i).trim() + " ";
allUsers += allShadowConnectUsers.get(i).trim() + " ";
}
vars.setProperty(VAR_ALL_CSPHOSTS, allHostsButCurrent.trim());
vars.setProperty(VAR_ALL_COPYUSERS, allUsers.trim());
}
vars.put(VAR_FIRST_TASK, "true");
wait = true;
try {
//And execute the first task in the singleThreadPool
singleThreadPool.execute(new InstallTask(h, this, vars, localizedMessages));
} catch (RejectedExecutionException e) {
setHostState(h, State.CANCELED);
}
} else {
try {
//Only execd get installed in parallel
threadPool.execute(new InstallTask(h, this, variablesCopy, localizedMessages));
} catch (RejectedExecutionException e) {
setHostState(h, State.CANCELED);
}
}
started++;
//In case the task is a BDB or qmaster host, we have to wait for sucessful finish!
while (wait) {
if (singleThreadPool.getCompletedTaskCount() >= completed + 1 && !singleThreadPool.isTerminated()) {
wait = false;
//If bdb, qmaster, prereq tasks fail => it's over!
if (h.getState() != Host.State.SUCCESS) {
for (Host host : installList) {
setHostLog(host, "FAILED: " + MessageFormat.format(localizedMessages.getProperty("msg.previous.dependent.install.failed"), h.getComponentString()));
setHostState(host, State.FAILED_DEPENDENT_ON_PREVIOUS);
}
observer.setTaskCount(-1);
return;
}
completed++;
} else if (singleThreadPool.isTerminated()){
//There is not guarantee that the currently executing task will be interrupted. It may also finish as SUCCESS or FAILED!
for (Host host : installList) {
setHostLog(host, "CANCELED: " + MessageFormat.format(localizedMessages.getProperty("msg.install.canceled"), ""));
setHostState(host, State.CANCELED);
}
observer.setTaskCount(-1);
return;
} else {
try {
Thread.sleep(200);
} catch (InterruptedException ex) {
}
}
}
}
} catch (Exception e) {
Debug.error(e);
} finally {
//Wait until all tasks have finished
while (threadPool.getCompletedTaskCount() + singleThreadPool.getCompletedTaskCount() < started && !(threadPool.isTerminated() && singleThreadPool.isTerminated())) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}
//Execute final task to setup correct submit and remove invalid admin hosts silently on local host
Properties vars = new Properties();
if (lastTaskHost == null) {
Debug.error("lastTaskHost not set!");
throw new IllegalArgumentException("lastTaskHost not set!");
} else if (lastTaskHost.getState() != Host.State.FAILED_DEPENDENT_ON_PREVIOUS) {
//Run the last task only if we have the lastTaskHost and we are not in FAILED_DEPENDENT_ON_PREVIOUS state
vars.putAll(idata.getVariables());
vars.put(VAR_ALL_ADMIN_HOSTS, Util.listToString(adminHosts));
vars.put(VAR_ALL_HOSTS, Util.listToString(allHosts));
vars.put(VAR_ALL_SUBMIT_HOSTS, Util.listToString(submitHosts));
vars.put(VAR_LAST_TASK, "true");
//And execute the last task in the singleThreadPool
try {
singleThreadPool.execute(new InstallTask(lastTaskHost, this, vars, localizedMessages));
} catch (RejectedExecutionException e) {
setHostState(lastTaskHost, State.CANCELED);
}
started++;
//Wait until it's finished