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;
}
Esempio n. 2
0
void ArangoScheduler::makePersistent (const mesos::Offer& offer,
                                      const mesos::Resources& resources) const {
  mesos::Offer::Operation reserve;
  reserve.set_type(mesos::Offer::Operation::CREATE);
  reserve.mutable_create()->mutable_volumes()->CopyFrom(resources);

  _driver->acceptOffers({offer.id()}, {reserve});
}
Esempio n. 3
0
void ArangoScheduler::reserveDynamically (const mesos::Offer& offer,
                                          const mesos::Resources& resources) const {
  mesos::Offer::Operation reserve;
  reserve.set_type(mesos::Offer::Operation::RESERVE);
  reserve.mutable_reserve()->mutable_resources()->CopyFrom(resources);

  _driver->acceptOffers({offer.id()}, {reserve});
}
Esempio n. 4
0
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;
}