Search in sources :

Example 1 with TaskOperationFailure

use of org.opensearch.action.TaskOperationFailure in project OpenSearch by opensearch-project.

the class CancelTasksResponseTests method assertInstances.

@Override
protected void assertInstances(ByNodeCancelTasksResponse serverTestInstance, org.opensearch.client.tasks.CancelTasksResponse clientInstance) {
    // checking tasks
    List<TaskInfo> sTasks = serverTestInstance.getTasks();
    List<org.opensearch.client.tasks.TaskInfo> cTasks = clientInstance.getTasks();
    Map<org.opensearch.client.tasks.TaskId, org.opensearch.client.tasks.TaskInfo> cTasksMap = cTasks.stream().collect(Collectors.toMap(org.opensearch.client.tasks.TaskInfo::getTaskId, Function.identity()));
    for (TaskInfo ti : sTasks) {
        org.opensearch.client.tasks.TaskInfo taskInfo = cTasksMap.get(new org.opensearch.client.tasks.TaskId(ti.getTaskId().getNodeId(), ti.getTaskId().getId()));
        assertEquals(ti.getAction(), taskInfo.getAction());
        assertEquals(ti.getDescription(), taskInfo.getDescription());
        assertEquals(new HashMap<>(ti.getHeaders()), new HashMap<>(taskInfo.getHeaders()));
        assertEquals(ti.getType(), taskInfo.getType());
        assertEquals(ti.getStartTime(), taskInfo.getStartTime());
        assertEquals(ti.getRunningTimeNanos(), taskInfo.getRunningTimeNanos());
        assertEquals(ti.isCancellable(), taskInfo.isCancellable());
        assertEquals(ti.isCancelled(), taskInfo.isCancelled());
        assertEquals(ti.getParentTaskId().getNodeId(), taskInfo.getParentTaskId().getNodeId());
        assertEquals(ti.getParentTaskId().getId(), taskInfo.getParentTaskId().getId());
        FakeTaskStatus status = (FakeTaskStatus) ti.getStatus();
        assertEquals(status.code, taskInfo.getStatus().get("code"));
        assertEquals(status.status, taskInfo.getStatus().get("status"));
    }
    // checking failures
    List<OpenSearchException> serverNodeFailures = serverTestInstance.getNodeFailures();
    List<org.opensearch.client.tasks.OpenSearchException> cNodeFailures = clientInstance.getNodeFailures();
    List<String> sExceptionsMessages = serverNodeFailures.stream().map(x -> org.opensearch.client.tasks.OpenSearchException.buildMessage("exception", x.getMessage(), null)).collect(Collectors.toList());
    List<String> cExceptionsMessages = cNodeFailures.stream().map(org.opensearch.client.tasks.OpenSearchException::getMsg).collect(Collectors.toList());
    assertEquals(new HashSet<>(sExceptionsMessages), new HashSet<>(cExceptionsMessages));
    List<TaskOperationFailure> sTaskFailures = serverTestInstance.getTaskFailures();
    List<org.opensearch.client.tasks.TaskOperationFailure> cTaskFailures = clientInstance.getTaskFailures();
    Map<Long, org.opensearch.client.tasks.TaskOperationFailure> cTasksFailuresMap = cTaskFailures.stream().collect(Collectors.toMap(org.opensearch.client.tasks.TaskOperationFailure::getTaskId, Function.identity()));
    for (TaskOperationFailure tof : sTaskFailures) {
        org.opensearch.client.tasks.TaskOperationFailure failure = cTasksFailuresMap.get(tof.getTaskId());
        assertEquals(tof.getNodeId(), failure.getNodeId());
        assertTrue(failure.getReason().getMsg().contains("runtime_exception"));
        assertTrue(failure.getStatus().contains("" + tof.getStatus().name()));
    }
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) AbstractResponseTestCase(org.opensearch.client.AbstractResponseTestCase) Version(org.opensearch.Version) StreamOutput(org.opensearch.common.io.stream.StreamOutput) HashMap(java.util.HashMap) OpenSearchException(org.opensearch.OpenSearchException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) XContentParser(org.opensearch.common.xcontent.XContentParser) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Map(java.util.Map) CancelTasksResponse(org.opensearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) TaskId(org.opensearch.tasks.TaskId) IOException(java.io.IOException) Task(org.opensearch.tasks.Task) Collectors(java.util.stream.Collectors) TransportAddress(org.opensearch.common.transport.TransportAddress) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) TaskInfo(org.opensearch.tasks.TaskInfo) List(java.util.List) TaskOperationFailure(org.opensearch.action.TaskOperationFailure) XContentType(org.opensearch.common.xcontent.XContentType) Collections(java.util.Collections) TaskId(org.opensearch.tasks.TaskId) TaskInfo(org.opensearch.tasks.TaskInfo) TaskOperationFailure(org.opensearch.action.TaskOperationFailure) OpenSearchException(org.opensearch.OpenSearchException)

Example 2 with TaskOperationFailure

use of org.opensearch.action.TaskOperationFailure in project OpenSearch by opensearch-project.

the class CancelTasksResponseTests method createServerTestInstance.

