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

Method resources

src/slave/containerizer/containerizer.cpp:66–214  ·  view source on GitHub ↗

TODO(idownes): Move this to the Containerizer interface to complete the delegation of containerization.

Source from the content-addressed store, hash-verified

64// TODO(idownes): Move this to the Containerizer interface to complete
65// the delegation of containerization.
66Try<Resources> Containerizer::resources(const Flags& flags)
67{
68 Try<Resources> parsed = Resources::parse(
69 flags.resources.getOrElse(""), flags.default_role);
70
71 if (parsed.isError()) {
72 return Error(parsed.error());
73 }
74
75 Resources resources = parsed.get();
76
77 // NOTE: We need to check for the "cpus" resource within the flags
78 // because once the `Resources` object is created, we cannot distinguish
79 // between
80 // (1) "cpus:0", and
81 // (2) no cpus specified.
82 // due to `Resources:add` discarding empty resources.
83 // We only auto-detect cpus in case (2).
84 // The same logic applies for the other resources!
85 // `Resources::fromString().get()` is safe because `Resources::parse()` above
86 // is valid.
87 vector<Resource> resourceList = Resources::fromString(
88 flags.resources.getOrElse(""), flags.default_role).get();
89
90 bool hasCpus = false;
91 bool hasMem = false;
92 bool hasDisk = false;
93 bool hasPorts = false;
94
95 foreach (const Resource& resource, resourceList) {
96 if (resource.name() == "cpus") {
97 hasCpus = true;
98 } else if (resource.name() == "mem") {
99 hasMem = true;
100 } else if (resource.name() == "disk") {
101 hasDisk = true;
102 } else if (resource.name() == "ports") {
103 hasPorts = true;
104 }
105 }
106
107 if (!hasCpus) {
108 // No CPU specified so probe OS or resort to DEFAULT_CPUS.
109 double cpus;
110 Try<long> cpus_ = os::cpus();
111 if (!cpus_.isSome()) {
112 LOG(WARNING) << "Failed to auto-detect the number of cpus to use: '"
113 << cpus_.error()
114 << "'; defaulting to " << DEFAULT_CPUS;
115 cpus = DEFAULT_CPUS;
116 } else {
117 cpus = cpus_.get();
118 }
119
120 resources += Resources::parse(
121 "cpus",
122 stringify(cpus),
123 flags.default_role).get();

Callers 15

updateStateMethod · 0.45
recoverMethod · 0.45
publishResourcesMethod · 0.45
foreachMethod · 0.45
updateMethod · 0.45
synchronizedFunction · 0.45
launchMethod · 0.45
foreachMethod · 0.45
TEST_FFunction · 0.45
TEST_PFunction · 0.45
foreachFunction · 0.45

Calls 15

GigabytesFunction · 0.85
BytesClass · 0.85
getOrElseMethod · 0.80
parseFunction · 0.70
errorMethod · 0.65
ErrorFunction · 0.50
cpusFunction · 0.50
stringifyFunction · 0.50
memoryFunction · 0.50
sizeFunction · 0.50
validateFunction · 0.50
isErrorMethod · 0.45

Tested by 15

TEST_FFunction · 0.36
TEST_PFunction · 0.36
foreachFunction · 0.36
createTasksFunction · 0.36
initializeClusterMethod · 0.36
TEST_PFunction · 0.36
TEST_FFunction · 0.36
TEST_PFunction · 0.36
TEST_FFunction · 0.36