use of org.elasticsearch.action.TaskOperationFailure in project elasticsearch by elastic.
the class TransportRethrottleActionTests method testRethrottleTaskOperationFailure.
public void testRethrottleTaskOperationFailure() {
Exception e = new Exception();
TaskOperationFailure failure = new TaskOperationFailure("test", 123, e);
rethrottleTestCase(slices, listener -> listener.onResponse(new ListTasksResponse(emptyList(), singletonList(failure), emptyList())), expectException(hasToString(containsString("Rethrottle of [test:123] failed"))));
}
use of org.elasticsearch.action.TaskOperationFailure in project elasticsearch by elastic.
the class BaseTasksResponse method readFrom.
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
int size = in.readVInt();
List<TaskOperationFailure> taskFailures = new ArrayList<>();
for (int i = 0; i < size; i++) {
taskFailures.add(new TaskOperationFailure(in));
}
size = in.readVInt();
this.taskFailures = Collections.unmodifiableList(taskFailures);
List<FailedNodeException> nodeFailures = new ArrayList<>();
for (int i = 0; i < size; i++) {
nodeFailures.add(new FailedNodeException(in));
}
this.nodeFailures = Collections.unmodifiableList(nodeFailures);
}
use of org.elasticsearch.action.TaskOperationFailure in project elasticsearch by elastic.
the class ListTasksResponse method toXContentCommon.
private void toXContentCommon(XContentBuilder builder, Params params) throws IOException {
if (getTaskFailures() != null && getTaskFailures().size() > 0) {
builder.startArray("task_failures");
for (TaskOperationFailure ex : getTaskFailures()) {
builder.startObject();
builder.value(ex);
builder.endObject();
}
builder.endArray();
}
if (getNodeFailures() != null && getNodeFailures().size() > 0) {
builder.startArray("node_failures");
for (FailedNodeException ex : getNodeFailures()) {
builder.startObject();
ex.toXContent(builder, params);
builder.endObject();
}
builder.endArray();
}
}
use of org.elasticsearch.action.TaskOperationFailure in project elasticsearch by elastic.
the class BaseTasksResponse method writeTo.
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(taskFailures.size());
for (TaskOperationFailure exp : taskFailures) {
exp.writeTo(out);
}
out.writeVInt(nodeFailures.size());
for (FailedNodeException exp : nodeFailures) {
exp.writeTo(out);
}
}
use of org.elasticsearch.action.TaskOperationFailure in project elasticsearch by elastic.
the class TransportTasksAction method nodeOperation.
private void nodeOperation(NodeTaskRequest nodeTaskRequest, ActionListener<NodeTasksResponse> listener) {
TasksRequest request = nodeTaskRequest.tasksRequest;
List<OperationTask> tasks = new ArrayList<>();
processTasks(request, tasks::add);
if (tasks.isEmpty()) {
listener.onResponse(new NodeTasksResponse(clusterService.localNode().getId(), emptyList(), emptyList()));
return;
}
AtomicArray<Tuple<TaskResponse, Exception>> responses = new AtomicArray<>(tasks.size());
final AtomicInteger counter = new AtomicInteger(tasks.size());
for (int i = 0; i < tasks.size(); i++) {
final int taskIndex = i;
ActionListener<TaskResponse> taskListener = new ActionListener<TaskResponse>() {
@Override
public void onResponse(TaskResponse response) {
responses.setOnce(taskIndex, response == null ? null : new Tuple<>(response, null));
respondIfFinished();
}
@Override
public void onFailure(Exception e) {
responses.setOnce(taskIndex, new Tuple<>(null, e));
respondIfFinished();
}
private void respondIfFinished() {
if (counter.decrementAndGet() != 0) {
return;
}
List<TaskResponse> results = new ArrayList<>();
List<TaskOperationFailure> exceptions = new ArrayList<>();
for (AtomicArray.Entry<Tuple<TaskResponse, Exception>> response : responses.asList()) {
if (response.value.v1() == null) {
assert response.value.v2() != null;
exceptions.add(new TaskOperationFailure(clusterService.localNode().getId(), tasks.get(taskIndex).getId(), response.value.v2()));
} else {
assert response.value.v2() == null;
results.add(response.value.v1());
}
}
listener.onResponse(new NodeTasksResponse(clusterService.localNode().getId(), results, exceptions));
}
};
try {
taskOperation(request, tasks.get(taskIndex), taskListener);
} catch (Exception e) {
taskListener.onFailure(e);
}
}
}
Aggregations