本文整理汇总了C++中ContainerID::value方法的典型用法代码示例。如果您正苦于以下问题:C++ ContainerID::value方法的具体用法?C++ ContainerID::value怎么用?C++ ContainerID::value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContainerID
的用法示例。
在下文中一共展示了ContainerID::value方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Failure
Future<Termination> ExternalContainerizerProcess::wait(
const ContainerID& containerId)
{
VLOG(1) << "Wait triggered on container '" << containerId << "'";
if (!containers.contains(containerId)) {
LOG(ERROR) << "not running";
return Failure("Container '" + containerId.value() + "' not running");
}
Try<Subprocess> invoked = invoke("wait", containerId);
if (invoked.isError()) {
LOG(ERROR) << "not running";
terminate(containerId);
return Failure("Wait on container '" + containerId.value()
+ "' failed (error: " + invoked.error() + ")");
}
// Await both, input from the pipe as well as an exit of the
// process.
await(read(invoked.get().out()), invoked.get().status())
.onAny(defer(
PID<ExternalContainerizerProcess>(this),
&ExternalContainerizerProcess::_wait,
containerId,
lambda::_1));
return containers[containerId]->termination.future();
}
示例2: Failure
Future<Nothing> NetworkCniIsolatorProcess::detach(
const ContainerID& containerId,
const std::string& networkName)
{
CHECK(infos.contains(containerId));
CHECK(infos[containerId]->containerNetworks.contains(networkName));
const ContainerNetwork& containerNetwork =
infos[containerId]->containerNetworks[networkName];
// Prepare environment variables for CNI plugin.
map<string, string> environment;
environment["CNI_COMMAND"] = "DEL";
environment["CNI_CONTAINERID"] = containerId.value();
environment["CNI_PATH"] = pluginDir.get();
environment["CNI_IFNAME"] = containerNetwork.ifName;
environment["CNI_NETNS"] =
paths::getNamespacePath(rootDir.get(), containerId.value());
// Some CNI plugins need to run "iptables" to set up IP Masquerade, so we
// need to set the "PATH" environment variable so that the plugin can locate
// the "iptables" executable file.
Option<string> value = os::getenv("PATH");
if (value.isSome()) {
environment["PATH"] = value.get();
} else {
environment["PATH"] =
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
}
const NetworkConfigInfo& networkConfig = networkConfigs[networkName];
// Invoke the CNI plugin.
const string& plugin = networkConfig.config.type();
Try<Subprocess> s = subprocess(
path::join(pluginDir.get(), plugin),
{plugin},
Subprocess::PATH(networkConfig.path),
Subprocess::PIPE(),
Subprocess::PATH("/dev/null"),
NO_SETSID,
None(),
environment);
if (s.isError()) {
return Failure(
"Failed to execute the CNI plugin '" + plugin + "': " + s.error());
}
return await(s->status(), io::read(s->out().get()))
.then(defer(
PID<NetworkCniIsolatorProcess>(this),
&NetworkCniIsolatorProcess::_detach,
containerId,
networkName,
plugin,
lambda::_1));
}
示例3: Failure
Future<Option<ContainerLaunchInfo>> CgroupsNetClsIsolatorProcess::prepare(
const ContainerID& containerId,
const ContainerConfig& containerConfig)
{
if (infos.contains(containerId)) {
return Failure("Container has already been prepared");
}
// Use this info to create the cgroup, but do not insert it into
// infos till the cgroup has been created successfully.
Info info(path::join(flags.cgroups_root, containerId.value()));
// Create a cgroup for this container.
Try<bool> exists = cgroups::exists(hierarchy, info.cgroup);
if (exists.isError()) {
return Failure("Failed to check if the cgroup already exists: " +
exists.error());
} else if (exists.get()) {
return Failure("The cgroup already exists");
}
Try<Nothing> create = cgroups::create(hierarchy, info.cgroup);
if (create.isError()) {
return Failure("Failed to create the cgroup: " + create.error());
}
// 'chown' the cgroup so the executor can create nested cgroups. Do
// not recurse so the control files are still owned by the slave
// user and thus cannot be changed by the executor.
if (containerConfig.has_user()) {
Try<Nothing> chown = os::chown(
containerConfig.user(),
path::join(hierarchy, info.cgroup),
false);
if (chown.isError()) {
return Failure("Failed to change ownership of cgroup hierarchy: " +
chown.error());
}
}
infos.emplace(containerId, info);
return update(containerId, containerConfig.executorinfo().resources())
.then([]() -> Future<Option<ContainerLaunchInfo>> {
return None();
});
}
示例4: iscntrl
Option<Error> validateContainerId(const ContainerID& containerId)
{
// Slashes are disallowed as these IDs are mapped to directories.
//
// Periods are disallowed because our string representation of
// ContainerID uses periods: <uuid>.<child>.<grandchild>.
// For example: <uuid>.redis.backup
//
// Spaces are disallowed as they can render logs confusing and
// need escaping on terminals when dealing with paths.
//
// TODO(bmahler): Add common/validation.hpp to share ID validation.
// Note that this however is slightly stricter than other IDs in
// that we do not allow periods or spaces.
auto invalidCharacter = [](char c) {
return iscntrl(c) ||
c == os::POSIX_PATH_SEPARATOR ||
c == os::WINDOWS_PATH_SEPARATOR ||
c == '.' ||
c == ' ';
};
const string& id = containerId.value();
if (id.empty()) {
return Error("'ContainerID.value' must be non-empty");
}
if (std::any_of(id.begin(), id.end(), invalidCharacter)) {
return Error("'ContainerID.value' '" + id + "'"
" contains invalid characters");
}
// TODO(bmahler): Print the invalid field nicely within the error
// (e.g. 'parent.parent.parent.value'). For now we only have one
// level of nesting so it's ok.
if (containerId.has_parent()) {
Option<Error> parentError = validateContainerId(containerId.parent());
if (parentError.isSome()) {
return Error("'ContainerID.parent' is invalid: " + parentError->message);
}
}
return None();
}
示例5: Error
Option<Error> validateContainerId(const ContainerID& containerId)
{
const string& id = containerId.value();
// Check common Mesos ID rules.
Option<Error> error = common::validation::validateID(id);
if (error.isSome()) {
return Error(error->message);
}
// Check ContainerID specific rules.
//
// Periods are disallowed because our string representation of
// ContainerID uses periods: <uuid>.<child>.<grandchild>.
// For example: <uuid>.redis.backup
//
// Spaces are disallowed as they can render logs confusing and
// need escaping on terminals when dealing with paths.
auto invalidCharacter = [](char c) {
return c == '.' || c == ' ';
};
if (std::any_of(id.begin(), id.end(), invalidCharacter)) {
return Error("'ContainerID.value' '" + id + "'"
" contains invalid characters");
}
// TODO(bmahler): Print the invalid field nicely within the error
// (e.g. 'parent.parent.parent.value'). For now we only have one
// level of nesting so it's ok.
if (containerId.has_parent()) {
Option<Error> parentError = validateContainerId(containerId.parent());
if (parentError.isSome()) {
return Error("'ContainerID.parent' is invalid: " + parentError->message);
}
}
return None();
}
示例6: Nothing
process::Future<Nothing> CalicoIsolatorProcess::isolate(
const ContainerID& containerId,
pid_t pid)
{
const Info* info = (*infos)[containerId];
foreach (const Parameter& parameter, parameters.parameter()) {
if (parameter.key() == isolateKey) {
std::vector<std::string> argv(7);
argv[0] = "python";
argv[1] = parameter.value();
argv[2] = "isolate";
argv[3] = stringify(pid);
argv[4] = containerId.value();
argv[5] = stringify(info->ipAddress.get());
argv[6] = stringify(info->profile.get());
Try<process::Subprocess> child = process::subprocess(pythonPath, argv);
CHECK_SOME(child);
waitpid(child.get().pid(), NULL, 0);
break;
}
}
return Nothing();
}
示例7: Error
Try<RunState> RunState::recover(
const string& rootDir,
const SlaveID& slaveId,
const FrameworkID& frameworkId,
const ExecutorID& executorId,
const ContainerID& containerId,
bool strict)
{
RunState state;
state.id = containerId;
string message;
// Find the tasks.
Try<list<string> > tasks = os::glob(strings::format(
paths::TASK_PATH,
rootDir,
slaveId,
frameworkId,
executorId,
containerId,
"*").get());
if (tasks.isError()) {
return Error(
"Failed to find tasks for executor run " + containerId.value() +
": " + tasks.error());
}
// Recover tasks.
foreach (const string& path, tasks.get()) {
TaskID taskId;
taskId.set_value(os::basename(path).get());
Try<TaskState> task = TaskState::recover(
rootDir, slaveId, frameworkId, executorId, containerId, taskId, strict);
if (task.isError()) {
return Error(
"Failed to recover task " + taskId.value() + ": " + task.error());
}
state.tasks[taskId] = task.get();
state.errors += task.get().errors;
}
// Read the forked pid.
string path = paths::getForkedPidPath(
rootDir, slaveId, frameworkId, executorId, containerId);
if (!os::exists(path)) {
// This could happen if the slave died before the isolator
// checkpointed the forked pid.
LOG(WARNING) << "Failed to find executor forked pid file '" << path << "'";
return state;
}
Try<string> pid = os::read(path);
if (pid.isError()) {
message = "Failed to read executor forked pid from '" + path +
"': " + pid.error();
if (strict) {
return Error(message);
} else {
LOG(WARNING) << message;
state.errors++;
return state;
}
}
if (pid.get().empty()) {
// This could happen if the slave died after opening the file for
// writing but before it checkpointed anything.
LOG(WARNING) << "Found empty executor forked pid file '" << path << "'";
return state;
}
Try<pid_t> forkedPid = numify<pid_t>(pid.get());
if (forkedPid.isError()) {
return Error("Failed to parse forked pid " + pid.get() +
": " + forkedPid.error());
}
state.forkedPid = forkedPid.get();
// Read the libprocess pid.
path = paths::getLibprocessPidPath(
rootDir, slaveId, frameworkId, executorId, containerId);
if (!os::exists(path)) {
// This could happen if the slave died before the executor
// registered with the slave.
LOG(WARNING)
<< "Failed to find executor libprocess pid file '" << path << "'";
return state;
}
pid = os::read(path);
if (pid.isError()) {
//.........这里部分代码省略.........
示例8: Failure
Future<ResourceStatistics> CpuacctSubsystem::usage(
const ContainerID& containerId)
{
ResourceStatistics result;
// TODO(chzhcn): Getting the number of processes and threads is
// available as long as any cgroup subsystem is used so this best
// not be tied to a specific cgroup subsystem. A better place is
// probably Linux Launcher, which uses the cgroup freezer subsystem.
// That requires some change for it to adopt the new semantics of
// reporting subsystem-independent cgroup usage.
// Note: The complexity of this operation is linear to the number of
// processes and threads in a container: the kernel has to allocate
// memory to contain the list of pids or tids; the userspace has to
// parse the cgroup files to get the size. If this proves to be a
// performance bottleneck, some kind of rate limiting mechanism
// needs to be employed.
if (flags.cgroups_cpu_enable_pids_and_tids_count) {
Try<set<pid_t>> pids = cgroups::processes(
hierarchy,
path::join(flags.cgroups_root, containerId.value()));
if (pids.isError()) {
return Failure("Failed to get number of processes: " + pids.error());
}
result.set_processes(pids.get().size());
Try<set<pid_t>> tids = cgroups::threads(
hierarchy,
path::join(flags.cgroups_root, containerId.value()));
if (tids.isError()) {
return Failure("Failed to get number of threads: " + tids.error());
}
result.set_threads(tids.get().size());
}
// Get the number of clock ticks, used for cpu accounting.
static long ticks = sysconf(_SC_CLK_TCK);
PCHECK(ticks > 0) << "Failed to get sysconf(_SC_CLK_TCK)";
// Add the cpuacct.stat information.
Try<hashmap<string, uint64_t>> stat = cgroups::stat(
hierarchy,
path::join(flags.cgroups_root, containerId.value()),
"cpuacct.stat");
if (stat.isError()) {
return Failure("Failed to read 'cpuacct.stat': " + stat.error());
}
// TODO(bmahler): Add namespacing to cgroups to enforce the expected
// structure, e.g., cgroups::cpuacct::stat.
Option<uint64_t> user = stat.get().get("user");
Option<uint64_t> system = stat.get().get("system");
if (user.isSome() && system.isSome()) {
result.set_cpus_user_time_secs((double) user.get() / (double) ticks);
result.set_cpus_system_time_secs((double) system.get() / (double) ticks);
}
return result;
}
示例9: Error
Try<RunState> RunState::recover(
const string& rootDir,
const SlaveID& slaveId,
const FrameworkID& frameworkId,
const ExecutorID& executorId,
const ContainerID& containerId,
bool strict,
bool rebooted)
{
RunState state;
state.id = containerId;
string message;
// See if the sentinel file exists. This is done first so it is
// known even if partial state is returned, e.g., if the libprocess
// pid file is not recovered. It indicates the slave removed the
// executor.
string path = paths::getExecutorSentinelPath(
rootDir, slaveId, frameworkId, executorId, containerId);
state.completed = os::exists(path);
// Find the tasks.
Try<list<string>> tasks = paths::getTaskPaths(
rootDir,
slaveId,
frameworkId,
executorId,
containerId);
if (tasks.isError()) {
return Error(
"Failed to find tasks for executor run " + containerId.value() +
": " + tasks.error());
}
// Recover tasks.
foreach (const string& path, tasks.get()) {
TaskID taskId;
taskId.set_value(Path(path).basename());
Try<TaskState> task = TaskState::recover(
rootDir, slaveId, frameworkId, executorId, containerId, taskId, strict);
if (task.isError()) {
return Error(
"Failed to recover task " + taskId.value() + ": " + task.error());
}
state.tasks[taskId] = task.get();
state.errors += task->errors;
}
path = paths::getForkedPidPath(
rootDir, slaveId, frameworkId, executorId, containerId);
// If agent host is rebooted, we do not read the forked pid and libprocess pid
// since those two pids are obsolete after reboot. And we remove the forked
// pid file to make sure we will not read it in the case the agent process is
// restarted after we checkpoint the new boot ID in `Slave::__recover` (i.e.,
// agent recovery is done after the reboot).
if (rebooted) {
if (os::exists(path)) {
Try<Nothing> rm = os::rm(path);
if (rm.isError()) {
return Error(
"Failed to remove executor forked pid file '" + path + "': " +
rm.error());
}
}
return state;
}
if (!os::exists(path)) {
// This could happen if the slave died before the containerizer checkpointed
// the forked pid or agent process is restarted after agent host is rebooted
// since we remove this file in the above code.
LOG(WARNING) << "Failed to find executor forked pid file '" << path << "'";
return state;
}
// Read the forked pid.
Result<string> pid = state::read<string>(path);
if (pid.isError()) {
message = "Failed to read executor forked pid from '" + path +
"': " + pid.error();
if (strict) {
return Error(message);
} else {
LOG(WARNING) << message;
state.errors++;
return state;
}
}
if (pid->empty()) {
// This could happen if the slave is hard rebooted after the file is created
// but before the data is synced on disk.
//.........这里部分代码省略.........
示例10:
inline bool operator==(const ContainerID& left, const std::string& right)
{
return left.value() == right;
}
示例11:
bool operator==(const ContainerID& left, const ContainerID& right)
{
return left.value() == right.value() &&
left.has_parent() == right.has_parent() &&
(!left.has_parent() || left.parent() == right.parent());
}
示例12: cgroup
string LinuxLauncher::cgroup(const ContainerID& containerId)
{
return path::join(flags.cgroups_root, containerId.value());
}
示例13:
inline std::size_t hash_value(const ContainerID& containerId)
{
size_t seed = 0;
boost::hash_combine(seed, containerId.value());
return seed;
}