@@ -89,15 +89,26 @@ public static SingleNodeShutdownMetadata parse(XContentParser parser) {
8989 private final NodeShutdownComponentStatus persistentTasksStatus ;
9090 private final NodeShutdownComponentStatus pluginsStatus ;
9191
92-
93- public SingleNodeShutdownMetadata (
92+ /**
93+ * @param nodeId The node ID that this shutdown metadata refers to.
94+ * @param type The type of shutdown. See {@link Type}.
95+ * @param reason The reason for the shutdown, per the original shutdown request.
96+ * @param status The overall status of this shutdown.
97+ * @param startedAtMillis The timestamp at which this shutdown was requested.
98+ * @param shardMigrationStatus The status of shard migrations away from this node.
99+ * @param persistentTasksStatus The status of persistent task migration away from this node.
100+ * @param pluginsStatus The status of plugin shutdown on this node.
101+ */
102+ private SingleNodeShutdownMetadata (
94103 String nodeId ,
95104 Type type ,
96105 String reason ,
97106 Status status ,
98107 long startedAtMillis ,
99108 NodeShutdownComponentStatus shardMigrationStatus ,
100- NodeShutdownComponentStatus persistentTasksStatus , NodeShutdownComponentStatus pluginsStatus ) {
109+ NodeShutdownComponentStatus persistentTasksStatus ,
110+ NodeShutdownComponentStatus pluginsStatus
111+ ) {
101112 this .nodeId = Objects .requireNonNull (nodeId , "node ID must not be null" );
102113 this .type = Objects .requireNonNull (type , "shutdown type must not be null" );
103114 this .reason = Objects .requireNonNull (reason , "shutdown reason must not be null" );
@@ -143,7 +154,7 @@ public String getReason() {
143154 /**
144155 * @return The status of this node's shutdown.
145156 */
146- public Status isStatus () {
157+ public Status getStatus () {
147158 return status ;
148159 }
149160
@@ -154,6 +165,27 @@ public long getStartedAtMillis() {
154165 return startedAtMillis ;
155166 }
156167
168+ /**
169+ * @return The status of shard migrations off of this node.
170+ */
171+ public NodeShutdownComponentStatus getShardMigrationStatus () {
172+ return shardMigrationStatus ;
173+ }
174+
175+ /**
176+ * @return The status of persistent task shutdown on this node.
177+ */
178+ public NodeShutdownComponentStatus getPersistentTasksStatus () {
179+ return persistentTasksStatus ;
180+ }
181+
182+ /**
183+ * @return The status of plugin shutdown on this node.
184+ */
185+ public NodeShutdownComponentStatus getPluginsStatus () {
186+ return pluginsStatus ;
187+ }
188+
157189 @ Override
158190 public void writeTo (StreamOutput out ) throws IOException {
159191 out .writeString (nodeId );
@@ -213,11 +245,137 @@ public int hashCode() {
213245 );
214246 }
215247
248+ public static Builder builder () {
249+ return new Builder ();
250+ }
251+
252+ public static Builder builder (SingleNodeShutdownMetadata original ) {
253+ if (original == null ) {
254+ return builder ();
255+ }
256+ return new Builder ()
257+ .setNodeId (original .getNodeId ())
258+ .setType (original .getType ())
259+ .setReason (original .getReason ())
260+ .setStatus (original .getStatus ())
261+ .setStartedAtMillis (original .getStartedAtMillis ())
262+ .setShardMigrationStatus (original .getShardMigrationStatus ())
263+ .setPersistentTasksStatus (original .getPersistentTasksStatus ())
264+ .setPluginsStatus (original .getPluginsStatus ());
265+ }
266+
267+ public static class Builder {
268+ private String nodeId ;
269+ private Type type ;
270+ private String reason ;
271+ private long startedAtMillis = -1 ;
272+ private Status status = Status .IN_PROGRESS ;
273+ private NodeShutdownComponentStatus shardMigrationStatus = new NodeShutdownComponentStatus ();
274+ private NodeShutdownComponentStatus persistentTasksStatus = new NodeShutdownComponentStatus ();
275+ private NodeShutdownComponentStatus pluginsStatus = new NodeShutdownComponentStatus ();
276+
277+ private Builder () {}
278+
279+ /**
280+ * @param nodeId The node ID this metadata refers to.
281+ * @return This builder.
282+ */
283+ public Builder setNodeId (String nodeId ) {
284+ this .nodeId = nodeId ;
285+ return this ;
286+ }
287+
288+ /**
289+ * @param type The type of shutdown.
290+ * @return This builder.
291+ */
292+ public Builder setType (Type type ) {
293+ this .type = type ;
294+ return this ;
295+ }
296+
297+ /**
298+ * @param reason The reason for the shutdown. An arbitrary string provided by the user.
299+ * @return This builder.
300+ */
301+ public Builder setReason (String reason ) {
302+ this .reason = reason ;
303+ return this ;
304+ }
305+
306+ /**
307+ * @param startedAtMillis The timestamp at which this shutdown was requested.
308+ * @return This builder.
309+ */
310+ public Builder setStartedAtMillis (long startedAtMillis ) {
311+ this .startedAtMillis = startedAtMillis ;
312+ return this ;
313+ }
314+
315+ /**
316+ * @param status The status of this shutdown.
317+ * @return This builder.
318+ */
319+ public Builder setStatus (Status status ) {
320+ this .status = status ;
321+ return this ;
322+ }
323+
324+ /**
325+ * @param shardMigrationStatus An object describing the status of shard migration away from this node.
326+ * @return This builder.
327+ */
328+ public Builder setShardMigrationStatus (NodeShutdownComponentStatus shardMigrationStatus ) {
329+ this .shardMigrationStatus = shardMigrationStatus ;
330+ return this ;
331+ }
332+
333+ /**
334+ * @param persistentTasksStatus An object describing the status of persistent task migration away from this node.
335+ * @return This builder.
336+ */
337+ public Builder setPersistentTasksStatus (NodeShutdownComponentStatus persistentTasksStatus ) {
338+ this .persistentTasksStatus = persistentTasksStatus ;
339+ return this ;
340+ }
341+
342+ /**
343+ * @param pluginsStatus An object describing the status of plugin shutdown on this node.
344+ * @return
345+ */
346+ public Builder setPluginsStatus (NodeShutdownComponentStatus pluginsStatus ) {
347+ this .pluginsStatus = pluginsStatus ;
348+ return this ;
349+ }
350+
351+ public SingleNodeShutdownMetadata build () {
352+ if (startedAtMillis == -1 ) {
353+ throw new IllegalArgumentException ("start timestamp must be set" );
354+ }
355+ return new SingleNodeShutdownMetadata (
356+ nodeId ,
357+ type ,
358+ reason ,
359+ status ,
360+ startedAtMillis ,
361+ shardMigrationStatus ,
362+ persistentTasksStatus ,
363+ pluginsStatus
364+ );
365+ }
366+ }
367+
368+ /**
369+ * Describes the type of node shutdown - permanent (REMOVE) or temporary (RESTART).
370+ */
216371 public enum Type {
217372 REMOVE ,
218373 RESTART
219374 }
220375
376+ /**
377+ * Describes the status of a component of shutdown.
378+ */
221379 public enum Status {
222380 NOT_STARTED ,
223381 IN_PROGRESS ,
0 commit comments