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

Function validateRoles

src/master/validation.cpp:470–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468namespace internal {
469
470Option<Error> validateRoles(const FrameworkInfo& frameworkInfo)
471{
472 bool multiRole = protobuf::frameworkHasCapability(
473 frameworkInfo,
474 FrameworkInfo::Capability::MULTI_ROLE);
475
476 // Ensure that the right fields are used.
477 if (multiRole) {
478 if (frameworkInfo.has_role()) {
479 return Error("'FrameworkInfo.role' must not be set when the"
480 " framework is MULTI_ROLE capable");
481 }
482 } else {
483 if (frameworkInfo.roles_size() > 0) {
484 return Error("'FrameworkInfo.roles' must not be set when the"
485 " framework is not MULTI_ROLE capable");
486 }
487 }
488
489 // Check for duplicate entries.
490 //
491 // TODO(bmahler): Use a generic duplicate check function.
492 if (multiRole) {
493 const hashset<string> duplicateRoles = [&]() {
494 hashset<string> roles;
495 hashset<string> duplicates;
496
497 foreach (const string& role, frameworkInfo.roles()) {
498 if (roles.contains(role)) {
499 duplicates.insert(role);
500 } else {
501 roles.insert(role);
502 }
503 }
504
505 return duplicates;
506 }();
507
508 if (!duplicateRoles.empty()) {
509 return Error("'FrameworkInfo.roles' contains duplicate items: " +
510 stringify(duplicateRoles));
511 }
512 }
513
514 // Validate the role(s).
515 if (multiRole) {
516 foreach (const string& role, frameworkInfo.roles()) {
517 Option<Error> error = roles::validate(role);
518 if (error.isSome()) {
519 return Error("'FrameworkInfo.roles' contains invalid role: " +
520 error->message);
521 }
522 }
523 } else {
524 Option<Error> error = roles::validate(frameworkInfo.role());
525 if (error.isSome()) {
526 return Error("'FrameworkInfo.role' is not a valid role: " +
527 error->message);

Callers 1

validateFunction · 0.85

Calls 7

frameworkHasCapabilityFunction · 0.85
NoneClass · 0.85
validateFunction · 0.70
ErrorFunction · 0.50
stringifyFunction · 0.50
emptyMethod · 0.45
isSomeMethod · 0.45

Tested by

no test coverage detected