| 359 | |
| 360 | |
| 361 | void SlavesWriter::writeSlave( |
| 362 | const Slave* slave, JSON::ObjectWriter* writer) const |
| 363 | { |
| 364 | SlaveWriter( |
| 365 | *slave, |
| 366 | slaves_.draining.get(slave->id), |
| 367 | slaves_.deactivated.contains(slave->id), |
| 368 | approvers_)(writer); |
| 369 | |
| 370 | // Add the complete protobuf->JSON for all used, reserved, |
| 371 | // and offered resources. The other endpoints summarize |
| 372 | // resource information, which omits the details of |
| 373 | // reservations and persistent volumes. Full resource |
| 374 | // information is necessary so that operators can use the |
| 375 | // `/unreserve` and `/destroy-volumes` endpoints. |
| 376 | |
| 377 | hashmap<string, Resources> reserved = slave->totalResources.reservations(); |
| 378 | |
| 379 | writer->field( |
| 380 | "reserved_resources_full", |
| 381 | [&reserved, this](JSON::ObjectWriter* writer) { |
| 382 | foreachpair (const string& role, |
| 383 | const Resources& resources, |
| 384 | reserved) { |
| 385 | if (approvers_->approved<VIEW_ROLE>(role)) { |
| 386 | writer->field(role, [&resources, this]( |
| 387 | JSON::ArrayWriter* writer) { |
| 388 | foreach (Resource resource, resources) { |
| 389 | if (approvers_->approved<VIEW_ROLE>(resource)) { |
| 390 | convertResourceFormat(&resource, ENDPOINT); |
| 391 | writer->element(JSON::Protobuf(resource)); |
| 392 | } |
| 393 | } |
| 394 | }); |
| 395 | } |
| 396 | } |
| 397 | }); |
| 398 | |
| 399 | Resources unreservedResources = slave->totalResources.unreserved(); |
| 400 | |
| 401 | writer->field( |
| 402 | "unreserved_resources_full", |
| 403 | [&unreservedResources, this](JSON::ArrayWriter* writer) { |
| 404 | foreach (Resource resource, unreservedResources) { |
| 405 | if (approvers_->approved<VIEW_ROLE>(resource)) { |
| 406 | convertResourceFormat(&resource, ENDPOINT); |
| 407 | writer->element(JSON::Protobuf(resource)); |
| 408 | } |
| 409 | } |
| 410 | }); |
| 411 | |
| 412 | Resources usedResources = Resources::sum(slave->usedResources); |
| 413 | |
| 414 | writer->field( |
| 415 | "used_resources_full", |
| 416 | [&usedResources, this](JSON::ArrayWriter* writer) { |
| 417 | foreach (Resource resource, usedResources) { |
| 418 | if (approvers_->approved<VIEW_ROLE>(resource)) { |
nothing calls this directly
no test coverage detected