Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move --plugins from application to binary #1427 #1437

Merged
merged 16 commits into from
Jan 20, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,6 @@ void application::set_program_options(boost::program_options::options_descriptio
("genesis-json", bpo::value<boost::filesystem::path>(), "File to read Genesis State from")
("dbg-init-key", bpo::value<string>(), "Block signing key to use for init witnesses, overrides genesis file")
("api-access", bpo::value<boost::filesystem::path>(), "JSON file specifying API permissions")
("plugins", bpo::value<string>(), "Space-separated list of plugins to activate")
("io-threads", bpo::value<uint16_t>()->implicit_value(0), "Number of IO threads, default to 0 for auto-configuration")
("enable-subscribe-to-all", bpo::value<bool>()->implicit_value(true),
"Whether allow API clients to subscribe to universal object creation and removal events")
Expand Down Expand Up @@ -1006,33 +1005,6 @@ void application::initialize(const fc::path& data_dir, const boost::program_opti
const uint16_t num_threads = options["io-threads"].as<uint16_t>();
fc::asio::default_io_service_scope::set_num_threads(num_threads);
}

std::vector<string> wanted;
if( options.count("plugins") )
{
boost::split(wanted, options.at("plugins").as<std::string>(), [](char c){return c == ' ';});
}
else
{
wanted.push_back("witness");
wanted.push_back("account_history");
wanted.push_back("market_history");
wanted.push_back("grouped_orders");
}
int es_ah_conflict_counter = 0;
for (auto& it : wanted)
{
if(it == "account_history")
++es_ah_conflict_counter;
if(it == "elasticsearch")
++es_ah_conflict_counter;

if(es_ah_conflict_counter > 1) {
elog("Can't start program with elasticsearch and account_history plugin at the same time");
std::exit(EXIT_FAILURE);
}
if (!it.empty()) enable_plugin(it);
}
}

