You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2017/11/29 18:22:21 UTC

[2/2] mesos git commit: Added infrastructure to support master capabilities.

Added infrastructure to support master capabilities.

This includes the necessary constants in the protobuf
definition as well as various support methods to get
the current master capabilities.

Note that the actual feature is implemented in a later
commit, so the capability is not yet activated on the
master.

Review: https://reviews.apache.org/r/64007/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/17d186e3
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/17d186e3
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/17d186e3

Branch: refs/heads/master
Commit: 17d186e379d2db3edb04743a061dc05e24c32c9b
Parents: dfb2c62
Author: Benno Evers <be...@mesosphere.com>
Authored: Wed Nov 29 10:21:57 2017 -0800
Committer: Vinod Kone <vi...@gmail.com>
Committed: Wed Nov 29 10:21:57 2017 -0800

----------------------------------------------------------------------
 include/mesos/mesos.proto     | 13 +++++++++++++
 include/mesos/v1/mesos.proto  | 13 +++++++++++++
 src/CMakeLists.txt            |  1 +
 src/Makefile.am               |  1 +
 src/common/protobuf_utils.cpp |  6 ++++++
 src/common/protobuf_utils.hpp | 25 ++++++++++++++++++++++++
 src/master/constants.cpp      | 39 ++++++++++++++++++++++++++++++++++++++
 src/master/constants.hpp      |  4 ++++
 src/master/http.cpp           |  9 +++++++++
 src/master/master.cpp         |  4 ++++
 src/tests/master_tests.cpp    |  3 +++
 11 files changed, 118 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/include/mesos/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/mesos.proto b/include/mesos/mesos.proto
