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 2016/07/13 19:10:57 UTC
[2/8] mesos git commit: Implemented 'GetExecutors' call in v1 agent
API.
Implemented 'GetExecutors' call in v1 agent API.
Review: https://reviews.apache.org/r/49758/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/950e9ce9
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/950e9ce9
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/950e9ce9
Branch: refs/heads/master
Commit: 950e9ce90f08f2f3c946fed8dd0bdfe1d1d75c29
Parents: e71233c
Author: haosdent huang <ha...@gmail.com>
Authored: Wed Jul 13 12:10:11 2016 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Wed Jul 13 12:10:11 2016 -0700
----------------------------------------------------------------------
include/mesos/agent/agent.proto | 14 +++++
include/mesos/v1/agent/agent.proto | 14 +++++
src/slave/http.cpp | 107 ++++++++++++++++++++++++++++++++
src/slave/slave.hpp | 9 +++
src/slave/validation.cpp | 3 +
5 files changed, 147 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/950e9ce9/include/mesos/agent/agent.proto
----------------------------------------------------------------------
diff --git a/include/mesos/agent/agent.proto b/include/mesos/agent/agent.proto
index 7acb2d4..2d39a63 100644
--- a/include/mesos/agent/agent.proto
+++ b/include/mesos/agent/agent.proto
@@ -51,6 +51,7 @@ message Call {
GET_CONTAINERS = 10;
GET_FRAMEWORKS = 11; // Retrieves the information about known frameworks.
+ GET_EXECUTORS = 12; // Retrieves the information about known executors.
}
// Provides a snapshot of the current metrics tracked by the agent.
@@ -122,6 +123,7 @@ message Response {
GET_CONTAINERS = 9;
GET_FRAMEWORKS = 10; // See 'GetFrameworks' below.
+ GET_EXECUTORS = 11; // See 'GetExecutors' below.
}
// `healthy` would be true if the agent is healthy. Delayed responses are also
@@ -194,6 +196,17 @@ message Response {
repeated Framework completed_frameworks = 2;
}
+ // Lists information about all the executors known to the agent at the
+ // current time.
+ message GetExecutors {
+ message Executor {
+ required ExecutorInfo executor_info = 1;
+ }
+
+ repeated Executor executors = 1;
+ repeated Executor completed_executors = 2;
+ }
+
optional Type type = 1;
optional GetHealth get_health = 2;
@@ -206,4 +219,5 @@ message Response {
optional GetState get_state = 9;
optional GetContainers get_containers = 10;
optional GetFrameworks get_frameworks = 11;
+ optional GetExecutors get_executors = 12;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mesos/blob/950e9ce9/include/mesos/v1/agent/agent.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/agent/agent.proto b/include/mesos/v1/agent/agent.proto
index 878e499..052f942 100644
--- a/include/mesos/v1/agent/agent.proto
+++ b/include/mesos/v1/agent/agent.proto
@@ -51,6 +51,7 @@ message Call {
GET_CONTAINERS = 10;
GET_FRAMEWORKS = 11; // Retrieves the information about known frameworks.
+ GET_EXECUTORS = 12; // Retrieves the information about known executors.
}
// Provides a snapshot of the current metrics tracked by the agent.
@@ -122,6 +123,7 @@ message Response {
GET_CONTAINERS = 9;
GET_FRAMEWORKS = 10; // See 'GetFrameworks' below.
+ GET_EXECUTORS = 11; // See 'GetExecutors' below.
}
// `healthy` would be true if the agent is healthy. Delayed responses are also
@@ -194,6 +196,17 @@ message Response {
repeated Framework completed_frameworks = 2;
}
+ // Lists information about all the executors known to the agent at the
+ // current time.
+ message GetExecutors {
+ message Executor {
+ required ExecutorInfo executor_info = 1;
+ }
+
+ repeated Executor executors = 1;
+ repeated Executor completed_executors = 2;
+ }
+
optional Type type = 1;
optional GetHealth get_health = 2;
@@ -206,4 +219,5 @@ message Response {
optional GetState get_state = 9;
optional GetContainers get_containers = 10;
optional GetFrameworks get_frameworks = 11;
+ optional GetExecutors get_executors = 12;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mesos/blob/950e9ce9/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 7132e7a..a242e0b 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -392,6 +392,9 @@ Future<Response> Slave::Http::api(
case agent::Call::GET_FRAMEWORKS:
return getFrameworks(call, principal, acceptType);
+
+ case agent::Call::GET_EXECUTORS:
+ return getExecutors(call, principal, acceptType);
}
UNREACHABLE();
@@ -1120,6 +1123,110 @@ agent::Response::GetFrameworks Slave::Http::_getFrameworks(
}
+Future<Response> Slave::Http::getExecutors(
+ const agent::Call& call,
+ const Option<string>& principal,
+ ContentType contentType) const
+{
+ CHECK_EQ(agent::Call::GET_EXECUTORS, call.type());
+
+ // Retrieve `ObjectApprover`s for authorizing frameworks and executors.
+ Future<Owned<ObjectApprover>> frameworksApprover;
+ Future<Owned<ObjectApprover>> executorsApprover;
+ if (slave->authorizer.isSome()) {
+ authorization::Subject subject;
+ if (principal.isSome()) {
+ subject.set_value(principal.get());
+ }
+
+ frameworksApprover = slave->authorizer.get()->getObjectApprover(
+ subject, authorization::VIEW_FRAMEWORK);
+
+ executorsApprover = slave->authorizer.get()->getObjectApprover(
+ subject, authorization::VIEW_EXECUTOR);
+ } else {
+ frameworksApprover = Owned<ObjectApprover>(new AcceptingObjectApprover());
+ executorsApprover = Owned<ObjectApprover>(new AcceptingObjectApprover());
+ }
+
+ return collect(frameworksApprover, executorsApprover)
+ .then(defer(slave->self(),
+ [this, contentType](const tuple<Owned<ObjectApprover>,
+ Owned<ObjectApprover>>& approvers)
+ -> Future<Response> {
+ // Get approver from tuple.
+ Owned<ObjectApprover> frameworksApprover;
+ Owned<ObjectApprover> executorsApprover;
+ tie(frameworksApprover, executorsApprover) = approvers;
+
+ agent::Response response;
+ response.set_type(agent::Response::GET_EXECUTORS);
+
+ response.mutable_get_executors()->CopyFrom(
+ _getExecutors(frameworksApprover, executorsApprover));
+
+ return OK(serialize(contentType, evolve(response)),
+ stringify(contentType));
+ }));
+}
+
+
+agent::Response::GetExecutors Slave::Http::_getExecutors(
+ const Owned<ObjectApprover>& frameworksApprover,
+ const Owned<ObjectApprover>& executorsApprover) const
+{
+ // Construct framework list with both active and completed frameworks.
+ vector<const Framework*> frameworks;
+ foreachvalue (Framework* framework, slave->frameworks) {
+ // Skip unauthorized frameworks.
+ if (!approveViewFrameworkInfo(frameworksApprover, framework->info)) {
+ continue;
+ }
+
+ frameworks.push_back(framework);
+ }
+
+ foreach (const Owned<Framework>& framework, slave->completedFrameworks) {
+ // Skip unauthorized frameworks.
+ if (!approveViewFrameworkInfo(frameworksApprover, framework->info)) {
+ continue;
+ }
+
+ frameworks.push_back(framework.get());
+ }
+
+ agent::Response::GetExecutors getExecutors;
+
+ foreach (const Framework* framework, frameworks) {
+ foreachvalue (Executor* executor, framework->executors) {
+ // Skip unauthorized executors.
+ if (!approveViewExecutorInfo(executorsApprover,
+ executor->info,
+ framework->info)) {
+ continue;
+ }
+
+ getExecutors.add_executors()->mutable_executor_info()->CopyFrom(
+ executor->info);
+ }
+
+ foreach (const Owned<Executor>& executor, framework->completedExecutors) {
+ // Skip unauthorized executors.
+ if (!approveViewExecutorInfo(executorsApprover,
+ executor->info,
+ framework->info)) {
+ continue;
+ }
+
+ getExecutors.add_completed_executors()->mutable_executor_info()->CopyFrom(
+ executor->info);
+ }
+ }
+
+ return getExecutors;
+}
+
+
string Slave::Http::STATISTICS_HELP()
{
return HELP(
http://git-wip-us.apache.org/repos/asf/mesos/blob/950e9ce9/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 8e1921c..48cf77d 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -557,6 +557,15 @@ private:
mesos::agent::Response::GetFrameworks _getFrameworks(
const process::Owned<ObjectApprover>& frameworksApprover) const;
+ process::Future<process::http::Response> getExecutors(
+ const mesos::agent::Call& call,
+ const Option<std::string>& principal,
+ ContentType contentType) const;
+
+ mesos::agent::Response::GetExecutors _getExecutors(
+ const process::Owned<ObjectApprover>& frameworksApprover,
+ const process::Owned<ObjectApprover>& executorsApprover) const;
+
Slave* slave;
// Used to rate limit the statistics endpoint.
http://git-wip-us.apache.org/repos/asf/mesos/blob/950e9ce9/src/slave/validation.cpp
----------------------------------------------------------------------
diff --git a/src/slave/validation.cpp b/src/slave/validation.cpp
index c5720f3..717169a 100644
--- a/src/slave/validation.cpp
+++ b/src/slave/validation.cpp
@@ -93,6 +93,9 @@ Option<Error> validate(
case mesos::agent::Call::GET_FRAMEWORKS:
return None();
+
+ case mesos::agent::Call::GET_EXECUTORS:
+ return None();
}
UNREACHABLE();