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 #include <string.h>
26 #include <string>
27 #include <vector>
28 
29 #include "aossl/core/include/buffers.h"
30 #include "aossl/core/include/kv_store_interface.h"
31 
32 #ifndef AOSSL_CONSUL_INCLUDE_CONSUL_INTERFACE_H_
33 #define AOSSL_CONSUL_INCLUDE_CONSUL_INTERFACE_H_
34 
35 namespace AOSSL {
36 
37 // ----------------------------Health Checks----------------------------------//
38 
40 struct HealthCheck {
42  std::string url;
43 
45  std::string interval;
46 
48  std::string ttl;
49 };
50 
51 // -------------------------------Service-------------------------------------//
52 
54 
58  public:
59  virtual ~ServiceInterface() {}
61 
64  virtual std::string to_json() const = 0;
65 
67  virtual std::string get_id() const = 0;
68 
70  virtual std::string get_name() const = 0;
71 
73  virtual std::string get_address() const = 0;
74 
76  virtual std::string get_port() const = 0;
77 
79  virtual void set_id(std::string new_id) = 0;
80 
82  virtual void set_name(std::string new_name) = 0;
83 
85  virtual void set_address(std::string new_address) = 0;
86 
88  virtual void set_port(std::string new_port) = 0;
89 
91  virtual std::vector<std::string> get_tags() = 0;
93  virtual void add_tag(std::string new_tag) = 0;
95  virtual void clear_tags() = 0;
97  virtual int num_tags() const = 0;
98 
100  virtual HealthCheck get_check() = 0;
102  virtual void set_check(std::string scr, int interval_seconds) = 0;
104  virtual void set_check(std::string scr, int interv_seconds, int interv_ttl) = 0;
105 };
106 
107 // ----------------------------Consul Admin-----------------------------------//
108 
110 
116  public:
118 
122 
126  virtual void base64_decode_by_reference(std::string const& encoded_string, \
127  StringBuffer& ret_buffer) = 0;
129 
133 
136  virtual StringBuffer* \
137  base64_decode_safe(std::string const& encoded_string) = 0;
138 
139  virtual ~ConsulInterface() {}
140 
141  // -----------------Service Registry Functions------------------------------//
142 
144 
147  virtual bool register_service(const ServiceInterface& s) = 0;
148 
150 
153  virtual bool deregister_service(const ServiceInterface& s) = 0;
154 
155  // ------------Configuration Key-Value Storage Functions--------------------//
156 
158 
161 
165  virtual bool set_config_value(std::string key, std::string val) = 0;
166 
168  virtual bool del_config_value(std::string key) = 0;
169 
170  // Basic Queries
171  // All Return a JSON string
172 
173  // Local Agent Queries
174 
176 
178  virtual AOSSL::StringBuffer* services() = 0;
179 
181  virtual AOSSL::StringBuffer* agent_info() = 0;
182 
184  virtual AOSSL::StringBuffer* healthy_services() = 0;
185 
187  virtual AOSSL::StringBuffer* datacenters() = 0;
188 
190 
193  virtual AOSSL::StringBuffer* nodes_dc(std::string data_center) = 0;
194 
196 
199  virtual AOSSL::StringBuffer* services_dc(std::string data_center) = 0;
200 
202 
205  virtual AOSSL::StringBuffer* nodes_service(std::string service) = 0;
206 
208 
212  virtual AOSSL::StringBuffer* \
213  services_node(std::string node, std::string data_center) = 0;
214 
216  virtual void add_acl_token(std::string& token) = 0;
217 };
218 
219 } // namespace AOSSL
220 
221 #endif // AOSSL_CONSUL_INCLUDE_CONSUL_INTERFACE_H_
std::string ttl
The TTL for the health check.
Definition: consul_interface.h:48
A Structure for holding a single value.
Definition: buffers.h:42
std::string interval
The interval for the health check.
Definition: consul_interface.h:45
A struct to hold health check information which can be added to a service.
Definition: consul_interface.h:40
std::string url
The HTTP URL to hit with a GET request for the healthcheck.
Definition: consul_interface.h:42
The Consul Administrator, who handles configuration & service discovery.
Definition: consul_interface.h:115
A Service class which can be registered with Consul for each app instance.
Definition: consul_interface.h:57
Key Value Store.
Definition: kv_store_interface.h:38
Definition: cli.h:35