diff --git a/src/analytics/db_handler.cc b/src/analytics/db_handler.cc index cb913c129e8..32596556363 100644 --- a/src/analytics/db_handler.cc +++ b/src/analytics/db_handler.cc @@ -561,7 +561,12 @@ void DbHandler::MessageTableOnlyInsert(const VizMsg *vmsgp) { uint32_t temp_u32; std::string temp_str; - int ttl = GetTtl(TtlType::GLOBAL_TTL); + int ttl; + if (message_type == "VncApiConfigLog") { + ttl = GetTtl(TtlType::CONFIGAUDIT_TTL); + } else { + ttl = GetTtl(TtlType::GLOBAL_TTL); + } std::auto_ptr col_list(new GenDb::ColList); col_list->cfname_ = g_viz_constants.COLLECTOR_GLOBAL_TABLE; // Rowkey diff --git a/src/analytics/test/db_handler_test.cc b/src/analytics/test/db_handler_test.cc index d1041954560..62f5a2a40ec 100644 --- a/src/analytics/test/db_handler_test.cc +++ b/src/analytics/test/db_handler_test.cc @@ -155,13 +155,71 @@ TEST_F(DbHandlerTest, MessageTableOnlyInsertTest) { xmlmessage.size())); msg->SetHeader(hdr); boost::uuids::uuid unm(rgen_()); - VizMsg vmsgp(msg, unm); + VizMsg vmsgp(msg, unm); GenDb::DbDataValueVec rowkey; rowkey.push_back(unm); - int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second; - boost::ptr_vector msg_table_expected_vector = + int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600; + boost::ptr_vector msg_table_expected_vector = + boost::assign::ptr_list_of + (GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), ttl)) + (GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), ttl)) + (GenDb::NewCol(g_viz_constants.MODULE, hdr.get_Module(), ttl)) + (GenDb::NewCol(g_viz_constants.INSTANCE_ID, hdr.get_InstanceId(), ttl)) + (GenDb::NewCol(g_viz_constants.NODE_TYPE, hdr.get_NodeType(), ttl)) + (GenDb::NewCol(g_viz_constants.TIMESTAMP, + static_cast(hdr.get_Timestamp()), ttl)) + (GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), ttl)) + (GenDb::NewCol(g_viz_constants.LEVEL, + static_cast(0), ttl)) + (GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, ttl)) + (GenDb::NewCol(g_viz_constants.SEQUENCE_NUM, + static_cast(0), ttl)) + (GenDb::NewCol(g_viz_constants.VERSION, + static_cast(0), ttl)) + (GenDb::NewCol(g_viz_constants.SANDESH_TYPE, + static_cast(0), ttl)) + (GenDb::NewCol(g_viz_constants.DATA, xmlmessage, ttl)); + + EXPECT_CALL(*dbif_mock(), + Db_AddColumnProxy( + Pointee( + AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.COLLECTOR_GLOBAL_TABLE), + Field(&GenDb::ColList::rowkey_, rowkey), + Field(&GenDb::ColList::columns_, msg_table_expected_vector))))) + .Times(1) + .WillOnce(Return(true)); + + db_handler()->MessageTableOnlyInsert(&vmsgp); + vmsgp.msg = NULL; + delete msg; +} + +TEST_F(DbHandlerTest, MessageTableOnlyInsertConfigAuditTest) { + SandeshHeader hdr; + + hdr.set_Source("127.0.0.1"); + hdr.set_Module("VizdTest"); + hdr.set_InstanceId("Test"); + hdr.set_NodeType("Test"); + hdr.set_Timestamp(UTCTimestampUsec()); + std::string messagetype("VncApiConfigLog"); + std::string xmlmessage = "src/analytics/test/viz_collector_test.cc80sat2string101101101"; + + SandeshXMLMessageTest *msg = dynamic_cast( + builder_->Create( + reinterpret_cast(xmlmessage.c_str()), + xmlmessage.size())); + msg->SetHeader(hdr); + boost::uuids::uuid unm(rgen_()); + VizMsg vmsgp(msg, unm); + + GenDb::DbDataValueVec rowkey; + rowkey.push_back(unm); + + int ttl = ttl_map.find(TtlType::CONFIGAUDIT_TTL)->second*3600; + boost::ptr_vector msg_table_expected_vector = boost::assign::ptr_list_of (GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), ttl)) (GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), ttl)) @@ -203,7 +261,7 @@ TEST_F(DbHandlerTest, MessageIndexTableInsertTest) { hdr.set_Timestamp(UTCTimestampUsec()); boost::uuids::uuid unm(rgen_()); - int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second; + int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600; #ifdef USE_CASSANDRA_CQL DbDataValueVec *colname(new DbDataValueVec()); @@ -420,26 +478,27 @@ TEST_F(DbHandlerTest, MessageTableInsertTest) { GenDb::DbDataValueVec rowkey; rowkey.push_back(unm); + int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600; boost::ptr_vector msg_table_expected_vector = boost::assign::ptr_list_of - (GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), 0)) - (GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), 0)) - (GenDb::NewCol(g_viz_constants.MODULE, hdr.get_Module(), 0)) - (GenDb::NewCol(g_viz_constants.INSTANCE_ID, hdr.get_InstanceId(), 0)) - (GenDb::NewCol(g_viz_constants.NODE_TYPE, hdr.get_NodeType(), 0)) + (GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), ttl)) + (GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), ttl)) + (GenDb::NewCol(g_viz_constants.MODULE, hdr.get_Module(), ttl)) + (GenDb::NewCol(g_viz_constants.INSTANCE_ID, hdr.get_InstanceId(), ttl)) + (GenDb::NewCol(g_viz_constants.NODE_TYPE, hdr.get_NodeType(), ttl)) (GenDb::NewCol(g_viz_constants.TIMESTAMP, - static_cast(hdr.get_Timestamp()), 0)) - (GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), 0)) + static_cast(hdr.get_Timestamp()), ttl)) + (GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), ttl)) (GenDb::NewCol(g_viz_constants.LEVEL, - static_cast(0), 0)) - (GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, 0)) + static_cast(0), ttl)) + (GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, ttl)) (GenDb::NewCol(g_viz_constants.SEQUENCE_NUM, - static_cast(0), 0)) + static_cast(0), ttl)) (GenDb::NewCol(g_viz_constants.VERSION, - static_cast(0), 0)) + static_cast(0), ttl)) (GenDb::NewCol(g_viz_constants.SANDESH_TYPE, - static_cast(SandeshType::SYSTEM), 0)) - (GenDb::NewCol(g_viz_constants.DATA, xmlmessage, 0)); + static_cast(SandeshType::SYSTEM), ttl)) + (GenDb::NewCol(g_viz_constants.DATA, xmlmessage, ttl)); EXPECT_CALL(*dbif_mock(), Db_AddColumnProxy( @@ -452,7 +511,6 @@ TEST_F(DbHandlerTest, MessageTableInsertTest) { .Times(1) .WillOnce(Return(true)); - int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second; DbDataValueVec *colname(new DbDataValueVec()); colname->reserve(3); colname->push_back(hdr.get_Source()); @@ -606,6 +664,7 @@ TEST_F(DbHandlerTest, ObjectTableInsertTest) { msg->SetHeader(hdr); VizMsg vmsgp(msg, unm); + int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600; { DbDataValueVec *colname(new DbDataValueVec()); colname->reserve(2); @@ -615,7 +674,7 @@ TEST_F(DbHandlerTest, ObjectTableInsertTest) { DbDataValueVec *colvalue(new DbDataValueVec(1, unm)); boost::ptr_vector expected_vector = boost::assign::ptr_list_of - (GenDb::NewCol(colname, colvalue, 0)); + (GenDb::NewCol(colname, colvalue, ttl)); GenDb::DbDataValueVec rowkey; rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits)); @@ -639,7 +698,7 @@ TEST_F(DbHandlerTest, ObjectTableInsertTest) { "ObjectTableInsertTestRowkey")); boost::ptr_vector expected_vector = boost::assign::ptr_list_of - (GenDb::NewCol(colname, colvalue, 0)); + (GenDb::NewCol(colname, colvalue, ttl)); GenDb::DbDataValueVec rowkey; rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits)); @@ -878,7 +937,7 @@ TEST_F(DbHandlerTest, FlowTableInsertTest) { .WillOnce(Return(true)); } - int ttl = ttl_map.find(TtlType::FLOWDATA_TTL)->second; + int ttl = ttl_map.find(TtlType::FLOWDATA_TTL)->second*3600; GenDb::DbDataValueVec ocolvalue; #ifdef USE_CASSANDRA_CQL std::ostringstream cv_ss; diff --git a/src/database/gendb_if.h b/src/database/gendb_if.h index f89865542cd..34eee58d8cf 100644 --- a/src/database/gendb_if.h +++ b/src/database/gendb_if.h @@ -134,7 +134,8 @@ struct NewCol { bool operator==(const NewCol &rhs) const { return (*rhs.name == *name && - *rhs.value == *value); + *rhs.value == *value && + rhs.ttl == ttl); } size_t GetSize() const;