NodeStatusServerAction nodeStatusServerAction = new NodeStatusServerAction();
Long timeoutSeconds = new Long(1);
for (Server server : servers) {
ServerActionBean nodeStatusServerActionBean =
nodeStatusServerAction.getNewServerAction(myServerId, server.getServerId(), timeoutSeconds);
nodeStatusServerActionBean =
APILocator.getServerActionAPI().saveServerActionBean(nodeStatusServerActionBean);
actionBeans.add(nodeStatusServerActionBean);
}
//Waits for 3 seconds in order server respond.
int maxWaitTime =
timeoutSeconds.intValue() * 1000 + Config.getIntProperty("CLUSTER_SERVER_THREAD_SLEEP", 2000) ;
int passedWaitTime = 0;
//Trying to NOT wait whole time for returning the info.
while (passedWaitTime <= maxWaitTime){
try {
Thread.sleep(10);
passedWaitTime += 10;
resultActionBeans = new ArrayList<ServerActionBean>();
//Iterates over the Actions in order to see if we have it all.
for (ServerActionBean actionBean : actionBeans) {
ServerActionBean resultActionBean =
APILocator.getServerActionAPI().findServerActionBean(actionBean.getId());
//Add the ActionBean to the list of results.
if(resultActionBean.isCompleted()){
resultActionBeans.add(resultActionBean);
}
}
//No need to wait if we have all Action results.
if(resultActionBeans.size() == servers.size()){
passedWaitTime = maxWaitTime + 1;
}
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
passedWaitTime = maxWaitTime + 1;
}
}
//If some of the server didn't pick up the action, means they are down.
if(resultActionBeans.size() != actionBeans.size()){
//Need to find out which is missing?
for(ServerActionBean actionBean : actionBeans){
boolean isMissing = true;
for(ServerActionBean resultActionBean : resultActionBeans){
if(resultActionBean.getId().equals(actionBean.getId())){
isMissing = false;
}
}
//If the actionBean wasn't pick up.
if(isMissing){
//We need to save it as failed.
actionBean.setCompleted(true);
actionBean.setFailed(true);
actionBean.setResponse(new JSONObject().put(ServerAction.ERROR_STATE, "Server did NOT respond on time"));
APILocator.getServerActionAPI().saveServerActionBean(actionBean);
//Add it to the results.
resultActionBeans.add(actionBean);
}
}
}
//Iterate over all the results gathered.
for (ServerActionBean resultActionBean : resultActionBeans) {
JSONObject jsonNodeStatusObject = null;
//If the result is failed we need to gather the info available.
if(resultActionBean.isFailed()){
Logger.error(ClusterResource.class,
"Error trying to get Node Status for server " + resultActionBean.getServerId());
jsonNodeStatusObject =
ClusterUtilProxy.createFailedJson(APILocator.getServerAPI().getServer(resultActionBean.getServerId()));
//If the result is OK we need to get the response object.
} else {
jsonNodeStatusObject = resultActionBean.getResponse().getJSONObject(NodeStatusServerAction.JSON_NODE_STATUS);
jsonNodeStatusObject.put("myself", myServerId.equals(resultActionBean.getServerId()));
//Check Test File Asset
if(jsonNodeStatusObject.has("assetsStatus")
&& jsonNodeStatusObject.getString("assetsStatus").equals("green")
&& jsonNodeStatusObject.has("assetsTestPath")){