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 7 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
28 changes: 24 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,27 @@ 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("plugins")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, isn't this always true now that the option has a default value?

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry about that, you are right, fixed at 58ad814


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