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

Function applyCheckpointedResources

src/common/resources_utils.cpp:48–96  ·  view source on GitHub ↗

NOTE: We effectively duplicate the logic in 'Resources::apply' which is less than ideal. But we cannot simply create 'Offer::Operation' and invoke 'Resources::apply' here. 'RESERVE' operation requires that the specified resources are dynamically reserved only, and 'CREATE' requires that the specified resources are already dynamically reserved. These requirements are violated when we try to infer d

Source from the content-addressed store, hash-verified

46// TODO(mpark): Consider introducing an atomic 'RESERVE_AND_CREATE'
47// operation to solve this problem.
48Try<Resources> applyCheckpointedResources(
49 const Resources& resources,
50 const Resources& checkpointedResources)
51{
52 Resources totalResources = resources;
53
54 foreach (const Resource& resource, checkpointedResources) {
55 if (!needCheckpointing(resource)) {
56 return Error("Unexpected checkpointed resources " + stringify(resource));
57 }
58
59 Resource stripped = resource;
60
61 // Since only unreserved and statically reserved resources can be specified
62 // on the agent, we strip away all of the dynamic reservations here to
63 // deduce the agent resources on which to apply the checkpointed resources.
64 if (Resources::isDynamicallyReserved(resource)) {
65 Resource::ReservationInfo reservation = stripped.reservations(0);
66 stripped.clear_reservations();
67 if (reservation.type() == Resource::ReservationInfo::STATIC) {
68 stripped.add_reservations()->CopyFrom(reservation);
69 }
70 }
71
72 // Strip persistence and volume from the disk info so that we can
73 // check whether it is contained in the `totalResources`.
74 if (Resources::isPersistentVolume(resource)) {
75 if (stripped.disk().has_source()) {
76 stripped.mutable_disk()->clear_persistence();
77 stripped.mutable_disk()->clear_volume();
78 } else {
79 stripped.clear_disk();
80 }
81 }
82
83 stripped.clear_shared();
84
85 if (!totalResources.contains(stripped)) {
86 return Error(
87 "Incompatible agent resources: " + stringify(totalResources) +
88 " does not contain " + stringify(stripped));
89 }
90
91 totalResources -= stripped;
92 totalResources += resource;
93 }
94
95 return totalResources;
96}
97
98
99namespace internal {

Callers 4

recoverMethod · 0.85
SlaveMethod · 0.85
updateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected