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

Method checkAndTransitionDrainingAgent

src/master/master.cpp:5502–5581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5500
5501
5502void Master::checkAndTransitionDrainingAgent(Slave* slave)
5503{
5504 CHECK_NOTNULL(slave);
5505
5506 const SlaveID& slaveId = slave->id;
5507
5508 if (!slaves.draining.contains(slaveId) ||
5509 slaves.draining.at(slaveId).state() == DRAINED) {
5510 // Nothing to do for non-draining or already drained agents.
5511 return;
5512 }
5513
5514 // Check if the agent has any tasks running or operations pending.
5515 if (!slave->tasks.empty() ||
5516 !slave->operations.empty()) {
5517 size_t numTasks = 0u;
5518 foreachvalue (const auto& frameworkTasks, slave->tasks) {
5519 numTasks += frameworkTasks.size();
5520 }
5521
5522 VLOG(1)
5523 << "DRAINING Agent " << slaveId << " has "
5524 << numTasks << " tasks, and "
5525 << slave->operations.size() << " operations";
5526 return;
5527 }
5528
5529 if (slaves.markingGone.contains(slaveId)) {
5530 LOG(INFO)
5531 << "Ignoring transition of agent " << slaveId << " to the DRAINED"
5532 << " state because agent is being marked gone";
5533 return;
5534 }
5535
5536 // If the agent will be marked gone afterwards, we do not need to mark
5537 // the agent as DRAINED. Simply marking gone will suffice.
5538 if (slaves.draining.at(slaveId).config().mark_gone()) {
5539 LOG(INFO) << "Marking agent " << slaveId << " in the DRAINED state as gone";
5540
5541 slaves.markingGone.insert(slaveId);
5542
5543 TimeInfo goneTime = protobuf::getCurrentTime();
5544
5545 registrar->apply(Owned<RegistryOperation>(
5546 new MarkSlaveGone(slaveId, goneTime)))
5547 .onAny(defer(
5548 self(),
5549 [this, slaveId, goneTime](const Future<bool>& result) {
5550 CHECK_READY(result)
5551 << "Failed to mark agent gone in the registry";
5552
5553 markGone(slaveId, goneTime);
5554 }));
5555 } else {
5556 LOG(INFO) << "Transitioning agent " << slaveId << " to the DRAINED state";
5557
5558 registrar->apply(Owned<RegistryOperation>(
5559 new MarkAgentDrained(slaveId)))

Callers 1

_drainAgentMethod · 0.80

Calls 9

getCurrentTimeFunction · 0.85
deferFunction · 0.85
atMethod · 0.80
insertMethod · 0.80
containsMethod · 0.45
stateMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected