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/06/16 19:52:45 UTC

[09/15] mesos git commit: Devolved v1 operator protos to unversioned operator protos in Agent.

Devolved v1 operator protos to unversioned operator protos in Agent.

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


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

Branch: refs/heads/master
Commit: 4b2714a6e1b0c66683cf52b79410c2a1bf613abf
Parents: b3dd11c
Author: haosdent huang <ha...@gmail.com>
Authored: Thu Jun 16 12:51:09 2016 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Thu Jun 16 12:52:17 2016 -0700

----------------------------------------------------------------------
 src/internal/devolve.cpp |  6 ++++
 src/internal/devolve.hpp |  5 +++
 src/internal/evolve.cpp  |  8 +++++
 src/internal/evolve.hpp  |  4 +++
 src/slave/http.cpp       | 83 +++++++++++++++++++++----------------------
 src/slave/slave.hpp      | 12 ++++---
 src/slave/validation.cpp | 28 +++++++--------
 src/slave/validation.hpp |  6 ++--
 8 files changed, 88 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4b2714a6/src/internal/devolve.cpp
----------------------------------------------------------------------
diff --git a/src/internal/devolve.cpp b/src/internal/devolve.cpp
index 78052fa..cecb22e 100644
--- a/src/internal/devolve.cpp
+++ b/src/internal/devolve.cpp
@@ -133,6 +133,12 @@ scheduler::Event devolve(const v1::scheduler::Event& event)
 }
 
 
+mesos::agent::Call devolve(const v1::agent::Call& call)
+{
+  return devolve<mesos::agent::Call>(call);
+}
+
+
 mesos::master::Call devolve(const v1::master::Call& call)
 {
   return devolve<mesos::master::Call>(call);

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b2714a6/src/internal/devolve.hpp
----------------------------------------------------------------------
diff --git a/src/internal/devolve.hpp b/src/internal/devolve.hpp
index a48d076..181bcea 100644
--- a/src/internal/devolve.hpp
+++ b/src/internal/devolve.hpp
@@ -19,6 +19,8 @@
 
 #include <google/protobuf/message.h>
 
+#include <mesos/agent/agent.hpp>
+
 #include <mesos/mesos.hpp>
 
 #include <mesos/executor/executor.hpp>
@@ -27,6 +29,7 @@
 
 #include <mesos/scheduler/scheduler.hpp>
 
+#include <mesos/v1/agent.hpp>
 #include <mesos/v1/mesos.hpp>
 
 #include <mesos/v1/executor/executor.hpp>
@@ -56,6 +59,8 @@ scheduler::Event devolve(const v1::scheduler::Event& event);
 
 executor::Call devolve(const v1::executor::Call& call);
 
+mesos::agent::Call devolve(const v1::agent::Call& call);
+
 mesos::master::Call devolve(const v1::master::Call& call);
 
 // Helper for repeated field devolving to 'T1' from 'T2'.

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b2714a6/src/internal/evolve.cpp
----------------------------------------------------------------------
diff --git a/src/internal/evolve.cpp b/src/internal/evolve.cpp
index c4665c2..3b03599 100644
--- a/src/internal/evolve.cpp
+++ b/src/internal/evolve.cpp
@@ -14,6 +14,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#include <mesos/agent/agent.hpp>
+
 #include <mesos/master/master.hpp>
 
 #include <mesos/v1/agent.hpp>
@@ -154,6 +156,12 @@ v1::MasterInfo evolve(const MasterInfo& masterInfo)
 }
 
 
