void RandomSorter::remove(const SlaveID& slaveId, const Resources& resources) { if (!resources.empty()) { CHECK(total_.resources.contains(slaveId)); CHECK(total_.resources[slaveId].contains(resources)) << total_.resources[slaveId] << " does not contain " << resources; total_.resources[slaveId] -= resources; // Remove shared resources from the total quantities when there // are no instances of same resources left in the total. const Resources absentShared = resources.shared() .filter([this, slaveId](const Resource& resource) { return !total_.resources[slaveId].contains(resource); }); const ResourceQuantities scalarQuantities = ResourceQuantities::fromScalarResources( (resources.nonShared() + absentShared).scalars()); CHECK(total_.totals.contains(scalarQuantities)); total_.totals -= scalarQuantities; if (total_.resources[slaveId].empty()) { total_.resources.erase(slaveId); } } }
Slave( const SlaveInfo& _info, const protobuf::slave::Capabilities& _capabilities, bool _activated, const Resources& _total, const Resources& _allocated) : info(_info), capabilities(_capabilities), activated(_activated), total(_total), allocated(_allocated), shared(_total.shared()), hasGpu_(_total.gpus().getOrElse(0) > 0) { updateAvailable(); }
void RandomSorter::add(const SlaveID& slaveId, const Resources& resources) { if (!resources.empty()) { // Add shared resources to the total quantities when the same // resources don't already exist in the total. const Resources newShared = resources.shared() .filter([this, slaveId](const Resource& resource) { return !total_.resources[slaveId].contains(resource); }); total_.resources[slaveId] += resources; const ResourceQuantities scalarQuantities = ResourceQuantities::fromScalarResources( (resources.nonShared() + newShared).scalars()); total_.totals += scalarQuantities; } }