Add a number of auxiliary methods to persistent tasks classes.

Original commit: elastic/x-pack@7f44b41b7a
This commit is contained in:
Martijn van Groningen 2017-01-30 16:23:05 +01:00
parent f136bfa6e0
commit 777b21f2ef
No known key found for this signature in database
GPG Key ID: AB236F4FCF2AF12A
2 changed files with 17 additions and 1 deletions

View File

@ -30,8 +30,11 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* A cluster state record that contains a list of all running persistent tasks
@ -53,6 +56,19 @@ public final class PersistentTasksInProgress extends AbstractNamedDiffable<Clust
return this.entries;
}
public Collection<PersistentTaskInProgress<?>> findEntries(String actionName, Predicate<PersistentTaskInProgress<?>> predicate) {
return this.entries().stream()
.filter(p -> actionName.equals(p.getAction()))
.filter(predicate)
.collect(Collectors.toList());
}
public boolean entriesExist(String actionName, Predicate<PersistentTaskInProgress<?>> predicate) {
return this.entries().stream()
.filter(p -> actionName.equals(p.getAction()))
.anyMatch(predicate);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -112,7 +112,7 @@ public class RemovePersistentTaskAction extends Action<RemovePersistentTaskActio
}
public static class Response extends AcknowledgedResponse {
protected Response() {
public Response() {
super();
}