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

Method foreach

src/examples/test_csi_user_framework.cpp:217–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215 void resourceOffers(const vector<Offer>& offers)
216 {
217 foreach (const Offer& offer, offers) {
218 cout << "Received offer " << offer.id() << " with "
219 << Resources(offer.resources()) << endl;
220
221 // Filter resources and group interesting resources by resource provider.
222 //
223 // NOTE: We introduce a typedef here so we can use this type
224 // with the `foreachvalue` preprocessor macro below.
225 using ResourcesByType =
226 hashmap<Resource::DiskInfo::Source::Type, Resources>;
227
228 hashmap<ResourceProviderID, ResourcesByType> resourcesByProvider;
229
230 constexpr Resource::DiskInfo::Source::Type RAW =
231 Resource::DiskInfo::Source::RAW;
232
233 constexpr Resource::DiskInfo::Source::Type MOUNT =
234 Resource::DiskInfo::Source::MOUNT;
235
236 foreach(const Resource& resource, offer.resources()) {
237 // Ignore any resources not from a resource provider.
238 if (!resource.has_provider_id()) {
239 continue;
240 }
241
242 // We only convert reserved resources.
243 if (!Resources::isReserved(resource)) {
244 continue;
245 }
246
247 // We either work on `RAW` or `MOUNT` disk resources. Store
248 // them by type and ignore any other resources.
249 if (Resources::isDisk(resource, RAW)) {
250 resourcesByProvider[resource.provider_id()][RAW] += resource;
251 } else if (Resources::isDisk(resource, MOUNT)) {
252 resourcesByProvider[resource.provider_id()][MOUNT] += resource;
253 }
254 }
255
256 // Create operations.
257
258 // Create a single call which is either an accept and contains
259 // at least one operation, or a decline.
260 Call call;
261 CHECK(framework.has_id());
262 call.mutable_framework_id()->CopyFrom(framework.id());
263
264 // We create operations on resources from each resource provider
265 // separately as most operations currently cannot operate on multiple
266 // resource providers at once (`LAUNCH` being the obvious exception).
267 foreachvalue (
268 const ResourcesByType& resourcesByType,
269 resourcesByProvider) {
270 // Iterate over disk resources grouped by disk type since the
271 // performed operation depends on the type.
272 foreachpair (
273 const Resource::DiskInfo::Source::Type& type,
274 const Resources& resources,

Callers

nothing calls this directly

Calls 8

CopyFromMethod · 0.80
sendMethod · 0.65
ResourcesClass · 0.50
idMethod · 0.45
resourcesMethod · 0.45
emptyMethod · 0.45
acceptMethod · 0.45
secsMethod · 0.45

Tested by

no test coverage detected