2121import org .elasticsearch .cluster .ClusterStateApplier ;
2222import org .elasticsearch .cluster .node .DiscoveryNode ;
2323import org .elasticsearch .cluster .node .DiscoveryNodes ;
24+ import org .elasticsearch .common .UUIDs ;
2425import org .elasticsearch .common .settings .Settings ;
2526import org .elasticsearch .common .unit .ByteSizeValue ;
2627import org .elasticsearch .common .util .concurrent .AbstractRunnable ;
4849import java .util .List ;
4950import java .util .Map ;
5051import java .util .Objects ;
52+ import java .util .Optional ;
5153import java .util .Set ;
5254import java .util .concurrent .ConcurrentHashMap ;
5355import java .util .concurrent .CopyOnWriteArrayList ;
@@ -80,8 +82,7 @@ public class TaskManager implements ClusterStateApplier {
8082
8183 private TaskResultsService taskResultsService ;
8284
83- /** Should be set in tests where the lastDiscoveryNodes might not be updated before the first task is registered. */
84- private final @ Nullable String initialNodeId ;
85+ private final String initialNodeId ;
8586 private DiscoveryNodes lastDiscoveryNodes = DiscoveryNodes .EMPTY_NODES ;
8687
8788 private final Tracer tracer ;
@@ -98,7 +99,7 @@ public TaskManager(Settings settings, ThreadPool threadPool, Set<String> taskHea
9899 }
99100
100101 public TaskManager (Settings settings , ThreadPool threadPool , Set <String > taskHeaders , Tracer tracer ) {
101- this (settings , threadPool , taskHeaders , tracer , null );
102+ this (settings , threadPool , taskHeaders , tracer , UUIDs . randomBase64UUID () );
102103 }
103104
104105 public TaskManager (Settings settings , ThreadPool threadPool , Set <String > taskHeaders , Tracer tracer , @ Nullable String initialNodeId ) {
@@ -148,9 +149,7 @@ public Task register(String type, String action, TaskAwareRequest request, boole
148149 headers .put (key , httpHeader );
149150 }
150151 }
151- String lastDiscoveryNodeId = lastDiscoveryNodes .getLocalNodeId ();
152- String localNodeId = lastDiscoveryNodeId != null ? lastDiscoveryNodeId : initialNodeId ;
153- assert localNodeId != null : "lastDiscoveryNodes is not set, and no initialNodeId was provided" ;
152+ String localNodeId = Optional .ofNullable (lastDiscoveryNodes .getLocalNodeId ()).orElse (initialNodeId );
154153 Task task = request .createTask (
155154 new TaskId (localNodeId , taskIdGenerator .incrementAndGet ()),
156155 type ,
0 commit comments