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,15 @@ 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+ SingularityMachineStateHistoryUpdate stateHistoryUpdate = history
222+ .stream ()
223+ .filter (update -> update .getState () == MachineState .STARTING_DECOMMISSION )
224+ .max (Comparator .comparing (SingularityMachineStateHistoryUpdate ::getTimestamp ))
225+ .get ();
214226
215227 for (SingularityTask activeTask : taskManager .getTasksOnAgent (
216228 activeTaskIds ,
@@ -220,7 +232,8 @@ public void checkForDecomissions() {
220232 requestIdsToUserToReschedule ,
221233 matchingTaskIds ,
222234 activeTask ,
223- agent
235+ agent ,
236+ stateHistoryUpdate .getMessage ()
224237 );
225238 foundTask = true ;
226239 }
@@ -256,7 +269,8 @@ public void checkForDecomissions() {
256269 requestIdsToUserToReschedule ,
257270 matchingTaskIds ,
258271 maybeTask .get (),
259- rack
272+ rack ,
273+ Optional .empty ()
260274 );
261275 }
262276 }
0 commit comments