OpenSDN source code
config_client_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef config_client_manager_h
7 #define config_client_manager_h
8 
9 #include <atomic>
10 #include <set>
11 #include <map>
12 #include <mutex>
13 #include <condition_variable>
14 
15 #include <boost/function.hpp>
16 #include <boost/scoped_ptr.hpp>
17 #include <boost/shared_ptr.hpp>
18 
19 #include "config_client_options.h"
20 #include "config_factory.h"
21 #include <rapidjson/document.h>
22 
23 struct AutogenProperty;
24 class ConfigAmqpClient;
25 class ConfigDbClient;
26 struct DBRequest;
27 class EventManager;
28 class TaskTrigger;
31 struct ConfigClientManagerInfo;
32 
33 /*
34  * This class is the manager that over-sees the retrieval of user configuration.
35  * It interacts with the rabbit-mq client, the database-client and the parser
36  * that parses the configuration received from the database-client. Its the
37  * coordinator between these 3 pieces.
38  */
40 public:
41  static const int kNumConfigReaderTasks = 8;
42  static const std::set<std::string> skip_properties;
43 
44  typedef std::set<std::string> ObjectTypeList;
45 
47  ConfigJsonParserBase *cfg_json_base,
48  std::string hostname,
49  std::string module_name,
50  const ConfigClientOptions& config_options);
51 
53 
54  void Initialize();
57  void EnqueueUUIDRequest(std::string oper, std::string obj_type,
58  std::string uuid_str);
59 
63 
64  static int GetNumConfigReader();
65 
66  static int GetNumWorkers() {
67  // AMQP reader and ConfigDB readers
68  return GetNumConfigReader() + 1;
69  }
70 
71  void EndOfConfig();
72  void WaitForEndOfConfig();
73  void GetClientManagerInfo(ConfigClientManagerInfo &info) const;
74 
75  // Generation number identifies the current version of the config
76  // available with ifmap server. While enqueuing the DB request to create
77  // ifmap entries(node/link), config client manager uses the current
78  // generation number to tag the config version in each ifmap config db entru
79  uint64_t GetGenerationNumber() const {
80  return generation_number_;
81  }
82 
83  // Increment the generation number on reinit trigger
84  // IFMap server identifies stale config db entries based on this generation
85  // number. Any entry(node/link) which has generation number less than the
86  // current generation number will be cleaned with "stale entry cleanup"
87  // background task
89  return generation_number_++;
90  }
91 
92  // Reinit trigger with update of config parameter
93  void ReinitConfigClient(const ConfigClientOptions &config);
94 
95  // Reinit trigger without update of config parameter.
96  // Either from introspect or to force re-reading of cassandra
97  void ReinitConfigClient();
98 
99  // This task trigger handles with init and reinit of config client manager
100  bool InitConfigClient();
101 
103  return reinit_triggered_;
104  }
105  static bool end_of_rib_computed() { return end_of_rib_computed_; }
108  }
109 
110  bool GetEndOfRibComputed() const;
111  uint64_t GetEndOfRibComputedAt() const;
112  void PostShutdown();
113 
114 private:
115  typedef std::pair<std::string, std::string> LinkMemberPair;
116  typedef std::pair<std::string, bool> LinkDataPair;
117  typedef std::map<LinkMemberPair, std::string> ParentNameMap;
118  typedef std::map<LinkMemberPair, LinkDataPair> LinkNameMap;
119  typedef std::map<std::string, std::string> WrapperFieldMap;
120 
123 
127  boost::scoped_ptr<ConfigJsonParserBase> config_json_parser_;
128  boost::scoped_ptr<ConfigDbClient> config_db_client_;
129  boost::scoped_ptr<ConfigAmqpClient> config_amqp_client_;
132 
133  mutable std::mutex end_of_rib_sync_mutex_;
134  std::condition_variable cond_var_;
136  std::string hostname_;
137  std::string module_name_;
139  std::atomic<bool> reinit_triggered_;
140  boost::scoped_ptr<TaskTrigger> init_trigger_;
141  static bool end_of_rib_computed_;
142 };
143 
144 #endif // config_client_manager_h
std::map< std::string, std::string > WrapperFieldMap
std::pair< std::string, bool > LinkDataPair
void EnqueueUUIDRequest(std::string oper, std::string obj_type, std::string uuid_str)
static const std::set< std::string > skip_properties
std::map< LinkMemberPair, std::string > ParentNameMap
static void set_end_of_rib_computed(bool end_of_rib_computed)
boost::scoped_ptr< ConfigJsonParserBase > config_json_parser_
ConfigDbClient * config_db_client() const
ConfigClientOptions config_options_
ConfigDbClient * config_db_client()
static const int kNumConfigReaderTasks
boost::scoped_ptr< TaskTrigger > init_trigger_
uint64_t GetGenerationNumber() const
boost::scoped_ptr< ConfigAmqpClient > config_amqp_client_
uint64_t GetEndOfRibComputedAt() const
ConfigJsonParserBase * config_json_parser()
std::pair< std::string, std::string > LinkMemberPair
ConfigAmqpClient * config_amqp_client()
uint64_t IncrementGenerationNumber()
static bool end_of_rib_computed()
ConfigAmqpClient * config_amqp_client() const
void GetClientManagerInfo(ConfigClientManagerInfo &info) const
ConfigClientManager(EventManager *evm, ConfigJsonParserBase *cfg_json_base, std::string hostname, std::string module_name, const ConfigClientOptions &config_options)
std::map< LinkMemberPair, LinkDataPair > LinkNameMap
boost::scoped_ptr< ConfigDbClient > config_db_client_
void SetUp(ConfigJsonParserBase *)
std::set< std::string > ObjectTypeList
std::atomic< bool > reinit_triggered_
std::condition_variable cond_var_
static EventManager evm