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

Function validateCommandLineResources

src/common/resources.cpp:577–608  ·  view source on GitHub ↗

* Checks that a Resources object is valid for command line specification. * * Checks that the given Resources object is appropriate for specification at * the command line. Resources are appropriate if they do not have two resources * with the same name but different types, and do not attempt to specify * persistent volumes, revocable resources, or dynamic reservations. * * @param resources

Source from the content-addressed store, hash-verified

575 * Error otherwise.
576 */
577static Option<Error> validateCommandLineResources(const Resources& resources)
578{
579 hashmap<string, Value::Type> nameTypes;
580
581 foreach (const Resource& resource, resources) {
582 // These fields should only be provided programmatically,
583 // not at the command line.
584 if (Resources::isPersistentVolume(resource)) {
585 return Error(
586 "Persistent volumes cannot be specified at the command line");
587 } else if (Resources::isRevocable(resource)) {
588 return Error(
589 "Revocable resources cannot be specified at the command line; do"
590 " not include a 'revocable' key in the resources JSON");
591 } else if (Resources::isDynamicallyReserved(resource)) {
592 return Error(
593 "Dynamic reservations cannot be specified at the command line; do"
594 " not include a reservation with DYNAMIC type in the resources JSON");
595 }
596
597 if (nameTypes.contains(resource.name()) &&
598 nameTypes[resource.name()] != resource.type()) {
599 return Error(
600 "Resources with the same name ('" + resource.name() + "') but"
601 " different types are not allowed");
602 } else if (!nameTypes.contains(resource.name())) {
603 nameTypes[resource.name()] = resource.type();
604 }
605 }
606
607 return None();
608}
609
610} // namespace internal {
611

Callers 1

parseMethod · 0.70

Calls 1

NoneClass · 0.85

Tested by

no test coverage detected