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

Method add

src/resource_provider/daemon.cpp:201–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199
200
201Future<bool> LocalResourceProviderDaemonProcess::add(
202 const ResourceProviderInfo& info)
203{
204 CHECK(!info.has_id()); // Should have already been validated by the agent.
205
206 if (configDir.isNone()) {
207 return Failure("Missing required flag --resource_provider_config_dir");
208 }
209
210 // Return true if the info has been added for idempotency.
211 if (providers[info.type()].contains(info.name())) {
212 const ProviderData& data = providers[info.type()].at(info.name());
213
214 if (data.removing.isSome()) {
215 return Failure(
216 "Failed to add resource provider with type '" + info.type() +
217 "' and name '" + info.name() + "' as a removal is still in progress");
218 }
219
220 return data.info == info;
221 }
222
223 // Generate a filename for the config.
224 // NOTE: We use the following template `<type>.<name>.<uuid>.json`
225 // with a random UUID to generate a new filename to avoid any conflict
226 // with existing ad-hoc config files.
227 const string path = path::join(
228 configDir.get(),
229 strings::join(".", info.type(), info.name(), id::UUID::random(), "json"));
230
231 LOG(INFO) << "Creating new config file '" << path << "'";
232
233 Try<Nothing> _save = save(path, info);
234 if (_save.isError()) {
235 return Failure(
236 "Failed to write config file '" + path + "': " + _save.error());
237 }
238
239 providers[info.type()].put(info.name(), {path, info});
240
241 // Launch the resource provider if the daemon is already started.
242 if (slaveId.isSome()) {
243 auto err = [](const ResourceProviderInfo& info, const string& message) {
244 LOG(ERROR)
245 << "Failed to launch resource provider with type '" << info.type()
246 << "' and name '" << info.name() << "': " << message;
247 };
248
249 launch(info.type(), info.name())
250 .onFailed(std::bind(err, info, lambda::_1))
251 .onDiscarded(std::bind(err, info, "future discarded"));
252 }
253
254 return true;
255}
256
257
258Future<bool> LocalResourceProviderDaemonProcess::update(

Callers 4

watchResourcesMethod · 0.45
watchProfilesMethod · 0.45
_applyOperationMethod · 0.45
applyDestroyDiskMethod · 0.45

Calls 15

FailureClass · 0.85
randomFunction · 0.85
typeMethod · 0.80
atMethod · 0.80
errorMethod · 0.65
joinFunction · 0.50
launchFunction · 0.50
bindFunction · 0.50
dispatchFunction · 0.50
isNoneMethod · 0.45
containsMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected