| 2136 | |
| 2137 | |
| 2138 | function<void(JSON::ObjectWriter*)> Http::jsonifyGetTasks( |
| 2139 | const Owned<ObjectApprovers>& approvers) const |
| 2140 | { |
| 2141 | return [=](JSON::ObjectWriter* writer) { |
| 2142 | // Construct framework list with both active and completed frameworks. |
| 2143 | vector<const Framework*> frameworks; |
| 2144 | foreachvalue (Framework* f, slave->frameworks) { |
| 2145 | if (approvers->approved<VIEW_FRAMEWORK>(f->info)) { |
| 2146 | frameworks.push_back(f); |
| 2147 | } |
| 2148 | } |
| 2149 | foreachvalue (const Owned<Framework>& f, slave->completedFrameworks) { |
| 2150 | if (approvers->approved<VIEW_FRAMEWORK>(f->info)) { |
| 2151 | frameworks.push_back(f.get()); |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | // Construct executor list with both active and completed executors. |
| 2156 | hashmap<const Executor*, const Framework*> executors; |
| 2157 | foreach (const Framework* f, frameworks) { |
| 2158 | foreachvalue (const Executor* e, f->executors) { |
| 2159 | if (approvers->approved<VIEW_EXECUTOR>(e->info, f->info)) { |
| 2160 | executors.put(e, f); |
| 2161 | } |
| 2162 | } |
| 2163 | foreach (const Owned<Executor>& e, f->completedExecutors) { |
| 2164 | if (approvers->approved<VIEW_EXECUTOR>(e->info, f->info)) { |
| 2165 | executors.put(e.get(), f); |
| 2166 | } |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | // Jsonify the following message: |
| 2171 | // |
| 2172 | // v1::agent::Response::GetTasks getTasks; |
| 2173 | // |
| 2174 | // for each pending task: |
| 2175 | // *getTasks.add_pending_tasks() = task |
| 2176 | // for each queued task: |
| 2177 | // *getTasks.add_queued_tasks() = *task; |
| 2178 | // for each launched task: |
| 2179 | // *getTasks.add_launched_tasks() = *task; |
| 2180 | // for each terminated task: |
| 2181 | // *getTasks.add_terminated_tasks() = *task; |
| 2182 | // for each completed task: |
| 2183 | // *getTasks.add_completed_tasks() = *task; |
| 2184 | |
| 2185 | const google::protobuf::Descriptor* descriptor = |
| 2186 | v1::agent::Response::GetTasks::descriptor(); |
| 2187 | |
| 2188 | int field; |
| 2189 | |
| 2190 | // Pending tasks. |
| 2191 | field = v1::agent::Response::GetTasks::kPendingTasksFieldNumber; |
| 2192 | writer->field( |
| 2193 | descriptor->FindFieldByNumber(field)->name(), |
| 2194 | [&](JSON::ArrayWriter* writer) { |
| 2195 | foreach (const Framework* framework, frameworks) { |
nothing calls this directly
no test coverage detected