Apache Mesos
resources_utils.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __TESTS_RESOURCES_UTILS_HPP__
18 #define __TESTS_RESOURCES_UTILS_HPP__
19 
20 #include <string>
21 #include <ostream>
22 
23 #include <mesos/mesos.hpp>
24 #include <mesos/resources.hpp>
25 
26 #include <stout/try.hpp>
27 
28 namespace mesos {
29 namespace internal {
30 namespace tests {
31 
32 // Returns a copy of the resources that are allocated to the role.
33 //
34 // TODO(bmahler): Consider adding a top-level `AllocatedResources`
35 // that has the invariant that all resources contained within it
36 // have an `AllocationInfo` set. This class could prevent
37 // malformed operations between `Resources` and
38 // `AllocatedResources`, and could clarify interfaces that take
39 // allocated resources (e.g. allocator, sorter, etc).
40 Resources allocatedResources(
41  const Resources& resources,
42  const std::string& role);
43 
44 
45 // Creates a "ports(*)" resource for the given ranges.
46 Resource createPorts(const ::mesos::Value::Ranges& ranges);
47 
48 // Fragments the given range bounds into a number of subranges.
49 // Returns an Error if 'numRanges' is too large. E.g.
50 //
51 // [1-10], 1 -> [1-10]
52 // [1-10], 2 -> [1-1,3-10]
53 // [1-10], 3 -> [1-1,3-3,5-10]
54 // [1-10], 4 -> [1-1,3-3,5-5,7-10]
55 // [1-10], 5 -> [1-1,3-3,5-5,7-7,9-10]
56 // [1-10], 6 -> Error
57 //
59  const ::mesos::Value::Range& bounds,
60  size_t numRanges);
61 
62 ::mesos::Value::Range createRange(uint64_t begin, uint64_t end);
63 
64 } // namespace tests {
65 } // namespace internal {
66 } // namespace mesos {
67 
68 #endif // __TESTS_RESOURCES_UTILS_HPP__
Definition: check.hpp:33
::mesos::Value::Range createRange(uint64_t begin, uint64_t end)
Resources allocatedResources(const Resources &resources, const std::string &role)
Try<::mesos::Value::Ranges > fragment(const ::mesos::Value::Range &bounds, size_t numRanges)
Definition: agent.hpp:25
Definition: attributes.hpp:24
Resource createPorts(const ::mesos::Value::Ranges &ranges)