use of alluxio.stress.job.StressBenchConfig in project alluxio by Alluxio.
the class StressBenchDefinition method selectExecutors.
@Override
public Set<Pair<WorkerInfo, ArrayList<String>>> selectExecutors(StressBenchConfig config, List<WorkerInfo> jobWorkerInfoList, SelectExecutorsContext context) {
Set<Pair<WorkerInfo, ArrayList<String>>> result = Sets.newHashSet();
// sort copy of workers by hashcode
List<WorkerInfo> workerList = Lists.newArrayList(jobWorkerInfoList);
workerList.sort(Comparator.comparing(w -> w.getAddress().getHost()));
// take the first subset, according to cluster limit
int clusterLimit = config.getClusterLimit();
if (clusterLimit == 0) {
clusterLimit = workerList.size();
}
if (clusterLimit < 0) {
// if negative, reverse the list
clusterLimit = -clusterLimit;
Collections.reverse(workerList);
}
workerList = workerList.subList(0, clusterLimit);
for (WorkerInfo worker : workerList) {
LOG.info("Generating job for worker {}", worker.getId());
ArrayList<String> args = new ArrayList<>(2);
// Add the worker hostname + worker id as the unique task id for each distributed task.
// The worker id is used since there may be multiple workers on a single host.
args.add(BaseParameters.ID_FLAG);
args.add(worker.getAddress().getHost() + "-" + worker.getId());
result.add(new Pair<>(worker, args));
}
return result;
}
use of alluxio.stress.job.StressBenchConfig in project alluxio by Alluxio.
the class StressBenchDefinition method join.
@Override
public String join(StressBenchConfig config, Map<WorkerInfo, String> taskResults) throws Exception {
if (taskResults.isEmpty()) {
throw new IOException("No results from any workers.");
}
AtomicReference<IOException> error = new AtomicReference<>(null);
List<TaskResult> results = taskResults.entrySet().stream().map(entry -> {
try {
return JsonSerializable.fromJson(entry.getValue().trim(), new TaskResult[0]);
} catch (IOException | ClassNotFoundException e) {
// add log here because the exception details are lost at the client side
LOG.warn("Failed to parse result into class {}", TaskResult.class, e);
error.set(new IOException(String.format("Failed to parse task output from %s into result class %s: %s", entry.getKey().getAddress().getHost(), TaskResult.class, entry.getValue().trim()), e));
}
return null;
}).collect(Collectors.toList());
if (error.get() != null) {
throw error.get();
}
return results.get(0).aggregator().aggregate(results).toJson();
}
Aggregations