You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2015/10/08 07:34:03 UTC
mesos git commit: Extract gz file in fetcher.
Repository: mesos
Updated Branches:
refs/heads/master 575f3b352 -> 263316916
Extract gz file in fetcher.
Review: https://reviews.apache.org/r/38337
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/26331691
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/26331691
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/26331691
Branch: refs/heads/master
Commit: 263316916c447a88be9554d0401e6ddc5a6767a1
Parents: 575f3b3
Author: haosdent huang <ha...@gmail.com>
Authored: Wed Oct 7 21:55:57 2015 -0700
Committer: Adam B <ad...@mesosphere.io>
Committed: Wed Oct 7 21:57:19 2015 -0700
----------------------------------------------------------------------
src/launcher/fetcher.cpp | 5 +++++
src/tests/fetcher_tests.cpp | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/26331691/src/launcher/fetcher.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/fetcher.cpp b/src/launcher/fetcher.cpp
index 0f1533a..8fb6c83 100644
--- a/src/launcher/fetcher.cpp
+++ b/src/launcher/fetcher.cpp
@@ -26,6 +26,7 @@
#include <stout/net.hpp>
#include <stout/option.hpp>
#include <stout/os.hpp>
+#include <stout/path.hpp>
#include <stout/protobuf.hpp>
#include <stout/strings.hpp>
@@ -65,6 +66,10 @@ static Try<bool> extract(
strings::endsWith(sourcePath, ".txz") ||
strings::endsWith(sourcePath, ".tar.xz")) {
command = "tar -C '" + destinationDirectory + "' -xf";
+ } else if (strings::endsWith(sourcePath, ".gz")) {
+ string pathWithoutExtension = sourcePath.substr(0, sourcePath.length() - 3);
+ string filename = Path(pathWithoutExtension).basename();
+ command = "gzip -dc > '" + destinationDirectory + "/" + filename + "' <";
} else if (strings::endsWith(sourcePath, ".zip")) {
command = "unzip -d '" + destinationDirectory + "'";
} else {
http://git-wip-us.apache.org/repos/asf/mesos/blob/26331691/src/tests/fetcher_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/fetcher_tests.cpp b/src/tests/fetcher_tests.cpp
index 8d13352..46d0690 100644
--- a/src/tests/fetcher_tests.cpp
+++ b/src/tests/fetcher_tests.cpp
@@ -540,6 +540,45 @@ TEST_F(FetcherTest, ExtractNotExecutable)
}
+TEST_F(FetcherTest, ExtractGzipFile)
+{
+ // First construct a temporary file that can be fetched and archive
+ // with gzip.
+ Try<string> path = os::mktemp();
+
+ ASSERT_SOME(path);
+
+ ASSERT_SOME(os::write(path.get(), "hello world"));
+ ASSERT_SOME(os::shell("gzip " + path.get()));
+
+ ContainerID containerId;
+ containerId.set_value(UUID::random().toString());
+
+ CommandInfo commandInfo;
+ CommandInfo::URI* uri = commandInfo.add_uris();
+ uri->set_value(path.get() + ".gz");
+ uri->set_extract(true);
+
+ slave::Flags flags;
+ flags.launcher_dir = path::join(tests::flags.build_dir, "src");
+
+ Fetcher fetcher;
+ SlaveID slaveId;
+
+ Future<Nothing> fetch = fetcher.fetch(
+ containerId, commandInfo, os::getcwd(), None(), slaveId, flags);
+
+ AWAIT_READY(fetch);
+
+ string extractFile = path::join(".", Path(path.get()).basename());
+ ASSERT_TRUE(os::exists(extractFile));
+
+ ASSERT_SOME_EQ("hello world", os::read(extractFile));
+
+ ASSERT_SOME(os::rm(path.get() + ".gz"));
+}
+
+
// Tests fetching via the local HDFS client. Since we cannot rely on
// Hadoop being installed, we use our own mock version that works on
// the local file system only, but this lets us exercise the exact