@ Override public boolean onRestart ( Scheduler . RestartTopologyRequest request ) { // Containers would be restarted automatically once we destroy it int containerId = request . getContainerIndex ( ) ; List < Process > processesToRestart = new LinkedList <> ( ) ; if ( containerId == - 1 ) { LOG . info ( "Command to restart the entire topology: " + LocalContext . topologyName ( config ) ) ; processesToRestart . addAll ( processToContainer . keySet ( ) ) ; } else { // restart that particular container LOG . info ( "Command to restart a container of topology: " + LocalContext . topologyName ( config ) ) ; LOG . info ( "Restart container requested: " + containerId ) ; // locate the container and destroy it for ( Process p : processToContainer . keySet ( ) ) { if ( containerId == processToContainer . get ( p ) ) { processesToRestart . add ( p ) ; } } } if ( processesToRestart . isEmpty ( ) ) { LOG . severe ( "Container not exist." ) ; return false ; } for ( Process process : processesToRestart ) { process . destroy ( ) ; } return true ; }
Handler to restart topology