2323import com .fasterxml .jackson .annotation .JsonProperty ;
2424import com .fasterxml .jackson .core .type .TypeReference ;
2525import com .google .common .base .Optional ;
26+ import org .apache .druid .error .InvalidInput ;
2627import org .apache .druid .indexer .TaskLocation ;
2728import org .apache .druid .indexing .common .task .Task ;
2829import org .apache .druid .indexing .overlord .TaskRunner ;
2930
31+ import java .util .Objects ;
32+
33+ /**
34+ * Notifies the Overlord that the location of a task is now updated.
35+ * Used when running K8s-based tasks in encapsulated mode.
36+ */
3037public class UpdateLocationAction implements TaskAction <Void >
3138{
32- private final TaskLocation taskLocation ;
39+ private final TaskLocation location ;
3340
3441 @ JsonCreator
3542 public UpdateLocationAction (
3643 @ JsonProperty ("location" ) TaskLocation location
3744 )
3845 {
39- this .taskLocation = location ;
46+ InvalidInput .conditionalException (location != null , "No task location specified" );
47+ this .location = location ;
4048 }
4149
4250 @ JsonProperty
43- public TaskLocation getTaskLocation ()
51+ public TaskLocation getLocation ()
4452 {
45- return taskLocation ;
53+ return location ;
4654 }
4755
4856 @ Override
@@ -56,7 +64,7 @@ public Void perform(Task task, TaskActionToolbox toolbox)
5664 {
5765 Optional <TaskRunner > taskRunner = toolbox .getTaskRunner ();
5866 if (taskRunner .isPresent ()) {
59- taskRunner .get ().updateLocation (task , taskLocation );
67+ taskRunner .get ().updateLocation (task , location );
6068 }
6169 return null ;
6270 }
@@ -65,7 +73,26 @@ public Void perform(Task task, TaskActionToolbox toolbox)
6573 public String toString ()
6674 {
6775 return "UpdateLocationAction{" +
68- "taskLocation=" + taskLocation +
76+ "taskLocation=" + location +
6977 '}' ;
7078 }
79+
80+ @ Override
81+ public boolean equals (Object object )
82+ {
83+ if (this == object ) {
84+ return true ;
85+ }
86+ if (object == null || getClass () != object .getClass ()) {
87+ return false ;
88+ }
89+ UpdateLocationAction that = (UpdateLocationAction ) object ;
90+ return Objects .equals (location , that .location );
91+ }
92+
93+ @ Override
94+ public int hashCode ()
95+ {
96+ return Objects .hashCode (location );
97+ }
7198}
0 commit comments