| 2059 | |
| 2060 | |
| 2061 | Future<Response> Http::getTasks( |
| 2062 | const mesos::agent::Call& call, |
| 2063 | ContentType contentType, |
| 2064 | const Option<Principal>& principal) const |
| 2065 | { |
| 2066 | CHECK_EQ(mesos::agent::Call::GET_TASKS, call.type()); |
| 2067 | |
| 2068 | LOG(INFO) << "Processing GET_TASKS call"; |
| 2069 | |
| 2070 | return ObjectApprovers::create( |
| 2071 | slave->authorizer, |
| 2072 | principal, |
| 2073 | {VIEW_FRAMEWORK, VIEW_TASK, VIEW_EXECUTOR}) |
| 2074 | .then(defer( |
| 2075 | slave->self(), |
| 2076 | [this, contentType]( |
| 2077 | const Owned<ObjectApprovers>& approvers) -> Response { |
| 2078 | // Serialize the following message: |
| 2079 | // |
| 2080 | // v1::agent::Response response; |
| 2081 | // response.set_type(mesos::agent::Response::GET_TASKS); |
| 2082 | // *response.mutable_get_tasks() = _...; |
| 2083 | |
| 2084 | switch (contentType) { |
| 2085 | case ContentType::PROTOBUF: { |
| 2086 | string output; |
| 2087 | google::protobuf::io::StringOutputStream stream(&output); |
| 2088 | google::protobuf::io::CodedOutputStream writer(&stream); |
| 2089 | |
| 2090 | WireFormatLite::WriteEnum( |
| 2091 | v1::agent::Response::kTypeFieldNumber, |
| 2092 | v1::agent::Response::GET_TASKS, |
| 2093 | &writer); |
| 2094 | |
| 2095 | WireFormatLite::WriteBytes( |
| 2096 | v1::agent::Response::kGetTasksFieldNumber, |
| 2097 | serializeGetTasks(approvers), |
| 2098 | &writer); |
| 2099 | |
| 2100 | // We must manually trim the unused buffer space since |
| 2101 | // we use the string before the coded output stream is |
| 2102 | // destructed. |
| 2103 | writer.Trim(); |
| 2104 | |
| 2105 | return OK(std::move(output), stringify(contentType)); |
| 2106 | } |
| 2107 | |
| 2108 | case ContentType::JSON: { |
| 2109 | string body = jsonify([&](JSON::ObjectWriter* writer) { |
| 2110 | const google::protobuf::Descriptor* descriptor = |
| 2111 | v1::agent::Response::descriptor(); |
| 2112 | |
| 2113 | int field; |
| 2114 | |
| 2115 | field = v1::agent::Response::kTypeFieldNumber; |
| 2116 | writer->field( |
| 2117 | descriptor->FindFieldByNumber(field)->name(), |
| 2118 | v1::agent::Response::Type_Name( |