index 8c28b81..b1ebfe2 100644
--- a/include/mesos/mesos.proto
+++ b/include/mesos/mesos.proto
@@ -884,6 +884,19 @@ message MasterInfo {
   // The domain that this master belongs to. All masters in a Mesos
   // cluster should belong to the same region.
   optional DomainInfo domain = 8;
+
+  message Capability {
+    enum Type {
+      UNKNOWN = 0;
+
+      // The master can handle slaves whose state
+      // changes after re-registering.
+      AGENT_UPDATE = 1;
+    }
+    optional Type type = 1;
+  }
+
+  repeated Capability capabilities = 9;
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/include/mesos/v1/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/mesos.proto b/include/mesos/v1/mesos.proto
index 35bc6e1..d535eb4 100644
--- a/include/mesos/v1/mesos.proto
+++ b/include/mesos/v1/mesos.proto
@@ -882,6 +882,19 @@ message MasterInfo {
   // The domain that this master belongs to. All masters in a Mesos
   // cluster should belong to the same region.
   optional DomainInfo domain = 8;
+
+  message Capability {
+    enum Type {
+      UNKNOWN = 0;
+
+      // The master can handle slaves whose state
+      // changes after re-registering.
+      AGENT_UPDATE = 1;
+    }
+    optional Type type = 1;
+  }
+
+  repeated Capability capabilities = 9;
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6b50062..3f5d946 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -427,6 +427,7 @@ set(LOGGING_SRC
   logging/logging.cpp)
 
 set(MASTER_SRC
+  master/constants.cpp
   master/flags.cpp
   master/http.cpp
   master/maintenance.cpp

http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index ec70b5f..b1ed4e5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -973,6 +973,7 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   local/local.cpp							\
   logging/flags.cpp							\
   logging/logging.cpp							\
+  master/constants.cpp              \
   master/flags.cpp							\
   master/http.cpp							\
   master/maintenance.cpp						\

http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/src/common/protobuf_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/protobuf_utils.cpp b/src/common/protobuf_utils.cpp
index c0ff306..d557342 100644
--- a/src/common/protobuf_utils.cpp
+++ b/src/common/protobuf_utils.cpp
@@ -51,6 +51,7 @@
 #include "common/resources_utils.hpp"
 
 #include "master/master.hpp"
+#include "master/constants.hpp"
 
 #include "messages/messages.hpp"
 
@@ -534,6 +535,11 @@ MasterInfo createMasterInfo(const UPID& pid)
     info.mutable_address()->set_hostname(hostname.get());
   }
 
+  foreach (const MasterInfo::Capability& capability,
+           mesos::internal::master::MASTER_CAPABILITIES()) {
+    info.add_capabilities()->CopyFrom(capability);
+  }
+
   return info;
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/src/common/protobuf_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/protobuf_utils.hpp b/src/common/protobuf_utils.hpp
index 6f991e8..31217bf 100644
--- a/src/common/protobuf_utils.hpp
+++ b/src/common/protobuf_utils.hpp
@@ -344,7 +344,32 @@ mesos::maintenance::Schedule createSchedule(
 
 } // namespace maintenance {
 
+
 namespace master {
+
+// TODO(bmahler): Store the repeated field within this so that we
+// don't drop unknown capabilities.
+struct Capabilities
+{
+  Capabilities() = default;
+
+  template <typename Iterable>
+  Capabilities(const Iterable& capabilities)
+  {
+    foreach (const MasterInfo::Capability& capability, capabilities) {
+      switch (capability.type()) {
+        case MasterInfo::Capability::UNKNOWN:
+          break;
+        case MasterInfo::Capability::AGENT_UPDATE:
+          agentUpdate = true;
+          break;
+      }
+    }
+  }
+
+  bool agentUpdate = false;
+};
+
 namespace event {
 
 // Helper for creating a `TASK_UPDATED` event from a `Task`, its

http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/src/master/constants.cpp
----------------------------------------------------------------------
diff --git a/src/master/constants.cpp b/src/master/constants.cpp
new file mode 100644
index 0000000..bf3d3e4
--- /dev/null
+++ b/src/master/constants.cpp
@@ -0,0 +1,39 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "master/constants.hpp"
+
+namespace mesos {
+namespace internal {
+namespace master {
+
+std::vector<MasterInfo::Capability> MASTER_CAPABILITIES()
+{
+  MasterInfo::Capability::Type types[] = {}; // Empty for now.
+
+  std::vector<MasterInfo::Capability> result;
+  foreach (MasterInfo::Capability::Type type, types) {
+    MasterInfo::Capability capability;
+    capability.set_type(type);
+    result.push_back(capability);
+  }
+
+  return result;
+}
+
+} // namespace master {
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/src/master/constants.hpp
----------------------------------------------------------------------
diff --git a/src/master/constants.hpp b/src/master/constants.hpp
index 725680b..17092ea 100644
--- a/src/master/constants.hpp
+++ b/src/master/constants.hpp
@@ -19,6 +19,8 @@
 
 #include <stdint.h>
 
+#include <mesos/mesos.hpp>
+
 #include <stout/bytes.hpp>
 #include <stout/duration.hpp>
 #include <stout/version.hpp>
@@ -149,6 +151,8 @@ constexpr char DEFAULT_HTTP_FRAMEWORK_AUTHENTICATION_REALM[] =
 // Agents older than this version are not allowed to register.
 const Version MINIMUM_AGENT_VERSION = Version(1, 0, 0);
 
+std::vector<MasterInfo::Capability> MASTER_CAPABILITIES();
+
 } // namespace master {
 } // namespace internal {
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index e7291ce..9dcdcbe 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -146,6 +146,14 @@ static void json(
 }
 
 
+static void json(
+    JSON::StringWriter* writer,
+    const MasterInfo::Capability& capability)
+{
+  writer->append(MasterInfo::Capability::Type_Name(capability.type()));
+}
+
+
 static void json(JSON::ObjectWriter* writer, const Offer& offer)
 {
   writer->field("id", offer.id().value());
@@ -2908,6 +2916,7 @@ Future<Response> Master::Http::state(
         writer->field("id", master->info().id());
         writer->field("pid", string(master->self()));
         writer->field("hostname", master->info().hostname());
+        writer->field("capabilities", master->info().capabilities());
         writer->field("activated_slaves", master->_slaves_active());
         writer->field("deactivated_slaves", master->_slaves_inactive());
         writer->field("unreachable_slaves", master->_slaves_unreachable());

http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index f61a10b..7bcdb74 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -338,6 +338,10 @@ Master::Master(
   info_.set_pid(self());
   info_.set_version(MESOS_VERSION);
 
+  for (const MasterInfo::Capability& capability : MASTER_CAPABILITIES()) {
+    info_.add_capabilities()->CopyFrom(capability);
+  }
+
   // Determine our hostname or use the hostname provided.
   string hostname;
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/17d186e3/src/tests/master_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index f60f822..57eae32 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -4516,6 +4516,9 @@ TEST_F(MasterTest, StateEndpoint)
       state.values["unregistered_frameworks"].is<JSON::Array>());
   EXPECT_TRUE(
       state.values["unregistered_frameworks"].as<JSON::Array>().values.empty());
+
+  ASSERT_TRUE(state.values["capabilities"].is<JSON::Array>());
+  EXPECT_TRUE(state.values["capabilities"].as<JSON::Array>().values.empty());
 }