You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bb...@apache.org on 2017/11/08 16:01:27 UTC
[6/9] mesos git commit: Allowed toggling of agent capabilities via
command line flags.
Allowed toggling of agent capabilities via command line flags.
This patch introduces a new agent command line flags
'--agent_features' which can be used to whitelist capabilities to
enable. This flag is intended to enable introducing feature flags in
the future so experimental features can be added while still reducing
the risk of breaking existing functionality. Currently only the
'RESOURCE_PROVIDER' capability can be toggled.
Review: https://reviews.apache.org/r/63519/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9850482c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9850482c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9850482c
Branch: refs/heads/master
Commit: 9850482cc5a409762443206a79d186b06be36e4f
Parents: ca49562
Author: Benjamin Bannier <bb...@apache.org>
Authored: Wed Nov 8 00:51:45 2017 +0100
Committer: Benjamin Bannier <bb...@apache.org>
Committed: Wed Nov 8 15:51:20 2017 +0100
----------------------------------------------------------------------
docs/configuration/agent.md | 22 ++++++++++++++++++++++
src/slave/flags.cpp | 32 ++++++++++++++++++++++++++++++++
src/slave/flags.hpp | 1 +
src/slave/slave.cpp | 21 ++++++++++++++-------
src/slave/slave.hpp | 2 ++
5 files changed, 71 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/9850482c/docs/configuration/agent.md
----------------------------------------------------------------------
diff --git a/docs/configuration/agent.md b/docs/configuration/agent.md
index 116e7c6..f1e0681 100644
--- a/docs/configuration/agent.md
+++ b/docs/configuration/agent.md
@@ -85,6 +85,28 @@ Example:
}</code></pre>
</td>
</tr>
+
+<tr>
+ <td>
+ --agent_features=VALUE
+ </td>
+ <td>
+JSON representation of agent features to whitelist. We always require
+'MULTI_ROLE', 'HIERARCHICAL_ROLE', and 'RESERVATION_REFINEMENT'.
+<p/>
+Example:
+<pre><code>
+{
+ "capabilities": [
+ {"type": "MULTI_ROLE"},
+ {"type": "HIERARCHICAL_ROLE"},
+ {"type": "RESERVATION_REFINEMENT"}
+ ]
+}
+</pre></code>
+ </td>
+</tr>
+
<tr>
<td>
--agent_subsystems=VALUE,
http://git-wip-us.apache.org/repos/asf/mesos/blob/9850482c/src/slave/flags.cpp
----------------------------------------------------------------------
diff --git a/src/slave/flags.cpp b/src/slave/flags.cpp
index 63aaac2..c5078a8 100644
--- a/src/slave/flags.cpp
+++ b/src/slave/flags.cpp
@@ -27,6 +27,7 @@
#include "common/http.hpp"
#include "common/parse.hpp"
+#include "common/protobuf_utils.hpp"
#include "slave/constants.hpp"
@@ -641,6 +642,37 @@ mesos::internal::slave::Flags::Flags()
"This flag has the same syntax as `--effective_capabilities`."
);
+ add(&Flags::agent_features,
+ "agent_features",
+ "JSON representation of agent features to whitelist. We always require\n"
+ "'MULTI_ROLE', 'HIERARCHICAL_ROLE', and 'RESERVATION_REFINEMENT'.\n"
+ "\n"
+ "Example:\n"
+ "{\n"
+ " \"capabilities\": [\n"
+ " {\"type\": \"MULTI_ROLE\"},\n"
+ " {\"type\": \"HIERARCHICAL_ROLE\"},\n"
+ " {\"type\": \"RESERVATION_REFINEMENT\"}\n"
+ " ]\n"
+ "}\n",
+ [](const Option<SlaveCapabilities>& agentFeatures) -> Option<Error> {
+ // Check all required capabilities are enabled.
+ if (agentFeatures.isSome()) {
+ protobuf::slave::Capabilities capabilities(
+ agentFeatures->capabilities());
+
+ if (!capabilities.multiRole ||
+ !capabilities.hierarchicalRole ||
+ !capabilities.reservationRefinement) {
+ return Error(
+ "At least the following agent features need to be enabled: "
+ "MULTI_ROLE, HIERARCHICAL_ROLE, RESERVATION_REFINEMENT");
+ }
+ }
+
+ return None();
+ });
+
add(&Flags::disallow_sharing_agent_pid_namespace,
"disallow_sharing_agent_pid_namespace",
"If set to `true`, each top-level container will have its own pid\n"
http://git-wip-us.apache.org/repos/asf/mesos/blob/9850482c/src/slave/flags.hpp
----------------------------------------------------------------------
diff --git a/src/slave/flags.hpp b/src/slave/flags.hpp
index d02edbf..0c02b49 100644
--- a/src/slave/flags.hpp
+++ b/src/slave/flags.hpp
@@ -176,6 +176,7 @@ public:
std::string xfs_project_range;
#endif
bool http_command_executor;
+ Option<SlaveCapabilities> agent_features;
Option<DomainInfo> domain;
// The following flags are executable specific (e.g., since we only
http://git-wip-us.apache.org/repos/asf/mesos/blob/9850482c/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index c108239..0e342cd 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -56,17 +56,19 @@
#include <stout/duration.hpp>
#include <stout/exit.hpp>
#include <stout/fs.hpp>
+#include <stout/json.hpp>
#include <stout/lambda.hpp>
#include <stout/net.hpp>
#include <stout/numify.hpp>
#include <stout/option.hpp>
#include <stout/os.hpp>
#include <stout/path.hpp>
+#include <stout/protobuf.hpp>
#include <stout/stringify.hpp>
#include <stout/strings.hpp>
#include <stout/try.hpp>
-#include <stout/uuid.hpp>
#include <stout/utils.hpp>
+#include <stout/uuid.hpp>
#include "authentication/cram_md5/authenticatee.hpp"
@@ -196,6 +198,11 @@ Slave::Slave(const string& id,
state(RECOVERING),
flags(_flags),
http(this),
+ capabilities(
+ _flags.agent_features.isNone()
+ ? protobuf::slave::Capabilities(AGENT_CAPABILITIES())
+ : protobuf::slave::Capabilities(
+ _flags.agent_features->capabilities())),
completedFrameworks(MAX_COMPLETED_FRAMEWORKS),
detector(_detector),
containerizer(_containerizer),
@@ -1481,9 +1488,9 @@ void Slave::doReliableRegistration(Duration maxBackoff)
RegisterSlaveMessage message;
message.set_version(MESOS_VERSION);
message.mutable_slave()->CopyFrom(slaveInfo);
- foreach (const SlaveInfo::Capability& capability, AGENT_CAPABILITIES()) {
- message.add_agent_capabilities()->CopyFrom(capability);
- }
+
+ message.mutable_agent_capabilities()->CopyFrom(
+ capabilities.toRepeatedPtrField());
// Include checkpointed resources.
message.mutable_checkpointed_resources()->CopyFrom(checkpointedResources_);
@@ -1493,9 +1500,9 @@ void Slave::doReliableRegistration(Duration maxBackoff)
// Re-registering, so send tasks running.
ReregisterSlaveMessage message;
message.set_version(MESOS_VERSION);
- foreach (const SlaveInfo::Capability& capability, AGENT_CAPABILITIES()) {
- message.add_agent_capabilities()->CopyFrom(capability);
- }
+
+ message.mutable_agent_capabilities()->CopyFrom(
+ capabilities.toRepeatedPtrField());
// Include checkpointed resources.
message.mutable_checkpointed_resources()->CopyFrom(checkpointedResources_);
http://git-wip-us.apache.org/repos/asf/mesos/blob/9850482c/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index df1b020..79c7f02 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -571,6 +571,8 @@ private:
SlaveInfo info;
+ protobuf::slave::Capabilities capabilities;
+
// Resources that are checkpointed by the slave.
Resources checkpointedResources;