Validates that all the given resources are allocated to same role.
| 976 | |
| 977 | // Validates that all the given resources are allocated to same role. |
| 978 | Option<Error> validateAllocatedToSingleRole(const Resources& resources) |
| 979 | { |
| 980 | Option<string> role; |
| 981 | |
| 982 | foreach (const Resource& resource, resources) { |
| 983 | // Note that the master normalizes `Offer::Operation` resources |
| 984 | // to have allocation info set, so we can validate it here. |
| 985 | if (!resource.allocation_info().has_role()) { |
| 986 | return Error("The resources are not allocated to a role"); |
| 987 | } |
| 988 | |
| 989 | string _role = resource.allocation_info().role(); |
| 990 | |
| 991 | if (role.isNone()) { |
| 992 | role = _role; |
| 993 | continue; |
| 994 | } |
| 995 | |
| 996 | if (_role != role.get()) { |
| 997 | return Error("The resources have multiple allocation roles" |
| 998 | " ('" + _role + "' and '" + role.get() + "')" |
| 999 | " but only one allocation role is allowed"); |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | return None(); |
| 1004 | } |
| 1005 | |
| 1006 | |
| 1007 | bool detectOverlappingSetAndRangeResources( |
no test coverage detected