You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/01/10 08:21:18 UTC
[2/3] mesos git commit: Style fix for curl URI fetcher plugin.
Style fix for curl URI fetcher plugin.
Review: https://reviews.apache.org/r/41957
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/dcea0841
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/dcea0841
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/dcea0841
Branch: refs/heads/master
Commit: dcea08411790c24270f00b4e17db89890768605a
Parents: 66b7ab5
Author: Jie Yu <yu...@gmail.com>
Authored: Sun Jan 3 22:11:13 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Sat Jan 9 23:20:06 2016 -0800
----------------------------------------------------------------------
src/uri/fetchers/curl.cpp | 119 ++++++++++++++++++++---------------------
1 file changed, 58 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/dcea0841/src/uri/fetchers/curl.cpp
----------------------------------------------------------------------
diff --git a/src/uri/fetchers/curl.cpp b/src/uri/fetchers/curl.cpp
index c6645cc..269df87 100644
--- a/src/uri/fetchers/curl.cpp
+++ b/src/uri/fetchers/curl.cpp
@@ -32,21 +32,24 @@
#include "uri/fetchers/curl.hpp"
-using namespace process;
+namespace http = process::http;
+namespace io = process::io;
using std::set;
using std::string;
+using std::tuple;
using std::vector;
-namespace mesos {
-namespace uri {
+using process::await;
+using process::subprocess;
-// Forward declarations.
-static Future<Nothing> _fetch(const Future<std::tuple<
- Future<Option<int>>,
- Future<string>,
- Future<string>>>& future);
+using process::Failure;
+using process::Future;
+using process::Owned;
+using process::Subprocess;
+namespace mesos {
+namespace uri {
Try<Owned<Fetcher::Plugin>> CurlFetcherPlugin::create(const Flags& flags)
{
@@ -107,59 +110,53 @@ Future<Nothing> CurlFetcherPlugin::fetch(
s.get().status(),
io::read(s.get().out().get()),
io::read(s.get().err().get()))
- .then(_fetch);
-}
-
-
-static Future<Nothing> _fetch(const Future<std::tuple<
- Future<Option<int>>,
- Future<string>,
- Future<string>>>& future)
-{
- CHECK_READY(future);
-
- Future<Option<int>> status = std::get<0>(future.get());
- if (!status.isReady()) {
- return Failure(
- "Failed to get the exit status of the curl subprocess: " +
- (status.isFailed() ? status.failure() : "discarded"));
- }
-
- if (status->isNone()) {
- return Failure("Failed to reap the curl subprocess");
- }
-
- if (status->get() != 0) {
- Future<string> error = std::get<2>(future.get());
- if (!error.isReady()) {
- return Failure(
- "Failed to perform 'curl'. Reading stderr failed: " +
- (error.isFailed() ? error.failure() : "discarded"));
- }
-
- return Failure("Failed to perform 'curl': " + error.get());
- }
-
- Future<string> output = std::get<1>(future.get());
- if (!output.isReady()) {
- return Failure(
- "Failed to read stdout from 'curl': " +
- (output.isFailed() ? output.failure() : "discarded"));
- }
-
- // Parse the output and get the HTTP response code.
- Try<int> code = numify<int>(output.get());
- if (code.isError()) {
- return Failure("Unexpected output from 'curl': " + output.get());
- }
-
- if (code.get() != http::Status::OK) {
- return Failure(
- "Unexpected HTTP response code: " +
- http::Status::string(code.get()));
- }
-
- return Nothing();
+ .then([](const std::tuple<
+ Future<Option<int>>,
+ Future<string>,
+ Future<string>>& t) -> Future<Nothing> {
+ Future<Option<int>> status = std::get<0>(t);
+ if (!status.isReady()) {
+ return Failure(
+ "Failed to get the exit status of the curl subprocess: " +
+ (status.isFailed() ? status.failure() : "discarded"));
+ }
+
+ if (status->isNone()) {
+ return Failure("Failed to reap the curl subprocess");
+ }
+
+ if (status->get() != 0) {
+ Future<string> error = std::get<2>(t);
+ if (!error.isReady()) {
+ return Failure(
+ "Failed to perform 'curl'. Reading stderr failed: " +
+ (error.isFailed() ? error.failure() : "discarded"));
+ }
+
+ return Failure("Failed to perform 'curl': " + error.get());
+ }
+
+ Future<string> output = std::get<1>(t);
+ if (!output.isReady()) {
+ return Failure(
+ "Failed to read stdout from 'curl': " +
+ (output.isFailed() ? output.failure() : "discarded"));
+ }
+
+ // Parse the output and get the HTTP response code.
+ Try<int> code = numify<int>(output.get());
+ if (code.isError()) {
+ return Failure("Unexpected output from 'curl': " + output.get());
+ }
+
+ if (code.get() != http::Status::OK) {
+ return Failure(
+ "Unexpected HTTP response code: " +
+ http::Status::string(code.get()));
+ }
+
+ return Nothing();
+ });
}
} // namespace uri {