Search in sources :

Example 1 with TaskOperationFailure

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"))));
}
Also used : TaskOperationFailure(org.elasticsearch.action.TaskOperationFailure) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) FailedNodeException(org.elasticsearch.action.FailedNodeException)

Example 2 with TaskOperationFailure

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);
}
Also used : TaskOperationFailure(org.elasticsearch.action.TaskOperationFailure) ArrayList(java.util.ArrayList) FailedNodeException(org.elasticsearch.action.FailedNodeException)

Example 3 with TaskOperationFailure

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();
    }
}
Also used : TaskOperationFailure(org.elasticsearch.action.TaskOperationFailure) FailedNodeException(org.elasticsearch.action.FailedNodeException)

Example 4 with TaskOperationFailure

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);
    }
}
Also used : TaskOperationFailure(org.elasticsearch.action.TaskOperationFailure) FailedNodeException(org.elasticsearch.action.FailedNodeException)

Example 5 with TaskOperationFailure

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);
        }
    }
}
Also used : AtomicArray(org.elasticsearch.common.util.concurrent.AtomicArray) ArrayList(java.util.ArrayList) FailedNodeException(org.elasticsearch.action.FailedNodeException) NodeShouldNotConnectException(org.elasticsearch.transport.NodeShouldNotConnectException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) NoSuchNodeException(org.elasticsearch.action.NoSuchNodeException) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException) ActionListener(org.elasticsearch.action.ActionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TaskOperationFailure(org.elasticsearch.action.TaskOperationFailure) Tuple(org.elasticsearch.common.collect.Tuple)

Aggregations

FailedNodeException (org.elasticsearch.action.FailedNodeException)5 TaskOperationFailure (org.elasticsearch.action.TaskOperationFailure)5 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)1 ActionListener (org.elasticsearch.action.ActionListener)1 NoSuchNodeException (org.elasticsearch.action.NoSuchNodeException)1 ListTasksResponse (org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)1 Tuple (org.elasticsearch.common.collect.Tuple)1 AtomicArray (org.elasticsearch.common.util.concurrent.AtomicArray)1 NodeShouldNotConnectException (org.elasticsearch.transport.NodeShouldNotConnectException)1 TransportException (org.elasticsearch.transport.TransportException)1