Unverified Commit 4c4d5463 authored by CryTime's avatar CryTime Committed by GitHub
Browse files

Merge pull request #11 from centreon/enginemerge

Enginemerge
parents 0d2afb40 c9a24274
......@@ -245,7 +245,14 @@ message EngineHost {
string name = 1;
string alias = 2;
string address = 3;
uint32 id = 4;
string check_period = 4;
uint32 id = 5;
enum State {
UP = 0;
DOWN = 1;
UNREACHABLE = 2;
}
State current_state = 6;
}
message ContactIdentifier {
......@@ -270,8 +277,8 @@ message IdIdentifier {
message ServiceIdentifier {
oneof identifier {
NameIdentifier names = 1;
IdIdentifier ids = 2;
NameIdentifier names = 1;
IdIdentifier ids = 2;
}
}
......@@ -280,4 +287,12 @@ message EngineService {
uint32 service_id = 2;
string host_name = 3;
string description = 4;
string check_period = 5;
enum State {
OK = 0;
WARNING = 1;
CRITICAL = 2;
UNKNOWN = 3;
}
State current_state = 6;
}
......@@ -109,6 +109,9 @@ grpc::Status engine_impl::GetHost(grpc::ServerContext* context,
host->set_name(selectedhost->get_name());
host->set_alias(selectedhost->get_alias());
host->set_address(selectedhost->get_address());
host->set_check_period(selectedhost->get_check_period());
host->set_current_state(
static_cast<EngineHost::State>(selectedhost->get_current_state()));
host->set_id(selectedhost->get_host_id());
return 0;
});
......@@ -186,6 +189,9 @@ grpc::Status engine_impl::GetService(grpc::ServerContext* context,
service->set_service_id(selectedservice->get_service_id());
service->set_host_name(selectedservice->get_hostname());
service->set_description(selectedservice->get_description());
service->set_check_period(selectedservice->get_check_period());
service->set_current_state(
static_cast<EngineService::State>(selectedservice->get_current_state()));
return 0;
});
......
......@@ -369,6 +369,8 @@ int main(int argc, char** argv) {
std::cout << "Host alias: " << response.alias() << std::endl;
std::cout << "Host id: " << response.id() << std::endl;
std::cout << "Host address: " << response.address() << std::endl;
std::cout << "Host state: " << response.current_state() << std::endl;
std::cout << "Host period: " << response.check_period() << std::endl;
} else if (strcmp(argv[2], "byhostname") == 0) {
EngineHost response;
std::string str(argv[3]);
......@@ -378,6 +380,8 @@ int main(int argc, char** argv) {
std::cout << "Host alias: " << response.alias() << std::endl;
std::cout << "Host id: " << response.id() << std::endl;
std::cout << "Host address: " << response.address() << std::endl;
std::cout << "Host state: " << response.current_state() << std::endl;
std::cout << "Host period: " << response.check_period() << std::endl;
}
} else if (strcmp(argv[1], "GetContact") == 0) {
if (argc != 3) {
......@@ -409,6 +413,8 @@ int main(int argc, char** argv) {
std::cout << "Service id: " << response.service_id() << std::endl;
std::cout << "Host name: " << response.host_name() << std::endl;
std::cout << "Serv desc: " << response.description() << std::endl;
std::cout << "Service state: " << response.current_state() << std::endl;
std::cout << "Service period: " << response.check_period() << std::endl;
} else if (strcmp(argv[2], "byids") == 0) {
EngineService response;
uint32_t hostid = atoi(argv[3]);
......@@ -419,6 +425,8 @@ int main(int argc, char** argv) {
std::cout << "Service id: " << response.service_id() << std::endl;
std::cout << "Host name: " << response.host_name() << std::endl;
std::cout << "Serv desc: " << response.description() << std::endl;
std::cout << "Service state: " << response.current_state() << std::endl;
std::cout << "Service period: " << response.check_period() << std::endl;
}
}
exit(status);
......
......@@ -139,6 +139,27 @@ TEST_F(EngineRpc, StartStop) {
ASSERT_NO_THROW(erpc.shutdown());
}
/* calls command manager in an other thread (function is used for units tests)
*/
static void call_command_manager(std::unique_ptr<std::thread>& th,
std::condition_variable* condvar,
std::mutex* mutex,
bool* continuerunning) {
auto fn = [continuerunning, mutex, condvar]() {
std::unique_lock<std::mutex> lock(*mutex);
while (true) {
command_manager::instance().execute();
if (condvar->wait_for(
lock, std::chrono::milliseconds(50),
[continuerunning]() -> bool { return *continuerunning; })) {
break;
}
}
};
th.reset(new std::thread(fn));
}
TEST_F(EngineRpc, GetVersion) {
std::ostringstream oss;
oss << "GetVersion: major: " << CENTREON_ENGINE_VERSION_MAJOR;
......@@ -159,26 +180,21 @@ TEST_F(EngineRpc, GetVersion) {
TEST_F(EngineRpc, GetHost) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
std::vector<std::string> vectests = {"GetHost", "Host name: test_host",
"Host alias: test_host", "Host id: 12",
"Host address: 127.0.0.1"};
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
std::vector<std::string> vectests = {"GetHost",
"Host name: test_host",
"Host alias: test_host",
"Host id: 12",
"Host address: 127.0.0.1",
"Host state: 1",
"Host period: test_period"};
_host->set_current_state(engine::host::state_down);
_host->set_check_period("test_period");
call_command_manager(th, &condvar, &mutex, &continuerunning);
std::thread th(fn);
auto output = execute("GetHost byhostid 12");
auto output2 = execute("GetHost byhostname test_host");
{
......@@ -186,7 +202,7 @@ TEST_F(EngineRpc, GetHost) {
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
std::vector<std::string> result_ids(output.size());
std::copy(output.begin(), output.end(), result_ids.begin());
......@@ -202,63 +218,49 @@ TEST_F(EngineRpc, GetHost) {
TEST_F(EngineRpc, GetContact) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
std::vector<std::string> vectests = {"admin", "admin", "admin@centreon.com"};
std::vector<std::string> vectests = {"GetContact", "admin", "admin",
"admin@centreon.com"};
int j = 0;
_contact->set_email("admin@centreon.com");
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
call_command_manager(th, &condvar, &mutex, &continuerunning);
std::thread th(fn);
auto output = execute("GetContact admin");
{
std::lock_guard<std::mutex> lock(mutex);
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
std::vector<std::string> result_names(output.size());
std::copy(output.begin(), output.end(), result_names.begin());
std::list<std::string>::const_iterator it = output.begin();
++it;
for (; it != output.end() && j < vectests.size(); ++it, ++j)
ASSERT_EQ(it->c_str(), vectests[j]);
ASSERT_EQ(vectests, result_names);
erpc.shutdown();
}
TEST_F(EngineRpc, GetService) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
std::vector<std::string> vectests = {"GetService", "Host id: 12",
"Service id: 13", "Host name: test_host",
"Serv desc: test_svc"};
std::vector<std::string> vectests = {"GetService",
"Host id: 12",
"Service id: 13",
"Host name: test_host",
"Serv desc: test_svc",
"Service state: 2",
"Service period: test_period"};
_svc->set_current_state(engine::service::state_critical);
_svc->set_check_period("test_period");
call_command_manager(th, &condvar, &mutex, &continuerunning);
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
std::thread th(fn);
auto output = execute("GetService bynames test_host test_svc");
auto output2 = execute("GetService byids 12 13");
{
......@@ -266,7 +268,7 @@ TEST_F(EngineRpc, GetService) {
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
std::vector<std::string> result_names(output.size());
std::copy(output.begin(), output.end(), result_names.begin());
......@@ -282,30 +284,20 @@ TEST_F(EngineRpc, GetService) {
TEST_F(EngineRpc, GetHostsCount) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
call_command_manager(th, &condvar, &mutex, &continuerunning);
std::thread th(fn);
auto output = execute("GetHostsCount");
{
std::lock_guard<std::mutex> lock(mutex);
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
ASSERT_EQ(output.back(), "1");
erpc.shutdown();
......@@ -313,30 +305,20 @@ TEST_F(EngineRpc, GetHostsCount) {
TEST_F(EngineRpc, GetContactsCount) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
call_command_manager(th, &condvar, &mutex, &continuerunning);
std::thread th(fn);
auto output = execute("GetContactsCount");
{
std::lock_guard<std::mutex> lock(mutex);
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
ASSERT_EQ(output.back(), "1");
erpc.shutdown();
......@@ -344,30 +326,20 @@ TEST_F(EngineRpc, GetContactsCount) {
TEST_F(EngineRpc, GetServicesCount) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
call_command_manager(th, &condvar, &mutex, &continuerunning);
std::thread th(fn);
auto output = execute("GetServicesCount");
{
std::lock_guard<std::mutex> lock(mutex);
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
ASSERT_EQ(output.back(), "2");
erpc.shutdown();
......@@ -375,30 +347,20 @@ TEST_F(EngineRpc, GetServicesCount) {
TEST_F(EngineRpc, GetServiceGroupsCount) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
call_command_manager(th, &condvar, &mutex, &continuerunning);
std::thread th(fn);
auto output = execute("GetServiceGroupsCount");
{
std::lock_guard<std::mutex> lock(mutex);
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
ASSERT_EQ(output.back(), "0");
erpc.shutdown();
......@@ -406,30 +368,20 @@ TEST_F(EngineRpc, GetServiceGroupsCount) {
TEST_F(EngineRpc, GetContactGroupsCount) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
call_command_manager(th, &condvar, &mutex, &continuerunning);
std::thread th(fn);
auto output = execute("GetContactGroupsCount");
{
std::lock_guard<std::mutex> lock(mutex);
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
ASSERT_EQ(output.back(), "0");
erpc.shutdown();
......@@ -437,30 +389,20 @@ TEST_F(EngineRpc, GetContactGroupsCount) {
TEST_F(EngineRpc, GetHostGroupsCount) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
call_command_manager(th, &condvar, &mutex, &continuerunning);
std::thread th(fn);
auto output = execute("GetHostGroupsCount");
{
std::lock_guard<std::mutex> lock(mutex);
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
ASSERT_EQ(output.back(), "0");
erpc.shutdown();
......@@ -468,30 +410,20 @@ TEST_F(EngineRpc, GetHostGroupsCount) {
TEST_F(EngineRpc, GetServiceDependenciesCount) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
call_command_manager(th, &condvar, &mutex, &continuerunning);
std::thread th(fn);
auto output = execute("GetServiceDependenciesCount");
{
std::lock_guard<std::mutex> lock(mutex);
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
ASSERT_EQ(output.back(), "0");
erpc.shutdown();
......@@ -499,30 +431,20 @@ TEST_F(EngineRpc, GetServiceDependenciesCount) {
TEST_F(EngineRpc, GetHostDependenciesCount) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
bool continuerunning = false;
auto fn = [&continuerunning, &mutex, &condvar]() {
std::unique_lock<std::mutex> lock(mutex);
while (true) {
command_manager::instance().execute();
if (condvar.wait_for(
lock, std::chrono::milliseconds(50),
[&continuerunning]() -> bool { return continuerunning; })) {
break;
}
}
};
call_command_manager(th, &condvar, &mutex, &continuerunning);
std::thread th(fn);
auto output = execute("GetHostDependenciesCount");
{
std::lock_guard<std::mutex> lock(mutex);
continuerunning = true;
}
condvar.notify_one();
th.join();
th->join();
ASSERT_EQ(output.back(), "0");
erpc.shutdown();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment