You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ch...@apache.org on 2018/12/14 02:03:41 UTC

[mesos] 03/05: Set up the `Resource.DiskInfo.Source.vendor` field in SLRP.

This is an automated email from the ASF dual-hosted git repository.

chhsiao pushed a commit to branch 1.7.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 3c0b147fe3409984e78eb9b43b45253ea6b89883
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
AuthorDate: Thu Dec 6 15:28:16 2018 -0800

    Set up the `Resource.DiskInfo.Source.vendor` field in SLRP.
    
    For a CSI-backed disk resource, this field is set to the concatenation
    of the type and name of its CSI plugin, with a dot in between. This
    enables frameworks to identify the storage backend the disk resource.
    
    Review: https://reviews.apache.org/r/69520
---
 src/resource_provider/storage/provider.cpp | 33 ++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/resource_provider/storage/provider.cpp b/src/resource_provider/storage/provider.cpp
index 93df4a2..a151ead 100644
--- a/src/resource_provider/storage/provider.cpp
+++ b/src/resource_provider/storage/provider.cpp
@@ -246,32 +246,41 @@ static inline Resource createRawDiskResource(
     const ResourceProviderInfo& info,
     const Bytes& capacity,
     const Option<string>& profile,
+    const Option<string>& vendor,
     const Option<string>& id = None(),
     const Option<Labels>& metadata = None())
 {
   CHECK(info.has_id());
+  CHECK(info.has_storage());
 
   Resource resource;
   resource.set_name("disk");
   resource.set_type(Value::SCALAR);
   resource.mutable_scalar()
-    ->set_value((double) capacity.bytes() / Bytes::MEGABYTES);
+    ->set_value(static_cast<double>(capacity.bytes()) / Bytes::MEGABYTES);
+
   resource.mutable_provider_id()->CopyFrom(info.id()),
   resource.mutable_reservations()->CopyFrom(info.default_reservations());
-  resource.mutable_disk()->mutable_source()
-    ->set_type(Resource::DiskInfo::Source::RAW);
+
+  Resource::DiskInfo::Source* source =
+    resource.mutable_disk()->mutable_source();
+
+  source->set_type(Resource::DiskInfo::Source::RAW);
 
   if (profile.isSome()) {
-    resource.mutable_disk()->mutable_source()->set_profile(profile.get());
+    source->set_profile(profile.get());
+  }
+
+  if (vendor.isSome()) {
+    source->set_vendor(vendor.get());
   }
 
   if (id.isSome()) {
-    resource.mutable_disk()->mutable_source()->set_id(id.get());
+    source->set_id(id.get());
   }
 
   if (metadata.isSome()) {
-    resource.mutable_disk()->mutable_source()->mutable_metadata()
-      ->CopyFrom(metadata.get());
+    source->mutable_metadata()->CopyFrom(metadata.get());
   }
 
   return resource;
@@ -296,6 +305,9 @@ public:
       metaDir(slave::paths::getMetaRootDir(_workDir)),
       contentType(ContentType::PROTOBUF),
       info(_info),
+      vendor(
+          info.storage().plugin().type() + "." +
+          info.storage().plugin().name()),
       slaveId(_slaveId),
       authToken(_authToken),
       strict(_strict),
@@ -455,6 +467,7 @@ private:
   const string metaDir;
   const ContentType contentType;
   ResourceProviderInfo info;
+  const string vendor;
   const SlaveID slaveId;
   const Option<string> authToken;
   const bool strict;
@@ -1374,6 +1387,8 @@ ResourceConversion StorageLocalResourceProviderProcess::reconcileResources(
         Bytes(resource.scalar().value() * Bytes::MEGABYTES),
         resource.disk().source().has_profile()
           ? resource.disk().source().profile() : Option<string>::none(),
+        resource.disk().source().has_vendor()
+          ? resource.disk().source().vendor() : Option<string>::none(),
         resource.disk().source().has_id()
           ? resource.disk().source().id() : Option<string>::none(),
         resource.disk().source().has_metadata()
@@ -2913,6 +2928,7 @@ Future<Resources> StorageLocalResourceProviderProcess::listVolumes()
                 volumesToProfiles.contains(entry.volume().id())
                   ? volumesToProfiles.at(entry.volume().id())
                   : Option<string>::none(),
+                vendor,
                 entry.volume().id(),
                 entry.volume().attributes().empty()
                   ? Option<Labels>::none()
@@ -2960,7 +2976,8 @@ Future<Resources> StorageLocalResourceProviderProcess::getCapacities()
             return createRawDiskResource(
                 info,
                 Bytes(response.available_capacity()),
-                profile);
+                profile,
+                vendor);
           })));
       }