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()));
}
}
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);
}
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"))));
}
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;
}
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);
}
}
Aggregations