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

Method updateAllocation

src/master/allocator/mesos/hierarchical.cpp:1289–1416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1287
1288
1289void HierarchicalAllocatorProcess::updateAllocation(
1290 const FrameworkID& frameworkId,
1291 const SlaveID& slaveId,
1292 const Resources& offeredResources,
1293 const vector<ResourceConversion>& conversions)
1294{
1295 CHECK(initialized);
1296 CHECK_CONTAINS(frameworks, frameworkId);
1297
1298 Slave& slave = *CHECK_NOTNONE(getSlave(slaveId));
1299
1300 // We require that an allocation is tied to a single role.
1301 //
1302 // TODO(bmahler): The use of `Resources::allocations()` induces
1303 // unnecessary copying of `Resources` objects (which is expensive
1304 // at the time this was written).
1305 hashmap<string, Resources> allocations = offeredResources.allocations();
1306
1307 CHECK_EQ(1u, allocations.size());
1308
1309 string role = allocations.begin()->first;
1310
1311 Sorter* frameworkSorter = CHECK_NOTNONE(getFrameworkSorter(role));
1312
1313 const Resources frameworkAllocation =
1314 frameworkSorter->allocation(frameworkId.value(), slaveId);
1315
1316 // We keep a copy of the offered resources here and it is updated
1317 // by the specified resource conversions.
1318 //
1319 // The resources in the resource conversions should have been
1320 // normalized by the master (contains proper AllocationInfo).
1321 //
1322 // TODO(bmahler): Check that the resources in the resource
1323 // conversions have AllocationInfo set. The master should enforce
1324 // this. E.g.
1325 //
1326 // foreach (const ResourceConversion& conversion, conversions) {
1327 // CHECK_NONE(validateConversionOnAllocatedResources(conversion));
1328 // }
1329 Resources updatedOfferedResources =
1330 CHECK_NOTERROR(offeredResources.apply(conversions));
1331
1332 // Update the per-slave allocation.
1333 slave.increaseAvailable(frameworkId, offeredResources);
1334 slave.decreaseAvailable(frameworkId, updatedOfferedResources);
1335
1336 roleTree.untrackOfferedOrAllocated(slaveId, offeredResources);
1337 roleTree.trackOfferedOrAllocated(slaveId, updatedOfferedResources);
1338
1339 // Update the allocation in the framework sorter.
1340 frameworkSorter->update(
1341 frameworkId.value(),
1342 slaveId,
1343 offeredResources,
1344 updatedOfferedResources);
1345
1346 // Update the allocation in the role sorter.

Callers

nothing calls this directly

Calls 14

getSlaveFunction · 0.85
increaseAvailableMethod · 0.80
decreaseAvailableMethod · 0.80
allocationsMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
allocationMethod · 0.45
valueMethod · 0.45
applyMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected