From ea973e5c8244e4b80bda880f467403ad88079676 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 7 Mar 2014 17:40:10 +0100 Subject: [PATCH] Move cluster endpoint/jsonrpc functionality into libremote. Refs #5690 Refs #5636 --- components/cluster/CMakeLists.txt | 5 +-- components/cluster/cluster-type.conf | 24 ----------- components/cluster/clusterchecktask.cpp | 2 +- components/cluster/clusterlistener.cpp | 2 +- components/cluster/clusterlistener.h | 2 +- lib/CMakeLists.txt | 1 + lib/db_ido/dbobject.cpp | 2 +- lib/db_ido/endpointdbobject.h | 2 +- lib/remote/CMakeLists.txt | 41 ++++++++++++++++++ .../cluster => lib/remote}/endpoint.cpp | 16 +++---- {components/cluster => lib/remote}/endpoint.h | 2 +- .../cluster => lib/remote}/endpoint.ti | 0 .../cluster => lib/remote}/jsonrpc.cpp | 2 +- {components/cluster => lib/remote}/jsonrpc.h | 2 +- lib/remote/remote-type.conf | 42 +++++++++++++++++++ 15 files changed, 102 insertions(+), 43 deletions(-) create mode 100644 lib/remote/CMakeLists.txt rename {components/cluster => lib/remote}/endpoint.cpp (87%) rename {components/cluster => lib/remote}/endpoint.h (98%) rename {components/cluster => lib/remote}/endpoint.ti (100%) rename {components/cluster => lib/remote}/jsonrpc.cpp (98%) rename {components/cluster => lib/remote}/jsonrpc.h (98%) create mode 100644 lib/remote/remote-type.conf diff --git a/components/cluster/CMakeLists.txt b/components/cluster/CMakeLists.txt index 883d50aac..387873957 100644 --- a/components/cluster/CMakeLists.txt +++ b/components/cluster/CMakeLists.txt @@ -16,16 +16,15 @@ # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. mkclass_target(clusterlistener.ti clusterlistener.th) -mkclass_target(endpoint.ti endpoint.th) mkembedconfig_target(cluster-type.conf cluster-type.cpp) add_library(cluster SHARED clusterchecktask.cpp clusterlistener.cpp clusterlistener.th - endpoint.cpp endpoint.th jsonrpc.cpp cluster-type.cpp + cluster-type.cpp ) -target_link_libraries(cluster ${Boost_LIBRARIES} base config icinga) +target_link_libraries(cluster ${Boost_LIBRARIES} base config icinga remote) set_target_properties ( cluster PROPERTIES diff --git a/components/cluster/cluster-type.conf b/components/cluster/cluster-type.conf index 127927c71..71497cb2c 100644 --- a/components/cluster/cluster-type.conf +++ b/components/cluster/cluster-type.conf @@ -36,27 +36,3 @@ type ClusterListener { %attribute name(Endpoint) "*" } } - -type Endpoint { - %require "host", - %attribute string "host", - - %require "port", - %attribute string "port", - - %attribute array "config_files" { - %attribute string "*" - }, - - %attribute array "config_files_recursive" { - %attribute string "*", - %attribute dictionary "*" { - %attribute string "path", - %attribute string "pattern" - } - }, - - %attribute array "accept_config" { - %attribute name(Endpoint) "*" - } -} diff --git a/components/cluster/clusterchecktask.cpp b/components/cluster/clusterchecktask.cpp index 0404cc00f..2d0dc65bb 100644 --- a/components/cluster/clusterchecktask.cpp +++ b/components/cluster/clusterchecktask.cpp @@ -18,8 +18,8 @@ ******************************************************************************/ #include "cluster/clusterchecktask.h" -#include "cluster/endpoint.h" #include "cluster/clusterlistener.h" +#include "remote/endpoint.h" #include "icinga/cib.h" #include "icinga/service.h" #include "icinga/icingaapplication.h" diff --git a/components/cluster/clusterlistener.cpp b/components/cluster/clusterlistener.cpp index bcb707e3b..f3d771c29 100644 --- a/components/cluster/clusterlistener.cpp +++ b/components/cluster/clusterlistener.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "cluster/clusterlistener.h" -#include "cluster/endpoint.h" +#include "remote/endpoint.h" #include "icinga/cib.h" #include "icinga/domain.h" #include "icinga/icingaapplication.h" diff --git a/components/cluster/clusterlistener.h b/components/cluster/clusterlistener.h index e1d5eb341..1691e7290 100644 --- a/components/cluster/clusterlistener.h +++ b/components/cluster/clusterlistener.h @@ -31,7 +31,7 @@ #include "base/stdiostream.h" #include "base/workqueue.h" #include "icinga/service.h" -#include "cluster/endpoint.h" +#include "remote/endpoint.h" namespace icinga { diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 2945e539a..9a70c2377 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -21,3 +21,4 @@ add_subdirectory(icinga) add_subdirectory(db_ido) add_subdirectory(methods) add_subdirectory(hello) +add_subdirectory(remote) diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp index f20f731a3..ab6280d18 100644 --- a/lib/db_ido/dbobject.cpp +++ b/lib/db_ido/dbobject.cpp @@ -21,7 +21,7 @@ #include "db_ido/dbtype.h" #include "db_ido/dbvalue.h" #include "icinga/service.h" -#include "cluster/endpoint.h" +#include "remote/endpoint.h" #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/utility.h" diff --git a/lib/db_ido/endpointdbobject.h b/lib/db_ido/endpointdbobject.h index a15a820a6..3ada7dd43 100644 --- a/lib/db_ido/endpointdbobject.h +++ b/lib/db_ido/endpointdbobject.h @@ -22,7 +22,7 @@ #include "db_ido/dbobject.h" #include "base/dynamicobject.h" -#include "cluster/endpoint.h" +#include "remote/endpoint.h" namespace icinga { diff --git a/lib/remote/CMakeLists.txt b/lib/remote/CMakeLists.txt new file mode 100644 index 000000000..d681ce925 --- /dev/null +++ b/lib/remote/CMakeLists.txt @@ -0,0 +1,41 @@ +# Icinga 2 +# Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +mkclass_target(endpoint.ti endpoint.th) + +mkembedconfig_target(remote-type.conf remote-type.cpp) + +add_library(remote SHARED + endpoint.cpp endpoint.th jsonrpc.cpp remote-type.cpp +) + +target_link_libraries(remote ${Boost_LIBRARIES} base config) + +set_target_properties ( + icinga PROPERTIES + INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/icinga2 + DEFINE_SYMBOL I2_ICINGA_BUILD + FOLDER Lib +) + +install( + TARGETS remote + RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/icinga2 +) + + diff --git a/components/cluster/endpoint.cpp b/lib/remote/endpoint.cpp similarity index 87% rename from components/cluster/endpoint.cpp rename to lib/remote/endpoint.cpp index ba8bd378c..ca8ee4a8a 100644 --- a/components/cluster/endpoint.cpp +++ b/lib/remote/endpoint.cpp @@ -17,8 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "cluster/endpoint.h" -#include "cluster/jsonrpc.h" +#include "remote/endpoint.h" +#include "remote/jsonrpc.h" #include "base/application.h" #include "base/dynamictype.h" #include "base/objectlock.h" @@ -62,10 +62,10 @@ void Endpoint::SetClient(const Stream::Ptr& client) thread.detach(); OnConnected(GetSelf()); - Log(LogWarning, "cluster", "Endpoint connected: " + GetName()); + Log(LogWarning, "remote", "Endpoint connected: " + GetName()); } else { OnDisconnected(GetSelf()); - Log(LogWarning, "cluster", "Endpoint disconnected: " + GetName()); + Log(LogWarning, "remote", "Endpoint disconnected: " + GetName()); } } @@ -81,12 +81,12 @@ void Endpoint::SendMessage(const Dictionary::Ptr& message) } catch (const std::exception& ex) { std::ostringstream msgbuf; msgbuf << "Error while sending JSON-RPC message for endpoint '" << GetName() << "': " << DiagnosticInformation(ex); - Log(LogWarning, "cluster", msgbuf.str()); + Log(LogWarning, "remote", msgbuf.str()); m_Client.reset(); OnDisconnected(GetSelf()); - Log(LogWarning, "cluster", "Endpoint disconnected: " + GetName()); + Log(LogWarning, "remote", "Endpoint disconnected: " + GetName()); } } @@ -100,12 +100,12 @@ void Endpoint::MessageThreadProc(const Stream::Ptr& stream) try { message = JsonRpc::ReadMessage(stream); } catch (const std::exception& ex) { - Log(LogWarning, "cluster", "Error while reading JSON-RPC message for endpoint '" + GetName() + "': " + DiagnosticInformation(ex)); + Log(LogWarning, "remote", "Error while reading JSON-RPC message for endpoint '" + GetName() + "': " + DiagnosticInformation(ex)); m_Client.reset(); OnDisconnected(GetSelf()); - Log(LogWarning, "cluster", "Endpoint disconnected: " + GetName()); + Log(LogWarning, "remote", "Endpoint disconnected: " + GetName()); return; } diff --git a/components/cluster/endpoint.h b/lib/remote/endpoint.h similarity index 98% rename from components/cluster/endpoint.h rename to lib/remote/endpoint.h index 97f369a5e..2206cb927 100644 --- a/components/cluster/endpoint.h +++ b/lib/remote/endpoint.h @@ -20,7 +20,7 @@ #ifndef ENDPOINT_H #define ENDPOINT_H -#include "cluster/endpoint.th" +#include "remote/endpoint.th" #include "base/stream.h" #include "base/array.h" #include diff --git a/components/cluster/endpoint.ti b/lib/remote/endpoint.ti similarity index 100% rename from components/cluster/endpoint.ti rename to lib/remote/endpoint.ti diff --git a/components/cluster/jsonrpc.cpp b/lib/remote/jsonrpc.cpp similarity index 98% rename from components/cluster/jsonrpc.cpp rename to lib/remote/jsonrpc.cpp index 2eabf2df8..1a3788ea5 100644 --- a/components/cluster/jsonrpc.cpp +++ b/lib/remote/jsonrpc.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "cluster/jsonrpc.h" +#include "remote/jsonrpc.h" #include "base/netstring.h" #include "base/objectlock.h" #include "base/logger_fwd.h" diff --git a/components/cluster/jsonrpc.h b/lib/remote/jsonrpc.h similarity index 98% rename from components/cluster/jsonrpc.h rename to lib/remote/jsonrpc.h index 61bd974b2..6a44e4005 100644 --- a/components/cluster/jsonrpc.h +++ b/lib/remote/jsonrpc.h @@ -29,7 +29,7 @@ namespace icinga /** * A JSON-RPC connection. * - * @ingroup cluster + * @ingroup remote */ class JsonRpc { diff --git a/lib/remote/remote-type.conf b/lib/remote/remote-type.conf new file mode 100644 index 000000000..37530293f --- /dev/null +++ b/lib/remote/remote-type.conf @@ -0,0 +1,42 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +type Endpoint { + %require "host", + %attribute string "host", + + %require "port", + %attribute string "port", + + %attribute array "config_files" { + %attribute string "*" + }, + + %attribute array "config_files_recursive" { + %attribute string "*", + %attribute dictionary "*" { + %attribute string "path", + %attribute string "pattern" + } + }, + + %attribute array "accept_config" { + %attribute name(Endpoint) "*" + } +}