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

Function validateContainerId

src/slave/validation.cpp:41–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39namespace container {
40
41Option<Error> validateContainerId(const ContainerID& containerId)
42{
43 const string& id = containerId.value();
44
45 // Check common Mesos ID rules.
46 Option<Error> error = common::validation::validateID(id);
47 if (error.isSome()) {
48 return Error(error->message);
49 }
50
51 // Check ContainerID specific rules.
52 //
53 // Valid the container id length
54 if (id.length() > MAX_CONTAINER_ID_LENGTH) {
55 return Error("'ContainerID.value' '" + id + "' exceeds the maximum"
56 " length (" + stringify(MAX_CONTAINER_ID_LENGTH) + ")");
57 }
58
59 // Periods are disallowed because our string representation of
60 // ContainerID uses periods: <uuid>.<child>.<grandchild>.
61 // For example: <uuid>.redis.backup
62 //
63 // Spaces are disallowed as they can render logs confusing and
64 // need escaping on terminals when dealing with paths.
65 auto invalidCharacter = [](char c) {
66 return c == '.' || c == ' ';
67 };
68
69 if (std::any_of(id.begin(), id.end(), invalidCharacter)) {
70 return Error("'ContainerID.value' '" + id + "'"
71 " contains invalid characters");
72 }
73
74 // TODO(bmahler): Print the invalid field nicely within the error
75 // (e.g. 'parent.parent.parent.value'). For now we only have one
76 // level of nesting so it's ok.
77 if (containerId.has_parent()) {
78 Option<Error> parentError = validateContainerId(containerId.parent());
79
80 if (parentError.isSome()) {
81 return Error("'ContainerID.parent' is invalid: " + parentError->message);
82 }
83 }
84
85 return None();
86}
87
88} // namespace container {
89

Callers 3

TESTFunction · 0.85
validateFunction · 0.85
createExecutorDirectoryFunction · 0.85

Calls 8

validateIDFunction · 0.85
NoneClass · 0.85
ErrorFunction · 0.50
stringifyFunction · 0.50
valueMethod · 0.45
isSomeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

TESTFunction · 0.68