void application::startup()
Expand Down
18 changes: 11 additions & 7 deletions libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,17 @@ namespace graphene { namespace app {
application();
~application();

void set_program_options( boost::program_options::options_description& command_line_options,
boost::program_options::options_description& configuration_file_options )const;
void initialize(const fc::path& data_dir, const boost::program_options::variables_map&options);
void initialize_plugins( const boost::program_options::variables_map& options );
void set_program_options(boost::program_options::options_description& command_line_options,
boost::program_options::options_description& configuration_file_options)const;
void initialize(const fc::path& data_dir, const boost::program_options::variables_map& options);
void initialize_plugins(const boost::program_options::variables_map& options);
void startup();
void shutdown();
void startup_plugins();
void shutdown_plugins();

template<typename PluginType>
std::shared_ptr<PluginType> register_plugin()
{
std::shared_ptr<PluginType> register_plugin(bool auto_load = false) {
auto plug = std::make_shared<PluginType>();
plug->plugin_set_app(this);

Expand All @@ -72,6 +71,10 @@ namespace graphene { namespace app {
_cfg_options.add(plugin_cfg_options);

add_available_plugin( plug );

if (auto_load)
enable_plugin(plug->plugin_name());

return plug;
}
std::shared_ptr<abstract_plugin> get_plugin( const string& name )const;
Expand All @@ -98,8 +101,9 @@ namespace graphene { namespace app {

const application_options& get_options();

private:
void enable_plugin( const string& name );

private:
void add_available_plugin( std::shared_ptr<abstract_plugin> p );
std::shared_ptr<detail::application_impl> my;

Expand Down
41 changes: 27 additions & 14 deletions programs/delayed_node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ int main(int argc, char** argv) {
bpo::options_description app_options("Graphene Delayed Node");
bpo::options_description cfg_options("Graphene Delayed Node");
app_options.add_options()
("help,h", "Print this help message and exit.")
("data-dir,d", bpo::value<boost::filesystem::path>()->default_value("delayed_node_data_dir"), "Directory containing databases, configuration file, etc.")
;
("help,h", "Print this help message and exit.")
("data-dir,d", bpo::value<boost::filesystem::path>()->default_value("delayed_node_data_dir"), "Directory containing databases, configuration file, etc.")
("plugins", bpo::value<std::string>()->default_value("delayed_node account_history market_history"),
"Space-separated list of plugins to activate");
;

bpo::variables_map options;

Expand All @@ -84,8 +86,8 @@ int main(int argc, char** argv) {
}
catch (const boost::program_options::error& e)
{
std::cerr << "Error parsing command line: " << e.what() << "\n";
return 1;
std::cerr << "Error parsing command line: " << e.what() << "\n";
return 1;
}

if( options.count("help") )
Expand Down Expand Up @@ -160,9 +162,20 @@ int main(int argc, char** argv) {
elog("Error parsing configuration file: ${e}", ("e", e.what()));
return 1;
}
if( !options.count("plugins") )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should keep the "plugins" option. We don't want to change the behaviour of the executable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is done 1326a5c

options.insert( std::make_pair( "plugins", bpo::variable_value(std::string("delayed_node account_history market_history"), true) ) );

std::set<std::string> plugins;
boost::split(plugins, options.at("plugins").as<std::string>(), [](char c){return c == ' ';});

if(plugins.count("account_history") && plugins.count("elasticsearch")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is useless. Elasticsearch is not available in delayed_node.

std::cerr << "Plugin conflict: Cannot load both account_history plugin and elasticsearch plugin\n";
return 1;
}

std::for_each(plugins.begin(), plugins.end(), [&](const std::string& plug) mutable {
if (!plug.empty()) {
node.enable_plugin(plug);
}
});
node.initialize(data_dir, options);
node.initialize_plugins( options );

Expand All @@ -171,7 +184,7 @@ int main(int argc, char** argv) {

fc::promise<int>::ptr exit_promise = new fc::promise<int>("UNIX Signal Handler");
fc::set_signal_handler([&exit_promise](int signal) {
exit_promise->set_value(signal);
exit_promise->set_value(signal);
}, SIGINT);

ilog("Started delayed node on a chain with ${h} blocks.", ("h", node.chain_database()->head_block_num()));
Expand Down Expand Up @@ -241,14 +254,14 @@ fc::optional<fc::logging_config> load_logging_config_from_ini_file(const fc::pat
// stdout/stderr will be taken from ini file, everything else hard-coded here
fc::console_appender::config console_appender_config;
console_appender_config.level_colors.emplace_back(
fc::console_appender::level_color(fc::log_level::debug,
fc::console_appender::color::green));
fc::console_appender::level_color(fc::log_level::debug,
fc::console_appender::color::green));
console_appender_config.level_colors.emplace_back(
fc::console_appender::level_color(fc::log_level::warn,
fc::console_appender::color::brown));
fc::console_appender::level_color(fc::log_level::warn,
fc::console_appender::color::brown));
console_appender_config.level_colors.emplace_back(
fc::console_appender::level_color(fc::log_level::error,
fc::console_appender::color::cyan));
fc::console_appender::level_color(fc::log_level::error,
fc::console_appender::color::cyan));
console_appender_config.stream = fc::variant(stream_name, 1).as<fc::console_appender::stream::type>(1);
logging_config.appenders.push_back(fc::appender_config(console_appender_name, "console", fc::variant(console_appender_config, GRAPHENE_MAX_NESTED_OBJECTS)));
found_logging_config = true;
Expand Down
25 changes: 21 additions & 4 deletions programs/witness_node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/algorithm/string.hpp>

#include <graphene/utilities/git_revision.hpp>
#include <boost/algorithm/string/replace.hpp>
Expand All @@ -64,9 +65,11 @@ int main(int argc, char** argv) {
bpo::options_description cfg_options("Graphene Witness Node");
app_options.add_options()
("help,h", "Print this help message and exit.")
("data-dir,d", bpo::value<boost::filesystem::path>()->default_value("witness_node_data_dir"), "Directory containing databases, configuration file, etc.")
("data-dir,d", bpo::value<boost::filesystem::path>()->default_value("witness_node_data_dir"),
"Directory containing databases, configuration file, etc.")
("version,v", "Display version information")
;
("plugins", bpo::value<std::string>()->default_value("witness account_history market_history grouped_orders"),
"Space-separated list of plugins to activate");

bpo::variables_map options;

Expand All @@ -90,10 +93,24 @@ int main(int argc, char** argv) {
}
catch (const boost::program_options::error& e)
{
std::cerr << "Error parsing command line: " << e.what() << "\n";
return 1;
std::cerr << "Error parsing command line: " << e.what() << "\n";
return 1;
}

std::set<std::string> plugins;
boost::split(plugins, options.at("plugins").as<std::string>(), [](char c){return c == ' ';});

if(plugins.count("account_history") && plugins.count("elasticsearch")) {
std::cerr << "Plugin conflict: Cannot load both account_history plugin and elasticsearch plugin\n";
return 1;
}

std::for_each(plugins.begin(), plugins.end(), [node](const std::string& plug) mutable {
if (!plug.empty()) {
node->enable_plugin(plug);
}
});

if( options.count("help") )
{
std::cout << app_options << "\n";
Expand Down
8 changes: 4 additions & 4 deletions tests/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ int get_available_port()
std::shared_ptr<graphene::app::application> start_application(fc::temp_directory& app_dir, int& server_port_number) {
std::shared_ptr<graphene::app::application> app1(new graphene::app::application{});

app1->register_plugin<graphene::account_history::account_history_plugin>();
app1->register_plugin< graphene::market_history::market_history_plugin >();
app1->register_plugin< graphene::witness_plugin::witness_plugin >();
app1->register_plugin< graphene::grouped_orders::grouped_orders_plugin>();
app1->register_plugin<graphene::account_history::account_history_plugin>(true);
app1->register_plugin< graphene::market_history::market_history_plugin >(true);
app1->register_plugin< graphene::witness_plugin::witness_plugin >(true);
app1->register_plugin< graphene::grouped_orders::grouped_orders_plugin>(true);
app1->startup_plugins();
boost::program_options::variables_map cfg;
#ifdef _WIN32
Expand Down