| 2486 | |
| 2487 | |
| 2488 | Future<Response> Http::getState( |
| 2489 | const mesos::agent::Call& call, |
| 2490 | ContentType contentType, |
| 2491 | const Option<Principal>& principal) const |
| 2492 | { |
| 2493 | CHECK_EQ(mesos::agent::Call::GET_STATE, call.type()); |
| 2494 | |
| 2495 | LOG(INFO) << "Processing GET_STATE call"; |
| 2496 | |
| 2497 | return ObjectApprovers::create( |
| 2498 | slave->authorizer, |
| 2499 | principal, |
| 2500 | {VIEW_FRAMEWORK, VIEW_TASK, VIEW_EXECUTOR}) |
| 2501 | .then(defer( |
| 2502 | slave->self(), |
| 2503 | [=](const Owned<ObjectApprovers>& approvers) -> Response { |
| 2504 | // Serialize the following message: |
| 2505 | // |
| 2506 | // v1::agent::Response response; |
| 2507 | // response.set_type(mesos::agent::Response::GET_STATE); |
| 2508 | // *response.mutable_get_state() = _...; |
| 2509 | |
| 2510 | switch (contentType) { |
| 2511 | case ContentType::PROTOBUF: { |
| 2512 | string output; |
| 2513 | google::protobuf::io::StringOutputStream stream(&output); |
| 2514 | google::protobuf::io::CodedOutputStream writer(&stream); |
| 2515 | |
| 2516 | WireFormatLite::WriteEnum( |
| 2517 | v1::agent::Response::kTypeFieldNumber, |
| 2518 | v1::agent::Response::GET_STATE, |
| 2519 | &writer); |
| 2520 | |
| 2521 | WireFormatLite::WriteBytes( |
| 2522 | v1::agent::Response::kGetStateFieldNumber, |
| 2523 | serializeGetState(approvers), |
| 2524 | &writer); |
| 2525 | |
| 2526 | // We must manually trim the unused buffer space since |
| 2527 | // we use the string before the coded output stream is |
| 2528 | // destructed. |
| 2529 | writer.Trim(); |
| 2530 | |
| 2531 | return OK(std::move(output), stringify(contentType)); |
| 2532 | } |
| 2533 | |
| 2534 | case ContentType::JSON: { |
| 2535 | string body = jsonify([&](JSON::ObjectWriter* writer) { |
| 2536 | const google::protobuf::Descriptor* descriptor = |
| 2537 | v1::agent::Response::descriptor(); |
| 2538 | |
| 2539 | int field; |
| 2540 | |
| 2541 | field = v1::agent::Response::kTypeFieldNumber; |
| 2542 | writer->field( |
| 2543 | descriptor->FindFieldByNumber(field)->name(), |
| 2544 | v1::agent::Response::Type_Name( |
| 2545 | v1::agent::Response::GET_STATE)); |