| 2286 | |
| 2287 | |
| 2288 | string Http::serializeGetTasks( |
| 2289 | const Owned<ObjectApprovers>& approvers) const |
| 2290 | { |
| 2291 | // Construct framework list with both active and completed frameworks. |
| 2292 | vector<const Framework*> frameworks; |
| 2293 | foreachvalue (Framework* f, slave->frameworks) { |
| 2294 | if (approvers->approved<VIEW_FRAMEWORK>(f->info)) { |
| 2295 | frameworks.push_back(f); |
| 2296 | } |
| 2297 | } |
| 2298 | foreachvalue (const Owned<Framework>& f, slave->completedFrameworks) { |
| 2299 | if (approvers->approved<VIEW_FRAMEWORK>(f->info)) { |
| 2300 | frameworks.push_back(f.get()); |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | // Construct executor list with both active and completed executors. |
| 2305 | hashmap<const Executor*, const Framework*> executors; |
| 2306 | foreach (const Framework* f, frameworks) { |
| 2307 | foreachvalue (Executor* e, f->executors) { |
| 2308 | if (approvers->approved<VIEW_EXECUTOR>(e->info, f->info)) { |
| 2309 | executors.put(e, f); |
| 2310 | } |
| 2311 | } |
| 2312 | foreach (const Owned<Executor>& e, f->completedExecutors) { |
| 2313 | if (approvers->approved<VIEW_EXECUTOR>(e->info, f->info)) { |
| 2314 | executors.put(e.get(), f); |
| 2315 | } |
| 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | // Serialize the following message: |
| 2320 | // |
| 2321 | // v1::agent::Response::GetTasks getTasks; |
| 2322 | // |
| 2323 | // for each pending task: |
| 2324 | // *getTasks.add_pending_tasks() = task |
| 2325 | // for each queued task: |
| 2326 | // *getTasks.add_queued_tasks() = *task; |
| 2327 | // for each launched task: |
| 2328 | // *getTasks.add_launched_tasks() = *task; |
| 2329 | // for each terminated task: |
| 2330 | // *getTasks.add_terminated_tasks() = *task; |
| 2331 | // for each completed task: |
| 2332 | // *getTasks.add_completed_tasks() = *task; |
| 2333 | |
| 2334 | string output; |
| 2335 | google::protobuf::io::StringOutputStream stream(&output); |
| 2336 | google::protobuf::io::CodedOutputStream writer(&stream); |
| 2337 | |
| 2338 | foreach (const Framework* framework, frameworks) { |
| 2339 | // Pending tasks. |
| 2340 | typedef hashmap<TaskID, TaskInfo> TaskMap; |
| 2341 | foreachvalue (const TaskMap& taskInfos, framework->pendingTasks) { |
| 2342 | foreachvalue (const TaskInfo& taskInfo, taskInfos) { |
| 2343 | if (approvers->approved<VIEW_TASK>(taskInfo, framework->info)) { |
| 2344 | // TODO(bmahler): Consider not constructing the temporary task |
| 2345 | // object and instead serialize directly. Since we don't expect |
nothing calls this directly
no test coverage detected