+v1::agent::Response evolve(const mesos::agent::Response& response)
+{
+  return evolve<v1::agent::Response>(response);
+}
+
+
 v1::master::Response evolve(const mesos::master::Response& response)
 {
   return evolve<v1::master::Response>(response);

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b2714a6/src/internal/evolve.hpp
----------------------------------------------------------------------
diff --git a/src/internal/evolve.hpp b/src/internal/evolve.hpp
index 9b076fe..e7df412 100644
--- a/src/internal/evolve.hpp
+++ b/src/internal/evolve.hpp
@@ -19,6 +19,8 @@
 
 #include <google/protobuf/message.h>
 
+#include <mesos/agent/agent.hpp>
+
 #include <mesos/mesos.hpp>
 
 #include <mesos/executor/executor.hpp>
@@ -60,6 +62,8 @@ v1::TaskInfo evolve(const TaskInfo& taskInfo);
 v1::TaskStatus evolve(const TaskStatus& status);
 v1::MasterInfo evolve(const MasterInfo& masterInfo);
 
+v1::agent::Response evolve(const mesos::agent::Response& response);
+
 v1::master::Response evolve(const mesos::master::Response& response);
 
 v1::scheduler::Call evolve(const scheduler::Call& call);

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b2714a6/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 93c23a0..d536f77 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -21,6 +21,11 @@
 #include <tuple>
 #include <vector>
 
+#include <mesos/attributes.hpp>
+#include <mesos/type_utils.hpp>
+
+#include <mesos/agent/agent.hpp>
+
 #include <mesos/authorizer/authorizer.hpp>
 
 #include <mesos/executor/executor.hpp>
@@ -29,9 +34,6 @@
 
 #include <mesos/v1/executor/executor.hpp>
 
-#include <mesos/attributes.hpp>
-#include <mesos/type_utils.hpp>
-
 #include <process/collect.hpp>
 #include <process/help.hpp>
 #include <process/http.hpp>
@@ -225,7 +227,7 @@ Future<Response> Slave::Http::api(
     return MethodNotAllowed({"POST"}, request.method);
   }
 
-  v1::agent::Call call;
+  v1::agent::Call v1Call;
 
   Option<string> contentType = request.headers.get("Content-Type");
   if (contentType.isNone()) {
@@ -233,7 +235,7 @@ Future<Response> Slave::Http::api(
   }
 
   if (contentType.get() == APPLICATION_PROTOBUF) {
-    if (!call.ParseFromString(request.body)) {
+    if (!v1Call.ParseFromString(request.body)) {
       return BadRequest("Failed to parse body into Call protobuf");
     }
   } else if (contentType.get() == APPLICATION_JSON) {
@@ -250,18 +252,19 @@ Future<Response> Slave::Http::api(
                         parse.error());
     }
 
-    call = parse.get();
+    v1Call = parse.get();
   } else {
     return UnsupportedMediaType(
         string("Expecting 'Content-Type' of ") +
         APPLICATION_JSON + " or " + APPLICATION_PROTOBUF);
   }
 
+  agent::Call call = devolve(v1Call);
+
   Option<Error> error = validation::agent::call::validate(call);
 
   if (error.isSome()) {
-    return BadRequest("Failed to validate v1::agent::Call: " +
-                      error.get().message);
+    return BadRequest("Failed to validate agent::Call: " + error.get().message);
   }
 
   LOG(INFO) << "Processing call " << call.type();
@@ -278,40 +281,40 @@ Future<Response> Slave::Http::api(
   }
 
   switch (call.type()) {
-    case v1::agent::Call::UNKNOWN:
+    case agent::Call::UNKNOWN:
       return NotImplemented();
 
-    case v1::agent::Call::GET_HEALTH:
+    case agent::Call::GET_HEALTH:
       return getHealth(call, principal, acceptType);
 
-    case v1::agent::Call::GET_FLAGS:
+    case agent::Call::GET_FLAGS:
       return getFlags(call, principal, acceptType);
 
-    case v1::agent::Call::GET_VERSION:
+    case agent::Call::GET_VERSION:
       return getVersion(call, principal, acceptType);
 
-    case v1::agent::Call::GET_METRICS:
+    case agent::Call::GET_METRICS:
       return NotImplemented();
 
-    case v1::agent::Call::GET_LOGGING_LEVEL:
+    case agent::Call::GET_LOGGING_LEVEL:
       return getLoggingLevel(call, principal, acceptType);
 
-    case v1::agent::Call::SET_LOGGING_LEVEL:
+    case agent::Call::SET_LOGGING_LEVEL:
       return NotImplemented();
 
-    case v1::agent::Call::LIST_FILES:
+    case agent::Call::LIST_FILES:
       return NotImplemented();
 
-    case v1::agent::Call::READ_FILE:
+    case agent::Call::READ_FILE:
       return NotImplemented();
 
-    case v1::agent::Call::GET_STATE:
+    case agent::Call::GET_STATE:
       return NotImplemented();
 
-    case v1::agent::Call::GET_RESOURCE_STATISTICS:
+    case agent::Call::GET_RESOURCE_STATISTICS:
       return NotImplemented();
 
-    case v1::agent::Call::GET_CONTAINERS:
+    case agent::Call::GET_CONTAINERS:
       return NotImplemented();
   }
 
@@ -527,16 +530,14 @@ JSON::Object Slave::Http::_flags() const
 
 
 Future<Response> Slave::Http::getFlags(
-    const v1::agent::Call& call,
+    const agent::Call& call,
     const Option<string>& principal,
     ContentType contentType) const
 {
-  CHECK_EQ(v1::agent::Call::GET_FLAGS, call.type());
-
-  v1::agent::Response response =
-    evolve<v1::agent::Response::GET_FLAGS>(_flags());
+  CHECK_EQ(agent::Call::GET_FLAGS, call.type());
 
-  return OK(serialize(contentType, response),
+  return OK(serialize(contentType,
+                      evolve<v1::agent::Response::GET_FLAGS>(_flags())),
             stringify(contentType));
 }
 
@@ -560,48 +561,46 @@ Future<Response> Slave::Http::health(const Request& request) const
 
 
 Future<Response> Slave::Http::getHealth(
-    const v1::agent::Call& call,
+    const agent::Call& call,
     const Option<string>& principal,
     ContentType contentType) const
 {
-  CHECK_EQ(v1::agent::Call::GET_HEALTH, call.type());
+  CHECK_EQ(agent::Call::GET_HEALTH, call.type());
 
-  v1::agent::Response response;
-  response.set_type(v1::agent::Response::GET_HEALTH);
+  agent::Response response;
+  response.set_type(agent::Response::GET_HEALTH);
   response.mutable_get_health()->set_healthy(true);
 
-  return OK(serialize(contentType, response),
+  return OK(serialize(contentType, evolve(response)),
             stringify(contentType));
 }
 
 
 Future<Response> Slave::Http::getVersion(
-    const v1::agent::Call& call,
+    const agent::Call& call,
     const Option<string>& principal,
     ContentType contentType) const
 {
-  CHECK_EQ(v1::agent::Call::GET_VERSION, call.type());
-
-  v1::agent::Response response =
-    evolve<v1::agent::Response::GET_VERSION>(version());
+  CHECK_EQ(agent::Call::GET_VERSION, call.type());
 
-  return OK(serialize(contentType, response),
+  return OK(serialize(contentType,
+                      evolve<v1::agent::Response::GET_VERSION>(version())),
             stringify(contentType));
 }
 
 
 Future<Response> Slave::Http::getLoggingLevel(
-    const v1::agent::Call& call,
+    const agent::Call& call,
     const Option<string>& principal,
     ContentType contentType) const
 {
-  CHECK_EQ(v1::agent::Call::GET_LOGGING_LEVEL, call.type());
+  CHECK_EQ(agent::Call::GET_LOGGING_LEVEL, call.type());
 
-  v1::agent::Response response;
-  response.set_type(v1::agent::Response::GET_LOGGING_LEVEL);
+  agent::Response response;
+  response.set_type(agent::Response::GET_LOGGING_LEVEL);
   response.mutable_get_logging_level()->set_level(FLAGS_v);
 
-  return OK(serialize(contentType, response),
+  return OK(serialize(contentType, evolve(response)),
             stringify(contentType));
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b2714a6/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 3ed026e..7b92665 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -30,6 +30,8 @@
 #include <mesos/resources.hpp>
 #include <mesos/type_utils.hpp>
 
+#include <mesos/agent/agent.hpp>
+
 #include <mesos/executor/executor.hpp>
 
 #include <mesos/master/detector.hpp>
@@ -509,25 +511,25 @@ private:
         const std::string& endpoint,
         const std::string& method) const;
 
-    // v1 agent API handlers.
+    // Agent API handlers.
 
     process::Future<process::http::Response> getFlags(
-        const v1::agent::Call& call,
+        const mesos::agent::Call& call,
         const Option<std::string>& principal,
         ContentType contentType) const;
 
     process::Future<process::http::Response> getHealth(
-        const v1::agent::Call& call,
+        const mesos::agent::Call& call,
         const Option<std::string>& principal,
         ContentType contentType) const;
 
     process::Future<process::http::Response> getVersion(
-        const v1::agent::Call& call,
+        const mesos::agent::Call& call,
         const Option<std::string>& principal,
         ContentType contentType) const;
 
     process::Future<process::http::Response> getLoggingLevel(
-        const v1::agent::Call& call,
+        const mesos::agent::Call& call,
         const Option<std::string>& principal,
         ContentType contentType) const;
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b2714a6/src/slave/validation.cpp
----------------------------------------------------------------------
diff --git a/src/slave/validation.cpp b/src/slave/validation.cpp
index 189d10c..86e95a2 100644
--- a/src/slave/validation.cpp
+++ b/src/slave/validation.cpp
@@ -16,7 +16,7 @@
 
 #include <string>
 
-#include <mesos/v1/agent.hpp>
+#include <mesos/agent/agent.hpp>
 
 #include <stout/unreachable.hpp>
 
@@ -33,7 +33,7 @@ namespace agent {
 namespace call {
 
 Option<Error> validate(
-    const mesos::v1::agent::Call& call,
+    const mesos::agent::Call& call,
     const Option<string>& principal)
 {
   if (!call.IsInitialized()) {
@@ -45,52 +45,52 @@ Option<Error> validate(
   }
 
   switch (call.type()) {
-    case v1::agent::Call::UNKNOWN:
+    case mesos::agent::Call::UNKNOWN:
       return None();
 
-    case v1::agent::Call::GET_HEALTH:
+    case mesos::agent::Call::GET_HEALTH:
       return None();
 
-    case v1::agent::Call::GET_FLAGS:
+    case mesos::agent::Call::GET_FLAGS:
       return None();
 
-    case v1::agent::Call::GET_VERSION:
+    case mesos::agent::Call::GET_VERSION:
       return None();
 
-    case v1::agent::Call::GET_METRICS:
+    case mesos::agent::Call::GET_METRICS:
       if (!call.has_get_metrics()) {
         return Error("Expecting 'get_metrics' to be present");
       }
       return None();
 
-    case v1::agent::Call::GET_LOGGING_LEVEL:
+    case mesos::agent::Call::GET_LOGGING_LEVEL:
       return None();
 
-    case v1::agent::Call::SET_LOGGING_LEVEL:
+    case mesos::agent::Call::SET_LOGGING_LEVEL:
       if (!call.has_set_logging_level()) {
         return Error("Expecting 'set_logging_level' to be present");
       }
       return None();
 
-    case v1::agent::Call::LIST_FILES:
+    case mesos::agent::Call::LIST_FILES:
       if (!call.has_list_files()) {
         return Error("Expecting 'list_files' to be present");
       }
       return None();
 
-    case v1::agent::Call::READ_FILE:
+    case mesos::agent::Call::READ_FILE:
       if (!call.has_read_file()) {
         return Error("Expecting 'read_file' to be present");
       }
       return None();
 
-    case v1::agent::Call::GET_STATE:
+    case mesos::agent::Call::GET_STATE:
       return None();
 
-    case v1::agent::Call::GET_RESOURCE_STATISTICS:
+    case mesos::agent::Call::GET_RESOURCE_STATISTICS:
       return None();
 
-    case v1::agent::Call::GET_CONTAINERS:
+    case mesos::agent::Call::GET_CONTAINERS:
       return None();
   }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b2714a6/src/slave/validation.hpp
----------------------------------------------------------------------
diff --git a/src/slave/validation.hpp b/src/slave/validation.hpp
index 59b12f0..94286f0 100644
--- a/src/slave/validation.hpp
+++ b/src/slave/validation.hpp
@@ -17,9 +17,9 @@
 #ifndef __SLAVE_VALIDATION_HPP__
 #define __SLAVE_VALIDATION_HPP__
 
-#include <mesos/executor/executor.hpp>
+#include <mesos/agent/agent.hpp>
 
-#include <mesos/v1/agent.hpp>
+#include <mesos/executor/executor.hpp>
 
 #include <stout/error.hpp>
 #include <stout/option.hpp>
@@ -35,7 +35,7 @@ namespace call {
 // Validates that a agent:Call is well-formed.
 // TODO(bmahler): Add unit tests.
 Option<Error> validate(
-    const mesos::v1::agent::Call& call,
+    const mesos::agent::Call& call,
     const Option<std::string>& principal = None());
 
 } // namespace call {