Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
fix(lua): The Lua cache should not be removed anymore
Browse files Browse the repository at this point in the history
* cleanup(lua): unused headers removed, coding style.

REFS: MON-11172
  • Loading branch information
bouda1 committed Oct 11, 2021
1 parent 04e58d3 commit 4a4854d
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 426 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### Fixes

*lua*

The Lua cache should no more disappear.

*tcp*

The flush() method from tcp\_connection could get stuck in cases of retention.
Expand Down
1 change: 1 addition & 0 deletions bam/src/configuration/applier/ba.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ std::shared_ptr<neb::service> applier::ba::_ba_service(
s->host_id = host_id;
s->service_id = service_id;
s->service_description = fmt::format("ba_{}", ba_id);
s->display_name = s->service_description;
s->last_update = time(nullptr);
return s;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/config/applier/endpoint.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Copyright 2011-2012,2015,2017 Centreon
** Copyright 2011-2012,2015,2017-2021 Centreon
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
Expand Down
1 change: 0 additions & 1 deletion lua/src/connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "com/centreon/broker/lua/connector.hh"
#include <fstream>
#include <sstream>
#include "com/centreon/broker/exceptions/msg.hh"
#include "com/centreon/broker/lua/stream.hh"

Expand Down
39 changes: 9 additions & 30 deletions lua/src/macro_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,34 +442,7 @@ void macro_cache::write(std::shared_ptr<io::data> const& data) {
void macro_cache::_process_instance(std::shared_ptr<io::data> const& data) {
std::shared_ptr<neb::instance> const& in =
std::static_pointer_cast<neb::instance>(data);
uint32_t poller_id = in->poller_id;

std::unordered_set<uint64_t> hosts_removed;
for (auto it = _hosts.begin(), end = _hosts.end(); it != end;) {
if (it->second->poller_id == poller_id) {
hosts_removed.insert(it->second->host_id);
it = _hosts.erase(it);
} else
++it;
}

for (uint64_t id : hosts_removed) {
auto it(_host_group_members.lower_bound({id, 0}));
while (it != _host_group_members.end() && it->first.first == id) {
it = _host_group_members.erase(it);
}
}

std::unordered_set<std::pair<uint64_t, uint64_t> > services_removed;
for (auto it(_services.begin()), end(_services.end()); it != end;) {
if (hosts_removed.count(it->second->host_id)) {
services_removed.insert(it->first);
it = _services.erase(it);
} else
++it;
}

_instances[poller_id] = in;
_instances[in->poller_id] = in;
}

/**
Expand All @@ -482,7 +455,10 @@ void macro_cache::_process_host(std::shared_ptr<io::data> const& data) {
std::static_pointer_cast<neb::host>(data);
logging::debug(logging::medium)
<< "lua: processing host '" << h->host_name << "' of id " << h->host_id;
_hosts[h->host_id] = h;
if (h->enabled)
_hosts[h->host_id] = h;
else
_hosts.erase(h->host_id);
}

/**
Expand Down Expand Up @@ -529,7 +505,10 @@ void macro_cache::_process_service(std::shared_ptr<io::data> const& data) {
<< "lua: processing service (" << s->host_id << ", " << s->service_id
<< ") "
<< "(description: " << s->service_description << ")";
_services[{s->host_id, s->service_id}] = s;
if (s->enabled)
_services[{s->host_id, s->service_id}] = s;
else
_services.erase({s->host_id, s->service_id});
}

/**
Expand Down
79 changes: 0 additions & 79 deletions lua/test/lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1002,85 +1002,6 @@ TEST_F(LuaTest, ServiceGroupCacheTest) {
RemoveFile("/tmp/log");
}

// When a query for service groups is made
// And the cache does know about them
// Then an array is returned by the lua method.
TEST_F(LuaTest, SetNewInstance) {
std::map<std::string, misc::variant> conf;
std::string filename("/tmp/cache_test.lua");
std::shared_ptr<neb::service_group> sg(new neb::service_group);
sg->id = 16;
sg->name = "centreon1";
_cache->write(sg);
sg.reset(new neb::service_group);
sg->id = 17;
sg->name = "centreon2";
_cache->write(sg);
std::shared_ptr<neb::host> hst(new neb::host);
hst->host_id = 22;
hst->host_name = "host_centreon";
hst->poller_id = 3;
_cache->write(hst);
std::shared_ptr<neb::host_group> hg(new neb::host_group);
hg->id = 19;
hg->name = "hg1";
_cache->write(hg);
std::shared_ptr<neb::service> svc(new neb::service);
svc->service_id = 17;
svc->host_id = 22;
svc->host_name = "host_centreon";
svc->service_description = "service_description";
_cache->write(svc);
std::shared_ptr<neb::host_group_member> hmember(new neb::host_group_member);
hmember->host_id = 22;
hmember->poller_id = 3;
hmember->enabled = true;
hmember->group_id = 19;
hmember->group_name = "hg1";
_cache->write(hmember);
std::shared_ptr<neb::service_group_member> member(
new neb::service_group_member);
member->host_id = 22;
member->service_id = 17;
member->poller_id = 3;
member->enabled = false;
member->group_id = 16;
member->group_name = "seize";
_cache->write(member);
member.reset(new neb::service_group_member);
member->host_id = 22;
member->service_id = 17;
member->poller_id = 3;
member->enabled = true;
member->group_id = 17;
member->group_name = "dix-sept";
_cache->write(member);

std::shared_ptr<neb::instance> ib(new neb::instance);
ib->broker_id = 42;
ib->engine = "engine name";
ib->is_running = true;
ib->poller_id = 3;
ib->name = "MyPoller";
_cache->write(ib);

CreateScript(filename,
"function init(conf)\n"
" broker_log:set_parameters(3, '/tmp/log')\n"
" local s = broker_cache:get_service_description(22, 17)\n"
" broker_log:info(1, 'service description ' .. tostring(s))\n"
"end\n\n"
"function write(d)\n"
"end\n");
std::unique_ptr<luabinding> binding(new luabinding(filename, conf, *_cache));
std::string lst(ReadFile("/tmp/log"));

ASSERT_NE(std::string::npos, lst.find("service description nil"));

RemoveFile(filename);
RemoveFile("/tmp/log");
}

// When a query for bvs containing a ba is made
// And the cache does know about them
// Then an array with bvs id is returned by the lua method.
Expand Down
2 changes: 0 additions & 2 deletions neb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ add_library("${NEB}" SHARED
# Main source.
"${SRC_DIR}/broker.cc"
"${SRC_DIR}/downtime_scheduler.cc"
"${SRC_DIR}/node_cache.cc"
"${SRC_DIR}/node_id.cc"
"${SRC_DIR}/timeperiod_serializable.cc"
"${SRC_DIR}/downtime_serializable.cc"
"${SRC_DIR}/downtime_map.cc"

# Inc
"${INC_DIR}/com/centreon/broker/neb/downtime_scheduler.hh"
"${INC_DIR}/com/centreon/broker/neb/node_cache.hh"
"${INC_DIR}/com/centreon/broker/neb/node_id.hh"
"${INC_DIR}/com/centreon/broker/neb/timeperiod_serializable.hh"
"${INC_DIR}/com/centreon/broker/neb/downtime_serializable.hh"
Expand Down
75 changes: 0 additions & 75 deletions neb/inc/com/centreon/broker/neb/node_cache.hh

This file was deleted.

Loading

0 comments on commit 4a4854d

Please sign in to comment.