Repository: mesos
Updated Branches:
  refs/heads/master 7fc706f71 -> ea2130fc0


Only accept v1 protobufs for HTTP API.

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


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

Branch: refs/heads/master
Commit: ea2130fc0b4ff4c812235e97517d260d921ad557
Parents: 7fc706f
Author: Benjamin Mahler <[email protected]>
Authored: Tue Aug 11 15:12:05 2015 -0700
Committer: Benjamin Mahler <[email protected]>
Committed: Tue Aug 11 15:24:52 2015 -0700

----------------------------------------------------------------------
 src/master/http.cpp   | 14 +++++++++-----
 src/master/master.hpp | 11 ++++-------
 2 files changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ea2130fc/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index c2bc69f..7c65055 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -49,6 +49,8 @@
 #include "common/http.hpp"
 #include "common/protobuf_utils.hpp"
 
+#include "internal/devolve.hpp"
+
 #include "logging/logging.hpp"
 
 #include "master/master.hpp"
@@ -324,7 +326,7 @@ const string Master::Http::SCHEDULER_HELP = HELP(
 
 Future<Response> Master::Http::scheduler(const Request& request) const
 {
-  scheduler::Call call;
+  v1::scheduler::Call v1Call;
 
   // TODO(anand): Content type values are case-insensitive.
   Option<string> contentType = request.headers.get("Content-Type");
@@ -334,7 +336,7 @@ Future<Response> Master::Http::scheduler(const Request& 
request) const
   }
 
   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) {
@@ -344,21 +346,23 @@ Future<Response> Master::Http::scheduler(const Request& 
request) const
       return BadRequest("Failed to parse body into JSON: " + value.error());
     }
 
-    Try<scheduler::Call> parse =
-      ::protobuf::parse<scheduler::Call>(value.get());
+    Try<v1::scheduler::Call> parse =
+      ::protobuf::parse<v1::scheduler::Call>(value.get());
 
     if (parse.isError()) {
       return BadRequest("Failed to convert JSON into Call protobuf: " +
                         parse.error());
     }
 
-    call = parse.get();
+    v1Call = parse.get();
   } else {
     return UnsupportedMediaType(
         string("Expecting 'Content-Type' of ") +
         APPLICATION_JSON + " or " + APPLICATION_PROTOBUF);
   }
 
+  scheduler::Call call = devolve(v1Call);
+
   Option<Error> error = validation::scheduler::call::validate(call);
 
   if (error.isSome()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/ea2130fc/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index ef24bf8..bb7c8e9 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -1257,12 +1257,9 @@ struct HttpConnection
   template <typename Message>
   bool send(const Message& message)
   {
-    // We need to evolve the internal "message" into a
-    // 'v1::scheduler::Event' which we then devolve back to an
-    // pre-versioned 'scheduler::Event' which we use internally.
-    //
-    // TODO(benh): This should only support v1!
-    return writer.write(encoder.encode(devolve(evolve(message))));
+    // We need to evolve the internal 'message' into a
+    // 'v1::scheduler::Event'.
+    return writer.write(encoder.encode(evolve(message)));
   }
 
   bool close()
@@ -1277,7 +1274,7 @@ struct HttpConnection
 
   process::http::Pipe::Writer writer;
   ContentType contentType;
-  recordio::Encoder<scheduler::Event> encoder;
+  recordio::Encoder<v1::scheduler::Event> encoder;
 };
 
 

Reply via email to