| 1286 | |
| 1287 | |
| 1288 | bool Resources::shrink(Resource* resource, const Value::Scalar& target) |
| 1289 | { |
| 1290 | if (resource->scalar() <= target) { |
| 1291 | return true; // Already within target. |
| 1292 | } |
| 1293 | |
| 1294 | // Some `disk` resources (e.g. MOUNT disk) are indivisible. |
| 1295 | // We use a containement check to verify this. Specifically, |
| 1296 | // if it contains a smaller version of itself, then it can |
| 1297 | // safely be chopped into a smaller amount. |
| 1298 | // |
| 1299 | // NOTE: If additional types of resources become indivisible, |
| 1300 | // this code needs updating! |
| 1301 | if (resource->has_disk()) { |
| 1302 | Resource original = *resource; |
| 1303 | |
| 1304 | Value::Scalar oldScalar = resource->scalar(); |
| 1305 | *resource->mutable_scalar() = target; |
| 1306 | |
| 1307 | if (mesos::contains(original, *resource)) { |
| 1308 | return true; |
| 1309 | } |
| 1310 | |
| 1311 | // Restore the old value. |
| 1312 | *resource->mutable_scalar() = std::move(oldScalar); |
| 1313 | return false; |
| 1314 | } |
| 1315 | |
| 1316 | *resource->mutable_scalar() = target; |
| 1317 | return true; |
| 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | Resources Resources::getReservationAncestor( |
nothing calls this directly
no test coverage detected