| 256 | |
| 257 | |
| 258 | Future<bool> LocalResourceProviderDaemonProcess::update( |
| 259 | const ResourceProviderInfo& info) |
| 260 | { |
| 261 | CHECK(!info.has_id()); // Should have already been validated by the agent. |
| 262 | |
| 263 | if (configDir.isNone()) { |
| 264 | return Failure("Missing required flag --resource_provider_config_dir"); |
| 265 | } |
| 266 | |
| 267 | if (!providers[info.type()].contains(info.name())) { |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | ProviderData& data = providers[info.type()].at(info.name()); |
| 272 | |
| 273 | if (data.removing.isSome()) { |
| 274 | return Failure( |
| 275 | "Failed to update resource provider with type '" + info.type() + |
| 276 | "' and name '" + info.name() + "' as a removal is still in progress"); |
| 277 | } |
| 278 | |
| 279 | // Return true if the info has been updated for idempotency. |
| 280 | if (data.info == info) { |
| 281 | return true; |
| 282 | } |
| 283 | |
| 284 | Try<Nothing> _save = save(data.path, info); |
| 285 | if (_save.isError()) { |
| 286 | return Failure( |
| 287 | "Failed to write config file '" + data.path + "': " + _save.error()); |
| 288 | } |
| 289 | |
| 290 | data.info = info; |
| 291 | |
| 292 | // Update `version` to indicate that the config has been updated. |
| 293 | data.version = id::UUID::random(); |
| 294 | |
| 295 | // Launch the resource provider if the daemon is already started. |
| 296 | if (slaveId.isSome()) { |
| 297 | auto err = [](const ResourceProviderInfo& info, const string& message) { |
| 298 | LOG(ERROR) |
| 299 | << "Failed to launch resource provider with type '" << info.type() |
| 300 | << "' and name '" << info.name() << "': " << message; |
| 301 | }; |
| 302 | |
| 303 | launch(info.type(), info.name()) |
| 304 | .onFailed(std::bind(err, info, lambda::_1)) |
| 305 | .onDiscarded(std::bind(err, info, "future discarded")); |
| 306 | } |
| 307 | |
| 308 | return true; |
| 309 | } |
| 310 | |
| 311 | |
| 312 | Future<Nothing> LocalResourceProviderDaemonProcess::remove( |