| 3892 | |
| 3893 | |
| 3894 | Future<Response> Master::Http::_deactivateAgent( |
| 3895 | const SlaveID& slaveId, |
| 3896 | const Owned<ObjectApprovers>& approvers) const |
| 3897 | { |
| 3898 | if (!approvers->approved<DEACTIVATE_AGENT>()) { |
| 3899 | return Forbidden(); |
| 3900 | } |
| 3901 | |
| 3902 | // Check that the agent is either recovering, registered, or unreachable. |
| 3903 | if (!master->slaves.recovered.contains(slaveId) && |
| 3904 | !master->slaves.registered.contains(slaveId) && |
| 3905 | !master->slaves.unreachable.contains(slaveId)) { |
| 3906 | return BadRequest("Unknown agent"); |
| 3907 | } |
| 3908 | |
| 3909 | // Save the deactivation to the registry. |
| 3910 | return master->registrar->apply(Owned<RegistryOperation>( |
| 3911 | new DeactivateAgent(slaveId))) |
| 3912 | .onAny([](const Future<bool>& result) { |
| 3913 | CHECK_READY(result) |
| 3914 | << "Failed to deactivate agent in the registry"; |
| 3915 | }) |
| 3916 | .then(defer(master->self(), [this, slaveId](bool result) -> Response { |
| 3917 | // Deactivate the agent. |
| 3918 | master->slaves.deactivated.insert(slaveId); |
| 3919 | |
| 3920 | Slave* slave = master->slaves.registered.get(slaveId); |
| 3921 | if (slave != nullptr) { |
| 3922 | master->deactivate(slave); |
| 3923 | } |
| 3924 | |
| 3925 | return OK(); |
| 3926 | })); |
| 3927 | } |
| 3928 | |
| 3929 | |
| 3930 | Future<Response> Master::Http::deactivateAgent( |