Resolve "Use thallium providers for RPC handlers instead of free functions."

Closes #11 (closed)

Merge request reports

Loading
+1 −1
Changes for lib/CMakeLists.txt: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ target_include_directories(

set_target_properties(cargo PROPERTIES PUBLIC_HEADER "${public_headers}")

target_link_libraries(cargo PRIVATE logger fmt::fmt thallium)
target_link_libraries(cargo PRIVATE logger::logger fmt::fmt thallium)

## Install library + targets ###################################################

src/config/config/CMakeLists.txt

deleted100644 → 0
+0 −84
Changes for src/config/config/CMakeLists.txt: 0 added lines, 84 removed lines.
Original line number Diff line number Diff line
################################################################################
# Copyright 2022-2023, Barcelona Supercomputing Center (BSC), Spain            #
#                                                                              #
# This software was partially supported by the EuroHPC-funded project ADMIRE   #
#   (Project ID: 956748, https://www.admire-eurohpc.eu).                       #
#                                                                              #
# This file is part of Cargo.                                                  #
#                                                                              #
# Cargo 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 3 of the License, or            #
# (at your option) any later version.                                          #
#                                                                              #
# Cargo 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 Cargo.  If not, see <https://www.gnu.org/licenses/>.              #
#                                                                              #
# SPDX-License-Identifier: GPL-3.0-or-later                                    #
################################################################################

# Create a config target for all configuration code
add_library(config STATIC)

target_include_directories(
  config PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
)

target_sources(
  config
  PRIVATE config.hpp
          defaults.hpp
          ${CMAKE_CURRENT_BINARY_DIR}/defaults.cpp
          ${CMAKE_CURRENT_BINARY_DIR}/config_options.hpp
          ${CMAKE_CURRENT_BINARY_DIR}/keywords.hpp
          parsers.cpp
          parsers.hpp
          settings.cpp
          settings.hpp
)

target_link_libraries(config PRIVATE utils file_options::file_options)

# ##############################################################################
# Produce several auto-generated files for 'config'
# ##############################################################################

# Default values for options
configure_file(defaults.cpp.in defaults.cpp)

# Automatic generation of file_options schemas. To facilitate the management of
# any file-based configuration options, we generate a C++ schema from a YAML
# file that allows the 'file_options' library to parse them fromm a
# configuration file. The process works as follows:
#  1. We define the desired options in 'file_options.yml'
#  2. We rely on the 'genopts' tool to generate valid C++ schemas for the
#     'file_options' library. This tool can be configured using a 'genopts.yml'
#     configuration file.
#  3. In the daemon code, we use the facilities provided by the 'file_options'
#     library to access the options values.

# Since the configuration in genopts.yml can be path-dependant, we rely on
# CMake to substitute any special @variables@ for their actual values
configure_file(genopts.yml.in genopts.yml @ONLY)

# Define the command that will generate config_options.hpp and keywords.hpp.
# It will be executed since there is a direct dependency between 'config'
# (defined below) and these output files.
# We also make the command depend on file_options.yml and genopts.yml so that
# it gets re-executed if they change.
add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/config_options.hpp
         ${CMAKE_CURRENT_BINARY_DIR}/keywords.hpp
  COMMENT "Generating config_options.hpp, keywords.hpp"
  DEPENDS genopts_virtualenv file_options.yml
          ${CMAKE_CURRENT_BINARY_DIR}/genopts.yml
  COMMAND
    Genopts::Python3_Interpreter -m genopts --config
    ${CMAKE_CURRENT_BINARY_DIR}/genopts.yml
    ${CMAKE_CURRENT_LIST_DIR}/file_options.yml
)
+0 −41
Changes for src/config/config/file_options.yml: 0 added lines, 41 removed lines.
Original line number Diff line number Diff line
sections:
  - name: "global_settings"
    required: true
    options:
      - name: "use_syslog"
        required: true
        type: "bool"
        converter: "parsers::parse_bool"

      - name: "log_file"
        required: false
        type: "std::filesystem::path"
        converter: "parsers::parse_path"

      - name: "log_file_max_size"
        required: false
        type: "uint32_t"
        converter: "parsers::parse_capacity"

      - name: "transport_protocol"
        required: true
        type: "std::string"

      - name: "bind_address"
        required: true
        type: "std::string"

      - name: "remote_port"
        required: true
        type: "uint32_t"
        converter: "parsers::parse_number"

      - name: "pidfile"
        required: true
        type: "std::filesystem::path"
        converter: "parsers::parse_path"

      - name: "workers"
        required: true
        type: "uint32_t"
        converter: "parsers::parse_number"

