size_t arangodb::numberPorts (mesos::Offer const& offer, std::string const& role) { size_t value = 0; for (int i = 0; i < offer.resources_size(); ++i) { auto const& resource = offer.resources(i); if (resource.name() == "ports" && resource.type() == mesos::Value::RANGES) { if (role.empty() || (resource.has_role() && resource.role() == role)) { // note that role is optional but has a default, therefore // has_role() should always be true. Should, for whatever reason, // no role be set in the offer, we do not count this range! const auto& ranges = resource.ranges(); for (int j = 0; j < ranges.range_size(); ++j) { const auto& range = ranges.range(j); value += range.end() - range.begin() + 1; } } } } return value; }
size_t arangodb::numberPorts (const mesos::Offer& offer) { size_t value = 0; for (int i = 0; i < offer.resources_size(); ++i) { const auto& resource = offer.resources(i); if (resource.name() == "ports" && resource.type() == mesos::Value::RANGES) { const auto& ranges = resource.ranges(); for (int j = 0; j < ranges.range_size(); ++j) { const auto& range = ranges.range(j); value += range.end() - range.begin() + 1; } } } return value; }