Commit 905e4ab1 authored by Giorgio Azzinnaro's avatar Giorgio Azzinnaro

added command line config

parent c0827fbe
......@@ -41,7 +41,7 @@ namespace profanedb {
namespace format {
namespace protobuf {
Loader::RootSourceTree::RootSourceTree(std::initializer_list<path> paths)
Loader::RootSourceTree::RootSourceTree(std::vector<path> paths)
: paths(paths)
{
if (paths.size() == 0)
......
......@@ -47,7 +47,7 @@ public:
friend class Loader;
public:
RootSourceTree(std::initializer_list<boost::filesystem::path> paths);
RootSourceTree(std::vector<boost::filesystem::path> paths);
private:
std::vector<boost::filesystem::path> paths;
......
find_package(gRPC REQUIRED)
add_definitions(-DBOOST_LOG_DYN_LINK) # This is for the Boost Log library to load the proper target namespace for the current platform
find_package(Boost REQUIRED COMPONENTS log)
find_package(Boost REQUIRED COMPONENTS log filesystem program_options)
include_directories (${Boost_INCLUDE_DIRS})
add_executable(profanedb_server main.cpp server.cpp)
add_executable(profanedb_server main.cpp server.cpp config.cpp)
target_link_libraries(profanedb_server ${Boost_LIBRARIES} profanedb_format profanedb_vault profanedb_grpc)
/*
* ProfaneDB - A Protocol Buffers database.
* Copyright (C) 2017 "Giorgio Azzinnaro" <giorgio.azzinnaro@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
using boost::program_options::value;
using boost::log::trivial::severity_level;
using boost::filesystem::path;
namespace profanedb {
namespace server {
// TODO Config file
Config::Config(int argc, char * argv[])
{
desc.add_options()
("help,h",
"Display this help message")
("log_level",
value<severity_level>(),
"trace, debug, info, warning, error, fatal")
("proto_path,I",
value< std::vector< path > >(),
"Specify the paths to import proto files (google/protobuf/..., profanedb/protobuf/...)")
("schema_path,S",
value< std::vector< path > >(),
"Specify the paths to load the user defined schema")
("rocksdb_path",
value<path>(),
"Set the path RocksDB uses to store its content");
boost::program_options::store(
boost::program_options::parse_command_line(argc, argv, desc), vm
);
boost::program_options::notify(vm);
}
const bool Config::ShowHelp() const
{
if (this->vm.count("help")) {
std::cout << this->desc << std::endl;
return true;
}
return false;
}
const severity_level Config::LogLevel() const
{
return this->vm["log_level"].as<severity_level>();
}
const std::vector<path> Config::IncludePath() const
{
return this->vm["proto_path"].as< std::vector< path > >();
}
const std::vector<path> Config::SchemaPath() const
{
return this->vm["schema_path"].as< std::vector< path > >();
}
const path Config::RocksPath() const
{
return this->vm["rocksdb_path"].as<path>();
}
// TODO
const rocksdb::Options Config::RocksOptions() const
{
rocksdb::Options options;
options.create_if_missing = true;
return options;
}
}
}
/*
* ProfaneDB - A Protocol Buffers database.
* Copyright (C) 2017 "Giorgio Azzinnaro" <giorgio.azzinnaro@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PROFANEDB_SERVER_CONFIG_H
#define PROFANEDB_SERVER_CONFIG_H
#include <iostream>
#include <boost/program_options.hpp>
#include <boost/log/trivial.hpp>
#include <boost/filesystem.hpp>
#include <rocksdb/db.h>
namespace profanedb {
namespace server {
class Config
{
public:
Config(int argc, char * argv[]);
// If asked to do so, display usage message and return true
const bool ShowHelp() const;
// Proto path are the import paths (eg /usr/include),
// where google/protobuf/*.proto and profanedb/protobuf/*.proto are
// By default it would usually be /usr/include and /usr/local/include
const std::vector< boost::filesystem::path > IncludePath() const;
// Schema path must be defined for the user proto definitions
const std::vector< boost::filesystem::path > SchemaPath() const;
const boost::log::trivial::severity_level LogLevel() const;
// Where RocksDB should save its content
const boost::filesystem::path RocksPath() const;
// RocksDB options, usually would come from file
const rocksdb::Options RocksOptions() const;
private:
boost::program_options::options_description desc;
boost::program_options::variables_map vm;
};
}
}
#endif // PROFANEDB_SERVER_CONFIG_H
......@@ -17,11 +17,20 @@
*
*/
#include "server.h"
#include "server.h"
// TODO Move in separate class
#include <boost/program_options.hpp>
namespace po = boost::program_options;
int main(int argc, char* argv[]) {
profanedb::server::Config config(argc, argv);
// If help message was requested stop execution here
if (config.ShowHelp())
return 0;
profanedb::server::Server server;
profanedb::server::Server server(config);
server.Run();
return 0;
......
......@@ -24,8 +24,14 @@ using profanedb::format::Marshaller;
using ProtobufMarshaller = profanedb::format::protobuf::Marshaller;
using profanedb::vault::Storage;
using RocksStorage = profanedb::vault::rocksdb::Storage;
using profanedb::server::Config;
using namespace profanedb::protobuf;
using profanedb::protobuf::GetReq;
using profanedb::protobuf::GetResp;
using profanedb::protobuf::PutReq;
using profanedb::protobuf::PutResp;
using profanedb::protobuf::DelReq;
using profanedb::protobuf::DelResp;
using google::protobuf::Message;
......@@ -33,31 +39,26 @@ using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using boost::program_options::variables_map;
namespace profanedb {
namespace server {
Server::Server()
Server::Server(const Config & config)
: config(config)
{
// TODO Config
boost::log::core::get()->set_filter(
boost::log::trivial::severity >= boost::log::trivial::trace
boost::log::trivial::severity >= config.LogLevel()
);
// TODO Config
rocksdb::Options rocksOptions;
rocksOptions.create_if_missing = true;
rocksdb::DB *rocks;
rocksdb::DB::Open(rocksOptions, "/tmp/profane", &rocks);
rocksdb::DB::Open(config.RocksOptions(), config.RocksPath().string(), &rocks);
auto storage = std::make_shared<RocksStorage>(std::unique_ptr<rocksdb::DB>(rocks));
// TODO Should be from config
auto includeSourceTree = new Loader::RootSourceTree{
"/usr/include", "/home/giorgio/Documents/ProfaneDB/ProfaneDB/src"};
auto includeSourceTree = new Loader::RootSourceTree(config.IncludePath());
// TODO Config
auto schemaSourceTree = new Loader::RootSourceTree{"/home/giorgio/Documents/ProfaneDB/ProfaneDB/test/profanedb/test/protobuf/schema"};
auto schemaSourceTree = new Loader::RootSourceTree(config.SchemaPath());
auto loader = std::make_shared<Loader>(
std::unique_ptr<Loader::RootSourceTree>(includeSourceTree),
......
......@@ -36,6 +36,8 @@
#include <profanedb/db.hpp>
#include "config.h"
namespace profanedb {
namespace server {
......@@ -43,7 +45,7 @@ namespace server {
class Server
{
public:
Server();
Server(const profanedb::server::Config & config);
~Server();
void Run();
......@@ -84,6 +86,8 @@ private:
std::shared_ptr<profanedb::format::protobuf::Loader> loader;
};
std::unique_ptr<DbServiceImpl> service;
const profanedb::server::Config & config;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment