Example #1
0
// Note that `reservationPrincipal` should be specified if and only if
// the volume uses dynamically reserved resources.
inline Resource createPersistentVolume(
    Resource volume,
    const std::string& persistenceId,
    const std::string& containerPath,
    const Option<std::string>& reservationPrincipal = None())
{
  Option<Resource::DiskInfo::Source> source = None();
  if (volume.has_disk() && volume.disk().has_source()) {
    source = volume.disk().source();
  }

  volume.mutable_disk()->CopyFrom(
      createDiskInfo(persistenceId, containerPath, None(), None(), source));

  if (reservationPrincipal.isSome()) {
    volume.mutable_reservation()->set_principal(reservationPrincipal.get());
  }

  return volume;
}
Example #2
0
string getPersistentVolumePath(
    const string& rootDir,
    const Resource& volume)
{
  CHECK(volume.has_role());
  CHECK(volume.has_disk());
  CHECK(volume.disk().has_persistence());

  // If no `source` is provided in `DiskInfo` volumes are mapped into
  // the `rootDir`.
  if (!volume.disk().has_source()) {
    return getPersistentVolumePath(
        rootDir,
        volume.role(),
        volume.disk().persistence().id());
  }

  // If a `source` was provided for the volume, we map it according
  // to the `type` of disk. Currently only the `PATH` and 'MOUNT'
  // types are supported.
  if (volume.disk().source().type() == Resource::DiskInfo::Source::PATH) {
    // For `PATH` we mount a directory inside the `root`.
    CHECK(volume.disk().source().has_path());
    return getPersistentVolumePath(
        volume.disk().source().path().root(),
        volume.role(),
        volume.disk().persistence().id());
  } else if (
      volume.disk().source().type() == Resource::DiskInfo::Source::MOUNT) {
    // For `MOUNT` we map straight onto the root of the mount.
    CHECK(volume.disk().source().has_mount());
    return volume.disk().source().mount().root();
  }

  UNREACHABLE();
}