-
Notifications
You must be signed in to change notification settings - Fork 390
/
config_client_manager.cc
254 lines (214 loc) · 8.97 KB
/
config_client_manager.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
*/
#include "config_client_manager.h"
#include <boost/assign/list_of.hpp>
#include <sandesh/sandesh_types.h>
#include <sandesh/sandesh.h>
#include <sandesh/request_pipeline.h>
#include "base/connection_info.h"
#include "base/task.h"
#include "config_amqp_client.h"
#include "config_db_client.h"
#include "config_cassandra_client.h"
#include "config_json_parser.h"
#include "ifmap/ifmap_config_options.h"
#include "ifmap/ifmap_factory.h"
#include "ifmap/ifmap_log.h"
#include "ifmap/ifmap_log_types.h"
#include "ifmap/ifmap_server.h"
#include "ifmap/ifmap_sandesh_context.h"
#include "ifmap/ifmap_server_show_types.h"
#include "ifmap/ifmap_server_table.h"
#include "io/event_manager.h"
#include "schema/bgp_schema_types.h"
#include "schema/vnc_cfg_types.h"
using namespace boost::assign;
using namespace std;
ConfigClientManager::ConfigClientManager(EventManager *evm,
IFMapServer *ifmap_server, string hostname, string module_name,
const IFMapConfigOptions& config_options)
: evm_(evm), ifmap_server_(ifmap_server) {
config_json_parser_.reset(new ConfigJsonParser(this));
thread_count_ = kNumConfigReaderTasks;
end_of_rib_computed_ = false;
end_of_rib_computed_at_ = UTCTimestampUsec();
config_db_client_.reset(
IFMapFactory::Create<ConfigCassandraClient>(this, evm,
config_options, config_json_parser_.get(), thread_count_));
config_amqp_client_.reset(new ConfigAmqpClient(this, hostname, module_name,
config_options));
vnc_cfg_FilterInfo vnc_filter_info;
bgp_schema_FilterInfo bgp_schema_filter_info;
bgp_schema_Server_GenerateGraphFilter(&bgp_schema_filter_info);
vnc_cfg_Server_GenerateGraphFilter(&vnc_filter_info);
for (vnc_cfg_FilterInfo::iterator it = vnc_filter_info.begin();
it != vnc_filter_info.end(); it++) {
link_name_map_.insert(make_pair(make_pair(it->left_, it->right_),
make_pair(it->metadata_, it->linkattr_)));
}
for (bgp_schema_FilterInfo::iterator it = bgp_schema_filter_info.begin();
it != bgp_schema_filter_info.end(); it++) {
link_name_map_.insert(make_pair(make_pair(it->left_, it->right_),
make_pair(it->metadata_, it->linkattr_)));
}
bgp_schema_Server_GenerateWrapperPropertyInfo(&wrapper_field_map_);
vnc_cfg_Server_GenerateWrapperPropertyInfo(&wrapper_field_map_);
}
void ConfigClientManager::Initialize() {
config_db_client_->InitDatabase();
}
ConfigJsonParser *ConfigClientManager::config_json_parser() const {
return config_json_parser_.get();
}
ConfigDbClient *ConfigClientManager::config_db_client() const {
return config_db_client_.get();
}
ConfigAmqpClient *ConfigClientManager::config_amqp_client() const {
return config_amqp_client_.get();
}
bool ConfigClientManager::GetEndOfRibComputed() const {
tbb::mutex::scoped_lock lock(end_of_rib_sync_mutex_);
return end_of_rib_computed_;
}
void ConfigClientManager::EnqueueUUIDRequest(string oper, string obj_type,
string uuid_str) {
config_db_client_->EnqueueUUIDRequest(oper, obj_type, uuid_str);
}
void ConfigClientManager::InsertRequestIntoQ(IFMapOrigin::Origin origin,
const string &neigh_type, const string &neigh_name,
const string &metaname, auto_ptr<AutogenProperty > pvalue,
const IFMapTable::RequestKey &key, bool add_change,
RequestList *req_list) const {
IFMapServerTable::RequestData *data =
new IFMapServerTable::RequestData(origin, neigh_type, neigh_name);
data->metadata = metaname;
data->content.reset(pvalue.release());
DBRequest *db_request = new DBRequest();
db_request->oper = (add_change ? DBRequest::DB_ENTRY_ADD_CHANGE :
DBRequest::DB_ENTRY_DELETE);
db_request->key.reset(CloneKey(key));
db_request->data.reset(data);
req_list->push_back(db_request);
}
void ConfigClientManager::EnqueueListToTables(RequestList *req_list) const {
while (!req_list->empty()) {
auto_ptr<DBRequest> req(req_list->front());
req_list->pop_front();
IFMapTable::RequestKey *key =
static_cast<IFMapTable::RequestKey *>(req->key.get());
IFMapTable *table = IFMapTable::FindTable(ifmap_server_->database(),
key->id_type);
if (table != NULL) {
table->Enqueue(req.get());
} else {
IFMAP_TRACE(IFMapTblNotFoundTrace, "Cant find table", key->id_type);
}
}
}
IFMapTable::RequestKey *ConfigClientManager::CloneKey(
const IFMapTable::RequestKey &src) const {
IFMapTable::RequestKey *retkey = new IFMapTable::RequestKey();
retkey->id_type = src.id_type;
retkey->id_name = src.id_name;
// TODO
//retkey->id_seq_num = what?
return retkey;
}
string ConfigClientManager::GetLinkName(const string &left,
const string &right) const {
LinkNameMap::const_iterator it =
link_name_map_.find(make_pair(left, right));
if (it == link_name_map_.end())
return "";
return it->second.first;
}
bool ConfigClientManager::IsLinkWithAttr(const string &left,
const string &right) const {
LinkNameMap::const_iterator it =
link_name_map_.find(make_pair(left, right));
if (it == link_name_map_.end())
return false;
return it->second.second;
}
string ConfigClientManager::GetWrapperFieldName(const string &type_name,
const string &property_name) const {
WrapperFieldMap::const_iterator it =
wrapper_field_map_.find(type_name+':'+property_name);
if (it == wrapper_field_map_.end()) {
return "";
} else {
// TODO: Fix the autogen to have _ instead of -
string temp_str = it->second;
std::replace(temp_str.begin(), temp_str.end(), '-', '_');
return temp_str;
}
}
void ConfigClientManager::EndOfConfig() {
{
// Notify waiting caller with the resultcjjjkkkk
tbb::mutex::scoped_lock lock(end_of_rib_sync_mutex_);
assert(!end_of_rib_computed_);
end_of_rib_computed_ = true;
cond_var_.notify_all();
end_of_rib_computed_at_ = UTCTimestampUsec();
}
process::ConnectionState::GetInstance()->Update();
}
void ConfigClientManager::WaitForEndOfConfig() {
tbb::interface5::unique_lock<tbb::mutex> lock(end_of_rib_sync_mutex_);
// Wait for End of config
if (!end_of_rib_computed_)
cond_var_.wait(lock);
}
void ConfigClientManager::GetPeerServerInfo(
IFMapPeerServerInfoUI *server_info) {
ConfigDBConnInfo status;
config_db_client()->GetConnectionInfo(status);
server_info->set_url(status.cluster);
server_info->set_connection_status(
(status.connection_status ? "Up" : "Down"));
server_info->set_connection_status_change_at(
status.connection_status_change_at);
}
void ConfigClientManager::GetClientManagerInfo(
ConfigClientManagerInfo &info) const {
tbb::mutex::scoped_lock lock(end_of_rib_sync_mutex_);
info.end_of_rib_computed = end_of_rib_computed_;
info.end_of_rib_computed_at = end_of_rib_computed_at_;
}
static bool ConfigClientInfoHandleRequest(const Sandesh *sr,
const RequestPipeline::PipeSpec ps,
int stage, int instNum,
RequestPipeline::InstData *data) {
const ConfigClientInfoReq *request =
static_cast<const ConfigClientInfoReq *>(ps.snhRequest_.get());
ConfigClientInfoResp *response = new ConfigClientInfoResp();
IFMapSandeshContext *sctx =
static_cast<IFMapSandeshContext *>(request->module_context("IFMap"));
ConfigClientManager *config_mgr =
sctx->ifmap_server()->get_config_manager();
ConfigAmqpConnInfo amqp_conn_info;
config_mgr->config_amqp_client()->GetConnectionInfo(amqp_conn_info);
ConfigDBConnInfo db_conn_info;
config_mgr->config_db_client()->GetConnectionInfo(db_conn_info);
ConfigClientManagerInfo client_mgr_info;
config_mgr->GetClientManagerInfo(client_mgr_info);
response->set_client_manager_info(client_mgr_info);
response->set_db_conn_info(db_conn_info);
response->set_amqp_conn_info(amqp_conn_info);
response->set_context(request->context());
response->set_more(false);
response->Response();
return true;
}
void ConfigClientInfoReq::HandleRequest() const {
RequestPipeline::StageSpec s0;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s0.taskId_ = scheduler->GetTaskId("config::SandeshCmd");
s0.cbFn_ = ConfigClientInfoHandleRequest;
s0.instances_.push_back(0);
RequestPipeline::PipeSpec ps(this);
ps.stages_= list_of(s0);
RequestPipeline rp(ps);
}