protected void processTasks(TasksRequest request, Consumer<OperationTask> operation) { if (request.getTaskId().isSet()) { // we are only checking one task, we can optimize it Task task = taskManager.getTask(request.getTaskId().getId()); if (task != null) { if (request.match(task)) { operation.accept((OperationTask) task); } else { throw new ResourceNotFoundException("task [{}] doesn't support this operation", request.getTaskId()); } } else { throw new ResourceNotFoundException("task [{}] is missing", request.getTaskId()); } } else { for (Task task : taskManager.getTasks().values()) { if (request.match(task)) { operation.accept((OperationTask) task); } } } }
private void assertShardIndexCounter() throws Exception { assertBusy(() -> { final Collection<NodeAndClient> nodesAndClients = nodes.values(); for (NodeAndClient nodeAndClient : nodesAndClients) { IndicesService indexServices = getInstance(IndicesService.class, nodeAndClient.name); for (IndexService indexService : indexServices) { for (IndexShard indexShard : indexService) { int activeOperationsCount = indexShard.getActiveOperationsCount(); if (activeOperationsCount > 0) { TaskManager taskManager = getInstance(TransportService.class, nodeAndClient.name).getTaskManager(); DiscoveryNode localNode = getInstance(ClusterService.class, nodeAndClient.name).localNode(); List<TaskInfo> taskInfos = taskManager.getTasks().values().stream() .filter(task -> task instanceof ReplicationTask) .map(task -> task.taskInfo(localNode.getId(), true)) .collect(Collectors.toList()); ListTasksResponse response = new ListTasksResponse(taskInfos, Collections.emptyList(), Collections.emptyList()); try { XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint().value(response); throw new AssertionError("expected index shard counter on shard " + indexShard.shardId() + " on node " + nodeAndClient.name + " to be 0 but was " + activeOperationsCount + ". Current replication tasks on node:\n" + builder.string()); } catch (IOException e) { throw new RuntimeException("caught exception while building response [" + response + "]", e); } } } } } }); }
protected void processTasks(TasksRequest request, Consumer<OperationTask> operation) { if (request.getTaskId().isSet()) { // we are only checking one task, we can optimize it Task task = taskManager.getTask(request.getTaskId().getId()); if (task != null) { if (request.match(task)) { operation.accept((OperationTask) task); } else { throw new ResourceNotFoundException("task [{}] doesn't support this operation", request.getTaskId()); } } else { throw new ResourceNotFoundException("task [{}] is missing", request.getTaskId()); } } else { for (Task task : taskManager.getTasks().values()) { if (request.match(task)) { operation.accept((OperationTask) task); } } } }
protected void processTasks(TasksRequest request, Consumer<OperationTask> operation) { if (request.getTaskId().isSet()) { // we are only checking one task, we can optimize it Task task = taskManager.getTask(request.getTaskId().getId()); if (task != null) { if (request.match(task)) { operation.accept((OperationTask) task); } else { throw new ResourceNotFoundException("task [{}] doesn't support this operation", request.getTaskId()); } } else { throw new ResourceNotFoundException("task [{}] is missing", request.getTaskId()); } } else { for (Task task : taskManager.getTasks().values()) { if (request.match(task)) { operation.accept((OperationTask) task); } } } }
protected void processTasks(TasksRequest request, Consumer<OperationTask> operation) { if (request.getTaskId().isSet()) { // we are only checking one task, we can optimize it Task task = taskManager.getTask(request.getTaskId().getId()); if (task != null) { if (request.match(task)) { operation.accept((OperationTask) task); } else { throw new ResourceNotFoundException("task [{}] doesn't support this operation", request.getTaskId()); } } else { throw new ResourceNotFoundException("task [{}] is missing", request.getTaskId()); } } else { for (Task task : taskManager.getTasks().values()) { if (request.match(task)) { operation.accept((OperationTask) task); } } } }
protected void processTasks(TasksRequest request, Consumer<OperationTask> operation) { if (request.getTaskId().isSet()) { // we are only checking one task, we can optimize it Task task = taskManager.getTask(request.getTaskId().getId()); if (task != null) { if (request.match(task)) { operation.accept((OperationTask) task); } else { throw new ResourceNotFoundException("task [{}] doesn't support this operation", request.getTaskId()); } } else { throw new ResourceNotFoundException("task [{}] is missing", request.getTaskId()); } } else { for (Task task : taskManager.getTasks().values()) { if (request.match(task)) { operation.accept((OperationTask) task); } } } }