2424import com .hubspot .singularity .SingularityDeployStatisticsBuilder ;
2525import com .hubspot .singularity .SingularityKilledTaskIdRecord ;
2626import com .hubspot .singularity .SingularityMachineAbstraction ;
27+ import com .hubspot .singularity .SingularityMachineStateHistoryUpdate ;
2728import com .hubspot .singularity .SingularityMainModule ;
2829import com .hubspot .singularity .SingularityManagedThreadPoolFactory ;
2930import com .hubspot .singularity .SingularityPendingDeploy ;
@@ -152,7 +153,8 @@ private void cleanupTaskDueToDecomission(
152153 final Map <String , Optional <String >> requestIdsToUserToReschedule ,
153154 final Set <SingularityTaskId > matchingTaskIds ,
154155 SingularityTask task ,
155- SingularityMachineAbstraction <?> decommissioningObject
156+ SingularityMachineAbstraction <?> decommissioningObject ,
157+ Optional <String > decomissionReason
156158 ) {
157159 requestIdsToUserToReschedule .put (
158160 task .getTaskRequest ().getRequest ().getId (),
@@ -175,9 +177,10 @@ private void cleanupTaskDueToDecomission(
175177 task .getTaskId (),
176178 Optional .of (
177179 String .format (
178- "%s %s is decomissioning" ,
180+ "%s %s is decomissioning%s " ,
179181 decommissioningObject .getTypeName (),
180- decommissioningObject .getName ()
182+ decommissioningObject .getName (),
183+ decomissionReason .map (r -> String .format (" (message: %s)" , r )).orElse ("" )
181184 )
182185 ),
183186 Optional .<String >empty (),
@@ -211,6 +214,17 @@ public void checkForDecomissions() {
211214
212215 for (SingularityAgent agent : agents .keySet ()) {
213216 boolean foundTask = false ;
217+ List <SingularityMachineStateHistoryUpdate > history = agentManager .getHistory (
218+ agent .getId ()
219+ );
220+
221+ // TODO: Is there a guaranteed order these come out of ZK in to prevent sort?
222+ // Probably nbd because this list will be very short, but still
223+ SingularityMachineStateHistoryUpdate stateHistoryUpdate = history
224+ .stream ()
225+ .filter (update -> update .getState () == MachineState .STARTING_DECOMMISSION )
226+ .max (Comparator .comparing (SingularityMachineStateHistoryUpdate ::getTimestamp ))
227+ .get ();
214228
215229 for (SingularityTask activeTask : taskManager .getTasksOnAgent (
216230 activeTaskIds ,
@@ -220,7 +234,8 @@ public void checkForDecomissions() {
220234 requestIdsToUserToReschedule ,
221235 matchingTaskIds ,
222236 activeTask ,
223- agent
237+ agent ,
238+ stateHistoryUpdate .getMessage ()
224239 );
225240 foundTask = true ;
226241 }
@@ -256,7 +271,8 @@ public void checkForDecomissions() {
256271 requestIdsToUserToReschedule ,
257272 matchingTaskIds ,
258273 maybeTask .get (),
259- rack
274+ rack ,
275+ Optional .empty ()
260276 );
261277 }
262278 }
0 commit comments