You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gi...@apache.org on 2017/12/27 17:34:32 UTC
[2/2] mesos git commit: Added a new operator API for `PRUNE_IMAGES`.
Added a new operator API for `PRUNE_IMAGES`.
Review: https://reviews.apache.org/r/56722/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4f4e0f25
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4f4e0f25
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4f4e0f25
Branch: refs/heads/1.5.x
Commit: 4f4e0f257d43e9edb042e6b0ec07baf0a82c83fc
Parents: 30eb221
Author: Zhitao Li <zh...@gmail.com>
Authored: Thu Dec 28 01:17:23 2017 +0800
Committer: Gilbert Song <so...@gmail.com>
Committed: Thu Dec 28 01:34:33 2017 +0800
----------------------------------------------------------------------
include/mesos/agent/agent.proto | 3 +++
include/mesos/v1/agent/agent.proto | 3 +++
src/slave/http.cpp | 37 +++++++++++++++++++++++++++++++++
src/slave/http.hpp | 6 ++++++
src/slave/validation.cpp | 4 ++++
5 files changed, 53 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/4f4e0f25/include/mesos/agent/agent.proto
----------------------------------------------------------------------
diff --git a/include/mesos/agent/agent.proto b/include/mesos/agent/agent.proto
index 25af6dc..756ea6e 100644
--- a/include/mesos/agent/agent.proto
+++ b/include/mesos/agent/agent.proto
@@ -93,6 +93,9 @@ message Call {
ADD_RESOURCE_PROVIDER_CONFIG = 27; // See 'AddResourceProviderConfig' below. // NOLINT
UPDATE_RESOURCE_PROVIDER_CONFIG = 28; // See 'UpdateResourceProviderConfig' below. // NOLINT
REMOVE_RESOURCE_PROVIDER_CONFIG = 29; // See 'RemoveResourceProviderConfig' below. // NOLINT
+
+ // Prune unused container images.
+ PRUNE_IMAGES = 30;
}
// Provides a snapshot of the current metrics tracked by the agent.
http://git-wip-us.apache.org/repos/asf/mesos/blob/4f4e0f25/include/mesos/v1/agent/agent.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/agent/agent.proto b/include/mesos/v1/agent/agent.proto
index 4ae9013..9c8d3cb 100644
--- a/include/mesos/v1/agent/agent.proto
+++ b/include/mesos/v1/agent/agent.proto
@@ -93,6 +93,9 @@ message Call {
ADD_RESOURCE_PROVIDER_CONFIG = 27; // See 'AddResourceProviderConfig' below. // NOLINT
UPDATE_RESOURCE_PROVIDER_CONFIG = 28; // See 'UpdateResourceProviderConfig' below. // NOLINT
REMOVE_RESOURCE_PROVIDER_CONFIG = 29; // See 'RemoveResourceProviderConfig' below. // NOLINT
+
+ // Prune unused container images.
+ PRUNE_IMAGES = 30;
}
// Provides a snapshot of the current metrics tracked by the agent.
http://git-wip-us.apache.org/repos/asf/mesos/blob/4f4e0f25/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 3e20c90..d0c1a0c 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -626,6 +626,9 @@ Future<Response> Http::_api(
case mesos::agent::Call::REMOVE_RESOURCE_PROVIDER_CONFIG:
return removeResourceProviderConfig(call, principal);
+
+ case mesos::agent::Call::PRUNE_IMAGES:
+ return pruneImages(call, mediaTypes.accept, principal);
}
UNREACHABLE();
@@ -2434,6 +2437,40 @@ Future<JSON::Array> Http::__containers(
}
+Future<Response> Http::pruneImages(
+ const agent::Call& call,
+ ContentType acceptType,
+ const Option<Principal>& principal) const
+{
+ CHECK_EQ(agent::Call::PRUNE_IMAGES, call.type());
+
+ // TODO(zhitao): Add AuthN/AuthZ.
+
+ LOG(INFO) << "Processing PRUNE_IMAGES call";
+ vector<Image> excludedImages;
+
+ return slave->containerizer->pruneImages(excludedImages)
+ .then([acceptType](const Future<Nothing>& result)
+ ->Future<Response> {
+ if (!result.isReady()) {
+ // TODO(zhitao): Because `containerizer::pruneImages` returns
+ // a `Nothing` now, we cannot distinguish between actual
+ // failure or the case that operator should drain the agent.
+ // Consider returning more information.
+ LOG(WARNING)
+ << "Failed to prune images: "
+ << (result.isFailed() ? result.failure() : "discarded");
+
+ return result.isFailed()
+ ? InternalServerError(result.failure())
+ : InternalServerError();
+ }
+
+ return OK();
+ });
+}
+
+
Try<string> Http::extractEndpoint(const process::http::URL& url) const
{
// Paths are of the form "/slave(n)/endpoint". We're only interested
http://git-wip-us.apache.org/repos/asf/mesos/blob/4f4e0f25/src/slave/http.hpp
----------------------------------------------------------------------
diff --git a/src/slave/http.hpp b/src/slave/http.hpp
index 3cdbf98..1619bb7 100644
--- a/src/slave/http.hpp
+++ b/src/slave/http.hpp
@@ -321,6 +321,12 @@ private:
const mesos::agent::Call& call,
const Option<process::http::authentication::Principal>& principal) const;
+ process::Future<process::http::Response> pruneImages(
+ const mesos::agent::Call& call,
+ ContentType acceptType,
+ const Option<process::http::authentication::Principal>&
+ principal) const;
+
Slave* slave;
// Used to rate limit the statistics endpoint.
http://git-wip-us.apache.org/repos/asf/mesos/blob/4f4e0f25/src/slave/validation.cpp
----------------------------------------------------------------------
diff --git a/src/slave/validation.cpp b/src/slave/validation.cpp
index b7243fc..7444d6a 100644
--- a/src/slave/validation.cpp
+++ b/src/slave/validation.cpp
@@ -525,6 +525,10 @@ Option<Error> validate(
return None();
}
+
+ case mesos::agent::Call::PRUNE_IMAGES: {
+ return None();
+ }
}
UNREACHABLE();