MCPcopy Create free account
hub / github.com/apache/mesos / parse

Function parse

src/slave/containerizer/docker.cpp:122–168  ·  view source on GitHub ↗

Parse the ContainerID from a Docker container and return None if the container was not launched from Mesos.

Source from the content-addressed store, hash-verified

120// Parse the ContainerID from a Docker container and return None if
121// the container was not launched from Mesos.
122Option<ContainerID> parse(const Docker::Container& container)
123{
124 Option<string> name = None();
125 Option<ContainerID> containerId = None();
126
127 if (strings::startsWith(container.name, DOCKER_NAME_PREFIX)) {
128 name = strings::remove(
129 container.name, DOCKER_NAME_PREFIX, strings::PREFIX);
130 } else if (strings::startsWith(container.name, "/" + DOCKER_NAME_PREFIX)) {
131 name = strings::remove(
132 container.name, "/" + DOCKER_NAME_PREFIX, strings::PREFIX);
133 }
134
135 if (name.isSome()) {
136 // For Mesos versions 0.23 to 1.3 (inclusive), the docker
137 // container name format was:
138 // DOCKER_NAME_PREFIX + SlaveID + DOCKER_NAME_SEPERATOR + ContainerID.
139 //
140 // In versions <= 0.22 or >= 1.4, the name format is:
141 // DOCKER_NAME_PREFIX + ContainerID.
142 //
143 // To be backward compatible during upgrade, we still have to
144 // support all formats.
145 if (!strings::contains(name.get(), DOCKER_NAME_SEPERATOR)) {
146 ContainerID id;
147 id.set_value(name.get());
148 containerId = id;
149 } else {
150 vector<string> parts = strings::split(name.get(), DOCKER_NAME_SEPERATOR);
151 if (parts.size() == 2 || parts.size() == 3) {
152 ContainerID id;
153 id.set_value(parts[1]);
154 containerId = id;
155 }
156 }
157
158 // Check if id is a valid UUID.
159 if (containerId.isSome()) {
160 Try<id::UUID> uuid = id::UUID::fromString(containerId->value());
161 if (uuid.isError()) {
162 return None();
163 }
164 }
165 }
166
167 return containerId;
168}
169
170
171Try<DockerContainerizer*> DockerContainerizer::create(

Callers 9

foreachFunction · 0.70
resourcesMethod · 0.70
foreachMethod · 0.50
executorMethod · 0.50
initializeMethod · 0.50
getExecutorInfoMethod · 0.50
mainFunction · 0.50
foreachFunction · 0.50
createMethod · 0.50

Calls 10

NoneClass · 0.85
startsWithFunction · 0.85
splitFunction · 0.85
removeFunction · 0.50
containsFunction · 0.50
isSomeMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
valueMethod · 0.45
isErrorMethod · 0.45

Tested by

no test coverage detected