private void execute(TaskInProgress tip, GroomServerStatus status) {
Task task = tip.constructTask(status);
GroomServerAction[] actions;
GroomProtocol worker = groomServerManager.get().findGroomServer(status);
if (!recoveryTasks.contains(tip)) {
actions = new GroomServerAction[1];
actions[0] = new LaunchTaskAction(task);
} else {
LOG.trace("Executing a recovery task");
recoveryTasks.remove(tip);
HashMap<String, GroomServerStatus> groomStatuses = new HashMap<String, GroomServerStatus>(
1);
groomStatuses.put(status.hostName, status);
Map<GroomServerStatus, List<GroomServerAction>> actionMap = new HashMap<GroomServerStatus, List<GroomServerAction>>(
2 * groomStatuses.size());
try {
tip.getJob().recoverTasks(groomStatuses, actionMap);
} catch (IOException e) {
LOG.warn("Task recovery failed", e);
}
List<GroomServerAction> actionList = actionMap.get(status);
actions = new GroomServerAction[actionList.size()];
actionList.toArray(actions);
}
Directive d1 = new DispatchTasksDirective(actions);
try {
worker.dispatch(d1);
} catch (IOException ioe) {
LOG.error(
"Fail to dispatch tasks to GroomServer " + status.getGroomName(), ioe);
}
}