Apache Mesos
registrar.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 __RESOURCE_PROVIDER_REGISTRAR_HPP__
18 #define __RESOURCE_PROVIDER_REGISTRAR_HPP__
19 
20 #include <memory>
21 
22 #include <mesos/state/storage.hpp>
23 
24 #include <process/future.hpp>
25 #include <process/owned.hpp>
26 
27 #include <stout/nothing.hpp>
28 #include <stout/try.hpp>
29 
30 #include "master/registrar.hpp"
31 
33 
34 #include "slave/flags.hpp"
35 
36 
37 namespace mesos {
38 namespace resource_provider {
39 
40 class Registrar
41 {
42 public:
43  // Defines an abstraction for operations that can be applied on the
44  // Registry.
45  // TODO(xujyan): Make Operation generic so that we can apply them
46  // against a generic "batch operation applier" abstraction, see TODO
47  // in master/registrar.hpp for more details.
48  class Operation : public process::Promise<bool>
49  {
50  public:
51  ~Operation() override = default;
52 
53  // Attempts to invoke the operation on the registry object.
54  //
55  // Returns whether the operation mutates 'registry', or an error if
56  // the operation cannot be applied successfully.
57  Try<bool> operator()(registry::Registry* registry);
58 
59  // Sets the promise based on whether the operation was successful.
60  bool set();
61 
62  protected:
63  virtual Try<bool> perform(registry::Registry* registry) = 0;
64 
65  private:
66  bool success = false;
67  };
68 
69  // Create a registry on top of generic storage.
72 
73  // Create a registry on top of a master's persistent state.
74  //
75  // The created registrar does not take ownership of the passed registrar
76  // which needs to be valid as long as the created registrar is alive.
79  registry::Registry registry);
80 
81  virtual ~Registrar() = default;
82 
85 };
86 
87 
89 {
90 public:
91  explicit AdmitResourceProvider(
92  const registry::ResourceProvider& resourceProvider);
93 
94 private:
95  Try<bool> perform(registry::Registry* registry) override;
96 
97  registry::ResourceProvider resourceProvider;
98 };
99 
100 
102 {
103 public:
104  explicit RemoveResourceProvider(const ResourceProviderID& id);
105 
106 private:
107  Try<bool> perform(registry::Registry* registry) override;
108 
109  ResourceProviderID id;
110 };
111 
112 
113 class GenericRegistrarProcess;
114 
115 
117 {
118 public:
120 
121  ~GenericRegistrar() override;
122 
124 
126 
127 private:
128  std::unique_ptr<GenericRegistrarProcess> process;
129 };
130 
131 
132 class MasterRegistrarProcess;
133 
134 
136 {
137 public:
138  // The created registrar does not take ownership of the passed registrar
139  // which needs to be valid as long as the created registrar is alive.
140  explicit MasterRegistrar(
142  registry::Registry registry);
143 
144  ~MasterRegistrar() override;
145 
146  // This registrar performs no recovery; instead to recover
147  // the underlying master registrar needs to be recovered.
149 
151 
152 private:
153  std::unique_ptr<MasterRegistrarProcess> process;
154 };
155 
156 } // namespace resource_provider {
157 } // namespace mesos {
158 
159 #endif // __RESOURCE_PROVIDER_REGISTRAR_HPP__
static Try< process::Owned< Registrar > > create(process::Owned< state::Storage > storage)
Definition: check.hpp:33
Definition: registrar.hpp:88
Try< bool > operator()(registry::Registry *registry)
virtual Try< bool > perform(registry::Registry *registry)=0
Definition: agent.hpp:25
Definition: future.hpp:74
Definition: registrar.hpp:40
Definition: registrar.hpp:135
Definition: registrar.hpp:116
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
Definition: owned.hpp:36
virtual process::Future< bool > apply(process::Owned< Operation > operation)=0
virtual process::Future< registry::Registry > recover()=0
Definition: future.hpp:58