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