@ Override public Job removeJob ( final JobId id , final String token ) throws JobDoesNotExistException , JobStillDeployedException , TokenVerificationException { log . info ( "removing job: id={}" , id ) ; final ZooKeeperClient client = provider . get ( "removeJob" ) ; final Job job = getJob ( client , id ) ; if ( job == null ) { throw new JobDoesNotExistException ( id ) ; } verifyToken ( token , job ) ; // TODO (dano): handle retry failures try { final ImmutableList . Builder < ZooKeeperOperation > operations = ImmutableList . builder ( ) ; final UUID jobCreationOperationId = getJobCreation ( client , id ) ; if ( jobCreationOperationId != null ) { operations . add ( delete ( Paths . configJobCreation ( id , jobCreationOperationId ) ) ) ; } operations . add ( delete ( Paths . configJobHosts ( id ) ) , delete ( Paths . configJobRefShort ( id ) ) , delete ( Paths . configJob ( id ) ) , // Touch the jobs root node so that its version is bumped on every job // change down the tree. Effectively, make it that version == cVersion. set ( Paths . configJobs ( ) , UUID . randomUUID ( ) . toString ( ) . getBytes ( ) ) ) ; client . transaction ( operations . build ( ) ) ; } catch ( final NoNodeException e ) { throw new JobDoesNotExistException ( id ) ; } catch ( final NotEmptyException e ) { throw new JobStillDeployedException ( id , listJobHosts ( client , id ) ) ; } catch ( final KeeperException e ) { throw new HeliosRuntimeException ( "removing job " + id + " failed" , e ) ; } // Delete job history on a best effort basis try { client . deleteRecursive ( Paths . historyJob ( id ) ) ; } catch ( NoNodeException ignored ) { // There's no history for this job } catch ( KeeperException e ) { log . warn ( "error removing job history for job {}" , id , e ) ; } return job ; }
Deletes a job from ZooKeeper . Ensures that job is not currently running anywhere .