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 2018/05/30 07:36:09 UTC

[2/2] mesos git commit: Fixed compilation issues in libprocess example.

Fixed compilation issues in libprocess example.

* Added the mandatory help string argument to calls
  to 'route()', failing compilation.

* The response returned from the '/vars' endpoint had
  its 'type' field set to 'NONE', causing indefinite
  hanging when trying to access the endpoint. Switched
  to a constructor for OK that implicitly sets that field.

* Removed a stray pid variable in main.

* Added http:: namespace to disambiguate calls to 'post()'.

* Added a name to the example process.

* Commented out example code that commits instant
  self-termination by default.

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


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

Branch: refs/heads/master
Commit: ffeb915b4bf395ccea89dfabdafce728be9b8898
Parents: 04ef101
Author: Benno Evers <be...@mesosphere.com>
Authored: Wed May 30 09:24:23 2018 +0200
Committer: Benjamin Bannier <bb...@apache.org>
Committed: Wed May 30 09:25:34 2018 +0200

----------------------------------------------------------------------
 3rdparty/libprocess/examples/example.cpp | 48 +++++++++++++--------------
 1 file changed, 24 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ffeb915b/3rdparty/libprocess/examples/example.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/examples/example.cpp b/3rdparty/libprocess/examples/example.cpp
index 8c507ae..0db2d03 100644
--- a/3rdparty/libprocess/examples/example.cpp
+++ b/3rdparty/libprocess/examples/example.cpp
@@ -11,7 +11,6 @@
 // limitations under the License
 
 #include <iostream>
-#include <sstream>
 #include <string>
 
 #include <process/defer.hpp>
@@ -20,6 +19,8 @@
 #include <process/http.hpp>
 #include <process/process.hpp>
 
+#include <stout/strings.hpp>
+
 using namespace process;
 
 using namespace process::http;
@@ -29,7 +30,7 @@ using std::string;
 class MyProcess : public Process<MyProcess>
 {
 public:
-  MyProcess() {}
+  MyProcess(): ProcessBase("my-process") {}
   virtual ~MyProcess() {}
 
   Future<int> func1()
@@ -48,14 +49,15 @@ public:
 
   Future<Response> vars(const Request& request)
   {
+    // Response response;
+    // response.code = Status::OK;
+    // response.headers["Content-Type"] = "text/plain";
+    // response.headers["Content-Length"] = stringify(body.size());
+    // response.type = Response::BODY;
+    // response.body = body;
+
     string body = "... vars here ...";
-    OK response;
-    response.headers["Content-Type"] = "text/plain";
-    std::ostringstream out;
-    out << body.size();
-    response.headers["Content-Length"] = out.str();
-    response.body = body;
-    return response;
+    return OK(body);
   }
 
   void stop(const UPID& from, const string& body)
@@ -66,16 +68,10 @@ public:
 protected:
   virtual void initialize()
   {
-    // route("/vars", &MyProcess::vars);
-    route("/vars", [=](const Request& request) {
+    // route("/vars", None(), &MyProcess::vars);
+    route("/vars", None(), [=](const Request& request) {
       string body = "... vars here ...";
-      OK response;
-      response.headers["Content-Type"] = "text/plain";
-      std::ostringstream out;
-      out << body.size();
-      response.headers["Content-Length"] = out.str();
-      response.body = body;
-      return response;
+      return OK(body);
     });
 
     // install("stop", &MyProcess::stop);
@@ -94,8 +90,6 @@ int main(int argc, char** argv)
   MyProcess process;
   PID<MyProcess> pid = spawn(&process);
 
-  PID<> pid2 = pid;
-
   //// --------------------------------------
 
   // Future<int> future = dispatch(pid, &MyProcess::func1);
@@ -103,7 +97,7 @@ int main(int argc, char** argv)
 
   // std::cout << future.get() << std::endl;
 
-  // post(pid, "stop");
+  // http::post(pid, "stop");
 
   //// --------------------------------------
 
@@ -116,7 +110,7 @@ int main(int argc, char** argv)
   //     })
   //   .then([=] (bool b) {
   //       if (b) {
-  //         post(pid, "stop");
+  //         http::post(pid, "stop");
   //       }
   //       return true; // No Future<void>.
   //     });
@@ -125,8 +119,14 @@ int main(int argc, char** argv)
 
   //// --------------------------------------
 
-  dispatch(pid, &MyProcess::func1);
-  dispatch(pid, &MyProcess::func2, 42);
+  // dispatch(pid, &MyProcess::func1);
+  // dispatch(pid, &MyProcess::func2, 42);
+
+  //// --------------------------------------
+
+  std::cout << strings::format("Endpoint listening on http://%s/%s/vars\n",
+      process::address(),
+      process.self().id).get();
 
   wait(pid);
   return 0;