src/config/config/genopts.yml.in

deleted100644 → 0
+0 −14
Changes for src/config/config/genopts.yml.in: 0 added lines, 14 removed lines.
Original line number Diff line number Diff line
genopts:
  schema:
    copyright_file: "@CMAKE_SOURCE_DIR@/COPYRIGHT_NOTICE"
    header_guard: "CONFIG_SCHEMA_HPP"
    namespace: "config"
    output_path:
      header: "@CMAKE_CURRENT_BINARY_DIR@/config_options.hpp"

  keywords:
    copyright_file: "@CMAKE_SOURCE_DIR@/COPYRIGHT_NOTICE"
    header_guard: "CONFIG_KEYWORDS_HPP"
    namespace: "config::keywords"
    output_path:
      header: "@CMAKE_CURRENT_BINARY_DIR@/keywords.hpp"

src/config/config/parsers.cpp

deleted100644 → 0
+0 −103
Changes for src/config/config/parsers.cpp: 0 added lines, 103 removed lines.
Original line number Diff line number Diff line
/******************************************************************************
 * Copyright 2022-2023, Barcelona Supercomputing Center (BSC), Spain
 *
 * This software was partially supported by the EuroHPC-funded project ADMIRE
 *   (Project ID: 956748, https://www.admire-eurohpc.eu).
 *
 * This file is part of Cargo.
 *
 * Cargo 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 3 of the License, or
 * (at your option) any later version.
 *
 * Cargo 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 Cargo.  If not, see <https://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *****************************************************************************/

#include <boost/algorithm/string/case_conv.hpp>
#include <exception>
#include <stdexcept>
#include <cstdint>
#include <string>
#include <filesystem>
#include <utils/utils.hpp>
#include "parsers.hpp"

namespace fs = std::filesystem;

namespace config::parsers {

bool
parse_bool(const std::string& name, const std::string& value) {

    if(value == "1" || boost::algorithm::to_lower_copy(value) == "true") {
        return true;
    }

    if(value == "0" || boost::algorithm::to_lower_copy(value) == "false") {
        return false;
    }

    throw std::invalid_argument("Value provided for option '" + name +
                                "' is not boolean");
}

uint32_t
parse_number(const std::string& name, const std::string& value) {

    int32_t optval = 0;

    try {
        optval = std::stoi(value);
    } catch(...) {
        throw std::invalid_argument("Value provided for option '" + name +
                                    "' is not a number");
    }

    if(optval <= 0) {
        throw std::invalid_argument("Value provided for option '" + name +
                                    "' must be greater than zero");
    }

    return static_cast<uint32_t>(optval);
}

fs::path
parse_path(const std::string& name, const std::string& value) {

    (void) name;

    return {value};
}

fs::path
parse_existing_path(const std::string& name, const std::string& value) {

    if(!fs::exists(value)) {
        throw std::invalid_argument("Path '" + value + "' in option '" + name +
                                    "' does not exist");
    }

    return {value};
}

uint64_t
parse_capacity(const std::string& name, const std::string& value) {

    try {
        return utils::parse_size(value);
    } catch(const std::exception& e) {
        throw std::invalid_argument("Value provided in option '" + name +
                                    "' is invalid");
    }
}

} // namespace config::parsers
Loading
Loading