@Override
protected CancelTasksResponseTests.ByNodeCancelTasksResponse createServerTestInstance(XContentType xContentType) {
    List<org.opensearch.tasks.TaskInfo> tasks = new ArrayList<>();
    List<TaskOperationFailure> taskFailures = new ArrayList<>();
    List<OpenSearchException> nodeFailures = new ArrayList<>();
    for (int i = 0; i < randomIntBetween(1, 4); i++) {
        taskFailures.add(new TaskOperationFailure(randomAlphaOfLength(4), (long) i, new RuntimeException(randomAlphaOfLength(4))));
    }
    for (int i = 0; i < randomIntBetween(1, 4); i++) {
        nodeFailures.add(new OpenSearchException(new RuntimeException(randomAlphaOfLength(10))));
    }
    for (int i = 0; i < 4; i++) {
        boolean cancellable = randomBoolean();
        boolean cancelled = cancellable == true ? randomBoolean() : false;
        tasks.add(new org.opensearch.tasks.TaskInfo(new TaskId(NODE_ID, (long) i), randomAlphaOfLength(4), randomAlphaOfLength(4), randomAlphaOfLength(10), new FakeTaskStatus(randomAlphaOfLength(4), randomInt()), randomLongBetween(1, 3), randomIntBetween(5, 10), cancellable, cancelled, new TaskId("node1", randomLong()), Collections.singletonMap("x-header-of", "some-value")));
    }
    return new ByNodeCancelTasksResponse(tasks, taskFailures, nodeFailures);
}
Also used : TaskId(org.opensearch.tasks.TaskId) ArrayList(java.util.ArrayList) TaskInfo(org.opensearch.tasks.TaskInfo) TaskInfo(org.opensearch.tasks.TaskInfo) TaskOperationFailure(org.opensearch.action.TaskOperationFailure) OpenSearchException(org.opensearch.OpenSearchException)

Example 3 with TaskOperationFailure

use of org.opensearch.action.TaskOperationFailure in project OpenSearch by opensearch-project.

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.opensearch.action.TaskOperationFailure) ListTasksResponse(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse) FailedNodeException(org.opensearch.action.FailedNodeException)

Example 4 with TaskOperationFailure

use of org.opensearch.action.TaskOperationFailure in project OpenSearch by opensearch-project.

the class ListTasksResponse method setupParser.

protected static <T> ConstructingObjectParser<T, Void> setupParser(String name, TriFunction<List<TaskInfo>, List<TaskOperationFailure>, List<OpenSearchException>, T> ctor) {
    ConstructingObjectParser<T, Void> parser = new ConstructingObjectParser<>(name, true, constructingObjects -> {
        int i = 0;
        @SuppressWarnings("unchecked") List<TaskInfo> tasks = (List<TaskInfo>) constructingObjects[i++];
        @SuppressWarnings("unchecked") List<TaskOperationFailure> tasksFailures = (List<TaskOperationFailure>) constructingObjects[i++];
        @SuppressWarnings("unchecked") List<OpenSearchException> nodeFailures = (List<OpenSearchException>) constructingObjects[i];
        return ctor.apply(tasks, tasksFailures, nodeFailures);
    });
    parser.declareObjectArray(optionalConstructorArg(), TaskInfo.PARSER, new ParseField(TASKS));
    parser.declareObjectArray(optionalConstructorArg(), (p, c) -> TaskOperationFailure.fromXContent(p), new ParseField(TASK_FAILURES));
    parser.declareObjectArray(optionalConstructorArg(), (p, c) -> OpenSearchException.fromXContent(p), new ParseField(NODE_FAILURES));
    return parser;
}
Also used : ConstructingObjectParser(org.opensearch.common.xcontent.ConstructingObjectParser) TaskInfo(org.opensearch.tasks.TaskInfo) TaskOperationFailure(org.opensearch.action.TaskOperationFailure) ArrayList(java.util.ArrayList) List(java.util.List) OpenSearchException(org.opensearch.OpenSearchException) ParseField(org.opensearch.common.ParseField)

Example 5 with TaskOperationFailure

use of org.opensearch.action.TaskOperationFailure in project OpenSearch by opensearch-project.

the class BaseTasksResponse method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeVInt(taskFailures.size());
    for (TaskOperationFailure exp : taskFailures) {
        exp.writeTo(out);
    }
    out.writeVInt(nodeFailures.size());
    for (OpenSearchException exp : nodeFailures) {
        exp.writeTo(out);
    }
}
Also used : TaskOperationFailure(org.opensearch.action.TaskOperationFailure) OpenSearchException(org.opensearch.OpenSearchException)

Aggregations

TaskOperationFailure (org.opensearch.action.TaskOperationFailure)11 OpenSearchException (org.opensearch.OpenSearchException)7 ArrayList (java.util.ArrayList)6 FailedNodeException (org.opensearch.action.FailedNodeException)4 TaskInfo (org.opensearch.tasks.TaskInfo)4 List (java.util.List)3 ListTasksResponse (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse)3 TaskId (org.opensearch.tasks.TaskId)3 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 CancelTasksResponse (org.opensearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse)2 InetAddress (java.net.InetAddress)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.emptySet (java.util.Collections.emptySet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1