Skip to content

Commit

Permalink
Merge pull request #4 from ReCodEx/modernization
Browse files Browse the repository at this point in the history
Much better code
  • Loading branch information
SemaiCZE committed May 30, 2018
2 parents 60d2a4a + 831108b commit aae2094
Show file tree
Hide file tree
Showing 39 changed files with 306 additions and 285 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ set(SOURCE_FILES
src/helpers/logger.cpp
src/helpers/curl.h
src/helpers/curl.cpp
src/worker.h
src/worker.cpp
src/notifier/status_notifier.h
src/notifier/http_status_notifier.h
src/notifier/http_status_notifier.cpp
src/notifier/empty_status_notifier.h
src/reactor/reactor.h
src/reactor/reactor.cpp
src/reactor/socket_wrapper_base.cpp
src/reactor/socket_wrapper_base.h
src/reactor/message_container.h
src/reactor/message_container.cpp
src/reactor/handler_interface.h
src/reactor/router_socket_wrapper.h
Expand Down
6 changes: 3 additions & 3 deletions recodex-broker.spec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%define name recodex-broker
%define short_name broker
%define version 1.0.0
%define unmangled_version 1bd664ddc7ba30e7666ce0737f5a714ecbce9ae8
%define release 6
%define version 1.2.1
%define unmangled_version 60d2a4ae569df9780f85446969718fa27193dd6c
%define release 1

%define spdlog_name spdlog
%define spdlog_version 0.13.0
Expand Down
4 changes: 2 additions & 2 deletions src/broker_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void broker_core::load_config()
}
}

void broker_core::force_exit(std::string msg)
void broker_core::force_exit(const std::string &msg)
{
// write to log
if (msg != "") {
Expand All @@ -78,7 +78,7 @@ void broker_core::force_exit(std::string msg)
std::cerr << msg << std::endl;
}

exit(1);
std::exit(1);
}

void broker_core::log_init()
Expand Down
2 changes: 1 addition & 1 deletion src/broker_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class broker_core
* Exit whole application with return code 1.
* @param msg String which is copied to stderr and logger if initialized (emerg level).
*/
void force_exit(std::string msg = "");
[[noreturn]] void force_exit(const std::string &msg = "");

