if (specialCaseIndex < 1 || specialCaseIndex > 3) {
LOG.error("Invalid special case index: " + specialCaseIndex);
}
// No tasks have preferences and we have the magic number of tasks
TSchedulingRequest newReq = new TSchedulingRequest();
newReq.user = req.user;
newReq.app = req.app;
newReq.probeRatio = req.probeRatio;
List<InetSocketAddress> allBackends = Lists.newArrayList();
List<InetSocketAddress> backends = Lists.newArrayList();
// We assume the below always returns the same order (invalid assumption?)
for (InetSocketAddress backend : state.getBackends(req.app)) {
allBackends.add(backend);
}
// Each time this is called, we restrict to 1/3 of the nodes in the cluster
for (int i = 0; i < allBackends.size(); i++) {
if (i % 3 == specialCaseIndex - 1) {
backends.add(allBackends.get(i));
}
}
Collections.shuffle(backends);
if (!(allBackends.size() >= (req.getTasks().size() * 3))) {
LOG.error("Special case expects at least three times as many machines as tasks.");
return null;
}
LOG.info(backends);
for (int i = 0; i < req.getTasksSize(); i++) {
TTaskSpec task = req.getTasks().get(i);
TTaskSpec newTask = new TTaskSpec();
newTask.message = task.message;
newTask.taskId = task.taskId;
newTask.preference = new TPlacementPreference();
newTask.preference.addToNodes(backends.get(i).getHostName());
newReq.addToTasks(newTask);
}
LOG.info("New request: " + newReq);
return newReq;
}