QualityControl  1.5.1
O2 Data Quality Control Framework
ServiceDiscovery.h
1 // Copyright CERN and copyright holders of ALICE O2. This software is
2 // distributed under the terms of the GNU General Public License v3 (GPL
3 // Version 3), copied verbatim in the file "COPYING".
4 //
5 // See http://alice-o2.web.cern.ch/license for full licensing information.
6 //
7 // In applying this license CERN does not waive the privileges and immunities
8 // granted to it by virtue of its status as an Intergovernmental Organization
9 // or submit itself to any jurisdiction.
10 
14 
15 #ifndef QC_SERVICEDISCOVERY_H
16 #define QC_SERVICEDISCOVERY_H
17 
18 #include <atomic>
19 #include <curl/curl.h>
20 #include <memory>
21 #include <string>
22 #include <thread>
23 #include <boost/asio/ip/host_name.hpp>
24 
26 {
27 
33 {
34  public:
41  ServiceDiscovery(const std::string& url, const std::string& name, const std::string& id, const std::string& healthEndpoint = GetDefaultUrl());
42 
45 
48  void _register(const std::string& objects);
49 
51  void deregister();
52 
53  static inline std::string GetDefaultUrl()
54  {
55  return GetDefaultUrl(DefaultHealthPort);
56  }
57 
58  static inline std::string GetDefaultUrl(size_t port)
59  {
60  return boost::asio::ip::host_name() + ":" + std::to_string(port);
61  }
62 
63  static constexpr size_t DefaultHealthPort = 7777;
64 
65  private:
67  static void deleteCurl(CURL* curl);
68 
70  std::unique_ptr<CURL, decltype(&ServiceDiscovery::deleteCurl)> curlHandle;
71 
72  const std::string mConsulUrl;
73  const std::string mName;
74  const std::string mId;
75  std::string mHealthEndpoint;
76  std::thread mHealthThread;
77  std::atomic<bool> mThreadRunning;
78 
80  CURL* initCurl();
81 
83  void send(const std::string& path, std::string&& request);
84 
86  void runHealthServer(unsigned int port);
87 };
88 
89 } // namespace o2::quality_control::core
90 #endif // QC_SERVICEDISCOVERY_H
Information service for QC.
Definition: ServiceDiscovery.h:32
void deregister()
Deregisters service.
Definition: ServiceDiscovery.cxx:97
static std::string GetDefaultUrl(size_t port)
Definition: ServiceDiscovery.h:58
~ServiceDiscovery()
Stops the health thread and deregisteres from Consul health checks.
Definition: ServiceDiscovery.cxx:39
ServiceDiscovery(const std::string &url, const std::string &name, const std::string &id, const std::string &healthEndpoint=GetDefaultUrl())
Definition: ServiceDiscovery.cxx:27
static constexpr size_t DefaultHealthPort
Health check default port.
Definition: ServiceDiscovery.h:63
These methods can be used to build a complex processing topology. It spawns 3 separate dummy processi...
Definition: Activity.h:19
void _register(const std::string &objects)
Definition: ServiceDiscovery.cxx:65