MCPcopy Create free account
hub / github.com/apache/mesos / _drainAgent

Method _drainAgent

src/master/http.cpp:3732–3820  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3730
3731
3732Future<Response> Master::Http::_drainAgent(
3733 const SlaveID& slaveId,
3734 const Option<DurationInfo>& maxGracePeriod,
3735 const bool markGone,
3736 const Owned<ObjectApprovers>& approvers) const
3737{
3738 if (!approvers->approved<DRAIN_AGENT>()) {
3739 return Forbidden();
3740 }
3741
3742 if (markGone && !approvers->approved<MARK_AGENT_GONE>()) {
3743 return Forbidden();
3744 }
3745
3746 // Check that the agent is either recovering, registered, or unreachable.
3747 if (!master->slaves.recovered.contains(slaveId) &&
3748 !master->slaves.registered.contains(slaveId) &&
3749 !master->slaves.unreachable.contains(slaveId)) {
3750 return BadRequest("Unknown agent");
3751 }
3752
3753 // If this agent is being marked gone, then no draining can be performed.
3754 if (master->slaves.markingGone.contains(slaveId)) {
3755 return Conflict("Agent is currently being marked gone");
3756 }
3757
3758 // Save the draining info to the registry.
3759 return master->registrar->apply(Owned<RegistryOperation>(
3760 new DrainAgent(slaveId, maxGracePeriod, markGone)))
3761 .onAny([](const Future<bool>& result) {
3762 CHECK_READY(result)
3763 << "Failed to update draining info in the registry";
3764 })
3765 .then(defer(
3766 master->self(),
3767 [this, slaveId, maxGracePeriod, markGone](bool result) -> Response {
3768 // Update the in-memory state.
3769 DrainConfig drainConfig;
3770 drainConfig.set_mark_gone(markGone);
3771
3772 if (maxGracePeriod.isSome()) {
3773 drainConfig.mutable_max_grace_period()
3774 ->CopyFrom(maxGracePeriod.get());
3775 }
3776
3777 DrainInfo drainInfo;
3778 drainInfo.set_state(DRAINING);
3779 drainInfo.mutable_config()->CopyFrom(drainConfig);
3780
3781 master->slaves.draining[slaveId] = drainInfo;
3782
3783 // Deactivate the agent.
3784 master->slaves.deactivated.insert(slaveId);
3785
3786 Slave* slave = master->slaves.registered.get(slaveId);
3787
3788 // It's possible for the slave to be removed in the interim
3789 // if it is marked unreachable.

Callers

nothing calls this directly

Calls 15

ForbiddenClass · 0.85
BadRequestClass · 0.85
ConflictClass · 0.85
deferFunction · 0.85
OKClass · 0.85
CopyFromMethod · 0.80
insertMethod · 0.80
sendMethod · 0.65
stringifyFunction · 0.50
containsMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected