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