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 <process/future.hpp>
23 #include <process/owned.hpp>
24 
25 #include <stout/nothing.hpp>
26 #include <stout/try.hpp>
27 
28 #include "master/registrar.hpp"
29 
31 
32 #include "slave/flags.hpp"
33 
34 
35 namespace mesos {
36 namespace resource_provider {
37 
38 class Registrar
39 {
40 public:
41  // Defines an abstraction for operations that can be applied on the
42  // Registry.
43  // TODO(xujyan): Make Operation generic so that we can apply them
44  // against a generic "batch operation applier" abstraction, see TODO
45  // in master/registrar.hpp for more details.
46  class Operation : public process::Promise<bool>
47  {
48  public:
49  virtual ~Operation() = default;
50 
51  // Attempts to invoke the operation on the registry object.
52  //
53  // Returns whether the operation mutates 'registry', or an error if
54  // the operation cannot be applied successfully.
55  Try<bool> operator()(registry::Registry* registry);
56 
57  // Sets the promise based on whether the operation was successful.
58  bool set();
59 
60  protected:
61  virtual Try<bool> perform(registry::Registry* registry) = 0;
62 
63  private:
64  bool success = false;
65  };
66 
67  // Create a registry on top of a master's persistent state.
70 
71  // Create a registry on top of an agent's persistent state.
73  const mesos::internal::slave::Flags& slaveFlags,
74  const SlaveID& slaveId);
75 
76  virtual ~Registrar() = default;
77 
78  virtual process::Future<Nothing> recover() = 0;
80 };
81 
82 
84 {
85 public:
86  explicit AdmitResourceProvider(const ResourceProviderID& id);
87 
88 private:
89  Try<bool> perform(registry::Registry* registry) override;
90 
91  ResourceProviderID id;
92 };
93 
94 
96 {
97 public:
98  explicit RemoveResourceProvider(const ResourceProviderID& id);
99 
100 private:
101  Try<bool> perform(registry::Registry* registry) override;
102 
103  ResourceProviderID id;
104 };
105 
106 
107 class AgentRegistrarProcess;
108 
109 
110 class AgentRegistrar : public Registrar
111 {
112 public:
114  const mesos::internal::slave::Flags& slaveFlags,
115  const SlaveID& slaveId);
116 
117  ~AgentRegistrar() override;
118 
120 
122 
123 private:
124  std::unique_ptr<AgentRegistrarProcess> process;
125 };
126 
127 
128 class MasterRegistrarProcess;
129 
130 
132 {
133 public:
135 
136  ~MasterRegistrar() override;
137 
138  // This registrar performs no recovery; instead to recover
139  // the underlying master registrar needs to be recovered.
141 
143 
144 private:
145  std::unique_ptr<MasterRegistrarProcess> process;
146 };
147 
148 } // namespace resource_provider {
149 } // namespace mesos {
150 
151 #endif // __RESOURCE_PROVIDER_REGISTRAR_HPP__
Definition: check.hpp:33
Definition: registrar.hpp:91
Try< bool > operator()(registry::Registry *registry)
virtual process::Future< Nothing > recover()=0
Definition: flags.hpp:39
static Try< process::Owned< Registrar > > create(mesos::internal::master::Registrar *registrar)
virtual Try< bool > perform(registry::Registry *registry)=0
Definition: spec.hpp:30
Definition: future.hpp:73
Definition: registrar.hpp:38
Definition: registrar.hpp:110
Definition: registrar.hpp:131
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
Definition: owned.hpp:36
virtual process::Future< bool > apply(process::Owned< Operation > operation)=0