/**
* Parse command line arguments given in constructor.
Expand Down
35 changes: 18 additions & 17 deletions src/config/broker_config.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "broker_config.h"

broker_config::broker_config()
{
}

broker_config::broker_config(const YAML::Node &config)
{
Expand All @@ -17,7 +14,7 @@ broker_config::broker_config(const YAML::Node &config)
client_address_ = config["clients"]["address"].as<std::string>();
} // no throw... can be omitted
if (config["clients"]["port"] && config["clients"]["port"].IsScalar()) {
client_port_ = config["clients"]["port"].as<uint16_t>();
client_port_ = config["clients"]["port"].as<std::uint16_t>();
} // no throw... can be omitted
}

Expand All @@ -27,16 +24,16 @@ broker_config::broker_config(const YAML::Node &config)
worker_address_ = config["workers"]["address"].as<std::string>();
} // no throw... can be omitted
if (config["workers"]["port"] && config["workers"]["port"].IsScalar()) {
worker_port_ = config["workers"]["port"].as<uint16_t>();
worker_port_ = config["workers"]["port"].as<std::uint16_t>();
} // no throw... can be omitted
if (config["workers"]["max_liveness"] && config["workers"]["max_liveness"].IsScalar()) {
max_worker_liveness_ = config["workers"]["max_liveness"].as<size_t>();
max_worker_liveness_ = config["workers"]["max_liveness"].as<std::size_t>();
} // no throw... can be omitted
if (config["workers"]["max_request_failures"] && config["workers"]["max_request_failures"].IsScalar()) {
max_request_failures_ = config["workers"]["max_request_failures"].as<size_t>();
max_request_failures_ = config["workers"]["max_request_failures"].as<std::size_t>();
} // no throw... can be omitted
if (config["workers"]["ping_interval"] && config["workers"]["ping_interval"].IsScalar()) {
worker_ping_interval_ = std::chrono::milliseconds(config["workers"]["ping_interval"].as<size_t>());
worker_ping_interval_ = std::chrono::milliseconds(config["workers"]["ping_interval"].as<std::size_t>());
} // no throw... can be omitted
}

Expand All @@ -46,7 +43,7 @@ broker_config::broker_config(const YAML::Node &config)
monitor_address_ = config["monitor"]["address"].as<std::string>();
} // no throw... can be omitted
if (config["monitor"]["port"] && config["monitor"]["port"].IsScalar()) {
monitor_port_ = config["monitor"]["port"].as<uint16_t>();
monitor_port_ = config["monitor"]["port"].as<std::uint16_t>();
} // no throw... can be omitted
}

Expand All @@ -56,7 +53,7 @@ broker_config::broker_config(const YAML::Node &config)
notifier_config_.address = config["notifier"]["address"].as<std::string>();
} // no throw... can be omitted
if (config["notifier"]["port"] && config["notifier"]["port"].IsScalar()) {
notifier_config_.port = config["notifier"]["port"].as<uint16_t>();
notifier_config_.port = config["notifier"]["port"].as<std::uint16_t>();
} // no throw... can be omitted
if (config["notifier"]["username"] && config["notifier"]["username"].IsScalar()) {
notifier_config_.username = config["notifier"]["username"].as<std::string>();
Expand All @@ -77,10 +74,10 @@ broker_config::broker_config(const YAML::Node &config)
log_config_.log_level = config["logger"]["level"].as<std::string>();
} // no throw... can be omitted
if (config["logger"]["max-size"] && config["logger"]["max-size"].IsScalar()) {
log_config_.log_file_size = config["logger"]["max-size"].as<size_t>();
log_config_.log_file_size = config["logger"]["max-size"].as<std::size_t>();
} // no throw... can be omitted
if (config["logger"]["rotations"] && config["logger"]["rotations"].IsScalar()) {
log_config_.log_files_count = config["logger"]["rotations"].as<size_t>();
log_config_.log_files_count = config["logger"]["rotations"].as<std::size_t>();
} // no throw... can be omitted
} // no throw... can be omitted
} catch (YAML::Exception &ex) {
Expand All @@ -93,7 +90,7 @@ const std::string &broker_config::get_client_address() const
return client_address_;
}

uint16_t broker_config::get_client_port() const
std::uint16_t broker_config::get_client_port() const
{
return client_port_;
}
Expand All @@ -103,7 +100,7 @@ const std::string &broker_config::get_worker_address() const
return worker_address_;
}

uint16_t broker_config::get_worker_port() const
std::uint16_t broker_config::get_worker_port() const
{
return worker_port_;
}
Expand All @@ -113,12 +110,12 @@ const std::string &broker_config::get_monitor_address() const
return monitor_address_;
}

uint16_t broker_config::get_monitor_port() const
std::uint16_t broker_config::get_monitor_port() const
{
return monitor_port_;
}

size_t broker_config::get_max_worker_liveness() const
std::size_t broker_config::get_max_worker_liveness() const
{
return max_worker_liveness_;
}
Expand All @@ -138,7 +135,11 @@ const notifier_config &broker_config::get_notifier_config() const
return notifier_config_;
}

size_t broker_config::get_max_request_failures() const
std::size_t broker_config::get_max_request_failures() const
{
return max_request_failures_;
}

config_error::config_error(const std::string &msg) : std::runtime_error(msg)
{
}
38 changes: 22 additions & 16 deletions src/config/broker_config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef RECODEX_BROKER_CONFIG_H
#define RECODEX_BROKER_CONFIG_H

#include <cstdint>
#include <iostream>
#include <map>
#include <string>
Expand All @@ -22,12 +23,16 @@ class broker_config
{
public:
/** A default constructor */
broker_config();
broker_config() = default;
/**
* A constructor that loads the configuration from a YAML document.
* @param config The input document.
*/
broker_config(const YAML::Node &config);
/**
* Destructor
*/
virtual ~broker_config() = default;
/**
* Get IP address for client connections (from frontend).
* @return Broker's IP address for client connections.
Expand All @@ -37,7 +42,7 @@ class broker_config
* Get the port to listen for incoming tasks.
* @return Broker's port for client connections.
*/
virtual uint16_t get_client_port() const;
virtual std::uint16_t get_client_port() const;
/**
* Get IP address for worker connections.
* @return Broker's IP address for worker connections.
Expand All @@ -47,7 +52,7 @@ class broker_config
* Get the port for communication with workers.
* @return Broker's port for worker connections.
*/
virtual uint16_t get_worker_port() const;
virtual std::uint16_t get_worker_port() const;
/**
* Get IP address for monitor connections.
* @return Broker's IP address for monitor connections.
Expand All @@ -57,17 +62,17 @@ class broker_config
* Get the port for communication with monitor.
* @return Broker's port for monitor connections.
*/
virtual uint16_t get_monitor_port() const;
virtual std::uint16_t get_monitor_port() const;
/**
* Get the maximum (i.e. initial) liveness of a worker.
* @return Maximum liveness of worker.
*/
virtual size_t get_max_worker_liveness() const;
virtual std::size_t get_max_worker_liveness() const;
/**
* Get the amount of times a request can fail before it's cancelled
* @return Maximum request failure count
*/
virtual size_t get_max_request_failures() const;
virtual std::size_t get_max_request_failures() const;
/**
* Get the time (in milliseconds) expected to pass between pings from the worker.
* @return Interval between two concurrent pings.
Expand All @@ -87,23 +92,23 @@ class broker_config
private:
/** Client socket address (from frontend) */
std::string client_address_ = "*"; // '*' is any address
/** Client socket port (from frontend) */
uint16_t client_port_ = 0;
/** Server socket address (to workers) */
std::string worker_address_ = "*"; // '*' is any address
/** Server socket port (to workers) */
uint16_t worker_port_ = 0;
/** Monitor socket address */
std::string monitor_address_ = "127.0.0.1";
/** Client socket port (from frontend) */
std::uint16_t client_port_ = 0;
/** Server socket port (to workers) */
std::uint16_t worker_port_ = 0;
/** Monitor socket port */
uint16_t monitor_port_ = 7894;
std::uint16_t monitor_port_ = 7894;
/**
* Maximum (initial) liveness of a worker
* (the amount of pings the worker can miss before it's considered dead)
*/
size_t max_worker_liveness_ = 4;
std::size_t max_worker_liveness_ = 4;
/** The amount of times a request can fail before it's cancelled */
size_t max_request_failures_ = 3;
std::size_t max_request_failures_ = 3;
/** Time (in milliseconds) expected to pass between pings from the worker */
std::chrono::milliseconds worker_ping_interval_ = std::chrono::milliseconds(1000);
/** Configuration of logger */
Expand All @@ -119,13 +124,14 @@ class broker_config
class config_error : public std::runtime_error
{
public:
/** Destructor */
~config_error() override = default;

/**
* Construction with message returned with @a what method.
* @param msg description of exception circumstances
*/
explicit config_error(const std::string &msg) : std::runtime_error(msg)
{
}
explicit config_error(const std::string &msg);
};

#endif // RECODEX_BROKER_CONFIG_H
4 changes: 2 additions & 2 deletions src/config/log_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ struct log_config {
/**
* File size of one rotation of log file.
*/
int log_file_size = 1024 * 1024;
std::size_t log_file_size = 1024 * 1024;
/**
* Number of rotations which will be kept saved.
*/
int log_files_count = 3;
std::size_t log_files_count = 3;

/**
* Equality operator on @ref log_config structures.
Expand Down
3 changes: 2 additions & 1 deletion src/config/notifier_config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef RECODEX_NOTIFIER_CONFIG_H
#define RECODEX_NOTIFIER_CONFIG_H

#include <cstdint>
#include <string>


Expand All @@ -16,7 +17,7 @@ struct notifier_config {
/**
* Port on which frontend runs.
*/
uint16_t port;
std::uint16_t port;

/**
* Username which is used in HTTP authentication.
Expand Down
Loading

0 comments on commit aae2094

Please sign in to comment.