Skip to content

Commit

Permalink
Move cluster endpoint/jsonrpc functionality into libremote.
Browse files Browse the repository at this point in the history
Refs #5690
Refs #5636
  • Loading branch information
Michael Friedrich committed Mar 10, 2014
1 parent bf2428e commit 4c5529f
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 44 deletions.
5 changes: 2 additions & 3 deletions components/cluster/CMakeLists.txt
Expand Up @@ -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
Expand Down
26 changes: 1 addition & 25 deletions components/cluster/cluster-type.conf
Expand Up @@ -35,28 +35,4 @@ type ClusterListener {
%attribute array "peers" {
%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) "*"
}
}
}
2 changes: 1 addition & 1 deletion components/cluster/clusterchecktask.cpp
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion components/cluster/clusterlistener.cpp
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion components/cluster/clusterlistener.h
Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Expand Up @@ -21,3 +21,4 @@ add_subdirectory(icinga)
add_subdirectory(db_ido)
add_subdirectory(methods)
add_subdirectory(hello)
add_subdirectory(remote)
2 changes: 1 addition & 1 deletion lib/db_ido/dbobject.cpp
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/db_ido/endpointdbobject.h
Expand Up @@ -22,7 +22,7 @@

#include "db_ido/dbobject.h"
#include "base/dynamicobject.h"
#include "cluster/endpoint.h"
#include "remote/endpoint.h"

namespace icinga
{
Expand Down
41 changes: 41 additions & 0 deletions 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
)


16 changes: 8 additions & 8 deletions components/cluster/endpoint.cpp → lib/remote/endpoint.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion components/cluster/endpoint.h → lib/remote/endpoint.h
Expand Up @@ -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 <boost/signals2.hpp>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion components/cluster/jsonrpc.cpp → lib/remote/jsonrpc.cpp
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion components/cluster/jsonrpc.h → lib/remote/jsonrpc.h
Expand Up @@ -29,7 +29,7 @@ namespace icinga
/**
* A JSON-RPC connection.
*
* @ingroup cluster
* @ingroup remote
*/
class JsonRpc
{
Expand Down
42 changes: 42 additions & 0 deletions 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) "*"
}
}

0 comments on commit 4c5529f

Please sign in to comment.