本文整理汇总了C++中commandinfo::URI::set_extract方法的典型用法代码示例。如果您正苦于以下问题:C++ URI::set_extract方法的具体用法?C++ URI::set_extract怎么用?C++ URI::set_extract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类commandinfo::URI
的用法示例。
在下文中一共展示了URI::set_extract方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fetcherEnvironment
TEST_F(MesosContainerizerProcessTest, NoExtractExecutable)
{
CommandInfo commandInfo;
CommandInfo::URI uri;
uri.set_value("hdfs:///uri");
uri.set_executable(true);
uri.set_extract(false);
commandInfo.add_uris()->MergeFrom(uri);
string directory = "/tmp/directory";
Option<string> user = "user";
Flags flags;
flags.frameworks_home = "/tmp/frameworks";
flags.hadoop_home = "/tmp/hadoop";
map<string, string> environment =
fetcherEnvironment(commandInfo, directory, user, flags);
EXPECT_EQ(5u, environment.size());
EXPECT_EQ("hdfs:///uri+1N", environment["MESOS_EXECUTOR_URIS"]);
EXPECT_EQ(directory, environment["MESOS_WORK_DIRECTORY"]);
EXPECT_EQ(user.get(), environment["MESOS_USER"]);
EXPECT_EQ(flags.frameworks_home, environment["MESOS_FRAMEWORKS_HOME"]);
EXPECT_EQ(flags.hadoop_home, environment["HADOOP_HOME"]);
}
示例2:
TEST_F(FetcherEnvironmentTest, NoExtractExecutable)
{
CommandInfo commandInfo;
CommandInfo::URI* uri = commandInfo.add_uris();
uri->set_value("hdfs:///uri");
uri->set_executable(true);
uri->set_extract(false);
string directory = "/tmp/directory";
Option<string> user = "user";
slave::Flags flags;
flags.frameworks_home = "/tmp/frameworks";
flags.hadoop_home = "/tmp/hadoop";
map<string, string> environment =
fetcher::environment(commandInfo, directory, user, flags);
EXPECT_EQ(5u, environment.size());
EXPECT_EQ(stringify(JSON::Protobuf(commandInfo)),
environment["MESOS_COMMAND_INFO"]);
EXPECT_EQ(directory, environment["MESOS_WORK_DIRECTORY"]);
EXPECT_EQ(user.get(), environment["MESOS_USER"]);
EXPECT_EQ(flags.frameworks_home, environment["MESOS_FRAMEWORKS_HOME"]);
EXPECT_EQ(flags.hadoop_home, environment["HADOOP_HOME"]);
}
示例3: None
TEST_F(FetcherTest, ExtractNotExecutable)
{
// First construct a temporary file that can be fetched and archive
// with tar gzip.
Try<string> path = os::mktemp();
ASSERT_SOME(path);
ASSERT_SOME(os::write(path.get(), "hello world"));
// TODO(benh): Update os::tar so that we can capture or ignore
// stdout/stderr output.
ASSERT_SOME(os::tar(path.get(), path.get() + ".tar.gz"));
CommandInfo commandInfo;
CommandInfo::URI* uri = commandInfo.add_uris();
uri->set_value(path.get() + ".tar.gz");
uri->set_executable(false);
uri->set_extract(true);
Option<int> stdout = None();
Option<int> stderr = None();
// Redirect mesos-fetcher output if running the tests verbosely.
if (tests::flags.verbose) {
stdout = STDOUT_FILENO;
stderr = STDERR_FILENO;
}
slave::Flags flags;
flags.launcher_dir = path::join(tests::flags.build_dir, "src");
Future<Option<int>> run =
fetcher::run(commandInfo, os::getcwd(), None(), flags, stdout, stderr);
AWAIT_READY(run);
EXPECT_SOME_EQ(0, run.get());
ASSERT_TRUE(os::exists(path::join(".", path.get())));
ASSERT_SOME_EQ("hello world", os::read(path::join(".", path.get())));
Try<os::Permissions> permissions =
os::permissions(path::join(".", path.get()));
ASSERT_SOME(permissions);
EXPECT_FALSE(permissions.get().owner.x);
EXPECT_FALSE(permissions.get().group.x);
EXPECT_FALSE(permissions.get().others.x);
ASSERT_SOME(os::rm(path.get()));
}
示例4: main
int main(int argc, char* argv[])
{
GOOGLE_PROTOBUF_VERIFY_VERSION;
CommandInfo commandInfo;
// Construct URIs from the encoded environment string.
const std::string& uris = os::getenv("MESOS_EXECUTOR_URIS");
foreach (const std::string& token, strings::tokenize(uris, " ")) {
// Delimiter between URI, execute permission and extract options
// Expected format: {URI}+[01][XN]
// {URI} - The actual URI for the asset to fetch
// [01] - 1 if the execute permission should be set else 0
// [XN] - X if we should extract the URI (if it's compressed) else N
size_t pos = token.rfind("+");
CHECK(pos != std::string::npos)
<< "Invalid executor uri token in env " << token;
CommandInfo::URI uri;
uri.set_value(token.substr(0, pos));
uri.set_executable(token.substr(pos + 1, 1) == "1");
uri.set_extract(token.substr(pos + 2, 1) == "X");
commandInfo.add_uris()->MergeFrom(uri);
}
CHECK(os::hasenv("MESOS_WORK_DIRECTORY"))
<< "Missing MESOS_WORK_DIRECTORY environment variable";
std::string directory = os::getenv("MESOS_WORK_DIRECTORY");
// We cannot use Some in the ternary expression because the compiler needs to
// be able to infer the type, thus the explicit Option<string>.
// TODO(idownes): Add an os::hasenv that returns an Option<string>.
Option<std::string> user = os::hasenv("MESOS_USER")
? Option<std::string>(os::getenv("MESOS_USER")) // Explicit so it compiles.
: None();
// Fetch each URI to a local file, chmod, then chown if a user is provided.
foreach (const CommandInfo::URI& uri, commandInfo.uris()) {
// Fetch the URI to a local file.
Try<string> fetched = fetch(uri.value(), directory);
if (fetched.isError()) {
EXIT(1) << "Failed to fetch: " << uri.value();
}
// Chmod the fetched URI if it's executable, else assume it's an archive
// that should be extracted.
if (uri.executable()) {
Try<Nothing> chmod = os::chmod(
fetched.get(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
if (chmod.isError()) {
EXIT(1) << "Failed to chmod " << fetched.get() << ": " << chmod.error();
}
} else if (uri.extract()) {
//TODO(idownes): Consider removing the archive once extracted.
// Try to extract the file if it's recognized as an archive.
Try<bool> extracted = extract(fetched.get(), directory);
if (extracted.isError()) {
EXIT(1) << "Failed to extract "
<< fetched.get() << ":" << extracted.error();
}
} else {
LOG(INFO) << "Skipped extracting path '" << fetched.get() << "'";
}
// Recursively chown the directory if a user is provided.
if (user.isSome()) {
Try<Nothing> chowned = os::chown(user.get(), directory);
if (chowned.isError()) {
EXIT(1) << "Failed to chown " << directory << ": " << chowned.error();
}
}
}
return 0;
}