MCPcopy Create free account
hub / github.com/apache/mesos / foreach

Method foreach

src/examples/test_http_framework.cpp:226–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224 void resourceOffers(const vector<Offer>& offers)
225 {
226 foreach (const Offer& offer, offers) {
227 cout << "Received offer " << offer.id() << " with "
228 << Resources(offer.resources()) << endl;
229
230 Resources taskResources = Resources::parse(
231 "cpus:" + stringify(CPUS_PER_TASK) +
232 ";mem:" + stringify(MEM_PER_TASK)).get();
233 taskResources.allocate(role);
234
235 Resources remaining = offer.resources();
236
237 // Launch tasks.
238 vector<TaskInfo> tasks;
239 while (tasksLaunched < totalTasks &&
240 remaining.toUnreserved().contains(taskResources)) {
241 int taskId = tasksLaunched++;
242
243 cout << "Launching task " << taskId << " using offer "
244 << offer.id() << endl;
245
246 TaskInfo task;
247 task.set_name("Task " + lexical_cast<string>(taskId));
248 task.mutable_task_id()->set_value(lexical_cast<string>(taskId));
249 task.mutable_agent_id()->MergeFrom(offer.agent_id());
250 task.mutable_executor()->MergeFrom(executor);
251
252 Option<Resources> resources = [&]() {
253 if (role == "*") {
254 return remaining.find(taskResources);
255 } else {
256 Resource::ReservationInfo reservation;
257 reservation.set_type(Resource::ReservationInfo::STATIC);
258 reservation.set_role(role);
259
260 return remaining.find(taskResources.pushReservation(reservation));
261 }
262 }();
263
264 CHECK_SOME(resources);
265
266 task.mutable_resources()->CopyFrom(resources.get());
267
268 remaining -= resources.get();
269
270 tasks.push_back(task);
271 }
272
273 Call call;
274 CHECK(framework.has_id());
275 call.mutable_framework_id()->CopyFrom(framework.id());
276 call.set_type(Call::ACCEPT);
277
278 Call::Accept* accept = call.mutable_accept();
279 accept->add_offer_ids()->CopyFrom(offer.id());
280
281 Offer::Operation* operation = accept->add_operations();
282 operation->set_type(Offer::Operation::LAUNCH);
283 foreach (const TaskInfo& taskInfo, tasks) {

Callers

nothing calls this directly

Calls 14

MergeFromMethod · 0.80
CopyFromMethod · 0.80
sendMethod · 0.65
ResourcesClass · 0.50
parseFunction · 0.50
stringifyFunction · 0.50
idMethod · 0.45
resourcesMethod · 0.45
getMethod · 0.45
allocateMethod · 0.45
containsMethod · 0.45
toUnreservedMethod · 0.45

Tested by

no test coverage detected