Обновление слоя хранилища
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#include "storage_wrapper.h"
|
||||
|
||||
#include <storage/storage.h>
|
||||
|
||||
using namespace server::details;
|
||||
|
||||
StorageWrapper::StorageWrapper(const userver::components::ComponentConfig& config,
|
||||
const userver::components::ComponentContext& context)
|
||||
: userver::components::LoggableComponentBase(config, context) {
|
||||
auto settings = config[kName];
|
||||
|
||||
storage::ConnectionData connection_data;
|
||||
connection_data.database = settings["database"].As<std::string>();
|
||||
connection_data.username = settings["username"].As<std::string>();
|
||||
connection_data.password = settings["password"].As<std::string>();
|
||||
connection_data.host = settings["host"].As<std::string>();
|
||||
connection_data.port = settings["port"].As<std::string>();
|
||||
|
||||
storage::Storage::Connect(connection_data);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <userver/components/component.hpp>
|
||||
#include <userver/components/loggable_component_base.hpp>
|
||||
|
||||
namespace server::details {
|
||||
/// @brief Обёртка-компонент над хранилищем
|
||||
class StorageWrapper : public userver::components::LoggableComponentBase {
|
||||
public:
|
||||
/// @brief Название компонента
|
||||
static constexpr std::string_view kName = "storage-wrapper";
|
||||
|
||||
/// @brief Конструктор
|
||||
/// @param[in] config Конфигурация
|
||||
/// @param[in] context Контекст
|
||||
StorageWrapper(const userver::components::ComponentConfig& config, const userver::components::ComponentContext& context);
|
||||
};
|
||||
}
|
||||
@@ -11,42 +11,16 @@
|
||||
#include <controllers/statistics/get.h>
|
||||
|
||||
#include <configuration/configuration.h>
|
||||
#include <json/json.h>
|
||||
#include <server/logger.h>
|
||||
#include <storage/postgresql/postgresql_storage.h>
|
||||
|
||||
#include "details/controller_wrapper.h"
|
||||
#include "details/storage_wrapper.h"
|
||||
#include "details/details.h"
|
||||
|
||||
void Log(LogLevel level, const char* message) {
|
||||
std::cout << message << std::endl;
|
||||
}
|
||||
|
||||
void ConnectToStorage(const json& configuration) {
|
||||
Logger::Get().Write(LogLevel::Info, "connecting to postgresql...");
|
||||
|
||||
const auto& parameters = configuration["storage"];
|
||||
|
||||
ConnectionData connection_data;
|
||||
connection_data.database = parameters["database"].get<std::string>();
|
||||
connection_data.username = parameters["username"].get<std::string>();
|
||||
connection_data.password = parameters["password"].get<std::string>();
|
||||
connection_data.host = parameters["host"].get<std::string>();
|
||||
connection_data.port = std::to_string(parameters["port"].get<int>());
|
||||
|
||||
PostgreSqlStorage::Connect(connection_data);
|
||||
|
||||
Logger::Get().Write(LogLevel::Info, "connected to postgresql");
|
||||
}
|
||||
|
||||
json ParseConfiguration(const std::string& path_to_configuration) {
|
||||
json required_keys;
|
||||
required_keys["server"] = { "path", "port" };
|
||||
required_keys["storage"] = { "database", "username", "password", "host", "port" };
|
||||
|
||||
return ParseConfiguration(path_to_configuration, required_keys);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
std::cout << "usage: " << argv[0] << " <path-to-configuration>" << std::endl;
|
||||
@@ -66,6 +40,8 @@ int main(int argc, char** argv) {
|
||||
// static content
|
||||
.Append<userver::components::FsCache>("fs-cache-main")
|
||||
.Append<userver::server::handlers::HttpHandlerStatic>()
|
||||
// storage
|
||||
.Append<server::details::StorageWrapper>()
|
||||
// anomaly logs
|
||||
.Append<server::details::ControllerWrapper<controllers::anomaly_logs::Get>>()
|
||||
// clusters
|
||||
|
||||
Reference in New Issue
Block a user