| 1554 | |
| 1555 | |
| 1556 | Future<Response> Http::getFrameworks( |
| 1557 | const mesos::agent::Call& call, |
| 1558 | ContentType contentType, |
| 1559 | const Option<Principal>& principal) const |
| 1560 | { |
| 1561 | CHECK_EQ(mesos::agent::Call::GET_FRAMEWORKS, call.type()); |
| 1562 | |
| 1563 | LOG(INFO) << "Processing GET_FRAMEWORKS call"; |
| 1564 | |
| 1565 | return ObjectApprovers::create(slave->authorizer, principal, {VIEW_FRAMEWORK}) |
| 1566 | .then(defer( |
| 1567 | slave->self(), |
| 1568 | [this, contentType]( |
| 1569 | const Owned<ObjectApprovers>& approvers) -> Response { |
| 1570 | // Serialize the following message: |
| 1571 | // |
| 1572 | // v1::agent::Response response; |
| 1573 | // response.set_type(mesos::agent::Response::GET_FRAMEWORKS); |
| 1574 | // *response.mutable_get_frameworks() = _...; |
| 1575 | |
| 1576 | switch (contentType) { |
| 1577 | case ContentType::PROTOBUF: { |
| 1578 | string output; |
| 1579 | google::protobuf::io::StringOutputStream stream(&output); |
| 1580 | google::protobuf::io::CodedOutputStream writer(&stream); |
| 1581 | |
| 1582 | WireFormatLite::WriteEnum( |
| 1583 | v1::agent::Response::kTypeFieldNumber, |
| 1584 | v1::agent::Response::GET_FRAMEWORKS, |
| 1585 | &writer); |
| 1586 | |
| 1587 | WireFormatLite::WriteBytes( |
| 1588 | v1::agent::Response::kGetFrameworksFieldNumber, |
| 1589 | serializeGetFrameworks(approvers), |
| 1590 | &writer); |
| 1591 | |
| 1592 | // We must manually trim the unused buffer space since |
| 1593 | // we use the string before the coded output stream is |
| 1594 | // destructed. |
| 1595 | writer.Trim(); |
| 1596 | |
| 1597 | return OK(std::move(output), stringify(contentType)); |
| 1598 | } |
| 1599 | |
| 1600 | case ContentType::JSON: { |
| 1601 | string body = jsonify([&](JSON::ObjectWriter* writer) { |
| 1602 | const google::protobuf::Descriptor* descriptor = |
| 1603 | v1::agent::Response::descriptor(); |
| 1604 | |
| 1605 | int field; |
| 1606 | |
| 1607 | field = v1::agent::Response::kTypeFieldNumber; |
| 1608 | writer->field( |
| 1609 | descriptor->FindFieldByNumber(field)->name(), |
| 1610 | v1::agent::Response::Type_Name( |
| 1611 | v1::agent::Response::GET_FRAMEWORKS)); |
| 1612 | |
| 1613 | field = v1::agent::Response::kGetFrameworksFieldNumber; |