Commit 7ba73f0f authored by Julian Bigge's avatar Julian Bigge

Merge branch 'develop' into 'master'

Version 0.4.3

See merge request !13
parents 1d16f424 e173b2c9
Pipeline #52893 passed with stage
in 2 minutes and 36 seconds
......@@ -5,7 +5,7 @@ image: centos:7.6.1810
.setup_centos: &setup
before_script:
- yum -y install epel-release # for newer cmake
- yum -y install gcc-c++ cmake3 make mariadb-devel boost-devel boost-program-options libcurl-devel rpm-build rpmdevtools
- yum -y install gcc-c++ cmake3 make mariadb-devel boost-devel boost-static boost-program-options libcurl-devel rpm-build rpmbuildtools
variables:
GIT_SUBMODULE_STRATEGY: recursive
......
......@@ -3,19 +3,18 @@ cmake_minimum_required (VERSION 2.7)
project (sccuot)
set (sccuot_LIB_VERSION_MAJOR 0)
set (sccuot_LIB_VERSION_MINOR 3)
set (sccuot_LIB_VERSION_PATCH 4)
set (sccuot_LIB_VERSION_MINOR 4)
set (sccuot_LIB_VERSION_PATCH 3)
set (sccuot_VERSION_MAJOR 0)
set (sccuot_VERSION_MINOR 3)
set (sccuot_VERSION_PATCH 4)
set (sccuot_VERSION_MINOR 4)
set (sccuot_VERSION_PATCH 3)
set (sccuotd_VERSION_MAJOR 0)
set (sccuotd_VERSION_MINOR 3)
set (sccuotd_VERSION_PATCH 4)
set (sccuotd_VERSION_MINOR 4)
set (sccuotd_VERSION_PATCH 3)
include(GNUInstallDirs)
find_package (Boost COMPONENTS program_options system REQUIRED)
find_package (Threads)
execute_process (COMMAND mysql_config --libs
......@@ -50,11 +49,18 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -std=c++11")
option (USE_OLD_CXX_ABI "Use the old C++ ABI pre C++11" OFF)
option (STATIC_LIB "Build libsccuot as static library and links sccuot binary statically" OFF)
option (DAEMON "Build libsccuot daemon and protocol library" OFF)
if (USE_OLD_CXX_ABI)
add_definitions (-D_GLIBCXX_USE_CXX11_ABI=0)
endif (USE_OLD_CXX_ABI)
if (STATIC_LIB)
set(Boost_USE_STATIC_LIBS ON)
endif()
find_package (Boost COMPONENTS program_options REQUIRED)
configure_file (
"${PROJECT_SOURCE_DIR}/include/libsccuot/version.hpp.in"
"${PROJECT_SOURCE_DIR}/include/libsccuot/version.hpp"
......@@ -77,52 +83,61 @@ include_directories (${sqlpp11_SOURCE_DIR}/include)
include_directories (${PROJECT_SOURCE_DIR}/ext/sqlpp11-connector-mysql/include)
include (${PROJECT_SOURCE_DIR}/src/libsccuot/targets.cmake)
include (${PROJECT_SOURCE_DIR}/src/libsccuot_proto/targets.cmake)
if (DAEMON)
find_package (Boost COMPONENTS system REQUIRED)
include (${PROJECT_SOURCE_DIR}/src/libsccuot_proto/targets.cmake)
include (${PROJECT_SOURCE_DIR}/src/sccuotd/targets.cmake)
add_executable (sccuotd
${SCCUOTD_MAIN_SOURCES})
endif()
include (${PROJECT_SOURCE_DIR}/src/sccuot/targets.cmake)
include (${PROJECT_SOURCE_DIR}/src/sccuotd/targets.cmake)
add_executable ( sccuot_client
${SCCUOT_MAIN_SOURCES}
)
add_executable (sccuotd
${SCCUOTD_MAIN_SOURCES})
set_target_properties (sccuot_client PROPERTIES OUTPUT_NAME sccuot)
if (STATIC_LIB)
add_library (sccuot_static STATIC ${LIBSCCUOT_SOURCES})
add_library (sccuot_proto_static STATIC ${LIBSCCUOT_PROTO_SOURCES})
# Static lib
target_link_libraries (sccuot_static PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries (sccuot_proto_static PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries (sccuot_proto_static PUBLIC sccuot_static)
# Client
target_link_libraries (sccuot_client PUBLIC sccuot_static)
target_link_libraries (sccuot_client PRIVATE nlohmann_json::nlohmann_json)
# Daemon
target_link_libraries (sccuotd PUBLIC sccuot_static)
target_link_libraries (sccuotd PUBLIC sccuot_proto_static ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (sccuotd PRIVATE nlohmann_json::nlohmann_json)
install (TARGETS sccuot_static ARCHIVE DESTINATION lib)
if (DAEMON)
add_library (sccuot_proto_static STATIC ${LIBSCCUOT_PROTO_SOURCES})
target_link_libraries (sccuot_proto_static PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries (sccuot_proto_static PUBLIC sccuot_static)
target_link_libraries (sccuotd PUBLIC sccuot_static)
target_link_libraries (sccuotd PUBLIC sccuot_proto_static ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (sccuotd PRIVATE nlohmann_json::nlohmann_json)
endif()
install (TARGETS sccuot_static ARCHIVE DESTINATION lib)
else ()
add_library (sccuot SHARED ${LIBSCCUOT_SOURCES})
add_library (sccuot_proto SHARED ${LIBSCCUOT_PROTO_SOURCES})
# Dynamic lib
target_link_libraries (sccuot PUBLIC ${Boost_LIBRARIES})
target_link_libraries (sccuot PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries (sccuot_proto PUBLIC ${Boost_LIBRARIES})
target_link_libraries (sccuot_proto PRIVATE nlohmann_json::nlohmann_json)
# Client
target_link_libraries (sccuot_client PUBLIC sccuot)
target_link_libraries (sccuot_client PUBLIC sccuot_proto)
target_link_libraries (sccuot_client PRIVATE nlohmann_json::nlohmann_json)
install (TARGETS sccuot LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Daemon
target_link_libraries (sccuotd PUBLIC sccuot ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (sccuotd PUBLIC sccuot_proto)
target_link_libraries (sccuotd PRIVATE nlohmann_json::nlohmann_json)
install (TARGETS sccuot LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (TARGETS sccuot_proto LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (DAEMON)
add_library (sccuot_proto SHARED ${LIBSCCUOT_PROTO_SOURCES})
target_link_libraries (sccuot_client PUBLIC sccuot_proto)
target_link_libraries (sccuot_proto PUBLIC ${Boost_LIBRARIES})
target_link_libraries (sccuot_proto PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries (sccuotd PUBLIC sccuot ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (sccuotd PUBLIC sccuot_proto)
target_link_libraries (sccuotd PRIVATE nlohmann_json::nlohmann_json)
install (TARGETS sccuot_proto LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif ()
......@@ -132,14 +147,15 @@ target_link_libraries (sccuot_client PUBLIC
sqlpp-mysql
)
target_link_libraries (sccuotd PUBLIC
${Boost_LIBRARIES}
${MYSQL_LIBS}
sqlpp-mysql)
if (DAEMON)
target_link_libraries (sccuotd PUBLIC
${Boost_LIBRARIES}
${MYSQL_LIBS}
sqlpp-mysql)
endif()
# RPM packaging
set(CPACK_PACKAGE_NAME "sccuot")
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_VERSION "${sccuot_VERSION_MAJOR}.${sccuot_VERSION_MINOR}.${sccuot_VERSION_PATCH}")
set(CPACK_PACKAGE_RELEASE 1)
......@@ -155,7 +171,9 @@ include(CPack)
install (TARGETS sccuot_client RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install (TARGETS sccuotd RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install (DIRECTORY include/libsccuot DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install (DIRECTORY include/libsccuot_proto DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if (DAEMON)
install (DIRECTORY include/libsccuot_proto DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install (TARGETS sccuotd RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
This diff is collapsed.
......@@ -15,6 +15,6 @@ namespace sccuot {
void operator()(std::ostream& output, const Representor& result) const;
};
} /* namespace sccuot */
......@@ -5,20 +5,20 @@
namespace sccuot {
class Dat_formatter {
public:
Dat_formatter(std::size_t bin_size)
: _bin_size {bin_size}
{
}
public:
Dat_formatter(std::size_t bin_size)
: _bin_size {bin_size}
{
}
void operator()(std::ostream& output, const Representor& result) const
{
}
void operator()(std::ostream& output, const Representor& result) const
{
}
private:
std::size_t _bin_size;
private:
std::size_t _bin_size;
};
} /* namespace sccuot */
......@@ -11,77 +11,77 @@
namespace sccuot {
class Dataframe {
public:
using type = float;
using data_type = detail::Row<type>;
using collection_type = std::vector<data_type>;
using iterator = typename collection_type::iterator;
using const_iterator = typename collection_type::const_iterator;
using reverse_iterator = typename collection_type::reverse_iterator;
using const_reverse_iterator = typename collection_type::const_reverse_iterator;
public:
using type = float;
using data_type = detail::Row<type>;
using collection_type = std::vector<data_type>;
using iterator = typename collection_type::iterator;
using const_iterator = typename collection_type::const_iterator;
using reverse_iterator = typename collection_type::reverse_iterator;
using const_reverse_iterator = typename collection_type::const_reverse_iterator;
Dataframe() = default;
Dataframe(const Dataframe&) = default;
Dataframe(Dataframe&&) = default;
Dataframe() = default;
Dataframe(const Dataframe&) = default;
Dataframe(Dataframe&&) = default;
Dataframe& operator=(const Dataframe&) = default;
Dataframe& operator=(Dataframe&&) = default;
Dataframe& operator=(const Dataframe&) = default;
Dataframe& operator=(Dataframe&&) = default;
~Dataframe() = default;
~Dataframe() = default;
explicit Dataframe(collection_type&& data);
explicit Dataframe(collection_type&& data);
const collection_type& rows() const;
collection_type& rows();
const collection_type& rows() const;
collection_type& rows();
type scalar() const;
type scalar() const;
std::size_t size() const;
std::size_t size_x() const;
std::size_t size_y() const;
std::size_t size() const;
std::size_t size_x() const;
std::size_t size_y() const;
std::size_t num_rows() const;
std::size_t num_rows() const;
type min() const;
type max() const;
float avg() const;
float med() const;
float stquartile() const;
float rdquartile() const;
type min() const;
type max() const;
float avg() const;
float med() const;
float stquartile() const;
float rdquartile() const;
std::pair<std::size_t, std::size_t> dims() const;
std::pair<std::size_t, std::size_t> dims() const;
data_type& operator[](std::size_t pos);
const data_type& operator[](std::size_t pos) const;
data_type& operator[](std::size_t pos);
const data_type& operator[](std::size_t pos) const;
data_type& operator[](const std::string& row);
const data_type& operator[](const std::string& row) const;
data_type& operator[](const std::string& row);
const data_type& operator[](const std::string& row) const;
void add_row(const std::vector<type>& row, const std::string& label = {});
void add_row(std::vector<type>&& row, const std::string& label = {});
void add_row(const std::vector<type>& row, const std::string& label = {});
void add_row(std::vector<type>&& row, const std::string& label = {});
void sort_x();
void sort_y();
void sort();
void sort_x();
void sort_y();
void sort();
Dataframe relative(std::size_t fcol, std::size_t scol) const;
Dataframe relative(std::size_t fcol, std::size_t scol) const;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator crbegin() const;
const_reverse_iterator crend() const;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator crbegin() const;
const_reverse_iterator crend() const;
private:
collection_type _data;
private:
collection_type _data;
};
void to_json(nlohmann::json& j, const Dataframe& df);
void from_json(const nlohmann::json& j, Dataframe& df);
void from_json(const nlohmann::json& j, Dataframe& df);
} /* namespace sccuot */
......@@ -11,6 +11,6 @@ namespace sccuot {
void operator()(std::ostream& output, const Representor& result) const;
};
} /* namespace sccuot */
......@@ -6,7 +6,7 @@
namespace sccuot {
class Query;
class Query;
namespace db {
......@@ -18,24 +18,24 @@ namespace sccuot {
};
class Connection : public Handle {
public:
friend class Storage;
using connection_type = sqlpp::mysql::connection;
public:
friend class Storage;
using connection_type = sqlpp::mysql::connection;
Connection(const std::string& hostname, const std::string& user,
const std::string& passwd, const std::string& db);
explicit Connection(const Config& config);
Connection(const std::string& hostname, const std::string& user,
const std::string& passwd, const std::string& db);
explicit Connection(const Config& config);
void reconnect(const Config& config);
Connection& operator<<(Query& query);
void reconnect(const Config& config);
Connection& operator<<(Query& query);
void execute(Query& query) override;
void execute(Query& query) override;
connection_type& connection();
connection_type& connection();
private:
private:
std::unique_ptr<connection_type> _connection;
std::unique_ptr<connection_type> _connection;
};
} /* namespace db */
} /* namespace sccuot */
......@@ -8,10 +8,10 @@ namespace sccuot {
namespace db {
class Extractor : public ::sccuot::impl::Extractor {
public:
explicit Extractor(Connection& connection);
public:
explicit Extractor(Connection& connection);
std::unique_ptr<::sccuot::Query> make_query(Queries q, ::sccuot::Query::arglist&& args = {}) const override;
std::unique_ptr<::sccuot::Query> make_query(Queries q, ::sccuot::Query::arglist&& args = {}) const override;
};
} /* namespace db */
} /* namespace sccuot */
......@@ -3,63 +3,32 @@
#include <map>
#include <libsccuot/db/connection.hpp>
#include <libsccuot/impl/query.hpp>
#include <sqlpp11/select.h>
#include <sqlpp11/aggregate_functions/count.h>
#include <sqlpp11/parameter.h>
#include <sqlpp11/verbatim.h>
#include "libsccuot/queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
namespace db {
namespace impl {
class Count_active_users : public ::sccuot::impl::Query {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_active_users;
using base = Query;
using value_type = float;
using typename base::arglist;
explicit Count_active_users(arglist&& args)
: base(std::move(args))
{
}
Queries type() const override
{
return query_type;
};
protected:
void execute(Handle& handle) override
{
auto& connection = dynamic_cast<Connection&>(handle).connection();
static constexpr auto t = tables::oc_accounts::oc_accounts{};
_result.reset(new Dataframe {});
for (const auto& arg : _args) {
auto result = connection.run(sqlpp::select(
sqlpp::count(t.last_login))
.from(t)
.where(
sqlpp::verbatim<sqlpp::boolean>("DATE_SUB(CURDATE(), INTERVAL " + opts.at(arg)
+ " DAY) <= from_unixtime(last_login)")
));
_result->add_row({static_cast<float>(result.front().count)}, arg);
}
base::execute(handle);
}
private:
const std::map<std::string, std::string> opts = {
class Count_active_users : public ::sccuot::impl::Query {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_active_users;
using base = Query;
using value_type = float;
using typename base::arglist;
explicit Count_active_users(arglist&& args);
Queries type() const override;
protected:
void execute(Handle& handle) override;
private:
const std::map<std::string, std::string> opts = {
{"daily", "1"},
{"weekly", "7"},
{"monthly", "30"},
{"quarter", "90"}
};
};
};
......
......@@ -2,43 +2,25 @@
#include <libsccuot/db/connection.hpp>
#include <libsccuot/impl/query.hpp>
#include <sqlpp11/sqlpp11.h>
#include <sqlpp11/mysql/mysql.h>
#include <libsccuot/query.hpp>
#include "libsccuot/queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
namespace db {
namespace impl {
class Count_ext_shares : public ::sccuot::impl::Query {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_ext_shares;
using base = Query;
using value_type = float;
Count_ext_shares() = default;
class Count_ext_shares : public ::sccuot::impl::Query {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_ext_shares;
using base = Query;
using value_type = float;
Queries type() const override
{
return query_type;
}
Count_ext_shares() = default;
protected:
void execute(Handle& handle) override
{
auto& connection = dynamic_cast<db::Connection&>(handle).connection();
static constexpr auto t = tables::oc_share_external::oc_share_external {};
_result.reset(new Dataframe {});
for (const auto& row : connection.run(sqlpp::select(sqlpp::count(t.id)).from(t).unconditionally())) {
_result->add_row({static_cast<float>(row.count)});
}
Queries type() const override;
base::execute(handle);
}
protected:
void execute(Handle& handle) override;
};
} /* namespace impl */
......
......@@ -5,51 +5,24 @@
#include <libsccuot/impl/query.hpp>
#include "libsccuot/queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
namespace db {
namespace impl {
class Count_file_type : public ::sccuot::impl::Query {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_file_type;
using base = Query;
using value_type = float;
using typename base::arglist;
class Count_file_type : public ::sccuot::impl::Query {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_file_type;
using base = Query;
using value_type = float;
using typename base::arglist;
explicit Count_file_type(arglist&& args)
: base(std::move(args))
{
}
explicit Count_file_type(arglist&& args);
Queries type() const override;
Queries type() const override
{
return query_type;
}
protected:
void execute(Handle& handle) override
{
auto& connection = dynamic_cast<db::Connection&>(handle).connection();
static constexpr auto t = tables::oc_filecache::oc_filecache{};
_result.reset(new Dataframe {});
auto prep_stmt = connection.prepare(
sqlpp::select(sqlpp::count(t.fileid))
.from(t)
.where(t.name.like(sqlpp::parameter(t.name))));
for (const auto& arg : _args) {
prep_stmt.params.name = std::string {"%"} + arg;
auto result = connection.run(prep_stmt);
_result->add_row({static_cast<float>(result.front().count)}, arg);
}
base::execute(handle);
}
protected:
void execute(Handle& handle) override;
};
} /* namespace impl */
......
......@@ -4,38 +4,22 @@
#include <libsccuot/impl/query.hpp>
#include "libsccuot/queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
namespace db {
namespace impl {
class Count_files : public ::sccuot::impl::Query {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_files;
using base = Query;
using value_type = float;
class Count_files : public ::sccuot::impl::Query {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_files;
using base = Query;
using value_type = float;
Count_files() = default;
Count_files() = default;
Queries type() const override;
Queries type() const override
{
return query_type;
}
protected:
void execute(Handle& handle) override
{
auto& connection = dynamic_cast<db::Connection&>(handle).connection();
static constexpr auto t = tables::oc_filecache::oc_filecache{};
_result.reset(new Dataframe {});
for (const auto& row : connection.run(sqlpp::select(sqlpp::count(t.fileid)).from(t).unconditionally())) {
_result->add_row({static_cast<float>(row.count)});
}
base::execute(handle);
}
void execute(Handle& handle) override;
};
} /* namespace impl */
......
......@@ -4,39 +4,22 @@
#include <libsccuot/impl/query.hpp>
#include "libsccuot/queries.hpp"
#include "../tables/tables.hpp"