Containerizer
类(定义在src/slave/containerizer/containerizer.hpp
)是所有Containerizer
的抽象父类。除了默认的构造函数和一个什么都没做的析构函数,其只实现了create
和resources
方法。create
方法代码如下(v0.26
版本):
Try<Containerizer*> Containerizer::create(
const Flags& flags,
bool local,
Fetcher* fetcher)
{
if (flags.isolation == "external") {
LOG(WARNING) << "The 'external' isolation flag is deprecated, "
<< "please update your flags to"
<< " '--containerizers=external'.";
Try<ExternalContainerizer*> containerizer =
ExternalContainerizer::create(flags);
if (containerizer.isError()) {
return Error("Could not create ExternalContainerizer: " +
containerizer.error());
}
return containerizer.get();
}
// TODO(benh): We need to store which containerizer or
// containerizers were being used. See MESOS-1663.
// Create containerizer(s).
vector<Containerizer*> containerizers;
foreach (const string& type, strings::split(flags.containerizers, ",")) {
if (type == "mesos") {
Try<MesosContainerizer*> containerizer =
MesosContainerizer::create(flags, local, fetcher);
if (containerizer.isError()) {
return Error("Could not create MesosContainerizer: " +
containerizer.error());
} else {
containerizers.push_back(containerizer.get());
}
} else if (type == "docker") {
Try<DockerContainerizer*> containerizer =
DockerContainerizer::create(flags, fetcher);
if (containerizer.isError()) {
return Error("Could not create DockerContainerizer: " +
containerizer.error());
} else {
containerizers.push_back(containerizer.get());
}
} else if (type == "external") {
Try<ExternalContainerizer*> containerizer =
ExternalContainerizer::create(flags);
if (containerizer.isError()) {
return Error("Could not create ExternalContainerizer: " +
containerizer.error());
} else {
containerizers.push_back(containerizer.get());
}
} else {
return Error("Unknown or unsupported containerizer: " + type);
}
}
if (containerizers.size() == 1) {
return containerizers.front();
}
Try<ComposingContainerizer*> containerizer =
ComposingContainerizer::create(containerizers);
if (containerizer.isError()) {
return Error(containerizer.error());
}
return containerizer.get();
}
默认情况下,containerizers
的type
是mesos
,所以会调用MesosContainerizer::create
来生成containerizer
。关于resources
方法,参考Mesos笔记 (5)—— 资源。