refactor: Move config services to lib_system
The proto files are still in lib_spark, w/ the exception of system_config.proto, since that is a dep of ConfigurationState.
This commit is contained in:
1 parent
67a5f6fea2
commit
bc9e07a287
87 files changed
+836
-764
No files matched your search
+6
-6
@@ -28,7 +28,7 @@
|
||||
"CMAKE_SHARED_LINKER_FLAGS_RELEASE": "/OPT:REF /OPT:ICF /LTCG",
|
||||
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
|
||||
"EXTERNALS_ROOT": "${sourceDir}/externals/windows",
|
||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf",
|
||||
"CONFIG_DEFAULTS_PATH": "spark/config/profiles/default/*.conf",
|
||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net7.0-windows",
|
||||
"EXPORT_MD_CONSUMER": {
|
||||
"type": "BOOL",
|
||||
@@ -77,7 +77,7 @@
|
||||
"value": "ON"
|
||||
},
|
||||
"CCAPI_LOG_LEVEL": "Info",
|
||||
"CONFIG_DEFAULTS_PATH": "config/profiles/md_dev/*.conf;config/profiles/default/*.conf"
|
||||
"CONFIG_DEFAULTS_PATH": "spark/config/profiles/md_dev/*.conf;spark/config/profiles/default/*.conf"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release",
|
||||
"CCAPI_LOG_LEVEL": "Warn",
|
||||
"CONFIG_DEFAULTS_PATH": "config/profiles/md_prod/*.conf;config/profiles/default/*.conf"
|
||||
"CONFIG_DEFAULTS_PATH": "spark/config/profiles/md_prod/*.conf;spark/config/profiles/default/*.conf"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
},
|
||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf",
|
||||
"CONFIG_DEFAULTS_PATH": "spark/config/profiles/default/*.conf",
|
||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/Spark.Api.Server/$<CONFIG>/bin/net7.0",
|
||||
"EXPORT_MD_CONSUMER": {
|
||||
"type": "BOOL",
|
||||
@@ -207,7 +207,7 @@
|
||||
"description": "Data Stream utils ported over from Edge",
|
||||
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||
"cacheVariables": {
|
||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf;config/profiles/data_stream/*.conf",
|
||||
"CONFIG_DEFAULTS_PATH": "spark/config/profiles/default/*.conf;spark/config/profiles/data_stream/*.conf",
|
||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net7.0-windows"
|
||||
}
|
||||
},
|
||||
@@ -240,7 +240,7 @@
|
||||
"CMAKE_CXX_COMPILER": "clang++",
|
||||
"CMAKE_CXX_FLAGS_DEBUG": "-g -fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -DDEBUG",
|
||||
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -fno-omit-frame-pointer -DNDEBUG -O3",
|
||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf;config/profiles/data_stream/*.conf",
|
||||
"CONFIG_DEFAULTS_PATH": "spark/config/profiles/default/*.conf;spark/config/profiles/data_stream/*.conf",
|
||||
"CONFIG_PROFILES": "default;data_stream",
|
||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net8.0",
|
||||
"EXPORT_MD_CONSUMER": {
|
||||
|
||||
@@ -7,7 +7,11 @@ include(${CMAKE_SOURCE_DIR}/cmake/safe_dep_glob.cmake)
|
||||
|
||||
function(init_library)
|
||||
set(_options SHARED STATIC)
|
||||
set(_one_value_args NAME SOURCE_DIR INCLUDE_DIR)
|
||||
set(_one_value_args
|
||||
NAME
|
||||
SOURCE_DIR
|
||||
INCLUDE_DIR
|
||||
)
|
||||
set(_multi_value_args)
|
||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
||||
if (_ARGS_SHARED AND _ARGS_STATIC)
|
||||
|
||||
@@ -34,6 +34,7 @@ function(protobuf_generate_cpp)
|
||||
endif()
|
||||
list(APPEND ${_ARGS_CXX_SOURCES} "${_ARGS_CXX_OUT_DIR}/${_fil_we}.pb.cc")
|
||||
list(APPEND ${_ARGS_CXX_HEADERS} "${_ARGS_CXX_OUT_DIR}/${_fil_we}.pb.h")
|
||||
message(STATUS "add_custom_command for ${_fil} -> ${_ARGS_CXX_OUT_DIR}/${_fil_we}.pb.h")
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
"${_ARGS_CXX_OUT_DIR}/${_fil_we}.pb.cc"
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
function(protobuf_generate_cpp_config)
|
||||
set(_options)
|
||||
set(_one_value_args
|
||||
PROTO_SOURCES_HEADER
|
||||
PROTO_DEFAULTS_HEADER
|
||||
)
|
||||
set(_multi_value_args
|
||||
PROTO_SOURCES
|
||||
PROTO_DEFAULTS
|
||||
)
|
||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
||||
|
||||
# Configure the 'config_proto_files' header. It provides an array of strings populated with the
|
||||
# files in PROTO_SOURCES. At runtime, we use this array to generate a special 'config' proto
|
||||
# message with fields for each message defined in said files. A global instance of this 'config'
|
||||
# proto is then constructed, and populated with [compile-time] defaults, and [runtime] overrides
|
||||
# (i.e., in spark.conf). Calls to `bts::config::get<T>()` retrieve the value from the field
|
||||
# associated with type `T` in this global instance.
|
||||
message(STATUS "PROTO_SOURCES: ${_ARGS_PROTO_SOURCES}")
|
||||
message(STATUS "PROTO_SOURCES_HEADER: ${_ARGS_PROTO_SOURCES_HEADER}")
|
||||
message(STATUS "PROTO_DEFAULTS_HEADER: ${_ARGS_PROTO_DEFAULTS_HEADER}")
|
||||
if (_ARGS_PROTO_SOURCES_HEADER)
|
||||
set(PROTO_SOURCES)
|
||||
set(PROTO_SOURCES_CXX_ARRAY_ITEMS "")
|
||||
foreach(_proto_path ${_ARGS_PROTO_SOURCES})
|
||||
list(APPEND PROTO_SOURCES ${_proto_path})
|
||||
string(APPEND PROTO_SOURCES_CXX_ARRAY_ITEMS "\"${_proto_path}\",\n")
|
||||
endforeach()
|
||||
list(LENGTH PROTO_SOURCES PROTO_SOURCES_LENGTH)
|
||||
message(STATUS "CONFIGURING PROTO_SOURCES_HEADER): ${_ARGS_PROTO_SOURCES_HEADER}")
|
||||
configure_file(${CMAKE_SOURCE_DIR}/cmake/config_proto_files.h.in ${_ARGS_PROTO_SOURCES_HEADER})
|
||||
endif()
|
||||
|
||||
# Generate static defaults. Ideally, this would be a single string, but we use an array because
|
||||
# the compiler complains if the string is longer than 65k.
|
||||
set(_cfg_defaults_str "inline const char * config_static_defaults[] = { ")
|
||||
|
||||
foreach(_cfg_file_path ${_ARGS_PROTO_DEFAULTS})
|
||||
file(READ ${_cfg_file_path} _cfg_file_content)
|
||||
string(REPLACE "\"" "\\\"" _cfg_file_content_escaped ${_cfg_file_content})
|
||||
string(REPLACE "\n" ";" _cfg_lines ${_cfg_file_content_escaped})
|
||||
|
||||
foreach(_line ${_cfg_lines})
|
||||
string(APPEND _cfg_defaults_str "\n \"${_line}\",")
|
||||
endforeach(_line)
|
||||
endforeach(_cfg_file_path)
|
||||
|
||||
string(APPEND _cfg_defaults_str "};")
|
||||
set(_old_cfg_defaults_str "")
|
||||
|
||||
if(EXISTS ${_ARGS_PROTO_DEFAULTS_HEADER})
|
||||
file(READ ${_ARGS_PROTO_DEFAULTS_HEADER} _old_cfg_defaults_str)
|
||||
endif()
|
||||
|
||||
if(NOT _cfg_defaults_str STREQUAL _old_cfg_defaults_str)
|
||||
file(WRITE "${_ARGS_PROTO_DEFAULTS_HEADER}" "${_cfg_defaults_str}")
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace bts::@PROJECT_NAME@::protobufs {
|
||||
|
||||
inline std::array<const char *, @PROTO_SOURCES_LENGTH@> config_proto_files = {
|
||||
@PROTO_SOURCES_CXX_ARRAY_ITEMS@
|
||||
};
|
||||
|
||||
} // namespace bts::@PROJECT_NAME@::protobufs
|
||||
@@ -13,11 +13,11 @@
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/exchange_sim_cfg.pb.h"
|
||||
#include "spark/config/protos/ports.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/domain_model/Security.pb.h"
|
||||
#include "spark/md/PriceSize.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include "spark/domain_model/Security.pb.h"
|
||||
#include "spark/md/IntPrice.h"
|
||||
@@ -31,6 +31,9 @@
|
||||
|
||||
namespace bts {
|
||||
namespace sim {
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
auto cfg = "[DEFAULT]\n"
|
||||
"ConnectionType=acceptor\n"
|
||||
"SocketAcceptPort=$EXCHANGE_SIM_FIX_PORT\n"
|
||||
@@ -144,7 +147,7 @@ int start_exchange_sim(bts::api::Venue venue, md::MBOWriter *mbo) {
|
||||
auto venue_string = boost::to_lower_copy(api::Venue_Name(venue));
|
||||
boost::replace_all(
|
||||
str_settings, "$BTS_DATA_PATH",
|
||||
config::get<config::SystemConfig>().data_path());
|
||||
config::get<SystemConfig>().data_path());
|
||||
boost::replace_all(str_settings, "$SIM_VENUE", venue_string);
|
||||
std::string port_string;
|
||||
switch (venue) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "CboeMarketDataHandler.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "sparkd/md/databento/DatabentoDataHandler.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
@@ -14,14 +14,14 @@
|
||||
namespace bts::api::md::cboe {
|
||||
|
||||
using bts::domain::protobufs::Venue;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
void CboeMarketDatahandler::run(
|
||||
std::shared_ptr<::bts::md::IMarketDataListener> listner,
|
||||
std::shared_ptr<persistence::IDGenerator> sec_id_store,
|
||||
const CboeMarketDataConfig &config) {
|
||||
bts_assert_msg(config.use_databento(), "CboeMarketDatahandler only supports databento");
|
||||
std::string base_path =
|
||||
config::get<bts::config::SystemConfig>().data_path();
|
||||
std::string base_path = config::get<SystemConfig>().data_path();
|
||||
bts_assert(config.has_databento_settings());
|
||||
bts::md::DatabentoHandler::DatabentoDatahandler::run(
|
||||
config.databento_settings().read_from_file(),
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
#include "domain/security.h"
|
||||
#include "domain/security_id.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/md/IMarketDataListener.h"
|
||||
#include "spark/persistence/IDGenerator.h"
|
||||
#include "spark/utils/TimeStamp.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/bts_chrono.h"
|
||||
#include "spark/utils/datetime.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <databento/constants.hpp>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "EmumbaDeribitSubscription.h"
|
||||
#include "spark/api/md/EmumbaDeribitMarketDataConfig.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "sparkd/md/emumba/EmumbaDeribitData.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
namespace bts::md {
|
||||
using bts::config::SystemConfig;
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
using Path = boost::filesystem::path;
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#include "domain/protobufs/venue.pb.h"
|
||||
#include "spark/api/md/GlbxMarketDataConfig.pb.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "sparkd/md/databento/DatabentoDataHandler.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
@@ -16,6 +16,7 @@
|
||||
namespace bts::api::md::glbx {
|
||||
|
||||
using bts::domain::protobufs::Venue;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
void GlbxMarketDatahandler::run(
|
||||
std::shared_ptr<::bts::md::IMarketDataListener> listner,
|
||||
@@ -23,8 +24,7 @@ void GlbxMarketDatahandler::run(
|
||||
const GlbxMarketDataConfig &config) {
|
||||
bts_assert_msg(config.use_databento(),
|
||||
"GlbxMarketDatahandler only supports databento");
|
||||
std::string base_path =
|
||||
config::get<bts::config::SystemConfig>().data_path();
|
||||
std::string base_path = config::get<SystemConfig>().data_path();
|
||||
bts_assert(config.has_databento_settings());
|
||||
bts::md::DatabentoHandler::DatabentoDatahandler::run(
|
||||
config.databento_settings().read_from_file(),
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "EMTradingSession.h"
|
||||
#include "EmMDListener.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/md/GeneralSecurityIndex.h"
|
||||
#include "spark/md/MDProducer.h"
|
||||
#include "spark/md/SecurityDB.h"
|
||||
@@ -16,6 +15,7 @@
|
||||
#include "sparkd/cmds/crypto/DeribitDemoConfiguration.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
#include "system/protobufs/proto_helper.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
@@ -30,7 +30,7 @@ using namespace bts::orderman;
|
||||
|
||||
namespace bts::md {
|
||||
|
||||
using bts::config::SystemConfig;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
using Path = boost::filesystem::path;
|
||||
|
||||
struct EmumbaMain::PImpl {
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
#include "spark/utils/helper_macros.h"
|
||||
|
||||
#include "spark/config/protos/market_data.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/proto_helper.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <OnixS/ICE/iMpact/MarketData.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
@@ -27,7 +27,7 @@ using std::size_t;
|
||||
|
||||
namespace bts::md::ice {
|
||||
|
||||
using bts::config::SystemConfig;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
using Path = boost::filesystem::path;
|
||||
|
||||
struct ICEMain::PImpl {
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "domain/protobufs/trading_status.pb.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/market_data.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/md/MBOProcessor.h"
|
||||
#include "spark/md/SecurityDB.h"
|
||||
#include "spark/md/cme/MDP3Utils.h"
|
||||
@@ -15,6 +14,7 @@
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
#include "system/protobufs/proto_helper.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "spark/api/services/MarketDataRelay.client.pb.h"
|
||||
#include "spark/api/services/MarketDataRelay.pb.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/domain_model/Security.pb.h"
|
||||
#include "spark/md/MDClient.h"
|
||||
#include "spark/md/MDConsumer.h"
|
||||
@@ -18,6 +17,7 @@
|
||||
#include "spark/utils/datetime.h"
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
#include "system/time_stamp.h"
|
||||
|
||||
#include <array>
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
namespace bts::md::recording {
|
||||
|
||||
using bts::config::SystemConfig;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
using Path = boost::filesystem::path;
|
||||
|
||||
std::string MDRecorder::file_start_seq = "marketdata";
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
#include "domain/trade_record.h"
|
||||
#include "spark/api/md/TaifexMarketDataConfig.pb.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/md/IMarketDataListener.h"
|
||||
#include "spark/persistence/IDGenerator.h"
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "sparkd/md/taifex/TaifexDataProcessors.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
#include "system/time_stamp.h"
|
||||
|
||||
#include <exception>
|
||||
@@ -32,6 +32,7 @@
|
||||
namespace bts::md::taifex {
|
||||
|
||||
using bts::domain::protobufs::Venue;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
enum class LIVE_DATA_STATES {
|
||||
START = 0,
|
||||
@@ -337,8 +338,8 @@ void writeBufferWithSeparator(
|
||||
const std::vector<unsigned char> &buffer,
|
||||
size_t bytes_received,
|
||||
unsigned long position = 0) {
|
||||
auto filename = config::get<bts::config::SystemConfig>().data_path() +
|
||||
"taifex_default_reference";
|
||||
auto filename =
|
||||
config::get<SystemConfig>().data_path() + "taifex_default_reference";
|
||||
std::ofstream outputFile(
|
||||
filename, std::ios::binary | std::ios::app); // Open file in append mode
|
||||
if (!outputFile) {
|
||||
@@ -367,8 +368,7 @@ void HandleReferenceFeed(
|
||||
std::set<std::string> I010_seen;
|
||||
std::set<std::string> I011_seen;
|
||||
LoadReferenceFromFile(
|
||||
config::get<bts::config::SystemConfig>().data_path() +
|
||||
"taifex_default_reference",
|
||||
config::get<SystemConfig>().data_path() + "taifex_default_reference",
|
||||
snapshot_buffered_messages, I010_seen, I011_seen);
|
||||
// bool file_done =
|
||||
UNPROCESSED_MSG buffer(FEED_BUFFER_SIZE);
|
||||
@@ -817,8 +817,7 @@ void bts::md::taifex::TaifexDataGateway::run(
|
||||
config.ref_data_file_name(); //"reference_data_20240806_1";
|
||||
std::string realtime_file_name =
|
||||
config.realtime_data_file_name(); //"real_time_data_20240806_274";
|
||||
std::string base_path =
|
||||
config::get<bts::config::SystemConfig>().data_path();
|
||||
std::string base_path = config::get<SystemConfig>().data_path();
|
||||
runOnBinaryFile(
|
||||
base_path + reference_file_name, listner, sec_id_store, sec_details,
|
||||
REFERENCE);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "ErrorReportService.h"
|
||||
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/datetime.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
@@ -15,8 +15,10 @@
|
||||
namespace bts {
|
||||
namespace support {
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
std::string get_report_dir() {
|
||||
return config::get<config::SystemConfig>().data_path() + "error_reports/";
|
||||
return config::get<SystemConfig>().data_path() + "error_reports/";
|
||||
}
|
||||
|
||||
ErrorReportServer::ErrorReportServer(bts::api::ServiceContext &context)
|
||||
|
||||
@@ -3,8 +3,8 @@ project(spark)
|
||||
include(GNUInstallDirs)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/safe_dep_glob.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/ProtobufGenerateCpp.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/ProtobufGenerateCppConfig.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ProtobufGenerateCppService.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateDefaultConfig.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateConfigProfile.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/InstallBasic.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/PrintList.cmake)
|
||||
@@ -28,57 +28,71 @@ else()
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GetLinuxClientLinkLibraries.cmake)
|
||||
endif()
|
||||
|
||||
# Cpp sources
|
||||
set(${PROJECT_NAME}_Sources)
|
||||
get_cpp_sources(${PROJECT_NAME}_Sources)
|
||||
print_list(${PROJECT_NAME}_Sources VERBOSE)
|
||||
|
||||
# Proto sources
|
||||
get_proto_sources(_cfg_protos _non_cfg_protos _service_protos _cfg_defaults)
|
||||
print_list(_cfg_protos VERBOSE)
|
||||
print_list(_non_cfg_protos VERBOSE)
|
||||
print_list(_service_protos VERBOSE)
|
||||
print_list(_cfg_defaults VERBOSE)
|
||||
|
||||
update_deps_file("${${PROJECT_NAME}_Sources};${_cfg_protos};${_service_protos};${_non_cfg_protos};${_cfg_defaults}")
|
||||
|
||||
# Generate proto cpp
|
||||
message(STATUS "Generating proto cpp")
|
||||
get_proto_sources(
|
||||
${PROJECT_NAME}_PROTO_CONFIGS
|
||||
${PROJECT_NAME}_PROTO_SOURCES
|
||||
${PROJECT_NAME}_PROTO_SERVICES
|
||||
)
|
||||
get_cpp_sources(${PROJECT_NAME}_SOURCES)
|
||||
protobuf_generate_cpp(
|
||||
CXX_SOURCES _proto_srcs
|
||||
CXX_HEADERS _proto_hdrs
|
||||
CXX_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobufs
|
||||
CXX_SOURCES ${PROJECT_NAME}_CXX_PROTO_SOURCES
|
||||
CXX_HEADERS ${PROJECT_NAME}_CXX_PROTO_HEADERS
|
||||
CXX_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
|
||||
PROTO_INCLUDE_DIRS
|
||||
${EXTERNALS_INCLUDE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/src/lib_domain
|
||||
PROTO_SOURCES
|
||||
${_non_cfg_protos}
|
||||
${_cfg_protos}
|
||||
${${PROJECT_NAME}_PROTO_SOURCES}
|
||||
)
|
||||
protobuf_generate_cpp_service(
|
||||
CXX_SOURCES SERVICE_COMPILER_SRCS
|
||||
CXX_HEADERS SERVICE_COMPILER_HDRS
|
||||
CXX_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobufs
|
||||
PROTO_INCLUDE_DIRS
|
||||
${EXTERNALS_INCLUDE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/src/lib_domain
|
||||
PROTO_SOURCES
|
||||
${_service_protos}
|
||||
)
|
||||
message(STATUS "Generating default config")
|
||||
generate_default_config(_cfg_protos _cfg_defaults)
|
||||
foreach(profile ${CONFIG_PROFILES})
|
||||
message(STATUS "Generating config profile ${profile}")
|
||||
generate_config_profile(${profile} _cfg_protos)
|
||||
endforeach()
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_Sources} ${_proto_srcs} ${SERVICE_COMPILER_SRCS})
|
||||
protobuf_generate_cpp_service(
|
||||
CXX_SOURCES ${PROJECT_NAME}_CXX_PROTO_SERVICE_SOURCES
|
||||
CXX_HEADERS ${PROJECT_NAME}_CXX_PROTO_SERVICE_HEADERS
|
||||
CXX_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
|
||||
PROTO_INCLUDE_DIRS
|
||||
${EXTERNALS_INCLUDE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/src/lib_domain
|
||||
PROTO_SOURCES
|
||||
${${PROJECT_NAME}_PROTO_SERVICES}
|
||||
)
|
||||
|
||||
# Generate headers for config protos. One header provides the list of proto files in an array to be
|
||||
# read at runtime in order to generate the aggregated config message type. The other header provides
|
||||
# an array of strings whose items are lines representing the defaults for this aggregated config
|
||||
# message type.
|
||||
set(${PROJECT_NAME}_PROTO_DEFAULTS)
|
||||
foreach(cfg_path ${CONFIG_DEFAULTS_PATH})
|
||||
file(
|
||||
GLOB_RECURSE cfg_files
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${cfg_path})
|
||||
list(APPEND ${PROJECT_NAME}_PROTO_DEFAULTS ${cfg_files})
|
||||
endforeach()
|
||||
protobuf_generate_cpp_config(
|
||||
PROTO_SOURCES
|
||||
${${PROJECT_NAME}_PROTO_CONFIGS}
|
||||
PROTO_SOURCES_HEADER
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/protobufs/config_proto_files.h
|
||||
PROTO_DEFAULTS
|
||||
${${PROJECT_NAME}_PROTO_DEFAULTS}
|
||||
PROTO_DEFAULTS_HEADER
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/protobufs/config_defaults.h
|
||||
)
|
||||
|
||||
add_library(
|
||||
${PROJECT_NAME}
|
||||
SHARED
|
||||
${${PROJECT_NAME}_SOURCES}
|
||||
${${PROJECT_NAME}_CXX_PROTO_SOURCES}
|
||||
${${PROJECT_NAME}_CXX_PROTO_SERVICE_SOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
${PROJECT_NAME} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>/protobufs
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
@@ -104,8 +118,14 @@ if(WIN32)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/vs_filters.cmake)
|
||||
endif()
|
||||
|
||||
foreach(_hdr ${_proto_hdrs})
|
||||
file(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_BINARY_DIR}/protobufs ${_hdr})
|
||||
foreach(_hdr ${${PROJECT_NAME}_CXX_PROTO_HEADERS})
|
||||
file(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_BINARY_DIR} ${_hdr})
|
||||
install(FILES ${_hdr} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${_relative_path})
|
||||
endforeach()
|
||||
|
||||
foreach(_hdr ${${PROJECT_NAME}_CXX_PROTO_SERVICE_HEADERS})
|
||||
file(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_BINARY_DIR} ${_hdr})
|
||||
install(FILES ${_hdr} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${_relative_path})
|
||||
endforeach()
|
||||
|
||||
install_basic()
|
||||
@@ -1,54 +0,0 @@
|
||||
function(generate_default_config cfg_protos cfg_defaults)
|
||||
set(_out_dir ${CMAKE_CURRENT_BINARY_DIR}/protobufs/${PROJECT_NAME})
|
||||
# generate list of config protos
|
||||
set(_cfg_proto_file ${_out_dir}/config_proto_files.h)
|
||||
|
||||
# generate a string with the current config files
|
||||
set(_cfg_proto_str "const char * config_proto_files[] = { // generated file\n")
|
||||
|
||||
foreach(_proto_path ${${cfg_protos}})
|
||||
get_filename_component(_proto_name ${_proto_path} NAME)
|
||||
string(APPEND _cfg_proto_str "\"${_proto_name}\",\n")
|
||||
endforeach(_proto_path)
|
||||
|
||||
string(APPEND _cfg_proto_str "} ;\n")
|
||||
|
||||
# compare with file and if there is any difference update the file
|
||||
set(_old_cfg_proto_str "")
|
||||
|
||||
if(EXISTS "${_cfg_proto_file}")
|
||||
file(READ "${_cfg_proto_file}" _old_cfg_proto_str)
|
||||
endif()
|
||||
|
||||
if(NOT _old_cfg_proto_str STREQUAL _cfg_proto_str)
|
||||
file(WRITE "${_cfg_proto_file}" "${_cfg_proto_str}")
|
||||
endif()
|
||||
|
||||
# generate static defaults
|
||||
set(_cfg_defaults_file ${_out_dir}/config_defaults.h)
|
||||
|
||||
# Defaults cannot be a single string because the compiler complains about a
|
||||
# string longer than 65k
|
||||
set(_cfg_defaults_str "const char * config_static_defaults[] = { ")
|
||||
|
||||
foreach(_cfg_file_path ${${cfg_defaults}})
|
||||
file(READ ${_cfg_file_path} _cfg_file_content)
|
||||
string(REPLACE "\"" "\\\"" _cfg_file_content_escaped ${_cfg_file_content})
|
||||
string(REPLACE "\n" ";" _cfg_lines ${_cfg_file_content_escaped})
|
||||
|
||||
foreach(_line ${_cfg_lines})
|
||||
string(APPEND _cfg_defaults_str "\n \"${_line}\",")
|
||||
endforeach(_line)
|
||||
endforeach(_cfg_file_path)
|
||||
|
||||
string(APPEND _cfg_defaults_str "};")
|
||||
set(_old_cfg_defaults_str "")
|
||||
|
||||
if(EXISTS ${_cfg_defaults_file})
|
||||
file(READ ${_cfg_defaults_file} _old_cfg_defaults_str)
|
||||
endif()
|
||||
|
||||
if(NOT _cfg_defaults_str STREQUAL _old_cfg_defaults_str)
|
||||
file(WRITE "${_cfg_defaults_file}" "${_cfg_defaults_str}")
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -1,4 +1,4 @@
|
||||
function(get_proto_sources cfg_srcs non_cfg_srcs service_srcs cfg_defaults)
|
||||
function(get_proto_sources cfg_srcs non_cfg_srcs service_srcs)
|
||||
file(
|
||||
GLOB_RECURSE _cfg_srcs
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
@@ -17,19 +17,9 @@ function(get_proto_sources cfg_srcs non_cfg_srcs service_srcs cfg_defaults)
|
||||
)
|
||||
list(REMOVE_ITEM _non_cfg_srcs ${_service_srcs})
|
||||
|
||||
set(_cfg_defaults)
|
||||
foreach(cfg_path ${CONFIG_DEFAULTS_PATH})
|
||||
file(
|
||||
GLOB_RECURSE cfg_files
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${PROJECT_NAME}/${cfg_path})
|
||||
list(APPEND _cfg_defaults ${cfg_files})
|
||||
endforeach()
|
||||
|
||||
set(${cfg_srcs} ${_cfg_srcs} PARENT_SCOPE)
|
||||
set(${non_cfg_srcs} ${_non_cfg_srcs} PARENT_SCOPE)
|
||||
set(${service_srcs} ${_service_srcs} PARENT_SCOPE)
|
||||
set(${cfg_defaults} ${_cfg_defaults} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(get_cpp_sources dest)
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
function(get_proto_sources cfg_srcs non_cfg_srcs service_srcs cfg_defaults)
|
||||
function(get_proto_sources cfg_srcs non_cfg_srcs service_srcs)
|
||||
file(
|
||||
GLOB_RECURSE _cfg_srcs
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${PROJECT_NAME}/config/protos/*.proto
|
||||
${PROJECT_NAME}/api/md/MarketDataConfig.proto)
|
||||
${PROJECT_NAME}/api/md/MarketDataConfig.proto
|
||||
)
|
||||
list(APPEND _cfg_srcs
|
||||
system/protobufs/config/system_config.proto
|
||||
system/protobufs/config/threads.proto
|
||||
system/protobufs/logging.proto
|
||||
domain/protobufs/security_metadata_collection.proto
|
||||
)
|
||||
file(
|
||||
GLOB_RECURSE _service_srcs
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
@@ -12,21 +19,10 @@ function(get_proto_sources cfg_srcs non_cfg_srcs service_srcs cfg_defaults)
|
||||
GLOB_RECURSE _non_cfg_srcs
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${PROJECT_NAME}/*.proto)
|
||||
list(REMOVE_ITEM _non_cfg_srcs ${_service_srcs} ${_cfg_srcs})
|
||||
|
||||
set(_cfg_defaults)
|
||||
foreach(cfg_path ${CONFIG_DEFAULTS_PATH})
|
||||
file(
|
||||
GLOB_RECURSE cfg_files
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${PROJECT_NAME}/${cfg_path})
|
||||
list(APPEND _cfg_defaults ${cfg_files})
|
||||
endforeach()
|
||||
|
||||
list(REMOVE_ITEM _non_cfg_srcs ${_service_srcs})
|
||||
set(${cfg_srcs} ${_cfg_srcs} PARENT_SCOPE)
|
||||
set(${non_cfg_srcs} ${_non_cfg_srcs} PARENT_SCOPE)
|
||||
set(${service_srcs} ${_service_srcs} PARENT_SCOPE)
|
||||
set(${cfg_defaults} ${_cfg_defaults} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(get_cpp_sources dest)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
function(get_proto_sources cfg_srcs non_cfg_srcs service_srcs cfg_defaults)
|
||||
function(get_proto_sources cfg_srcs non_cfg_srcs service_srcs)
|
||||
file(
|
||||
GLOB_RECURSE _cfg_srcs
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
@@ -14,25 +14,9 @@ function(get_proto_sources cfg_srcs non_cfg_srcs service_srcs cfg_defaults)
|
||||
*.proto)
|
||||
list(REMOVE_ITEM _non_cfg_srcs ${_service_srcs} ${_cfg_srcs})
|
||||
|
||||
file(
|
||||
GLOB_RECURSE _cfg_defaults
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CONFIG_DEFAULTS_PATH})
|
||||
|
||||
set(_cfg_defaults)
|
||||
|
||||
foreach(cfg_path ${CONFIG_DEFAULTS_PATH})
|
||||
file(
|
||||
GLOB_RECURSE cfg_files
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${cfg_path})
|
||||
list(APPEND _cfg_defaults ${cfg_files})
|
||||
endforeach()
|
||||
|
||||
set(${cfg_srcs} ${_cfg_srcs} PARENT_SCOPE)
|
||||
set(${non_cfg_srcs} ${_non_cfg_srcs} PARENT_SCOPE)
|
||||
set(${service_srcs} ${_service_srcs} PARENT_SCOPE)
|
||||
set(${cfg_defaults} ${_cfg_defaults} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(get_cpp_sources dest)
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "spark/api/apicore.pb.h"
|
||||
#include "spark/config/protos/ports.pb.h"
|
||||
#include "spark/config/protos/quickbus_cfg.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <excpt.h>
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
#include "spark/utils/windows_wrapper.h"
|
||||
|
||||
#include "ConfigDownloader.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "spark/utils/bts_assert.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace bts {
|
||||
namespace config {
|
||||
namespace internal {
|
||||
|
||||
ConfigDownloader::ConfigDownloader() : _curl(NULL) {
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
_curl = curl_easy_init();
|
||||
bts_assert(_curl);
|
||||
}
|
||||
|
||||
ConfigDownloader::~ConfigDownloader() { curl_easy_cleanup(_curl); }
|
||||
|
||||
size_t curl_write(char *buffer, size_t size, size_t count, void *stream) {
|
||||
stringstream *out = static_cast<stringstream *>(stream);
|
||||
bts_assert(out);
|
||||
size_t bytes = size * count;
|
||||
out->write(buffer, bytes);
|
||||
return count;
|
||||
}
|
||||
|
||||
bool is_http(const string &url) { return url.substr(0, 7) == "http://"; }
|
||||
|
||||
int no_linger(void *, curl_socket_t socket, curlsocktype) {
|
||||
linger l;
|
||||
l.l_onoff = 1;
|
||||
l.l_linger = 0;
|
||||
setsockopt(socket, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l));
|
||||
return CURL_SOCKOPT_OK;
|
||||
}
|
||||
|
||||
ConfigDownloader::Result
|
||||
ConfigDownloader::get(const string &url, stringstream &out_stream) {
|
||||
curl_easy_setopt(_curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, curl_write);
|
||||
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, &out_stream);
|
||||
curl_easy_setopt(_curl, CURLOPT_VERBOSE, 0);
|
||||
curl_easy_setopt(_curl, CURLOPT_FAILONERROR, 1);
|
||||
curl_easy_setopt(_curl, CURLOPT_CONNECTTIMEOUT, 6);
|
||||
curl_easy_setopt(_curl, CURLOPT_SOCKOPTFUNCTION, no_linger);
|
||||
|
||||
CURLcode res = curl_easy_perform(_curl);
|
||||
|
||||
long http_code = 0;
|
||||
CURLcode r2 = curl_easy_getinfo(_curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||
bts_assert(r2 == CURLE_OK);
|
||||
|
||||
bool used_http = is_http(url);
|
||||
if (res == CURLE_OK && (http_code == 200 || !used_http)) {
|
||||
return SUCCESS;
|
||||
} else if (
|
||||
res == CURLE_OPERATION_TIMEDOUT || res == CURLE_COULDNT_RESOLVE_HOST ||
|
||||
res == CURLE_COULDNT_RESOLVE_PROXY || res == CURLE_COULDNT_CONNECT ||
|
||||
res == CURLE_REMOTE_ACCESS_DENIED || res == CURLE_FTP_CANT_GET_HOST) {
|
||||
// Cannot rely on logging before config is initialized
|
||||
// LOG(Error, Config) << "Permanent failure loading '" << url << "' - CURL
|
||||
// error: " << curl_easy_strerror(res);
|
||||
return PERMANENT_FAILURE;
|
||||
}
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace config
|
||||
} // namespace bts
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "ConfigQuerier.h"
|
||||
#include "spark/config/ConfigQueryErrors.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/text_format/text_format.h"
|
||||
#include "system/bts_export.h"
|
||||
#include "system/config/config_query_errors.h"
|
||||
#include "system/config/text_format/text_format.h"
|
||||
#include "system/enum_macros.h"
|
||||
#include "system/time_stamp.h"
|
||||
|
||||
|
||||
@@ -2,13 +2,17 @@
|
||||
#define CONFIG_H_
|
||||
|
||||
#include "config.h"
|
||||
#include "ConfigurationState.h"
|
||||
#include "system/bts_array_size.h"
|
||||
#include "system/config/configuration_state.h"
|
||||
#include "spark/protobufs/config_proto_files.h"
|
||||
#include "spark/protobufs/config_defaults.h"
|
||||
#include "system/os.h"
|
||||
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/descriptor.pb.h>
|
||||
#include <google/protobuf/dynamic_message.h>
|
||||
#include <google/protobuf/text_format.h>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
//#include <boost/thread.hpp>
|
||||
@@ -20,14 +24,37 @@ namespace config {
|
||||
|
||||
using std::string;
|
||||
|
||||
internal::ConfigurationState config_state;
|
||||
std::optional<internal::ConfigurationState> config_state_;
|
||||
|
||||
internal::ConfigurationState &config_state() {
|
||||
if (!config_state_) {
|
||||
static std::mutex mtx;
|
||||
static std::lock_guard<std::mutex> lck{mtx};
|
||||
if (!config_state_) {
|
||||
std::vector<std::string> proto_files_vec;
|
||||
proto_files_vec.reserve(spark::protobufs::config_proto_files.size());
|
||||
for (const char * str : spark::protobufs::config_proto_files) {
|
||||
proto_files_vec.emplace_back(str);
|
||||
}
|
||||
std::string defaults_str;
|
||||
// Estimate defaults_str length (30 * num_lines)
|
||||
defaults_str.reserve(30 * BTS_ARRAYSIZE(config_static_defaults));
|
||||
for (const char * line : config_static_defaults) {
|
||||
defaults_str.append(line);
|
||||
defaults_str.append("\n");
|
||||
}
|
||||
config_state_.emplace(proto_files_vec, defaults_str);
|
||||
}
|
||||
}
|
||||
return *config_state_;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////
|
||||
// Public API
|
||||
//////////////////////////////////////////
|
||||
|
||||
extern "C" BTS_EXPORT void initialize(const char *config_source) {
|
||||
config_state.initialize_settings(string{config_source});
|
||||
config_state().initialize_settings(string{config_source});
|
||||
}
|
||||
|
||||
extern "C" BTS_EXPORT bool initialize_nothrow(
|
||||
@@ -47,20 +74,20 @@ extern "C" BTS_EXPORT bool initialize_nothrow(
|
||||
// extern "C"
|
||||
const proto::Message &get_message(
|
||||
const google::protobuf::Descriptor *descriptor) {
|
||||
return config_state.get_message(descriptor);
|
||||
return config_state().get_message(descriptor);
|
||||
}
|
||||
|
||||
std::vector<const google::protobuf::FieldDescriptor *> get_fields(
|
||||
const std::vector<std::string> keys,
|
||||
const std::vector<std::string> excluded_keys) {
|
||||
return config_state.get_fields(keys, excluded_keys);
|
||||
return config_state().get_fields(keys, excluded_keys);
|
||||
}
|
||||
|
||||
std::vector<const google::protobuf::Message *> get_messages(
|
||||
const std::vector<std::string> keys,
|
||||
const std::vector<std::string> excluded_keys,
|
||||
std::vector<std::string> *unknown_keys) {
|
||||
return config_state.get_messages(keys, excluded_keys, unknown_keys);
|
||||
return config_state().get_messages(keys, excluded_keys, unknown_keys);
|
||||
}
|
||||
|
||||
namespace interop {
|
||||
@@ -87,11 +114,11 @@ extern "C" BTS_EXPORT const char *get_buffer(
|
||||
}
|
||||
|
||||
extern "C" BTS_EXPORT const proto::Message *get_named(const char *key_name) {
|
||||
return config_state.try_get_message_or_default(key_name);
|
||||
return config_state().try_get_message_or_default(key_name);
|
||||
}
|
||||
|
||||
BTS_EXPORT std::string get_macro_string(const char *name) {
|
||||
return config_state.get_macro_string(name);
|
||||
return config_state().get_macro_string(name);
|
||||
}
|
||||
|
||||
} // namespace interop
|
||||
@@ -106,15 +133,16 @@ extern "C" BTS_EXPORT void initialize_for_test(const char *config) {
|
||||
initialize_for_test(std::string(config), false);
|
||||
}
|
||||
void initialize_for_test(const std::string &values, bool print_errors) {
|
||||
config_state.reset();
|
||||
config_state.load_string(values, print_errors);
|
||||
config_state().reset();
|
||||
config_state().load_string(values, print_errors);
|
||||
}
|
||||
|
||||
extern "C" BTS_EXPORT void reset() { config_state.reset(); }
|
||||
extern "C" BTS_EXPORT void reset() { config_state().reset(); }
|
||||
|
||||
extern "C" BTS_EXPORT bool check_rules(char *error_msg, size_t len) {
|
||||
try {
|
||||
config_state.check_rules();
|
||||
initialize("");
|
||||
config_state().check_rules();
|
||||
} catch (std::exception &e) {
|
||||
std::string msg = e.what();
|
||||
if (msg.size() < len) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef BTS_CONFIG_H_
|
||||
#define BTS_CONFIG_H_
|
||||
|
||||
#include "spark/utils/bts_export.h"
|
||||
#include "system/bts_export.h"
|
||||
#include "system/checked_cast.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "spark/utils/TempDir.h"
|
||||
#include "spark/utils/TempFile.h"
|
||||
|
||||
#include "../ConfigurationException.h"
|
||||
#include "../ConfigurationState.h"
|
||||
#include "../config.h"
|
||||
#include "spark/config/invalid/invalid.pb.h"
|
||||
#include "spark/config/protos/testkeys.pb.h"
|
||||
#include "spark/expression/ParserExceptions.h"
|
||||
#include "system/expression/parser_exceptions.h"
|
||||
#include "system/config/configuration_exception.h"
|
||||
#include "system/config/configuration_state.h"
|
||||
|
||||
#include "HTTPServer.h"
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#include "spark/utils/TempFile.h"
|
||||
|
||||
#include "../ConfigurationException.h"
|
||||
#include "../ConfigurationState.h"
|
||||
#include "../config.h"
|
||||
#include "spark/expression/ParserExceptions.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/is_unittest_environment.h"
|
||||
#include "system/config/configuration_exception.h"
|
||||
#include "system/config/configuration_state.h"
|
||||
#include "system/expression/parser_exceptions.h"
|
||||
|
||||
#include "HTTPServer.h"
|
||||
|
||||
#include "spark/config/invalid/invalid.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/config/protos/testkeys.pb.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <iostream>
|
||||
@@ -30,6 +30,7 @@ namespace proto = google::protobuf;
|
||||
using bts::config::test::Foo;
|
||||
using bts::config::test::FooGroup;
|
||||
using bts::config::test::StringTable;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
namespace bts {
|
||||
int config_tests = 0;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "FIXFileStore.h"
|
||||
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/jetfix/codec/FIXEncodingStream.h"
|
||||
#include "spark/jetfix/common/InMsgBuffer.h"
|
||||
#include "spark/jetfix/common/OutFIX.h"
|
||||
@@ -11,6 +10,7 @@
|
||||
#include "spark/utils/file_utils.h"
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/date_time.hpp>
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
@@ -25,6 +25,8 @@
|
||||
namespace bts {
|
||||
namespace jetfix {
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
struct FIXFileStore::Event {
|
||||
Event()
|
||||
: out_msgs(), in_msg(), quit(false), has_last_msg_processed(false),
|
||||
@@ -108,7 +110,7 @@ std::string store_path(
|
||||
std::string const &connection_name,
|
||||
std::string const &session_name) {
|
||||
if (base_path.empty()) {
|
||||
base_path = config::get<config::SystemConfig>().data_path();
|
||||
base_path = config::get<SystemConfig>().data_path();
|
||||
}
|
||||
boost::filesystem::path result = utils::normalize_data_path(base_path);
|
||||
result /= "jetfix";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "MDPeriodicDumper.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/md/MDConsumer.h"
|
||||
#include "spark/md/SecurityCache.h"
|
||||
#include "spark/utils/Dispatcher.h"
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/market_data.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/domain_model/Security.h"
|
||||
#include "spark/md/Shm/FixedSecurity.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/container/flat_set.hpp>
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
@@ -25,6 +25,8 @@ namespace bts {
|
||||
namespace md {
|
||||
namespace db {
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
/*
|
||||
* Schema:
|
||||
* key, created_date, expiration_date
|
||||
@@ -32,8 +34,7 @@ namespace db {
|
||||
|
||||
std::unique_ptr<SQLite::Database> open_db() {
|
||||
// Directory location on disk
|
||||
auto db_dir =
|
||||
config::get<config::SystemConfig>().data_path() + "databases/md/";
|
||||
auto db_dir = config::get<SystemConfig>().data_path() + "databases/md/";
|
||||
auto db_path = db_dir + "/securities.sqlite";
|
||||
if (!boost::filesystem::exists(db_dir)) {
|
||||
boost::filesystem::create_directories(db_dir);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <tbb/concurrent_queue.h>
|
||||
|
||||
#include "spark/config/protos/market_data.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <memory>
|
||||
#include <sqlite/sqlite3.h>
|
||||
@@ -32,7 +32,7 @@ namespace md {
|
||||
using bts::api::Security;
|
||||
using bts::api::SecurityType;
|
||||
using bts::api::Venue;
|
||||
using bts::config::SystemConfig;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
using bts::persistence::IStore;
|
||||
using bts::persistence::SqliteStore;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#ifndef _WIN32
|
||||
#include "SettlementRecorder.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/utils/Sqlite_utils.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
@@ -13,6 +14,7 @@
|
||||
namespace bts {
|
||||
namespace co2 {
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
using datetime::Date;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
@@ -84,8 +86,7 @@ void apply_work(SettlementRecorderImpl &me, Work work) {
|
||||
}
|
||||
|
||||
SettlementRecorder::SettlementRecorder() : _self(new SettlementRecorderImpl()) {
|
||||
string db_dir =
|
||||
config::get<config::SystemConfig>().data_path() + "databases/md/";
|
||||
string db_dir = config::get<SystemConfig>().data_path() + "databases/md/";
|
||||
string db_path = db_dir + "/settlements.sqlite";
|
||||
if (!boost::filesystem::exists(db_dir)) {
|
||||
boost::filesystem::create_directories(db_dir);
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/deployment_type.pb.h"
|
||||
#include "spark/config/protos/market_data.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/md/SymbolLoader.h"
|
||||
#include "spark/utils/bts_chrono.h"
|
||||
#include "spark/utils/datetime.h"
|
||||
#include "spark/utils/download.h"
|
||||
#include "system/FMT.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <iostream>
|
||||
@@ -25,9 +25,10 @@ namespace bts {
|
||||
namespace md {
|
||||
|
||||
using bts::domain::SecurityCriteria;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
string data_path() {
|
||||
auto p = config::get<config::SystemConfig>().data_path() + "cme_mdp3/";
|
||||
auto p = config::get<SystemConfig>().data_path() + "cme_mdp3/";
|
||||
os::normalize_path(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
#include "system/spark_data_directory.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
@@ -28,7 +28,8 @@ struct Mdp3DataDirectory {
|
||||
}
|
||||
|
||||
private:
|
||||
spark::SparkDataDirectory root{config::get<config::SystemConfig>().data_path()};
|
||||
spark::SparkDataDirectory root{
|
||||
config::get<system::protobufs::SystemConfig>().data_path()};
|
||||
};
|
||||
|
||||
} // namespace bts::md
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
#include "spark/config/protos/deployment_type.pb.h"
|
||||
#include "spark/config/protos/market_data.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <pugixml/pugixml.hpp>
|
||||
@@ -24,6 +24,7 @@ namespace md {
|
||||
namespace ice {
|
||||
|
||||
using bts::domain::SecurityCriteria;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
std::string ICEChannel::to_string() const {
|
||||
std::string mt = name;
|
||||
@@ -57,7 +58,7 @@ const vector<ICEChannel> parse_ice_channels(const vector<UserSymbol> &symbols) {
|
||||
}
|
||||
|
||||
string ice_data_path() {
|
||||
auto p = config::get<config::SystemConfig>().data_path() + "onixs_ice/";
|
||||
auto p = config::get<SystemConfig>().data_path() + "onixs_ice/";
|
||||
os::normalize_path(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
#include "spark/api/services/AdminService.client.pb.h"
|
||||
#include "spark/api/services/MarketDataRelay.server.pb.h"
|
||||
#include "spark/config/protos/cme_reference_data.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/md/SecurityCache.h"
|
||||
#include "spark/md/protos/co2.pb.h"
|
||||
#include "spark/utils/ConcurrentAppendCollection.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
#ifndef _WIN32
|
||||
#include "spark/metrics/metrics.h"
|
||||
#endif
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
#include "spark/api/public/ServiceContext.h"
|
||||
#include "spark/api/services/MarketDataRelay.client.pb.h"
|
||||
#include "spark/config/protos/market_data.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/md/protos/co2.pb.h"
|
||||
#include "spark/utils/base64.hpp"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -33,6 +33,8 @@ namespace bts {
|
||||
namespace md {
|
||||
using namespace co2;
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
PriceSize convert(const PriceSizeMessage &psm) {
|
||||
return psm.size() > 0
|
||||
? PriceSize({psm.mantissa(), (int8_t)psm.exponent()}, psm.size())
|
||||
@@ -192,8 +194,8 @@ class RelayClient {
|
||||
: _request(), _rpc(rpc), _pconsumer(pconsumer), _writer(writer),
|
||||
_request_log(utils::TimeStamp::now()) {
|
||||
ostringstream fmt;
|
||||
fmt << config::get<config::SystemConfig>().host_name() << "("
|
||||
<< os::process_id() << ")";
|
||||
fmt << config::get<SystemConfig>().host_name() << "(" << os::process_id()
|
||||
<< ")";
|
||||
_request.set_host(fmt.str());
|
||||
for (const auto &s : symbols) {
|
||||
SecurityChannel ch;
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
#include "spark/utils/datetime.h"
|
||||
|
||||
#include "spark/config/protos/market_data.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/md/SecurityIDRecorder.h"
|
||||
#include "spark/md/common.h"
|
||||
#include "spark/md/protos/co2.pb.h"
|
||||
#include "spark/utils/bts_chrono.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <google/protobuf/text_format.h>
|
||||
@@ -26,6 +26,8 @@ using namespace bts::co2;
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
const char *magic = "Co2";
|
||||
const uint32_t recorder_version = 3;
|
||||
|
||||
@@ -62,7 +64,7 @@ RelayRecorder::RelayRecorder(
|
||||
header.set_magic(magic);
|
||||
header.set_version(recorder_version);
|
||||
header.set_timestamp(datetime::ll_now());
|
||||
header.set_host(config::get<config::SystemConfig>().config_host());
|
||||
header.set_host(config::get<SystemConfig>().config_host());
|
||||
header.set_naggle_ms(naggle);
|
||||
writebuf(_file, header);
|
||||
}
|
||||
@@ -293,7 +295,7 @@ void unprint_recording(const std::string &src, const std::string &dest) {
|
||||
header.set_magic(magic);
|
||||
header.set_version(recorder_version);
|
||||
header.set_timestamp(datetime::ll_now());
|
||||
header.set_host(config::get<config::SystemConfig>().host_name());
|
||||
header.set_host(config::get<SystemConfig>().host_name());
|
||||
writebuf(out, header);
|
||||
|
||||
int index = 0;
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
#include "OnixsUtils.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/market_data.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
using bts::config::SystemConfig;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
using Path = boost::filesystem::path;
|
||||
|
||||
// The onixs checksum includes the line endings as \r\n
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "system_metrics.h"
|
||||
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
@@ -11,6 +11,8 @@
|
||||
namespace bts {
|
||||
namespace metrics {
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
struct ProcessStats {
|
||||
int pid;
|
||||
std::string name, state, ppid, pgrp, session, tty_nr;
|
||||
@@ -55,7 +57,7 @@ void publish_system_metrics(MetricsContainer &stats) {
|
||||
auto version = std::make_shared<CounterMetric<int>>(
|
||||
"spark_version",
|
||||
std::vector<Label>(
|
||||
{{"version", config::get<config::SystemConfig>().version()}}));
|
||||
{{"version", config::get<SystemConfig>().version()}}));
|
||||
version->set(1);
|
||||
stats.publish(version);
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "SessionStore.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/jetfix/store/session_name.h"
|
||||
#include "spark/orderman/ilink3/IL3GW.h"
|
||||
#include "spark/orderman/ilink3/IL3SecDB.h"
|
||||
@@ -9,6 +8,7 @@
|
||||
#include "spark/utils/file_utils.h"
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <fstream>
|
||||
@@ -20,6 +20,7 @@ namespace bts {
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
using Action = std::function<void()>;
|
||||
|
||||
static std::string base_store_path(
|
||||
@@ -27,7 +28,7 @@ static std::string base_store_path(
|
||||
std::string const &connection_name,
|
||||
std::string const &session_name) {
|
||||
if (base_path.empty()) {
|
||||
base_path = config::get<config::SystemConfig>().data_path();
|
||||
base_path = config::get<SystemConfig>().data_path();
|
||||
}
|
||||
boost::filesystem::path result = utils::normalize_data_path(base_path);
|
||||
result /= "ilink3";
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "SqliteStore.h"
|
||||
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/persistence/persistence_utils.h"
|
||||
#include "spark/utils/Sqlite_utils.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
@@ -11,6 +10,7 @@
|
||||
#include "spark/utils/file_utils.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <sqlite/sqlite3.h>
|
||||
@@ -18,7 +18,7 @@
|
||||
namespace bts {
|
||||
namespace persistence {
|
||||
|
||||
using bts::config::SystemConfig;
|
||||
using system::protobufs::SystemConfig;
|
||||
|
||||
static boost::filesystem::path get_db_path(const std::string &str) {
|
||||
for (char c : str) {
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "spark/persistence/persistence_utils.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/utils/file_utils.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace bts {
|
||||
namespace persistence {
|
||||
|
||||
using bts::config::SystemConfig;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
std::string
|
||||
storage_location(std::string const &db, std::string const &store_root) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "spark/tracing/PerfLog.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/perflog_cfg.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/persistence/persistence_utils.h"
|
||||
#include "spark/utils/datetime.h"
|
||||
#include "spark/utils/stats.h"
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "system/bts_array_size.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <SQLiteCpp/SQLiteCpp.h>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
@@ -24,6 +24,8 @@
|
||||
namespace bts {
|
||||
namespace trace {
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
const char *PerfLog::get_thread_name() {
|
||||
char *thread_name_buffer = new char[17];
|
||||
pthread_getname_np(pthread_self(), thread_name_buffer, 16);
|
||||
@@ -134,9 +136,9 @@ PerfLog::PerfLog() : _pending(), _disabled(false), me() {
|
||||
me->session_start = datetime::FIX_timestamp(datetime::local_now());
|
||||
|
||||
me->insert_session_statement->bind(
|
||||
":version", config::get<config::SystemConfig>().version());
|
||||
":version", config::get<SystemConfig>().version());
|
||||
me->insert_session_statement->bind(
|
||||
":host", config::get<config::SystemConfig>().host_name());
|
||||
":host", config::get<SystemConfig>().host_name());
|
||||
#ifdef DEBUG
|
||||
me->insert_session_statement->bind(":build_type", "debug");
|
||||
#else
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#ifndef _WIN32
|
||||
#include "Puid.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include "../utils/bts_assert.h"
|
||||
#include "Uuid.h"
|
||||
@@ -26,7 +26,7 @@
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
|
||||
using bts::config::SystemConfig;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
using DirectoryIterator = boost::filesystem::directory_iterator;
|
||||
using Path = boost::filesystem::path;
|
||||
|
||||
@@ -160,7 +160,7 @@ uint64_t reserve_ids(std::string const &scope, int n_ids) {
|
||||
// we risk race conditions if the directory is not there.
|
||||
// but that's OK, this is rare and easily manageable.
|
||||
const auto path =
|
||||
Path{config::get<config::SystemConfig>().data_path()} / "puids" / scope;
|
||||
Path{config::get<SystemConfig>().data_path()} / "puids" / scope;
|
||||
auto lock_path = path / lock_file_name;
|
||||
auto counter_path = path / counter_file_name;
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#ifndef BTS_EDGE
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/deployment_type.pb.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/datetime.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
#else
|
||||
#include "bts_assert.h"
|
||||
#include "core/bts_core/config/config.h"
|
||||
@@ -35,6 +35,8 @@ using std::string;
|
||||
namespace bts {
|
||||
namespace glbx {
|
||||
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
bool is_expired(const string &expiration) {
|
||||
char_separator<char> sep("-\\");
|
||||
tokenizer<char_separator<char>> tokens(expiration, sep);
|
||||
@@ -49,8 +51,7 @@ bool is_expired(const string &expiration) {
|
||||
|
||||
std::tuple<string, string> load_session_keys(const string &session) {
|
||||
using namespace boost::filesystem;
|
||||
auto path = bts::config::get<bts::config::SystemConfig>().data_path() +
|
||||
"glbx_logon/";
|
||||
auto path = bts::config::get<SystemConfig>().data_path() + "glbx_logon/";
|
||||
|
||||
// we try to make it easier to run cert by copying the cert secure
|
||||
// logon file to the right place if in dev
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include "system/logging/logging.h"
|
||||
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <fstream>
|
||||
@@ -45,7 +45,8 @@ struct ALIGNED_(CACHE_LINE) SegmentHeader {
|
||||
|
||||
inline bool should_share(bool desire_shared) {
|
||||
using namespace bts::config;
|
||||
return desire_shared && !get<SystemConfig>().unittest_environment();
|
||||
return desire_shared &&
|
||||
!get<system::protobufs::SystemConfig>().unittest_environment();
|
||||
}
|
||||
|
||||
// Single writer, single thread!
|
||||
|
||||
@@ -1,252 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace bts {
|
||||
namespace util {
|
||||
namespace proto {
|
||||
|
||||
//
|
||||
// set<T>()
|
||||
|
||||
// template <typename T>
|
||||
// void set(
|
||||
// google::protobuf::Message *,
|
||||
// const google::protobuf::Reflection *,
|
||||
// const google::protobuf::FieldDescriptor *,
|
||||
// T) {
|
||||
// bts_assert(false);
|
||||
// #ifdef _MSC_VER
|
||||
// BOOST_STATIC_ASSERT(false);
|
||||
// #endif
|
||||
// }
|
||||
|
||||
// template <>
|
||||
inline void set(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
double value) {
|
||||
reflection->SetDouble(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void set(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
float value) {
|
||||
reflection->SetFloat(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void set(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
int value) {
|
||||
reflection->SetInt32(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void set(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
int64_t value) {
|
||||
reflection->SetInt64(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void set(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
uint64_t value) {
|
||||
reflection->SetUInt64(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void set(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
uint32_t value) {
|
||||
reflection->SetUInt32(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void set(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
bool value) {
|
||||
reflection->SetBool(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void set(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
std::string value) {
|
||||
reflection->SetString(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void set(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
const google::protobuf::EnumValueDescriptor *value) {
|
||||
reflection->SetEnum(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void set(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
const google::protobuf::Message *msg) {
|
||||
bts_assert(msg);
|
||||
reflection->MutableMessage(message, field)->CopyFrom(*msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Add<T>
|
||||
|
||||
// template <typename T>
|
||||
// void add(
|
||||
// google::protobuf::Message *,
|
||||
// const google::protobuf::Reflection *,
|
||||
// const google::protobuf::FieldDescriptor *,
|
||||
// T) {
|
||||
// bts_assert(false);
|
||||
// #ifdef _MSC_VER
|
||||
// BOOST_STATIC_ASSERT(false);
|
||||
// #endif
|
||||
// }
|
||||
|
||||
// template <>
|
||||
inline void add(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
double value) {
|
||||
reflection->AddDouble(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void add(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
float value) {
|
||||
reflection->AddFloat(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void add(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
int value) {
|
||||
reflection->AddInt32(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void add(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
int64_t value) {
|
||||
reflection->AddInt64(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void add(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
uint64_t value) {
|
||||
reflection->AddUInt64(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void add(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
uint32_t value) {
|
||||
reflection->AddUInt32(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void add(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
bool value) {
|
||||
reflection->AddBool(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void add(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
std::string value) {
|
||||
reflection->AddString(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void add(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
const google::protobuf::EnumValueDescriptor *value) {
|
||||
reflection->AddEnum(message, field, value);
|
||||
}
|
||||
|
||||
// template <>
|
||||
inline void add(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
const google::protobuf::Message *msg) {
|
||||
bts_assert(msg);
|
||||
reflection->AddMessage(message, field)->CopyFrom(*msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Assignment
|
||||
|
||||
template <class T>
|
||||
void set_field(
|
||||
google::protobuf::Message *message,
|
||||
const google::protobuf::Reflection *reflection,
|
||||
const google::protobuf::FieldDescriptor *field,
|
||||
T value,
|
||||
int &index) {
|
||||
if (field->is_repeated()) {
|
||||
int size = reflection->FieldSize(*message, field);
|
||||
add(message, reflection, field, value);
|
||||
if (index != size) {
|
||||
for (int i = index; i < size; ++i) {
|
||||
reflection->SwapElements(message, field, i, size);
|
||||
}
|
||||
}
|
||||
index++;
|
||||
} else {
|
||||
set(message, reflection, field, value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace proto
|
||||
} // namespace util
|
||||
} // namespace bts
|
||||
@@ -9,6 +9,7 @@ target_link_libraries(
|
||||
boost_filesystem
|
||||
boost_thread
|
||||
protobuf
|
||||
ssl
|
||||
uuid
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "config_downloader.h"
|
||||
#include "system/facades/bts_assert.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace bts {
|
||||
namespace config {
|
||||
namespace internal {
|
||||
|
||||
ConfigDownloader::ConfigDownloader() : _curl(NULL) {
|
||||
// curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
// _curl = curl_easy_init();
|
||||
bts_assert(_curl);
|
||||
}
|
||||
|
||||
ConfigDownloader::~ConfigDownloader() { /*curl_easy_cleanup(_curl);*/ }
|
||||
|
||||
size_t curl_write(char *buffer, size_t size, size_t count, void *stream) {
|
||||
stringstream *out = static_cast<stringstream *>(stream);
|
||||
bts_assert(out);
|
||||
size_t bytes = size * count;
|
||||
out->write(buffer, bytes);
|
||||
return count;
|
||||
}
|
||||
|
||||
bool is_http(const string &url) { return url.substr(0, 7) == "http://"; }
|
||||
|
||||
// int no_linger(void *, curl_socket_t socket, curlsocktype) {
|
||||
// linger l;
|
||||
// l.l_onoff = 1;
|
||||
// l.l_linger = 0;
|
||||
// setsockopt(socket, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l));
|
||||
// return CURL_SOCKOPT_OK;
|
||||
// }
|
||||
|
||||
ConfigDownloader::Result
|
||||
ConfigDownloader::get(const string &url, stringstream &out_stream) {
|
||||
(void)url;
|
||||
(void)out_stream;
|
||||
bts_assert_msg(
|
||||
false, "ConfigDownloader temporarily disabled due to libcurl dependency "
|
||||
"conflict");
|
||||
// curl_easy_setopt(_curl, CURLOPT_URL, url.c_str());
|
||||
// curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, curl_write);
|
||||
// curl_easy_setopt(_curl, CURLOPT_WRITEDATA, &out_stream);
|
||||
// curl_easy_setopt(_curl, CURLOPT_VERBOSE, 0);
|
||||
// curl_easy_setopt(_curl, CURLOPT_FAILONERROR, 1);
|
||||
// curl_easy_setopt(_curl, CURLOPT_CONNECTTIMEOUT, 6);
|
||||
// curl_easy_setopt(_curl, CURLOPT_SOCKOPTFUNCTION, no_linger);
|
||||
|
||||
// CURLcode res = curl_easy_perform(_curl);
|
||||
|
||||
// long http_code = 0;
|
||||
// CURLcode r2 = curl_easy_getinfo(_curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||
// bts_assert(r2 == CURLE_OK);
|
||||
|
||||
// bool used_http = is_http(url);
|
||||
// if (res == CURLE_OK && (http_code == 200 || !used_http)) {
|
||||
// return SUCCESS;
|
||||
// } else if (
|
||||
// res == CURLE_OPERATION_TIMEDOUT || res == CURLE_COULDNT_RESOLVE_HOST ||
|
||||
// res == CURLE_COULDNT_RESOLVE_PROXY || res == CURLE_COULDNT_CONNECT ||
|
||||
// res == CURLE_REMOTE_ACCESS_DENIED || res == CURLE_FTP_CANT_GET_HOST) {
|
||||
// // Cannot rely on logging before config is initialized
|
||||
// // LOG(Error, Config) << "Permanent failure loading '" << url << "' - CURL
|
||||
// // error: " << curl_easy_strerror(res);
|
||||
// return PERMANENT_FAILURE;
|
||||
// }
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace config
|
||||
} // namespace bts
|
||||
+6
-4
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
#include <curl/curl.h>
|
||||
// #include <curl/curl.h>
|
||||
#include <string>
|
||||
|
||||
namespace bts {
|
||||
@@ -11,6 +10,8 @@ namespace internal {
|
||||
class ConfigDownloader {
|
||||
public:
|
||||
ConfigDownloader();
|
||||
ConfigDownloader(const ConfigDownloader &) = delete;
|
||||
ConfigDownloader &operator=(const ConfigDownloader &) = delete;
|
||||
~ConfigDownloader();
|
||||
|
||||
enum Result { FAILURE, SUCCESS, PERMANENT_FAILURE };
|
||||
@@ -18,8 +19,9 @@ class ConfigDownloader {
|
||||
Result get(const std::string &url, std::stringstream &out_stream);
|
||||
|
||||
private:
|
||||
BTS_NO_COPY(ConfigDownloader);
|
||||
CURL *_curl;
|
||||
// CURL *_curl;
|
||||
// TODO: resolve libcurl dependency conflict so we can uncomment this
|
||||
void *_curl;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "ConfigErrorCollector.h"
|
||||
#include "config_error_collector.h"
|
||||
#include "system/os.h"
|
||||
|
||||
#include <string>
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "ConfigLog.h"
|
||||
#include "system/config/config_log.h"
|
||||
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/io/tokenizer.h>
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
#include "system/logging/logging.h"
|
||||
#include "system/macros/bts_no_copy.h"
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
File renamed without changes.
+5
-6
@@ -1,9 +1,8 @@
|
||||
#include "ConfigPropertyEvaluator.h"
|
||||
|
||||
#include "ConfigurationState.h"
|
||||
#include "spark/expression/ExpressionEvaluator.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/windows_wrapper.h"
|
||||
#include "config_property_evaluator.h"
|
||||
#include "system/config/configuration_state.h"
|
||||
#include "system/expression/expression_evaluator.h"
|
||||
#include "system/facades/bts_assert.h"
|
||||
#include "system/windows_wrapper.h"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
#ifndef CONFIGPROPERTYEVALUATOR_H_
|
||||
#define CONFIGPROPERTYEVALUATOR_H_
|
||||
|
||||
#include "spark/expression/IPropertyEvaluator.h"
|
||||
#include "spark/expression/Value.h"
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
#include "system/expression/i_property_evaluator.h"
|
||||
#include "system/expression/value.h"
|
||||
#include "system/macros/bts_no_copy.h"
|
||||
|
||||
namespace bts {
|
||||
namespace expression {
|
||||
File renamed without changes.
+19
-18
@@ -1,9 +1,11 @@
|
||||
|
||||
#include "ConfigValueQueue.h"
|
||||
#include "ConfigurationException.h"
|
||||
#include "system/config/config_value_queue.h"
|
||||
#include "system/config/configuration_exception.h"
|
||||
#include "system/facades/bts_assert.h"
|
||||
#include "system/protobufs/proto_helper.h"
|
||||
|
||||
// #include "config.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "spark/utils/proto_helper.h"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
|
||||
@@ -107,26 +109,25 @@ bool ConfigValueQueue::can_process(const std::string &source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_relevant(const proto::Message *message) {
|
||||
if (message) {
|
||||
const proto::Descriptor *desc = message->GetDescriptor();
|
||||
bts_assert_d(desc);
|
||||
const proto::Message &result = config::get_message(desc);
|
||||
return &result == message;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// bool is_relevant(const proto::Message *message) {
|
||||
// if (message) {
|
||||
// const proto::Descriptor *desc = message->GetDescriptor();
|
||||
// const proto::Message &result = config::get_message(desc);
|
||||
// return &result == message;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
void ConfigValueQueue::process_field(const DeferredValue &dv) {
|
||||
Value val;
|
||||
if (_eval.get_value(dv.sourceval, &val)) {
|
||||
assign_value_to_field(dv.message, dv.reflection, dv.field, val, dv.index);
|
||||
} else {
|
||||
if (is_relevant(dv.root_message)) {
|
||||
std::string message = "Error retrieving value for " + dv.sourceval;
|
||||
throw SelfReferenceException(
|
||||
message.c_str(), dv.filename.c_str(), dv.line, dv.col);
|
||||
}
|
||||
// if (is_relevant(dv.root_message)) {
|
||||
// std::string message = "Error retrieving value for " + dv.sourceval;
|
||||
// throw SelfReferenceException(
|
||||
// message.c_str(), dv.filename.c_str(), dv.line, dv.col);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/expression/IPropertyEvaluator.h"
|
||||
#include "spark/expression/Value.h"
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
#include "system/expression/i_property_evaluator.h"
|
||||
#include "system/expression/value.h"
|
||||
#include "system/macros/bts_no_copy.h"
|
||||
#include "text_format/text_format.h"
|
||||
|
||||
#include <string>
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "ConfigurationException.h"
|
||||
#include "system/config/configuration_exception.h"
|
||||
|
||||
namespace bts {
|
||||
namespace config {
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
#ifndef BADCONFIGURATIONEXCEPTION_H_
|
||||
#define BADCONFIGURATIONEXCEPTION_H_
|
||||
|
||||
#include "spark/utils/bts_export.h"
|
||||
#include "system/bts_export.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
+131
-122
@@ -1,18 +1,16 @@
|
||||
#include "ConfigurationState.h"
|
||||
#include "spark/config/ConfigErrorCollector.h"
|
||||
#include "spark/config/ConfigPropertyEvaluator.h"
|
||||
#include "spark/config/ConfigValueQueue.h"
|
||||
#include "spark/config/ConfigurationException.h"
|
||||
#include "spark/config/PreprocessInputStream.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/system_config.pb.h"
|
||||
#include "spark/io/ProtoPrinter.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/defer.h"
|
||||
#include "spark/utils/is_unittest_environment.h"
|
||||
#include "configuration_state.h"
|
||||
// #include "spark/config/config.h"
|
||||
#include "system/config/config_error_collector.h"
|
||||
#include "system/config/config_property_evaluator.h"
|
||||
#include "system/config/config_value_queue.h"
|
||||
#include "system/config/configuration_exception.h"
|
||||
#include "system/config/preprocess_input_stream.h"
|
||||
#include "system/facades/bts_assert.h"
|
||||
#include "system/defer.h"
|
||||
#include "system/FMT.h"
|
||||
#include "system/bts_array_size.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string.hpp> // iequals
|
||||
@@ -30,8 +28,8 @@
|
||||
#define URDL_DISALE_SSL 1
|
||||
#include <urdl/url.hpp>
|
||||
|
||||
#include "spark/config_defaults.h"
|
||||
#include "spark/config_proto_files.h"
|
||||
// #include "spark/config_defaults.h"
|
||||
// #include "system/protobufs/config_proto_files.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Winsock2.h>
|
||||
@@ -55,7 +53,9 @@ namespace internal {
|
||||
logger.is_loggable(level) && \
|
||||
logger.enqueue(level, __FILE__, __LINE__, __VA_ARGS__)
|
||||
|
||||
using bts::io::ProtoPrinter;
|
||||
using bts::system::protobufs::ConfigIntrospection;
|
||||
using bts::system::protobufs::ConfigProto;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
|
||||
const char *MESSAGE_STRING_RULE = "rule";
|
||||
const char *MESSAGE_STRING_VALUE = "value";
|
||||
@@ -67,13 +67,14 @@ const char *CONFIG_SERVER_ENV_VAR = "BTSConfig";
|
||||
|
||||
inline tuple<string, uint32_t> hostname(const std::string &path);
|
||||
|
||||
ConfigurationState::ConfigurationState(void)
|
||||
ConfigurationState::ConfigurationState(
|
||||
const std::vector<std::string> &proto_files, const std::string &defaults)
|
||||
: _is_initialized(false), _initialization_mutex(), _dynamic_pool(),
|
||||
_prototype_factory(), _prototype(nullptr), _config_chain(), _defaults(),
|
||||
_properties(new ConfigPropertyEvaluator(*this)),
|
||||
_rule_engine(_properties), _macros(),
|
||||
_deferred_queue(new ConfigValueQueue(*_properties.get())), _host(),
|
||||
_port(80) {}
|
||||
_port(80), proto_files_(proto_files), defaults_(defaults) {}
|
||||
|
||||
ConfigurationState::~ConfigurationState(void) {}
|
||||
|
||||
@@ -109,31 +110,17 @@ string ConfigurationState::settings_path() {
|
||||
}
|
||||
|
||||
void ConfigurationState::initialize_defaults(ConfigLog &log) {
|
||||
initialize_defaults(log, {"spark/config/protos/", "spark/api/md/"});
|
||||
}
|
||||
|
||||
void ConfigurationState::initialize_defaults(
|
||||
ConfigLog &log, const std::vector<std::string> &proto_dirs) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_initialization_mutex);
|
||||
if (_is_initialized)
|
||||
return;
|
||||
|
||||
CFG_LOG(
|
||||
log, Info,
|
||||
"Initializing config defaults with files from the following dirs: {}",
|
||||
FMT_JOIN(proto_dirs, ", "));
|
||||
generate_all_config_proto(log, proto_dirs);
|
||||
CFG_LOG(log, Info, "Initializing config defaults");
|
||||
generate_all_config_proto(log);
|
||||
|
||||
std::shared_ptr<proto::Message> new_message(_prototype->New());
|
||||
|
||||
std::string defaults;
|
||||
for (const char *str : config_static_defaults) {
|
||||
defaults += str;
|
||||
defaults += "\n";
|
||||
}
|
||||
|
||||
proto::io::ArrayInputStream input_stream(
|
||||
defaults.c_str(), (int)defaults.length());
|
||||
defaults_.c_str(), (int)defaults_.length());
|
||||
parse_stream(
|
||||
"static_defaults.conf", input_stream, *new_message.get(), log,
|
||||
*_deferred_queue.get());
|
||||
@@ -151,7 +138,7 @@ void ConfigurationState::initialize_builtins(ConfigLog *log) {
|
||||
sys.set_process_name(os::get_application_name());
|
||||
sys.set_directory(os::get_install_path());
|
||||
sys.set_platform(os::platform_name());
|
||||
sys.set_unittest_environment(utils::internal::is_unittest_environment());
|
||||
// sys.set_unittest_environment(utils::internal::is_unittest_environment());
|
||||
sys.set_config_path(os::app_data_path("conf/").string());
|
||||
sys.set_data_path(os::app_data_path("data/").string());
|
||||
sys.set_os_user(os::username());
|
||||
@@ -217,7 +204,7 @@ void ConfigurationState::initialize_builtins(ConfigLog *log) {
|
||||
if (log != nullptr) {
|
||||
CFG_LOG(
|
||||
(*log), Info, "Initialized SystemConfig:\n{}",
|
||||
ProtoPrinter::to_string(sys, 2));
|
||||
sys.DebugString());
|
||||
}
|
||||
|
||||
//
|
||||
@@ -250,9 +237,9 @@ void ConfigurationState::initialize_introspection() {
|
||||
// that another language can request "all" of config
|
||||
ConfigIntrospection ci;
|
||||
proto::DescriptorPool::generated_pool();
|
||||
for (size_t x = 0; x < BTS_ARRAYSIZE(config_proto_files); x++) {
|
||||
for (size_t x = 0; x < proto_files_.size(); x++) {
|
||||
std::string proto_path = "core/bts_core/config/";
|
||||
proto_path += config_proto_files[x];
|
||||
proto_path += proto_files_[x];
|
||||
const proto::FileDescriptor *file_desc =
|
||||
proto::DescriptorPool::generated_pool()->FindFileByName(proto_path);
|
||||
if (file_desc != nullptr) {
|
||||
@@ -365,7 +352,6 @@ void check_rule(
|
||||
}
|
||||
|
||||
void ConfigurationState::check_rules() {
|
||||
initialize("");
|
||||
std::vector<std::shared_ptr<proto::Message>>::iterator iter;
|
||||
for (iter = _config_chain.begin(); iter != _config_chain.end(); ++iter) {
|
||||
proto::Message *message = (*iter).get();
|
||||
@@ -429,7 +415,8 @@ int ConfigurationState::load(const std::string &url, ConfigLog &log) {
|
||||
|
||||
bool loaded = false;
|
||||
CFG_LOG(log, Info, "Loading '{}'", url);
|
||||
loaded = load_message(url, *new_message.get(), log, *_deferred_queue.get());
|
||||
loaded = load_message(
|
||||
url, *new_message.get(), log, *_deferred_queue.get(), proto_files_);
|
||||
if (_host.empty() || _host == "localhost") {
|
||||
const auto old_host = _host;
|
||||
const auto old_port = _port;
|
||||
@@ -523,14 +510,37 @@ void ConfigurationState::add_metadata_field(
|
||||
field_desc->set_label(proto::FieldDescriptorProto_Label_LABEL_REPEATED);
|
||||
}
|
||||
|
||||
void ConfigurationState::add_message_types(
|
||||
proto::FileDescriptorProto *bts_config_dp,
|
||||
proto::DescriptorProto *config_message,
|
||||
int &field_number) {
|
||||
for (size_t x = 0; x < proto_files_.size(); x++) {
|
||||
if (!add_message_type(
|
||||
bts_config_dp, config_message, field_number, proto_files_[x])) {
|
||||
#ifdef _WIN32
|
||||
// on linux the linker might throw away config protos that
|
||||
// are not used in sparkd. On windows we build a dll so that
|
||||
// should not happen
|
||||
throw InvalidDescriptorException(config_proto_files[x]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Construct a new Message that describes the save file format
|
||||
// This can then be used with google::protobuf::TextFormat to load and save
|
||||
// files
|
||||
void ConfigurationState::generate_all_config_proto(
|
||||
ConfigLog &log, const std::vector<std::string> &proto_dirs) {
|
||||
void ConfigurationState::generate_all_config_proto(ConfigLog &log) {
|
||||
const char *bts_config_classname = "__BTSConfig";
|
||||
int field_number = 0;
|
||||
|
||||
// add a meta type and field for each generated message
|
||||
const proto::DescriptorPool *gen_pool =
|
||||
proto::DescriptorPool::generated_pool();
|
||||
// Generate a proper FileDesctiptor from the FileDescriptorProto
|
||||
// The newly created descriptors live in the pool
|
||||
_dynamic_pool.reset(new proto::DescriptorPool(gen_pool));
|
||||
ConfigErrorCollector errors(log, "");
|
||||
proto::FileDescriptorProto bts_config_dp;
|
||||
bts_config_dp.set_name("config.proto");
|
||||
proto::DescriptorProto *config_message = bts_config_dp.add_message_type();
|
||||
@@ -566,46 +576,7 @@ void ConfigurationState::generate_all_config_proto(
|
||||
macro_field->set_type_name(MESSAGE_STRING_MACRO_TYPE);
|
||||
macro_field->set_label(proto::FieldDescriptorProto_Label_LABEL_REPEATED);
|
||||
|
||||
// add a meta type and field for each generated message
|
||||
proto::DescriptorPool::generated_pool();
|
||||
|
||||
auto find_proto_file =
|
||||
[&proto_dirs](const std::string &name) -> const proto::FileDescriptor * {
|
||||
for (const auto &proto_dir : proto_dirs) {
|
||||
const auto *res =
|
||||
proto::DescriptorPool::generated_pool()->FindFileByName(
|
||||
proto_dir + name);
|
||||
if (res != nullptr) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
for (size_t x = 0; x < BTS_ARRAYSIZE(config_proto_files); x++) {
|
||||
const auto *file_desc = find_proto_file(config_proto_files[x]);
|
||||
if (file_desc != nullptr) {
|
||||
bts_config_dp.add_dependency(file_desc->name());
|
||||
for (int y = 0; y < file_desc->message_type_count(); y++) {
|
||||
const proto::Descriptor *message_desc = file_desc->message_type(y);
|
||||
add_metadata_field(
|
||||
&bts_config_dp, config_message, message_desc, ++field_number);
|
||||
}
|
||||
} else {
|
||||
#ifdef _WIN32
|
||||
// on linux the linker might throw away config protos that
|
||||
// are not used in sparkd. On windows we build a dll so that
|
||||
// should not happen
|
||||
throw InvalidDescriptorException(config_proto_files[x]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a proper FileDesctiptor from the FileDescriptorProto
|
||||
// The newly created descriptors live in the pool
|
||||
_dynamic_pool.reset(
|
||||
new proto::DescriptorPool(proto::DescriptorPool::generated_pool()));
|
||||
ConfigErrorCollector errors(log, "");
|
||||
add_message_types(&bts_config_dp, config_message, field_number);
|
||||
const proto::FileDescriptor *file_desc =
|
||||
_dynamic_pool->BuildFileCollectingErrors(bts_config_dp, &errors);
|
||||
if (!file_desc) {
|
||||
@@ -628,12 +599,35 @@ void ConfigurationState::generate_all_config_proto(
|
||||
_prototype = _prototype_factory->GetPrototype(bts_config_desc);
|
||||
}
|
||||
|
||||
bool is_valid_key_descriptor(const proto::Descriptor *property_desc) {
|
||||
static const proto::FileDescriptor *find_proto_file(const std::string &name) {
|
||||
auto *pool = proto::DescriptorPool::generated_pool();
|
||||
return pool->FindFileByName(name);
|
||||
}
|
||||
|
||||
bool ConfigurationState::add_message_type(
|
||||
proto::FileDescriptorProto *bts_config_dp,
|
||||
proto::DescriptorProto *message_dp,
|
||||
int &field_number,
|
||||
const std::string &file_name) {
|
||||
const auto *file_desc = find_proto_file(file_name);
|
||||
if (file_desc == nullptr) {
|
||||
return false;
|
||||
}
|
||||
bts_config_dp->add_dependency(file_desc->name());
|
||||
for (int y = 0; y < file_desc->message_type_count(); y++) {
|
||||
const proto::Descriptor *message_desc = file_desc->message_type(y);
|
||||
add_metadata_field(
|
||||
bts_config_dp, message_dp, message_desc, ++field_number);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_valid_key_descriptor(
|
||||
const proto::Descriptor *property_desc,
|
||||
const std::vector<std::string> &proto_files) {
|
||||
std::string file_name = property_desc->file()->name();
|
||||
size_t file_name_start = file_name.find_last_of('/') + 1;
|
||||
file_name = file_name.substr(file_name_start);
|
||||
for (size_t x = 0; x < BTS_ARRAYSIZE(config_proto_files); x++) {
|
||||
std::string proto_name = config_proto_files[x];
|
||||
for (size_t x = 0; x < proto_files.size(); x++) {
|
||||
std::string proto_name = proto_files[x];
|
||||
if (boost::iequals(file_name, proto_name)) {
|
||||
return true;
|
||||
}
|
||||
@@ -765,7 +759,7 @@ const proto::Message *ConfigurationState::try_get_message_or_default(
|
||||
|
||||
const proto::Message &ConfigurationState::get_message(
|
||||
const proto::Descriptor *property_desc) {
|
||||
if (!is_valid_key_descriptor(property_desc)) {
|
||||
if (!is_valid_key_descriptor(property_desc, proto_files_)) {
|
||||
throw InvalidKeyException(property_desc->name().c_str());
|
||||
}
|
||||
|
||||
@@ -917,13 +911,15 @@ bool load_message(
|
||||
std::string url,
|
||||
proto::Message &out_message,
|
||||
ConfigLog &log,
|
||||
ConfigValueQueue &lookup) {
|
||||
ConfigValueQueue &lookup,
|
||||
const std::vector<std::string> &proto_files) {
|
||||
ConfigDownloader downloader;
|
||||
|
||||
bool result = false;
|
||||
switch (get_path_type(url)) {
|
||||
case PathType::directory:
|
||||
result = load_directory(url, downloader, out_message, log, lookup) > 0;
|
||||
result = load_directory(
|
||||
url, downloader, out_message, log, lookup, proto_files) > 0;
|
||||
break;
|
||||
case PathType::file:
|
||||
result = load_file(url, downloader, out_message, log, lookup) ==
|
||||
@@ -941,42 +937,16 @@ bool load_message(
|
||||
return result;
|
||||
}
|
||||
|
||||
int load_directory(
|
||||
std::string url,
|
||||
int load_dir(
|
||||
const std::string &url,
|
||||
ConfigDownloader &downloader,
|
||||
proto::Message &out_message,
|
||||
ConfigLog &log,
|
||||
ConfigValueQueue &lookup) {
|
||||
CFG_LOG(log, Info, "Loading config dir from '{}'", url);
|
||||
|
||||
const char last_char = url.at(url.length() - 1);
|
||||
if (last_char != '/') {
|
||||
url = url + '/';
|
||||
}
|
||||
|
||||
// If a file called "all" exists in the config directory we can short circuit
|
||||
// ~60 http requests
|
||||
ConfigDownloader::Result all_result =
|
||||
load_file(url + ".all", downloader, out_message, log, lookup, false);
|
||||
if (all_result == ConfigDownloader::SUCCESS) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// load spark.conf
|
||||
int load_count = 0;
|
||||
ConfigDownloader::Result result = load_file(
|
||||
url + "spark.conf", downloader, out_message, log, lookup, false);
|
||||
if (result == ConfigDownloader::SUCCESS) {
|
||||
load_count++;
|
||||
} else if (result == ConfigDownloader::PERMANENT_FAILURE) {
|
||||
// If the server is down it doesn't make sense to suffer though the
|
||||
// timeouts for the other files
|
||||
throw ServerUnreachableException(url.c_str());
|
||||
}
|
||||
|
||||
ConfigValueQueue &lookup,
|
||||
const std::vector<std::string> &proto_files) {
|
||||
bool edge_has_include = !get_include(out_message).empty();
|
||||
|
||||
for (const char *proto_file : config_proto_files) {
|
||||
int load_count = 0;
|
||||
for (const auto &proto_file : proto_files) {
|
||||
std::string config_file(proto_file);
|
||||
if (config_file == "system_config.proto") {
|
||||
continue;
|
||||
@@ -1007,6 +977,45 @@ int load_directory(
|
||||
return load_count;
|
||||
}
|
||||
|
||||
int load_directory(
|
||||
std::string url,
|
||||
ConfigDownloader &downloader,
|
||||
proto::Message &out_message,
|
||||
ConfigLog &log,
|
||||
ConfigValueQueue &lookup,
|
||||
const std::vector<std::string> &proto_files) {
|
||||
CFG_LOG(log, Info, "Loading config dir from '{}'", url);
|
||||
|
||||
const char last_char = url.at(url.length() - 1);
|
||||
if (last_char != '/') {
|
||||
url = url + '/';
|
||||
}
|
||||
|
||||
// If a file called "all" exists in the config directory we can short circuit
|
||||
// ~60 http requests
|
||||
ConfigDownloader::Result all_result =
|
||||
load_file(url + ".all", downloader, out_message, log, lookup, false);
|
||||
if (all_result == ConfigDownloader::SUCCESS) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// load spark.conf
|
||||
int load_count = 0;
|
||||
ConfigDownloader::Result result = load_file(
|
||||
url + "spark.conf", downloader, out_message, log, lookup, false);
|
||||
if (result == ConfigDownloader::SUCCESS) {
|
||||
load_count++;
|
||||
} else if (result == ConfigDownloader::PERMANENT_FAILURE) {
|
||||
// If the server is down it doesn't make sense to suffer though the
|
||||
// timeouts for the other files
|
||||
throw ServerUnreachableException(url.c_str());
|
||||
}
|
||||
|
||||
load_count +=
|
||||
load_dir(url, downloader, out_message, log, lookup, proto_files);
|
||||
return load_count;
|
||||
}
|
||||
|
||||
ConfigDownloader::Result load_file(
|
||||
std::string path,
|
||||
ConfigDownloader &downloader,
|
||||
+33
-16
@@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#ifndef CONFIGURATIONSTATE_H_
|
||||
#define CONFIGURATIONSTATE_H_
|
||||
|
||||
#include "ConfigDownloader.h"
|
||||
#include "ConfigLog.h"
|
||||
#include "ConfigurationException.h"
|
||||
#include "spark/expression/ExpressionEvaluator.h"
|
||||
#include "spark/expression/Value.h"
|
||||
#include "system/config/config_downloader.h"
|
||||
#include "system/config/config_log.h"
|
||||
#include "system/config/configuration_exception.h"
|
||||
#include "system/config/text_format/text_format.h"
|
||||
#include "system/expression/expression_evaluator.h"
|
||||
#include "system/expression/value.h"
|
||||
|
||||
#include "text_format/text_format.h"
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/descriptor.pb.h>
|
||||
#include <google/protobuf/dynamic_message.h>
|
||||
@@ -47,12 +48,13 @@ class ConfigValueQueue;
|
||||
|
||||
class ConfigurationState {
|
||||
public:
|
||||
ConfigurationState(void);
|
||||
ConfigurationState(
|
||||
const std::vector<std::string> &proto_files,
|
||||
const std::string &defaults);
|
||||
~ConfigurationState(void);
|
||||
|
||||
void initialize_defaults(ConfigLog &log);
|
||||
void initialize_defaults(ConfigLog &log, const std::vector<std::string> &proto_dirs);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize config with values loaded from a file, dir, or config
|
||||
* server.
|
||||
@@ -78,8 +80,8 @@ class ConfigurationState {
|
||||
|
||||
const proto::Message &get_message(const proto::Descriptor *property_desc);
|
||||
const proto::Message *try_get_message(const std::string &property_name);
|
||||
const proto::Message *
|
||||
try_get_message_or_default(const std::string &property_name);
|
||||
const proto::Message *try_get_message_or_default(
|
||||
const std::string &property_name);
|
||||
|
||||
bool is_initialized() { return _is_initialized; }
|
||||
|
||||
@@ -88,8 +90,8 @@ class ConfigurationState {
|
||||
|
||||
void check_rules();
|
||||
|
||||
const google::protobuf::Descriptor *
|
||||
get_descriptor_by_name(const std::string &name);
|
||||
const google::protobuf::Descriptor *get_descriptor_by_name(
|
||||
const std::string &name);
|
||||
|
||||
private:
|
||||
BTS_NO_COPY(ConfigurationState);
|
||||
@@ -103,7 +105,18 @@ class ConfigurationState {
|
||||
proto::DescriptorProto *message_dp,
|
||||
const proto::Descriptor *base_field,
|
||||
int index);
|
||||
void generate_all_config_proto(ConfigLog &, const std::vector<std::string> &proto_dirs);
|
||||
bool add_message_type(
|
||||
proto::FileDescriptorProto *bts_config_dp,
|
||||
proto::DescriptorProto *message_dp,
|
||||
int &field_number,
|
||||
const std::string &file_name);
|
||||
|
||||
void add_message_types(
|
||||
proto::FileDescriptorProto *bts_config_dp,
|
||||
proto::DescriptorProto *config_message,
|
||||
int &field_number);
|
||||
|
||||
void generate_all_config_proto(ConfigLog &);
|
||||
const proto::Message *try_get_value(
|
||||
const std::string &field_name, const proto::Message &message) const;
|
||||
|
||||
@@ -126,6 +139,8 @@ class ConfigurationState {
|
||||
// ConfigLog _log;
|
||||
std::string _host;
|
||||
uint32_t _port;
|
||||
std::vector<std::string> proto_files_;
|
||||
std::string defaults_;
|
||||
};
|
||||
|
||||
std::string get_include(const proto::Message &messages);
|
||||
@@ -142,13 +157,15 @@ bool load_message(
|
||||
std::string url,
|
||||
proto::Message &out_message,
|
||||
ConfigLog &,
|
||||
ConfigValueQueue &);
|
||||
ConfigValueQueue &,
|
||||
const std::vector<std::string> &proto_files);
|
||||
int load_directory(
|
||||
std::string url,
|
||||
ConfigDownloader &,
|
||||
proto::Message &out_message,
|
||||
ConfigLog &,
|
||||
ConfigValueQueue &);
|
||||
ConfigValueQueue &,
|
||||
const std::vector<std::string> &proto_files);
|
||||
ConfigDownloader::Result load_file(
|
||||
std::string url,
|
||||
ConfigDownloader &,
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "file_descriptor_builder.h"
|
||||
#include "system/config/message_descriptor_builder.h"
|
||||
|
||||
#include <google/protobuf/descriptor.pb.h>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::spark {
|
||||
|
||||
using google::protobuf::DescriptorProto;
|
||||
using google::protobuf::FieldDescriptorProto;
|
||||
using google::protobuf::FileDescriptorProto;
|
||||
using std::optional;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
using std::vector;
|
||||
|
||||
struct FileDescriptorBuilder::PImpl {
|
||||
FileDescriptorProto *proto;
|
||||
vector<unique_ptr<MessageDescriptorBuilder>> messages;
|
||||
|
||||
PImpl(const string &name, FileDescriptorProto *proto) {
|
||||
this->proto = proto == nullptr ? &own_proto_.emplace() : proto;
|
||||
if (!name.empty()) {
|
||||
this->proto->set_name(
|
||||
name.ends_with(".proto") ? name : name + ".proto");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
optional<FileDescriptorProto> own_proto_;
|
||||
};
|
||||
|
||||
FileDescriptorBuilder::FileDescriptorBuilder(
|
||||
const string &name, FileDescriptorProto *proto)
|
||||
: me_(std::make_unique<PImpl>(name, proto)) {
|
||||
if (!name.ends_with(".proto")) {
|
||||
me_->proto->set_name(name + ".proto");
|
||||
} else {
|
||||
me_->proto->set_name(name);
|
||||
}
|
||||
}
|
||||
|
||||
FileDescriptorBuilder::~FileDescriptorBuilder() = default;
|
||||
|
||||
MessageDescriptorBuilder *FileDescriptorBuilder::add_message_type(
|
||||
const std::string &name) {
|
||||
return me_->messages
|
||||
.emplace_back(std::make_unique<MessageDescriptorBuilder>(
|
||||
name, me_->proto->add_message_type()))
|
||||
.get();
|
||||
}
|
||||
|
||||
} // namespace bts::spark
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "system/config/message_descriptor_builder.h"
|
||||
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace bts::spark {
|
||||
|
||||
class FileDescriptorBuilder {
|
||||
public:
|
||||
explicit FileDescriptorBuilder(
|
||||
const std::string &name,
|
||||
google::protobuf::FileDescriptorProto *proto = nullptr);
|
||||
|
||||
~FileDescriptorBuilder();
|
||||
|
||||
MessageDescriptorBuilder *add_message_type(const std::string &name);
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me_;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
} // namespace bts::spark
|
||||
@@ -0,0 +1,103 @@
|
||||
#include "system/config/message_descriptor_builder.h"
|
||||
#include "file_descriptor_builder.h"
|
||||
|
||||
#include <google/protobuf/descriptor.pb.h>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::spark {
|
||||
|
||||
using google::protobuf::DescriptorProto;
|
||||
using google::protobuf::FieldDescriptorProto;
|
||||
using google::protobuf::FileDescriptorProto;
|
||||
using std::optional;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
using std::vector;
|
||||
|
||||
#define TYPE(x) \
|
||||
google::protobuf::FieldDescriptorProto_Type:: \
|
||||
FieldDescriptorProto_Type_TYPE_##x
|
||||
#define LABEL(x) \
|
||||
google::protobuf::FieldDescriptorProto_Label:: \
|
||||
FieldDescriptorProto_Label_LABEL_##x
|
||||
|
||||
struct MessageDescriptorBuilder::PImpl {
|
||||
DescriptorProto *proto;
|
||||
int field_num;
|
||||
|
||||
PImpl(const string &name, DescriptorProto *proto) {
|
||||
this->proto = proto == nullptr ? &own_proto_.emplace() : proto;
|
||||
if (!name.empty()) {
|
||||
this->proto->set_name(
|
||||
name.ends_with(".proto") ? name : name + ".proto");
|
||||
}
|
||||
}
|
||||
|
||||
FieldDescriptorProto *add_field(
|
||||
const string &name, FieldType type, LabelType label) {
|
||||
auto *field = proto->add_field();
|
||||
field->set_name(name);
|
||||
field->set_type(type);
|
||||
field->set_number(++field_num);
|
||||
field->set_label(label);
|
||||
return field;
|
||||
}
|
||||
|
||||
void add_message(const string &name, LabelType label) {
|
||||
auto *field = proto->add_field();
|
||||
field->set_name(name);
|
||||
field->set_type(TYPE(MESSAGE));
|
||||
field->set_number(++field_num);
|
||||
field->set_label(label);
|
||||
}
|
||||
|
||||
private:
|
||||
optional<DescriptorProto> own_proto_;
|
||||
vector<unique_ptr<MessageDescriptorBuilder>> messages_;
|
||||
};
|
||||
|
||||
MessageDescriptorBuilder::MessageDescriptorBuilder(
|
||||
const string &name, DescriptorProto *proto)
|
||||
: me_(std::make_unique<PImpl>(name, proto)) {}
|
||||
|
||||
MessageDescriptorBuilder::~MessageDescriptorBuilder() = default;
|
||||
|
||||
void MessageDescriptorBuilder::add_message(
|
||||
const string &name, const string &type_name, bool required) {
|
||||
auto *field = me_->add_field(
|
||||
name, TYPE(MESSAGE), required ? LABEL(REQUIRED) : LABEL(OPTIONAL));
|
||||
field->set_type_name(type_name);
|
||||
}
|
||||
|
||||
void MessageDescriptorBuilder::add_messages(
|
||||
const string &name, const string &type_name) {
|
||||
auto *field = me_->add_field(name, TYPE(MESSAGE), LABEL(REPEATED));
|
||||
field->set_type_name(type_name);
|
||||
}
|
||||
|
||||
void MessageDescriptorBuilder::add_int32(const string &name, bool required) {
|
||||
me_->add_field(
|
||||
name, TYPE(INT32), required ? LABEL(REQUIRED) : LABEL(OPTIONAL));
|
||||
}
|
||||
|
||||
void MessageDescriptorBuilder::add_int32s(const string &name) {
|
||||
me_->add_field(name, TYPE(INT32), LABEL(REPEATED));
|
||||
}
|
||||
|
||||
void MessageDescriptorBuilder::add_string(const string &name, bool required) {
|
||||
me_->add_field(
|
||||
name, TYPE(STRING), required ? LABEL(REQUIRED) : LABEL(OPTIONAL));
|
||||
}
|
||||
|
||||
void MessageDescriptorBuilder::add_strings(const string &name) {
|
||||
me_->add_field(name, TYPE(STRING), LABEL(REPEATED));
|
||||
}
|
||||
|
||||
DescriptorProto &MessageDescriptorBuilder::proto() { return *me_->proto; }
|
||||
|
||||
const DescriptorProto &MessageDescriptorBuilder::proto() const {
|
||||
return *me_->proto;
|
||||
}
|
||||
|
||||
} // namespace bts::spark
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/descriptor.pb.h>
|
||||
#include <memory>
|
||||
|
||||
namespace bts::spark {
|
||||
|
||||
class MessageDescriptorBuilder {
|
||||
public:
|
||||
explicit MessageDescriptorBuilder(
|
||||
const std::string &name,
|
||||
google::protobuf::DescriptorProto *proto = nullptr);
|
||||
|
||||
~MessageDescriptorBuilder();
|
||||
|
||||
using FieldType = google::protobuf::FieldDescriptorProto_Type;
|
||||
using LabelType = google::protobuf::FieldDescriptorProto_Label;
|
||||
|
||||
google::protobuf::DescriptorProto &proto();
|
||||
const google::protobuf::DescriptorProto &proto() const;
|
||||
|
||||
void add_message(
|
||||
const std::string &name,
|
||||
const std::string &type_name,
|
||||
bool is_required = false);
|
||||
|
||||
void add_messages(const std::string &name, const std::string &type_name);
|
||||
|
||||
void add_string(const std::string &name, bool required = false);
|
||||
void add_strings(const std::string &name);
|
||||
|
||||
void add_int32(const std::string &name, bool required = false);
|
||||
void add_int32s(const std::string &name);
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me_;
|
||||
};
|
||||
|
||||
} // namespace bts::spark
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "PreprocessInputStream.h"
|
||||
#include "system/config/preprocess_input_stream.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <string>
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
#include "system/macros/bts_no_copy.h"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "BooleanGrammar.h"
|
||||
#include "boolean_grammar.h"
|
||||
|
||||
namespace bts {
|
||||
namespace expression {
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#ifndef BOOLEANGRAMMAR_H_
|
||||
#define BOOLEANGRAMMAR_H_
|
||||
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
#include "system/macros/bts_no_copy.h"
|
||||
|
||||
#include <boost/config/warning_disable.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
#include "ExpressionEvaluator.h"
|
||||
#include "BooleanGrammar.h"
|
||||
#include "IPropertyEvaluator.h"
|
||||
#include "ParserExceptions.h"
|
||||
#include "expression_evaluator.h"
|
||||
#include "system/expression/boolean_grammar.h"
|
||||
#include "system/expression/i_property_evaluator.h"
|
||||
#include "system/expression/parser_exceptions.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp> // iequals
|
||||
#include <boost/regex.hpp>
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
#ifndef EXPRESSIONEVALUATOR_H_
|
||||
#define EXPRESSIONEVALUATOR_H_
|
||||
|
||||
#include "RecursionGuard.h"
|
||||
#include "Value.h"
|
||||
#include "system/expression/recursion_guard.h"
|
||||
#include "system/expression/value.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
#ifndef IPROPERTY_EVAULATOR_H_
|
||||
#define IPROPERTY_EVAULATOR_H_
|
||||
|
||||
#include "ExpressionEvaluator.h"
|
||||
#include "Value.h"
|
||||
#include "system/expression/expression_evaluator.h"
|
||||
#include "system/expression/value.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "ParserExceptions.h"
|
||||
#include "parser_exceptions.h"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
File renamed without changes.
+2
-1
@@ -1,7 +1,8 @@
|
||||
#ifndef RECURSIONGUARD_H_
|
||||
#define RECURSIONGUARD_H_
|
||||
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
#include "system/macros/bts_no_copy.h"
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <vector>
|
||||
|
||||
File renamed without changes.
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "Value.h"
|
||||
#include "value.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
File renamed without changes.
@@ -1,11 +1,12 @@
|
||||
#include "logging.h"
|
||||
#include "system/facades/bts_assert.h"
|
||||
#include "system/logging/logger_hub.h"
|
||||
#include "system/logging/logging_config.h"
|
||||
#include "system/logging/protobufs/logging.h"
|
||||
#include "system/protobufs/logging.pb.h"
|
||||
#include "system/facades/bts_assert.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/system_config.pb.h"
|
||||
#include "system/protobufs/config/threads.pb.h"
|
||||
#include "system/protobufs/logging.pb.h"
|
||||
#include "system/threading/dispatcher.h"
|
||||
#include "system/threading/thread_manager.h"
|
||||
#ifdef SPARK_ENABLE_CCAPI
|
||||
@@ -30,6 +31,7 @@ namespace bts::logging {
|
||||
|
||||
using bts::logging::protobufs::Logging;
|
||||
using bts::logging::protobufs::SinkConfig;
|
||||
using bts::system::protobufs::SystemConfig;
|
||||
using bts::system::protobufs::ThreadGroupCfg;
|
||||
using Path = boost::filesystem::path;
|
||||
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package bts.config;
|
||||
package bts.system.protobufs;
|
||||
|
||||
option csharp_namespace = "bts.config";
|
||||
option csharp_namespace = "bts.system.protobufs";
|
||||
|
||||
message SystemConfig {
|
||||
string host_name = 1;
|
||||
Reference in new issue
Block a user