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

Method apply

src/slave/slave.cpp:9335–9397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9333}
9334
9335void Slave::apply(Operation* operation)
9336{
9337 vector<ResourceConversion> conversions;
9338
9339 // NOTE: 'totalResources' don't have allocations set, we need to
9340 // remove them from the conversions.
9341
9342 if (protobuf::isSpeculativeOperation(operation->info())) {
9343 Offer::Operation strippedOperation = operation->info();
9344 protobuf::stripAllocationInfo(&strippedOperation);
9345
9346 Try<vector<ResourceConversion>> _conversions =
9347 getResourceConversions(strippedOperation);
9348
9349 CHECK_SOME(_conversions);
9350
9351 conversions = _conversions.get();
9352 } else {
9353 // For non-speculative operations, we only apply the conversion
9354 // once it becomes terminal. Before that, we don't know the
9355 // converted resources of the conversion.
9356 CHECK_EQ(OPERATION_FINISHED, operation->latest_status().state());
9357
9358 Try<Resources> consumed = protobuf::getConsumedResources(operation->info());
9359 CHECK_SOME(consumed);
9360
9361 Resources converted = operation->latest_status().converted_resources();
9362
9363 consumed->unallocate();
9364 converted.unallocate();
9365
9366 conversions.emplace_back(consumed.get(), converted);
9367 }
9368
9369 // Now, actually apply the operation.
9370 Try<Resources> resources = totalResources.apply(conversions);
9371 CHECK_SOME(resources);
9372
9373 totalResources = resources.get();
9374
9375 Result<ResourceProviderID> resourceProviderId =
9376 getResourceProviderId(operation->info());
9377
9378 CHECK(!resourceProviderId.isError())
9379 << "Failed to get resource provider ID: "
9380 << resourceProviderId.error();
9381
9382 // Besides updating the agent's `totalResources`, we also need to
9383 // update the resource provider's `totalResources`.
9384 if (resourceProviderId.isSome()) {
9385 ResourceProvider* resourceProvider =
9386 getResourceProvider(resourceProviderId.get());
9387
9388 CHECK_NOTNULL(resourceProvider);
9389
9390 Try<Resources> resources =
9391 resourceProvider->totalResources.apply(conversions);
9392

Callers

nothing calls this directly

Calls 12

isSpeculativeOperationFunction · 0.85
stripAllocationInfoFunction · 0.85
getResourceConversionsFunction · 0.85
getConsumedResourcesFunction · 0.85
getResourceProviderIdFunction · 0.85
infoMethod · 0.80
errorMethod · 0.65
getMethod · 0.45
stateMethod · 0.45
unallocateMethod · 0.45
isErrorMethod · 0.45
isSomeMethod · 0.45

Tested by

no test coverage detected