Skip to content

Commit

Permalink
Merge "Options to control database writes from contrail-collector"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Nov 21, 2016
2 parents fc96817 + 59e23f4 commit 4698619
Show file tree
Hide file tree
Showing 20 changed files with 367 additions and 101 deletions.
62 changes: 55 additions & 7 deletions src/analytics/collector.cc
Expand Up @@ -519,10 +519,8 @@ void Collector::GetSmQueueWaterMarkInfo(
GetQueueWaterMarkInfo(QueueType::Sm, wm_info);
}


static void SendQueueParamsError(std::string estr, const std::string &context) {
// SandeshGenerator is required, send error
QueueParamsError *eresp(new QueueParamsError);
static void SendCollectorError(std::string estr, const std::string &context) {
CollectorError *eresp(new CollectorError);
eresp->set_context(context);
eresp->set_error(estr);
eresp->Response();
Expand All @@ -533,7 +531,7 @@ static Collector* ExtractCollectorFromRequest(SandeshContext *vscontext,
VizSandeshContext *vsc =
dynamic_cast<VizSandeshContext *>(vscontext);
if (!vsc) {
SendQueueParamsError("Sandesh client context NOT PRESENT",
SendCollectorError("Sandesh client context NOT PRESENT",
context);
return NULL;
}
Expand Down Expand Up @@ -562,7 +560,7 @@ static void SendQueueParamsResponse(Collector::QueueType::type type,

void DbQueueParamsSet::HandleRequest() const {
if (!(__isset.high && __isset.drop_level && __isset.queue_count)) {
SendQueueParamsError("Please specify all parameters", context());
SendCollectorError("Please specify all parameters", context());
return;
}
Collector *collector = ExtractCollectorFromRequest(client_context(),
Expand All @@ -578,7 +576,7 @@ void DbQueueParamsSet::HandleRequest() const {

void SmQueueParamsSet::HandleRequest() const {
if (!(__isset.high && __isset.drop_level && __isset.queue_count)) {
SendQueueParamsError("Please specify all parameters", context());
SendCollectorError("Please specify all parameters", context());
return;
}
Collector *collector = ExtractCollectorFromRequest(client_context(),
Expand Down Expand Up @@ -664,3 +662,53 @@ void FlowCollectionStatusRequest::HandleRequest() const {
// Send response
SendFlowCollectionStatusResponse(context());
}

static DbHandlerPtr ExtractDbHandlerFromRequest(SandeshContext *vscontext,
const std::string &context) {
VizSandeshContext *vsc =
dynamic_cast<VizSandeshContext *>(vscontext);
if (!vsc) {
SendCollectorError("Sandesh client context NOT PRESENT",
context);
return DbHandlerPtr();
}
return vsc->Analytics()->GetDbHandler();
}

static void SendDatabaseWritesStatusResponse(SandeshContext *vscontext, std::string context) {
DbHandlerPtr dbh(ExtractDbHandlerFromRequest(vscontext, context));
DatabaseWritesStatusResponse *dwsr(new DatabaseWritesStatusResponse);
dwsr->set_disable_all(dbh->IsAllWritesDisabled());
dwsr->set_disable_statistics(dbh->IsStatisticsWritesDisabled());
dwsr->set_disable_messages(dbh->IsMessagesWritesDisabled());
dwsr->set_disable_messages_keyword(dbh->IsMessagesKeywordWritesDisabled());
dwsr->set_disable_flows(Sandesh::IsFlowCollectionDisabled());
dwsr->set_context(context);
dwsr->Response();
}

void DisableDatabaseWritesRequest::HandleRequest() const {
DbHandlerPtr dbh(ExtractDbHandlerFromRequest(client_context(), context()));
if (__isset.disable_all) {
dbh->DisableAllWrites(get_disable_all());
}
if (__isset.disable_statistics) {
dbh->DisableStatisticsWrites(get_disable_statistics());
}
if (__isset.disable_messages) {
dbh->DisableMessagesWrites(get_disable_messages());
}
if (__isset.disable_messages_keyword) {
dbh->DisableMessagesKeywordWrites(get_disable_messages_keyword());
}
if (__isset.disable_flows) {
Sandesh::DisableFlowCollection(get_disable_flows());
}
// Send response
SendDatabaseWritesStatusResponse(client_context(), context());
}

void DatabaseWritesStatusRequest::HandleRequest() const {
// Send response
SendDatabaseWritesStatusResponse(client_context(), context());
}
27 changes: 23 additions & 4 deletions src/analytics/collector_uve.sandesh
Expand Up @@ -319,10 +319,6 @@ struct QueueParams {
3: string drop_level;
}

response sandesh QueueParamsError {
1: string error;
}

/**
* @description: sandesh response to return State Machine Queue params
*/
Expand Down Expand Up @@ -362,3 +358,26 @@ request sandesh FlowCollectionStatusRequest {
response sandesh FlowCollectionStatusResponse {
1: bool disable
}

response sandesh CollectorError {
1: string error
}

request sandesh DisableDatabaseWritesRequest {
1: optional bool disable_all
2: optional bool disable_statistics
3: optional bool disable_messages
4: optional bool disable_flows
5: optional bool disable_messages_keyword
}

request sandesh DatabaseWritesStatusRequest {
}

response sandesh DatabaseWritesStatusResponse {
1: bool disable_all
2: bool disable_statistics
3: bool disable_messages
4: bool disable_flows
5: bool disable_messages_keyword
}

0 comments on commit 4698619

Please sign in to comment.