AOSharedServiceLibrary
consul_interface.h
1 /*
2 MIT License Block
3 
4 Copyright (c) 2016 Alex Barry
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 
25 #ifndef AOSSL_CONSUL_INCLUDE_CONSUL_INTERFACE_H_
26 #define AOSSL_CONSUL_INCLUDE_CONSUL_INTERFACE_H_
27 
28 #include <string.h>
29 #include <string>
30 #include <vector>
31 
32 #include "aossl/core/include/buffers.h"
33 
34 // ----------------------------Health Checks----------------------------------//
35 
37 struct HealthCheck {
39  std::string script;
40 
42  std::string interval;
43 };
44 
45 // -------------------------------Service-------------------------------------//
46 
48 
52  public:
53  virtual ~ServiceInterface() {}
55 
58  virtual std::string to_json() const = 0;
59 
61  virtual std::string get_id() const = 0;
62 
64  virtual std::string get_name() const = 0;
65 
67  virtual std::string get_address() const = 0;
68 
70  virtual std::string get_port() const = 0;
71 
73  virtual void set_id(std::string new_id) = 0;
74 
76  virtual void set_name(std::string new_name) = 0;
77 
79  virtual void set_address(std::string new_address) = 0;
80 
82  virtual void set_port(std::string new_port) = 0;
83 
85  virtual std::vector<std::string> get_tags() = 0;
87  virtual void add_tag(std::string new_tag) = 0;
89  virtual void clear_tags() = 0;
91  virtual int num_tags() const = 0;
92 
94  virtual HealthCheck get_check() = 0;
96  virtual void set_check(std::string scr, int interval_seconds) = 0;
97 };
98 
99 // ----------------------------Consul Admin-----------------------------------//
100 
102 
108  public:
110 
115 
118  virtual std::string base64_decode(std::string const& encoded_string) = 0;
119 
121 
125 
128  virtual AOSSL::StringBuffer* \
129  base64_decode_safe(std::string const& encoded_string) = 0;
130 
131  virtual ~ConsulInterface() {}
132 
133  // -----------------Service Registry Functions------------------------------//
134 
136 
139  virtual bool register_service(const ServiceInterface& s) = 0;
140 
142 
145  virtual bool deregister_service(const ServiceInterface& s) = 0;
146 
147  // ------------Configuration Key-Value Storage Functions--------------------//
148 
150 
153 
157  virtual bool set_config_value(std::string key, std::string val) = 0;
158 
160 
163 
166  virtual std::string get_config_value(std::string key) = 0;
167 
169 
172  virtual AOSSL::StringBuffer* get_config_value_safe(std::string key) = 0;
173 
175  virtual bool del_config_value(std::string key) = 0;
176 
177  // Basic Queries
178  // All Return a JSON string
179 
180  // Local Agent Queries
181 
183 
186  virtual std::string services() = 0;
187 
189  virtual AOSSL::StringBuffer* services_safe() = 0;
190 
192 
195  virtual std::string agent_info() = 0;
196 
198  virtual AOSSL::StringBuffer* agent_info_safe() = 0;
199 
201 
204  virtual std::string healthy_services() = 0;
205 
207  virtual AOSSL::StringBuffer* healthy_services_safe() = 0;
208 
209  // Catalog Queries
210 
212 
215  virtual std::string datacenters() = 0;
216 
218  virtual AOSSL::StringBuffer* datacenters_safe() = 0;
219 
221 
224 
227  virtual std::string nodes_dc(std::string data_center) = 0;
228 
230 
233  virtual AOSSL::StringBuffer* nodes_dc_safe(std::string data_center) = 0;
234 
236 
239 
242  virtual std::string services_dc(std::string data_center) = 0;
243 
245 
248  virtual AOSSL::StringBuffer* services_dc_safe(std::string data_center) = 0;
249 
251 
254 
257  virtual std::string nodes_service(std::string service) = 0;
258 
260 
263  virtual AOSSL::StringBuffer* nodes_service_safe(std::string service) = 0;
264 
266 
269  virtual std::string \
270  services_node(std::string node, std::string data_center) = 0;
271 
273 
277  virtual AOSSL::StringBuffer* \
278  services_node_safe(std::string node, std::string data_center) = 0;
279 };
280 
281 #endif // AOSSL_CONSUL_INCLUDE_CONSUL_INTERFACE_H_
A struct to hold health check information which can be added to a service.
Definition: consul_interface.h:37
A Structure for holding a single value.
Definition: buffers.h:42
The Consul Administrator, who handles configuration & service discovery.
Definition: consul_interface.h:107
std::string interval
The interval for the health check.
Definition: consul_interface.h:42
std::string script
The script to run for the health check.
Definition: consul_interface.h:39
A Service class which can be registered with Consul for each app instance.
Definition: consul_interface.h:51