Apache Mesos
module.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 __MESOS_MODULE_HPP__
18 #define __MESOS_MODULE_HPP__
19 
20 // Mesos Module API (MESOS-1384).
21 //
22 // A Mesos module is an instance of a module 'kind' known to Mesos,
23 // implemented in a dynamically loaded library. A module library can
24 // hold multiple modules. When a Mesos master or slave is started, it
25 // takes a list of libraries with contained modules as command line
26 // argument (in JSON format or a path to a JSON file).
27 //
28 // JSON := {"libraries": [library, ...]}
29 // library := {"file": <library path>,
30 // "modules": [<module name>, ...]}
31 //
32 // How to write a module library:
33 // 1. Define a create() function that returns a pointer to an object
34 // of 'kind' type.
35 // 2. If you want to indicate backwards compatibility for a module,
36 // create:
37 // 'bool compatible() { return true; }
38 // (You can replace compatible with any other name).
39 // If you want custom compatibility checks, replace the return
40 // statement above with them.
41 // 3. Define a variable of Module<KIND> struct type and populate the
42 // fields (including pointers to 'create' and 'compatible'). The
43 // variable name thus becomes the module name.
44 
45 #include <mesos/version.hpp>
46 
47 #define MESOS_MODULE_API_VERSION "2"
48 
49 namespace mesos {
50 namespace modules {
51 
52 // Internal utilities, not part of the module API:
53 
54 // Declare a loadable module library.
55 // This also provides handshakes with Mesos for version checking.
56 struct ModuleBase
57 {
59  const char* _moduleApiVersion,
60  const char* _mesosVersion,
61  const char* _kind,
62  const char* _authorName,
63  const char* _authorEmail,
64  const char* _description,
65  bool (*_compatible)())
66  : moduleApiVersion(_moduleApiVersion),
67  mesosVersion(_mesosVersion),
68  kind(_kind),
69  authorName(_authorName),
70  authorEmail(_authorEmail),
71  description(_description),
72  compatible(_compatible) {}
73 
74  const char* moduleApiVersion;
75  const char* mesosVersion;
76 
77  // String representation of module 'kind' returned from 'create'.
78  const char* kind;
79  const char* authorName;
80  const char* authorEmail;
81  const char* description;
82 
83  // Callback invoked to check version compatibility. If this field
84  // is `nullptr`, backwards compatibility is disabled and the module
85  // version must match the Mesos release version exactly. If the
86  // macro is used, Mesos first checks backwards compatibility against
87  // its own internal table maintained by Mesos developers, then your
88  // implementation that follows the macro gets a say. If you return
89  // true, the module is admitted.
90  bool (*compatible)();
91 };
92 
93 
94 // These declarations are neeed only for later specializations.
95 
96 template <typename T>
97 struct Module;
98 
99 template <typename T>
100 const char* kind();
101 
102 // Each module "kind" specialization extends ModuleBase to provide a `create()`
103 // method that returns a pointer to an object of the given module "kind".
104 // template <> struct Module<mesos::SecretResolver> : ModuleBase {
105 // Module(..., T* (*_create)(const Parameters&))
106 // : ModuleBase(...), create(_create) {...}
107 // T* (*create)(const Parameters&);
108 // };
109 
110 // TODO(kapil): Update module interface to return a managed pointer instead of
111 // returning raw pointers. This would allow the caller to manage the lifecycle
112 // of the dynamically-allocated object. We should also allow passing
113 // master/agent flags during module initialization. E.g.,
114 // unique_ptr<T> (*create)(const Parameters&, const Flags&);
115 
116 } // namespace modules {
117 } // namespace mesos {
118 
119 #endif // __MESOS_MODULE_HPP__
ModuleBase(const char *_moduleApiVersion, const char *_mesosVersion, const char *_kind, const char *_authorName, const char *_authorEmail, const char *_description, bool(*_compatible)())
Definition: module.hpp:58
bool(* compatible)()
Definition: module.hpp:90
const char * mesosVersion
Definition: module.hpp:75
Definition: module.hpp:56
const char * authorEmail
Definition: module.hpp:80
const char * kind()
const char * kind
Definition: module.hpp:78
const char * authorName
Definition: module.hpp:79
const char * moduleApiVersion
Definition: module.hpp:74
const char * description
Definition: module.hpp:81
Definition: module.hpp:97