Commit 8b3f5603 authored by Julian Bigge's avatar Julian Bigge

Merge branch 'develop' into 'master'

Version 0.3.3

See merge request !11
parents 148bd95e 9b55302a
Pipeline #44870 passed with stage
in 6 minutes and 52 seconds
......@@ -7,3 +7,6 @@
[submodule "ext/date"]
path = ext/date
url = https://github.com/HowardHinnant/date
[submodule "ext/json"]
path = ext/json
url = https://github.com/nlohmann/json
......@@ -4,14 +4,19 @@ project (sccuot)
set (sccuot_LIB_VERSION_MAJOR 0)
set (sccuot_LIB_VERSION_MINOR 3)
set (sccuot_LIB_VERSION_PATCH 2)
set (sccuot_LIB_VERSION_PATCH 3)
set (sccuot_VERSION_MAJOR 0)
set (sccuot_VERSION_MINOR 3)
set (sccuot_VERSION_PATCH 2)
set (sccuot_VERSION_PATCH 3)
set (sccuotd_VERSION_MAJOR 0)
set (sccuotd_VERSION_MINOR 3)
set (sccuotd_VERSION_PATCH 3)
include(GNUInstallDirs)
find_package (Boost COMPONENTS program_options REQUIRED)
find_package (Boost COMPONENTS program_options system REQUIRED)
find_package (Threads)
execute_process (COMMAND mysql_config --libs
OUTPUT_VARIABLE MYSQL_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
......@@ -23,7 +28,7 @@ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/lib/DEBUG)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/lib/DEBUG)
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Configuration for sqlpp11
set(HinnantDate_ROOT_DIR ${PROJECT_SOURCE_DIR}/ext/date)
......@@ -36,8 +41,12 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/ext/date)
add_subdirectory(${PROJECT_SOURCE_DIR}/ext/sqlpp11)
add_subdirectory(${PROJECT_SOURCE_DIR}/ext/sqlpp11-connector-mysql)
set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(${PROJECT_SOURCE_DIR}/ext/json)
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
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)
......@@ -56,6 +65,10 @@ configure_file (
"${PROJECT_SOURCE_DIR}/src/sccuot/version.hpp"
)
configure_file (
"${PROJECT_SOURCE_DIR}/src/sccuotd/version.hpp.in"
"${PROJECT_SOURCE_DIR}/src/sccuotd/version.hpp"
)
include_directories (${PROJECT_SOURCE_DIR}/include)
include_directories (${Boost_INCLUDE_DIRS})
......@@ -64,32 +77,66 @@ 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)
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})
target_link_libraries (sccuot_client sccuot_static)
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)
else ()
add_library (sccuot SHARED ${LIBSCCUOT_SOURCES} include/libsccuot/db/tables/oc_mounts.hpp include/libsccuot/db/tables/oc_appconfig.hpp)
target_link_libraries (sccuot ${Boost_LIBRARIES})
target_link_libraries (sccuot_client sccuot)
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)
# 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})
endif ()
target_link_libraries (sccuot_client
target_link_libraries (sccuot_client PUBLIC
${Boost_LIBRARIES}
${MYSQL_LIBS}
sqlpp-mysql
)
target_link_libraries (sccuotd PUBLIC
${Boost_LIBRARIES}
${MYSQL_LIBS}
sqlpp-mysql)
# RPM packaging
set(CPACK_PACKAGE_NAME "sccuot")
set(CPACK_PACKAGE_VERSION ${VERSION})
......@@ -108,5 +155,7 @@ 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})
#FROM jdeathe/centos-ssh:centos-7
FROM centos:7.6.1810
########################################################
# Essential packages for remote debugging and login in
########################################################
RUN yum install -y epel-release && yum install -y openssh-server openssh-clients openssl passwd gdb-gdbserver rsync vim sudo
RUN echo 'root:root' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
# 22 for ssh server. 7777 for gdb server.
EXPOSE 22 7777
RUN useradd -ms /bin/bash debugger
RUN echo 'debugger:pwd' | chpasswd
RUN usermod -aG wheel debugger
RUN mkdir -p /home/debugger/code && chown -R debugger:debugger /home/debugger/code
########################################################
# Add custom packages and development environment here
########################################################
RUN yum install -y gcc-c++ cmake3 make mariadb-devel boost-devel boost-program-options \
libcurl-devel rpm-build rpmbuildtools
RUN ssh-keygen -A
########################################################
CMD ["/usr/sbin/sshd", "-D"]
\ No newline at end of file
......@@ -510,7 +510,7 @@ covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
If, pursuant to or in Connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
......@@ -527,9 +527,9 @@ in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
patent license (a) in Connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
for and in Connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
......@@ -614,7 +614,7 @@ SUCH DAMAGES.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
an absolute waiver of all civil liability in Connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
......
version: '3'
services:
gdbserver:
build:
context: ./
dockerfile: ./Dockerfile
image: clion_dev
security_opt:
- seccomp:unconfined
container_name: debug
ports:
- "7776:22"
- "7777:7777"
#volumes:
# - .:/home/debugger/code:Z
working_dir: /home/debugger/code
hostname: debug
\ No newline at end of file
Subproject commit 65e4b973bdc04420335f6e76950f53632ed903c2
......@@ -12,8 +12,7 @@ namespace sccuot {
}
struct Csv_formatter {
template <typename T>
void operator()(std::ostream& output, const Representor<T>& result) const;
void operator()(std::ostream& output, const Representor& result) const;
};
......
......@@ -13,8 +13,7 @@ namespace sccuot {
{
}
template <typename T>
void operator()(std::ostream& output, const Representor<T>& result) const
void operator()(std::ostream& output, const Representor& result) const
{
}
......
......@@ -4,16 +4,16 @@
#include <numeric>
#include <vector>
#include <libsccuot/db/query_base.hpp>
#include <nlohmann/json.hpp>
#include "detail/dataframe_row.hpp"
namespace sccuot {
template <typename T>
class Dataframe {
public:
using data_type = detail::Row<T>;
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;
......@@ -22,20 +22,28 @@ namespace sccuot {
Dataframe() = default;
Dataframe(const Dataframe&) = default;
Dataframe(Dataframe&&) = default;
Dataframe& operator=(const Dataframe&) = default;
Dataframe& operator=(Dataframe&&) = default;
~Dataframe() = default;
explicit Dataframe(collection_type&& data);
const collection_type& rows() const;
collection_type& rows();
type scalar() const;
std::size_t size() const;
std::size_t size_x() const;
std::size_t size_y() const;
T min() const;
T max() const;
std::size_t num_rows() const;
type min() const;
type max() const;
float avg() const;
float med() const;
float stquartile() const;
......@@ -49,8 +57,8 @@ namespace sccuot {
data_type& operator[](const std::string& row);
const data_type& operator[](const std::string& row) const;
void add_row(const std::vector<T>& row, const std::string& label = {});
void add_row(std::vector<T>&& 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();
......@@ -73,4 +81,7 @@ namespace sccuot {
collection_type _data;
};
void to_json(nlohmann::json& j, const Dataframe& df);
void from_json(const nlohmann::json& j, Dataframe& df);
} /* namespace sccuot */
......@@ -8,8 +8,7 @@
namespace sccuot {
struct Dataframe_formatter {
template <typename T>
void operator()(std::ostream& output, const Representor<T>& result) const;
void operator()(std::ostream& output, const Representor& result) const;
};
......
......@@ -2,11 +2,13 @@
#include <sqlpp11/mysql/mysql.h>
#include <libsccuot/handle.hpp>
namespace sccuot {
namespace db {
class Query_base;
class Query;
namespace db {
struct Config {
std::string hostname;
......@@ -15,19 +17,23 @@ namespace sccuot {
std::string db;
};
class Connection {
class Connection : public Handle {
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);
Connection(const Config& config);
explicit Connection(const Config& config);
void reconnect(const Config& config);
Connection& operator<<(Query& query);
void execute(Query& query) override;
Connection& operator<<(Query_base& query);
connection_type& connection();
private:
connection_type& connection();
std::unique_ptr<connection_type> _connection;
};
......
#pragma once
#include "query_base.hpp"
#include "query.hpp"
#include "make_query.hpp"
#include "libsccuot/query.hpp"
#include "connection.hpp"
namespace sccuot {
namespace db {
Dataframe<float> execute(Connection& connection, Queries q, typename Query_base::arglist&& args = {})
inline Dataframe execute(Connection& connection, Queries q, typename Query::arglist&& args = {})
{
auto q_ptr = query(q, std::move(args));
......
#pragma once
#include "connection.hpp"
#include "../extractor.hpp"
#include "../impl/extractor.hpp"
namespace sccuot {
namespace db {
class Extractor : public ::sccuot::impl::Extractor {
public:
explicit Extractor(Connection& connection);
std::unique_ptr<::sccuot::Query> make_query(Queries q, ::sccuot::Query::arglist&& args = {}) const override;
};
} /* namespace db */
} /* namespace sccuot */
#pragma once
#include <map>
#include <libsccuot/db/query.hpp>
#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 "../queries.hpp"
#include "libsccuot/queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
namespace db {
namespace impl {
class Count_active_users : public Query<float> {
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<float>;
using base = Query;
using value_type = float;
using typename base::arglist;
......@@ -33,10 +34,11 @@ namespace sccuot {
};
protected:
void execute(Connection::connection_type& connection) override
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<float> {});
_result.reset(new Dataframe {});
for (const auto& arg : _args) {
auto result = connection.run(sqlpp::select(
......@@ -49,7 +51,7 @@ namespace sccuot {
_result->add_row({static_cast<float>(result.front().count)}, arg);
}
base::execute(connection);
base::execute(handle);
}
private:
const std::map<std::string, std::string> opts = {
......@@ -63,4 +65,4 @@ namespace sccuot {
} /* namespace impl */
} /* namespace db */
} /* namespace sccuot */
\ No newline at end of file
} /* namespace sccuot */
#pragma once
#include <libsccuot/db/connection.hpp>
#include <libsccuot/impl/query.hpp>
#include <sqlpp11/sqlpp11.h>
#include <sqlpp11/mysql/mysql.h>
#include <libsccuot/db/query.hpp>
#include <libsccuot/query.hpp>
#include "../queries.hpp"
#include "libsccuot/queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
namespace db {
namespace impl {
class Count_ext_shares : public Query<float> {
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<float>;
using base = Query;
using value_type = float;
Count_ext_shares() = default;
......@@ -26,15 +28,16 @@ namespace sccuot {
}
protected:
void execute(Connection::connection_type& connection) override
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<value_type> {});
_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)});
}
base::execute(connection);
base::execute(handle);
}
};
......
#pragma once
#include <memory>
#include <libsccuot/db/query.hpp>
#include <libsccuot/db/connection.hpp>
#include <libsccuot/impl/query.hpp>
#include "../queries.hpp"
#include "libsccuot/queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
namespace db {
namespace impl {
class Count_file_type : public Query<float> {
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<float>;
using base = Query;
using value_type = float;
using typename base::arglist;
......@@ -29,10 +30,11 @@ namespace sccuot {
}
protected:
void execute(Connection::connection_type& connection) override
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<float> {});
_result.reset(new Dataframe {});
auto prep_stmt = connection.prepare(
sqlpp::select(sqlpp::count(t.fileid))
......@@ -46,7 +48,7 @@ namespace sccuot {
_result->add_row({static_cast<float>(result.front().count)}, arg);
}
base::execute(connection);
base::execute(handle);
}
};
......
#pragma once
#include <libsccuot/db/query.hpp>
#include <libsccuot/db/connection.hpp>
#include <libsccuot/impl/query.hpp>
#include "../queries.hpp"
#include "libsccuot/queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
namespace db {
namespace impl {
class Count_files : public Query<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<float>;
using base = Query;
using value_type = float;
Count_files() = default;
......@@ -24,15 +25,16 @@ namespace sccuot {
}
protected:
void execute(Connection::connection_type& connection) override
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<value_type>{});
_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(connection);
base::execute(handle);
}
};
......