Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(group) : adding constructor for host_group and service_group #58

Merged
merged 7 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/com/centreon/broker/neb/host_group.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ namespace neb {
class host_group : public group {
public:
host_group();
host_group(uint32_t poller_id,
uint32_t id,
bool enabled,
std::string const& name);
jbrouze marked this conversation as resolved.
Show resolved Hide resolved
host_group(host_group const& other);
~host_group();
host_group& operator=(host_group const& other);
host_group& operator=(host_group const& other) = delete;
constexpr static uint32_t static_type() {
return io::events::data_type<io::events::neb, neb::de_host_group>::value;
}
Expand Down
6 changes: 5 additions & 1 deletion include/com/centreon/broker/neb/service_group.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ namespace neb {
class service_group : public group {
public:
service_group();
service_group(uint32_t poller_id,
uint32_t id,
bool enabled,
std::string const& name);
jbrouze marked this conversation as resolved.
Show resolved Hide resolved
service_group(service_group const& other);
~service_group();
service_group& operator=(service_group const& other);
service_group& operator=(service_group const&) = delete;
constexpr static uint32_t static_type() {
return io::events::data_type<io::events::neb, neb::de_service_group>::value;
}
Expand Down
23 changes: 12 additions & 11 deletions src/cbmod/callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,11 @@ int neb::callback_group(int callback_type, void* data) {
engine::hostgroup const* host_group(
static_cast<engine::hostgroup*>(group_data->object_ptr));
if (!host_group->get_group_name().empty()) {
std::shared_ptr<neb::host_group> new_hg(new neb::host_group);
new_hg->poller_id = config::applier::state::instance().poller_id();
new_hg->id = host_group->get_id();
new_hg->enabled = (group_data->type != NEBTYPE_HOSTGROUP_DELETE &&
!host_group->members.empty());
new_hg->name = host_group->get_group_name();
std::shared_ptr<neb::host_group> new_hg = std::make_shared<neb::host_group>(
config::applier::state::instance().poller_id(),
host_group->get_id(),
(group_data->type != NEBTYPE_HOSTGROUP_DELETE && !host_group->members.empty()),
host_group->get_group_name());

// Send host group event.
if (new_hg->id) {
Expand All @@ -932,11 +931,13 @@ int neb::callback_group(int callback_type, void* data) {
static_cast<engine::servicegroup*>(group_data->object_ptr));
if (!service_group->get_group_name().empty()) {
std::shared_ptr<neb::service_group> new_sg(new neb::service_group);
new_sg->poller_id = config::applier::state::instance().poller_id();
new_sg->id = service_group->get_id();
new_sg->enabled = (group_data->type != NEBTYPE_SERVICEGROUP_DELETE &&
!service_group->members.empty());
new_sg->name = service_group->get_group_name();
auto s_g = std::make_shared<neb::service_group>(
config::applier::state::instance().poller_id(),
new_sg->id = service_group->get_id(),
new_sg->enabled =
(group_data->type != NEBTYPE_SERVICEGROUP_DELETE &&
!service_group->members.empty()),
new_sg->name = service_group->get_group_name());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem


// Send service group event.
if (new_sg->id) {
Expand Down
14 changes: 9 additions & 5 deletions src/ccb_neb/host_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ using namespace com::centreon::broker::neb;
*/
host_group::host_group() : group(host_group::static_type()) {}

host_group::host_group(uint32_t poller_id,
uint32_t id,
bool enabled,
std::string const& name)
: group(host_group::static_type()) {}

jbrouze marked this conversation as resolved.
Show resolved Hide resolved
/**
* @brief Copy constructor.
*
Expand All @@ -57,10 +63,10 @@ host_group::~host_group() {}
*
* @return This object.
*/
host_group& host_group::operator=(host_group const& other) {
/*host_group& host_group::operator=(host_group const& other) {
group::operator=(other);
return *this;
}
}*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove


/**************************************
* *
Expand All @@ -81,8 +87,6 @@ mapping::entry const host_group::entries[] = {
mapping::entry()};

// Operations.
static io::data* new_host_group() {
return new host_group;
}
static io::data* new_host_group() { return new host_group; }
io::event_info::event_operations const host_group::operations = {
&new_host_group};
14 changes: 7 additions & 7 deletions src/ccb_neb/service_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ using namespace com::centreon::broker::neb;
*/
service_group::service_group() : group(service_group::static_type()) {}

service_group::service_group(uint32_t poller_id,
uint32_t id,
bool enabled,
std::string const& name)
: group(service_group::static_type()) {}

jbrouze marked this conversation as resolved.
Show resolved Hide resolved
/**
* @brief Copy constructor.
*
Expand All @@ -59,10 +65,6 @@ service_group::~service_group() {}
*
* @return This object.
*/
service_group& service_group::operator=(service_group const& other) {
group::operator=(other);
return *this;
}

/**************************************
* *
Expand All @@ -83,8 +85,6 @@ mapping::entry const service_group::entries[] = {
mapping::entry()};

// Operations.
static io::data* new_service_group() {
return new service_group;
}
static io::data* new_service_group() { return new service_group; }
io::event_info::event_operations const service_group::operations = {
&new_service_group};
2 changes: 2 additions & 0 deletions tests/broker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ add_executable(ccb_ut
${CMAKE_SOURCE_DIR}/tests/broker/neb/host.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/host_check.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/host_dependency.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/host_group.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/host_parent.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/host_status.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/instance.cc
Expand All @@ -97,6 +98,7 @@ add_executable(ccb_ut
${CMAKE_SOURCE_DIR}/tests/broker/neb/module.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/randomize.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/service.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/service_group.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/service_check.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/service_dependency.cc
${CMAKE_SOURCE_DIR}/tests/broker/neb/service_status.cc
Expand Down
35 changes: 35 additions & 0 deletions tests/broker/neb/host_group.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/

#include "com/centreon/broker/neb/host_group.hh"
#include <gtest/gtest.h>

using namespace com::centreon::broker;

TEST(HostGroup, Constructor) {
neb::host_group hg(1,
2,
true,
"test host_group");

ASSERT_EQ(hg.poller_id, 1);
ASSERT_EQ(hg.id, 2);
ASSERT_EQ(hg.enabled, true);
ASSERT_EQ(hg.name, "test host_group");
}
35 changes: 35 additions & 0 deletions tests/broker/neb/service_group.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/

#include "com/centreon/broker/neb/service_group.hh"
#include <gtest/gtest.h>

using namespace com::centreon::broker;

TEST(ServiceGroup, Constructor) {
neb::service_group sg(3,
5,
true,
"test service_group");

ASSERT_EQ(sg.poller_id, 3);
ASSERT_EQ(sg.id, 5);
ASSERT_EQ(sg.enabled, true);
ASSERT_EQ(sg.name, "test service_group");
}