mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Test: Add new testsuite SDK
This commit is contained in:
committed by
Dennis Klein
parent
1a93da5be0
commit
90496c89fe
@@ -6,12 +6,17 @@
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
################
|
||||
# libFairMQSDK #
|
||||
################
|
||||
#################
|
||||
# libFairMQ_SDK #
|
||||
#################
|
||||
configure_file(DDSInfo.h.in ${CMAKE_CURRENT_BINARY_DIR}/DDSInfo.h @ONLY)
|
||||
|
||||
set(target SDK)
|
||||
|
||||
set(SDK_PUBLIC_HEADER_FILES
|
||||
DDSEnvironment.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/DDSInfo.h
|
||||
DDSSession.h
|
||||
Topology.h
|
||||
)
|
||||
|
||||
@@ -19,6 +24,8 @@ set(SDK_PRIVATE_HEADER_FILES
|
||||
)
|
||||
|
||||
set(SDK_SOURCE_FILES
|
||||
DDSEnvironment.cxx
|
||||
DDSSession.cxx
|
||||
Topology.cxx
|
||||
)
|
||||
|
||||
@@ -32,17 +39,21 @@ target_compile_definitions(${target} PUBLIC BOOST_ERROR_CODE_HEADER_ONLY)
|
||||
target_include_directories(${target}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
target_link_libraries(${target}
|
||||
PUBLIC
|
||||
Boost::filesystem
|
||||
FairLogger::FairLogger
|
||||
StateMachine
|
||||
|
||||
PRIVATE
|
||||
Tools
|
||||
Boost::boost
|
||||
DDS::dds_intercom_lib
|
||||
DDS::dds_protocol_lib
|
||||
DDS::dds_tools_lib
|
||||
DDS::dds_topology_lib
|
||||
Tools
|
||||
)
|
||||
set_target_properties(${target} PROPERTIES
|
||||
VERSION ${PROJECT_GIT_VERSION}
|
||||
|
73
fairmq/sdk/DDSEnvironment.cxx
Normal file
73
fairmq/sdk/DDSEnvironment.cxx
Normal file
@@ -0,0 +1,73 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "DDSEnvironment.h"
|
||||
|
||||
#include <DDS/Tools.h>
|
||||
#include <cstdlib>
|
||||
#include <fairmq/Tools.h>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <utility>
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
namespace sdk {
|
||||
|
||||
// TODO https://github.com/FairRootGroup/DDS/issues/224
|
||||
auto LoadDDSEnv(const boost::filesystem::path& config_home, const boost::filesystem::path& prefix)
|
||||
-> void
|
||||
{
|
||||
setenv("DDS_LOCATION", prefix.c_str(), 1);
|
||||
if (!config_home.empty()) {
|
||||
setenv("HOME", config_home.c_str(), 1);
|
||||
}
|
||||
std::string path(std::getenv("PATH"));
|
||||
path = DDSExecutableDir + std::string(":") + path;
|
||||
setenv("PATH", path.c_str(), 1);
|
||||
std::istringstream cmd;
|
||||
cmd.str("DDS_CFG=`dds-user-defaults --ignore-default-sid -p`\n"
|
||||
"if [ -z \"$DDS_CFG\" ]; then\n"
|
||||
" dds-user-defaults --ignore-default-sid -d -c \"$HOME/.DDS/DDS.cfg\"\n"
|
||||
"fi");
|
||||
std::system(cmd.str().c_str());
|
||||
}
|
||||
|
||||
struct DDSEnvironment::Impl
|
||||
{
|
||||
Impl(Path config_home, Path prefix)
|
||||
: fConfigHome(std::move(config_home))
|
||||
, fInstallPrefix(std::move(prefix))
|
||||
{
|
||||
LoadDDSEnv(fConfigHome, fInstallPrefix);
|
||||
if (fConfigHome.empty()) {
|
||||
fConfigHome = std::getenv("HOME");
|
||||
}
|
||||
}
|
||||
|
||||
Path fConfigHome;
|
||||
Path fInstallPrefix;
|
||||
};
|
||||
|
||||
DDSEnvironment::DDSEnvironment(Path config_home, Path prefix)
|
||||
: fImpl(std::make_shared<Impl>(std::move(config_home), std::move(prefix)))
|
||||
{}
|
||||
|
||||
auto DDSEnvironment::GetConfigHome() const -> Path { return fImpl->fConfigHome; }
|
||||
|
||||
auto DDSEnvironment::GetInstallPrefix() const -> Path { return fImpl->fInstallPrefix; }
|
||||
|
||||
auto operator<<(std::ostream& os, DDSEnvironment env) -> std::ostream&
|
||||
{
|
||||
return os << "$DDS_LOCATION: " << env.GetInstallPrefix() << ", "
|
||||
<< "$DDS_CONFIG_HOME: " << env.GetConfigHome() / DDSEnvironment::Path(".DDS");
|
||||
}
|
||||
|
||||
} // namespace sdk
|
||||
} // namespace mq
|
||||
} // namespace fair
|
54
fairmq/sdk/DDSEnvironment.h
Normal file
54
fairmq/sdk/DDSEnvironment.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_SDK_DDSENVIRONMENT_H
|
||||
#define FAIR_MQ_SDK_DDSENVIRONMENT_H
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <fairmq/sdk/DDSInfo.h>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
namespace sdk {
|
||||
|
||||
/**
|
||||
* @brief Sets up the DDS environment
|
||||
* @param config_home Path under which DDS creates a ".DDS" runtime directory for configuration and logs
|
||||
* @param prefix Path where DDS is installed
|
||||
*/
|
||||
auto LoadDDSEnv(const boost::filesystem::path& config_home = "", const boost::filesystem::path& prefix = DDSInstallPrefix)
|
||||
-> void;
|
||||
|
||||
/**
|
||||
* @class DDSEnvironment DDSSession.h <fairmq/sdk/DDSSession.h>
|
||||
* @brief Sets up the DDS environment (object helper)
|
||||
*/
|
||||
class DDSEnvironment
|
||||
{
|
||||
public:
|
||||
using Path = boost::filesystem::path;
|
||||
|
||||
/// @brief See fair::mq::sdk::LoadDDSEnv
|
||||
explicit DDSEnvironment(Path config_home = "", Path prefix = DDSInstallPrefix);
|
||||
|
||||
auto GetConfigHome() const -> Path;
|
||||
auto GetInstallPrefix() const -> Path;
|
||||
|
||||
friend auto operator<<(std::ostream& os, DDSEnvironment env) -> std::ostream&;
|
||||
private:
|
||||
struct Impl;
|
||||
std::shared_ptr<Impl> fImpl;
|
||||
};
|
||||
|
||||
} // namespace sdk
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
|
||||
#endif /* FAIR_MQ_SDK_DDSENVIRONMENT_H */
|
29
fairmq/sdk/DDSInfo.h.in
Normal file
29
fairmq/sdk/DDSInfo.h.in
Normal file
@@ -0,0 +1,29 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_SDK_DDSINFO_H
|
||||
#define FAIR_MQ_SDK_DDSINFO_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
namespace sdk {
|
||||
|
||||
const std::string DDSVersion("@DDS_VERSION@");
|
||||
const std::string DDSInstallPrefix("@DDS_INSTALL_PREFIX@");
|
||||
const std::string DDSExecutableDir("@DDS_BINDIR@");
|
||||
const std::string DDSIncludeDir("@DDS_INCDIR@");
|
||||
const std::string DDSLibraryDir("@DDS_LIBDIR@");
|
||||
const std::string DDSPluginDir("@DDS_PLUGINDIR@");
|
||||
|
||||
} // namespace sdk
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
|
||||
#endif /* FAIR_MQ_SDK_DDSINFO_H */
|
146
fairmq/sdk/DDSSession.cxx
Normal file
146
fairmq/sdk/DDSSession.cxx
Normal file
@@ -0,0 +1,146 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "DDSSession.h"
|
||||
|
||||
#include <DDS/Tools.h>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <fairlogger/Logger.h>
|
||||
#include <fairmq/Tools.h>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <utility>
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
namespace sdk {
|
||||
|
||||
auto operator<<(std::ostream& os, DDSRMSPlugin plugin) -> std::ostream&
|
||||
{
|
||||
switch (plugin) {
|
||||
case DDSRMSPlugin::ssh:
|
||||
return os << "ssh";
|
||||
case DDSRMSPlugin::localhost:
|
||||
return os << "localhost";
|
||||
default:
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
auto operator>>(std::istream& is, DDSRMSPlugin& plugin) -> std::istream&
|
||||
{
|
||||
std::string value;
|
||||
if (is >> value) {
|
||||
if (value == "ssh") {
|
||||
plugin = DDSRMSPlugin::ssh;
|
||||
} else if (value == "localhost") {
|
||||
plugin = DDSRMSPlugin::localhost;
|
||||
} else {
|
||||
throw std::runtime_error("Unknown or unsupported DDSRMSPlugin");
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
struct DDSSession::Impl
|
||||
{
|
||||
Impl(DDSEnvironment env, DDSRMSPlugin plugin)
|
||||
: fEnv(std::move(env))
|
||||
, fDefaultPlugin(std::move(plugin))
|
||||
, fSession()
|
||||
, fId(to_string(fSession.create()))
|
||||
{}
|
||||
|
||||
Impl(DDSEnvironment env, DDSRMSPlugin plugin, Id existing_id)
|
||||
: fEnv(std::move(env))
|
||||
, fDefaultPlugin(std::move(plugin))
|
||||
, fSession()
|
||||
, fId(std::move(existing_id))
|
||||
{
|
||||
fSession.attach(fId);
|
||||
}
|
||||
|
||||
~Impl()
|
||||
{
|
||||
fSession.stop();
|
||||
fSession.shutdown();
|
||||
}
|
||||
|
||||
const DDSEnvironment fEnv;
|
||||
const DDSRMSPlugin fDefaultPlugin;
|
||||
dds::tools_api::CSession fSession;
|
||||
const Id fId;
|
||||
};
|
||||
|
||||
DDSSession::DDSSession(DDSEnvironment env, DDSRMSPlugin default_plugin)
|
||||
: fImpl(std::make_shared<Impl>(std::move(env), std::move(default_plugin))) {}
|
||||
|
||||
DDSSession::DDSSession(DDSEnvironment env, Id existing_id)
|
||||
: fImpl(std::make_shared<Impl>(std::move(env), DDSRMSPlugin::localhost, std::move(existing_id))) {}
|
||||
|
||||
DDSSession::DDSSession(DDSEnvironment env, DDSRMSPlugin default_plugin, Id existing_id)
|
||||
: fImpl(std::make_shared<Impl>(std::move(env), std::move(default_plugin), std::move(existing_id))) {}
|
||||
|
||||
auto DDSSession::IsRunning() const -> bool { return fImpl->fSession.IsRunning(); }
|
||||
|
||||
auto DDSSession::GetId() const -> Id { return fImpl->fId; }
|
||||
|
||||
auto DDSSession::GetDefaultPlugin() const -> DDSRMSPlugin { return fImpl->fDefaultPlugin; }
|
||||
|
||||
auto DDSSession::SubmitAgents(Quantity agents) -> void
|
||||
{
|
||||
SubmitAgents(agents, GetDefaultPlugin(), Path());
|
||||
}
|
||||
|
||||
auto DDSSession::SubmitAgents(Quantity agents, DDSRMSPlugin plugin) -> void
|
||||
{
|
||||
SubmitAgents(agents, plugin, Path());
|
||||
}
|
||||
|
||||
auto DDSSession::SubmitAgents(Quantity agents, const Path& config) -> void
|
||||
{
|
||||
SubmitAgents(agents, GetDefaultPlugin(), std::move(config));
|
||||
}
|
||||
|
||||
auto DDSSession::SubmitAgents(Quantity agents, DDSRMSPlugin plugin, const Path& config) -> void
|
||||
{
|
||||
// Requesting to submit 0 agents is not meaningful
|
||||
assert(agents > 0);
|
||||
// The config argument is required with all plugins except localhost
|
||||
if (plugin != DDSRMSPlugin::localhost) {
|
||||
assert(exists(config));
|
||||
}
|
||||
|
||||
dds::tools_api::SSubmitRequestData submitInfo;
|
||||
submitInfo.m_rms = tools::ToString(plugin);
|
||||
submitInfo.m_instances = agents;
|
||||
submitInfo.m_config = config.string();
|
||||
|
||||
tools::Semaphore blocker;
|
||||
auto submitRequest = dds::tools_api::SSubmitRequest::makeRequest(submitInfo);
|
||||
submitRequest->setMessageCallback(
|
||||
[](const dds::tools_api::SMessageResponseData& message) { LOG(debug) << message; });
|
||||
submitRequest->setDoneCallback([&]() {
|
||||
LOG(debug) << agents << " Agents submitted";
|
||||
blocker.Signal();
|
||||
});
|
||||
|
||||
fImpl->fSession.sendRequest<dds::tools_api::SSubmitRequest>(submitRequest);
|
||||
blocker.Wait();
|
||||
}
|
||||
|
||||
auto operator<<(std::ostream& os, DDSSession session) -> std::ostream&
|
||||
{
|
||||
return os << "$DDS_SESSION_ID: " << session.GetId();
|
||||
}
|
||||
|
||||
} // namespace sdk
|
||||
} // namespace mq
|
||||
} // namespace fair
|
72
fairmq/sdk/DDSSession.h
Normal file
72
fairmq/sdk/DDSSession.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_SDK_DDSSESSION_H
|
||||
#define FAIR_MQ_SDK_DDSSESSION_H
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <cstdint>
|
||||
#include <fairmq/sdk/DDSEnvironment.h>
|
||||
#include <fairmq/sdk/DDSInfo.h>
|
||||
#include <istream>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
namespace sdk {
|
||||
|
||||
/**
|
||||
* @enum DDSRMSPlugin DDSSession.h <fairmq/sdk/DDSSession.h>
|
||||
* @brief Supported DDS resource management system plugins
|
||||
*/
|
||||
enum class DDSRMSPlugin
|
||||
{
|
||||
localhost,
|
||||
ssh
|
||||
};
|
||||
auto operator<<(std::ostream& os, DDSRMSPlugin plugin) -> std::ostream&;
|
||||
auto operator>>(std::istream& is, DDSRMSPlugin& plugin) -> std::istream&;
|
||||
|
||||
/**
|
||||
* @class DDSSession DDSSession.h <fairmq/sdk/DDSSession.h>
|
||||
* @brief Represents a DDS session
|
||||
*/
|
||||
class DDSSession
|
||||
{
|
||||
public:
|
||||
using Id = std::string;
|
||||
using Quantity = std::uint32_t;
|
||||
using Path = boost::filesystem::path;
|
||||
|
||||
DDSSession() = delete;
|
||||
explicit DDSSession(DDSEnvironment env, DDSRMSPlugin default_plugin = DDSRMSPlugin::localhost);
|
||||
explicit DDSSession(DDSEnvironment env, Id existing_id);
|
||||
explicit DDSSession(DDSEnvironment env, DDSRMSPlugin default_plugin, Id existing_id);
|
||||
|
||||
auto GetId() const -> Id;
|
||||
auto GetDefaultPlugin() const -> DDSRMSPlugin;
|
||||
auto IsRunning() const -> bool;
|
||||
auto SubmitAgents(Quantity agents) -> void;
|
||||
auto SubmitAgents(Quantity agents, DDSRMSPlugin plugin) -> void;
|
||||
auto SubmitAgents(Quantity agents, DDSRMSPlugin plugin, const Path& config) -> void;
|
||||
auto SubmitAgents(Quantity agents, const Path& config) -> void;
|
||||
|
||||
friend auto operator<<(std::ostream& os, DDSSession session) -> std::ostream&;
|
||||
private:
|
||||
struct Impl;
|
||||
std::shared_ptr<Impl> fImpl;
|
||||
};
|
||||
|
||||
} // namespace sdk
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
|
||||
#endif /* FAIR_MQ_SDK_DDSSESSION_H */
|
54
fairmq/sdk/DDSTopology.h
Normal file
54
fairmq/sdk/DDSTopology.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_SDK_DDSTOPOLOGY_H
|
||||
#define FAIR_MQ_SDK_DDSTOPOLOGY_H
|
||||
|
||||
#include <fairmq/sdk/DDSInfo.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace dds {
|
||||
namespace topology_api {
|
||||
|
||||
class CTopology;
|
||||
|
||||
} // namespace topology_api
|
||||
} // namespace dds
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
namespace sdk {
|
||||
|
||||
/**
|
||||
* @class DDSTopology DDSTopology.h <fairmq/sdk/DDSTopology.h>
|
||||
* @brief Represents a DDS topology
|
||||
*/
|
||||
class DDSSession
|
||||
{
|
||||
public:
|
||||
using CSessionPtr = std::shared_ptr<dds::tools_api::CSession>;
|
||||
|
||||
explicit DDSSession();
|
||||
explicit DDSSession(std::string existing_session_id);
|
||||
|
||||
auto GetId() const -> const std::string&;
|
||||
auto IsRunning() const -> bool;
|
||||
private:
|
||||
CSessionPtr fSession;
|
||||
const std::string fId;
|
||||
};
|
||||
|
||||
auto LoadDDSEnv(const std::string& config_home = "", const std::string& prefix = DDSInstallPrefix)
|
||||
-> void;
|
||||
|
||||
} // namespace sdk
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
|
||||
#endif /* FAIR_MQ_SDK_DDSTOPOLOGY_H */
|
@@ -0,0 +1,22 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "Topology.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
namespace sdk {
|
||||
|
||||
Topology::Topology()
|
||||
{}
|
||||
|
||||
} // namespace sdk
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
|
@@ -0,0 +1,37 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_SDK_TOPOLOGY_H
|
||||
#define FAIR_MQ_SDK_TOPOLOGY_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
namespace sdk {
|
||||
|
||||
/**
|
||||
* @class Topology Topology.h <fairmq/sdk/Topology.h>
|
||||
* @brief Represents a FairMQ topology
|
||||
*/
|
||||
class Topology
|
||||
{
|
||||
public:
|
||||
|
||||
/// Construct a FairMQ topology from a existing DDS session via the dds::topology_api
|
||||
/// @param topo a shared_ptr to an initialized CTopology object
|
||||
explicit Topology();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace sdk
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
|
||||
#endif /* FAIR_MQ_SDK_TOPOLOGY_H */
|
||||
|
Reference in New Issue
Block a user