Package org.elasticsearch.persistent
Class PersistentTasksExecutor<Params extends PersistentTaskParams>
java.lang.Object
org.elasticsearch.persistent.PersistentTasksExecutor<Params>
public abstract class PersistentTasksExecutor<Params extends PersistentTaskParams>
extends java.lang.Object
An executor of tasks that can survive restart of requesting or executing node.
These tasks are using cluster state rather than only transport service to send requests and responses.
-
Field Summary
Fields Modifier and Type Field Description static PersistentTasksCustomMetadata.Assignment
NO_NODE_FOUND
-
Constructor Summary
Constructors Modifier Constructor Description protected
PersistentTasksExecutor(java.lang.String taskName, java.lang.String executor)
-
Method Summary
Modifier and Type Method Description protected AllocatedPersistentTask
createTask(long id, java.lang.String type, java.lang.String action, TaskId parentTaskId, PersistentTasksCustomMetadata.PersistentTask<Params> taskInProgress, java.util.Map<java.lang.String,java.lang.String> headers)
Creates a AllocatedPersistentTask for communicating with task managerPersistentTasksCustomMetadata.Assignment
getAssignment(Params params, ClusterState clusterState)
Returns the node id where the params has to be executed,protected java.lang.String
getDescription(PersistentTasksCustomMetadata.PersistentTask<Params> taskInProgress)
Returns task description that will be available via task managerjava.lang.String
getExecutor()
java.lang.String
getTaskName()
protected abstract void
nodeOperation(AllocatedPersistentTask task, Params params, PersistentTaskState state)
This operation will be executed on the executor node.protected DiscoveryNode
selectLeastLoadedNode(ClusterState clusterState, java.util.function.Predicate<DiscoveryNode> selector)
Finds the least loaded node that satisfies the selector criteriavoid
validate(Params params, ClusterState clusterState)
Checks the current cluster state for compatibility with the paramsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
NO_NODE_FOUND
-
-
Constructor Details
-
PersistentTasksExecutor
protected PersistentTasksExecutor(java.lang.String taskName, java.lang.String executor)
-
-
Method Details
-
getTaskName
public java.lang.String getTaskName() -
getAssignment
public PersistentTasksCustomMetadata.Assignment getAssignment(Params params, ClusterState clusterState)Returns the node id where the params has to be executed,The default implementation returns the least loaded data node
-
selectLeastLoadedNode
protected DiscoveryNode selectLeastLoadedNode(ClusterState clusterState, java.util.function.Predicate<DiscoveryNode> selector)Finds the least loaded node that satisfies the selector criteria -
validate
Checks the current cluster state for compatibility with the paramsThrows an exception if the supplied params cannot be executed on the cluster in the current state.
-
createTask
protected AllocatedPersistentTask createTask(long id, java.lang.String type, java.lang.String action, TaskId parentTaskId, PersistentTasksCustomMetadata.PersistentTask<Params> taskInProgress, java.util.Map<java.lang.String,java.lang.String> headers)Creates a AllocatedPersistentTask for communicating with task manager -
getDescription
protected java.lang.String getDescription(PersistentTasksCustomMetadata.PersistentTask<Params> taskInProgress)Returns task description that will be available via task manager -
nodeOperation
protected abstract void nodeOperation(AllocatedPersistentTask task, Params params, @Nullable PersistentTaskState state)This operation will be executed on the executor node.NOTE: The nodeOperation has to throw an exception, trigger task.markAsCompleted() or task.completeAndNotifyIfNeeded() methods to indicate that the persistent task has finished.
-
getExecutor
public java.lang.String getExecutor()
-