| 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 | } |
no test coverage detected