| 11601 | |
| 11602 | |
| 11603 | void Master::removeOperation(Operation* operation) |
| 11604 | { |
| 11605 | CHECK_NOTNULL(operation); |
| 11606 | |
| 11607 | // Remove from framework. |
| 11608 | Framework* framework = operation->has_framework_id() |
| 11609 | ? getFramework(operation->framework_id()) |
| 11610 | : nullptr; |
| 11611 | |
| 11612 | if (framework != nullptr) { |
| 11613 | framework->removeOperation(operation); |
| 11614 | } |
| 11615 | |
| 11616 | // Remove from slave. |
| 11617 | CHECK(operation->has_slave_id()) |
| 11618 | << "External resource provider is not supported yet"; |
| 11619 | |
| 11620 | Slave* slave = slaves.registered.get(operation->slave_id()); |
| 11621 | CHECK(slave != nullptr) << operation->slave_id(); |
| 11622 | |
| 11623 | slave->removeOperation(operation); |
| 11624 | |
| 11625 | OperationState state = operation->latest_status().state(); |
| 11626 | |
| 11627 | // The common case is that an operation is removed after a terminal status |
| 11628 | // update has been acknowledged, in thase we have nothing to do here because |
| 11629 | // the counters for terminal operations represent lifetime totals. |
| 11630 | // However, it can happen that we need to remove non-terminal operations, |
| 11631 | // e.g. when an agent is marked gone or a resource provider on an agent |
| 11632 | // disappears. In this case we need to adjust the metrics to reflect the |
| 11633 | // current numbers. |
| 11634 | if (!protobuf::isTerminalState(state)) { |
| 11635 | metrics->decrementOperationState( |
| 11636 | operation->info().type(), |
| 11637 | state); |
| 11638 | } |
| 11639 | |
| 11640 | // If the operation was not speculated and is not terminal we |
| 11641 | // need to also recover its used resources in the allocator. |
| 11642 | // If the operation is an orphan, the resources have already been |
| 11643 | // recovered from the allocator. |
| 11644 | if (!protobuf::isSpeculativeOperation(operation->info()) && |
| 11645 | !protobuf::isTerminalState(state) && |
| 11646 | !slave->orphanedOperations.contains(operation->uuid())) { |
| 11647 | Try<Resources> consumed = protobuf::getConsumedResources(operation->info()); |
| 11648 | CHECK_SOME(consumed); |
| 11649 | |
| 11650 | allocator->recoverResources( |
| 11651 | operation->framework_id(), |
| 11652 | operation->slave_id(), |
| 11653 | consumed.get(), |
| 11654 | None(), |
| 11655 | false); |
| 11656 | } |
| 11657 | |
| 11658 | delete operation; |
| 11659 | } |
| 11660 |
no test coverage detected