#237 Create init_program_options(...) for plugins + little code refactoring
This commit is contained in:
parent
694fcf00f3
commit
f56e9a614e
2 changed files with 125 additions and 103 deletions
|
|
@ -58,6 +58,9 @@ class elasticsearch_plugin_impl
|
|||
return _self.database();
|
||||
}
|
||||
|
||||
friend class graphene::elasticsearch::elasticsearch_plugin;
|
||||
|
||||
private:
|
||||
elasticsearch_plugin& _self;
|
||||
primary_index< operation_history_index >* _oho_index;
|
||||
|
||||
|
|
@ -103,6 +106,7 @@ class elasticsearch_plugin_impl
|
|||
void createBulkLine(const account_transaction_history_object& ath);
|
||||
void prepareBulk(const account_transaction_history_id_type& ath_id);
|
||||
void populateESstruct();
|
||||
void init_program_options(const boost::program_options::variables_map& options);
|
||||
};
|
||||
|
||||
elasticsearch_plugin_impl::~elasticsearch_plugin_impl()
|
||||
|
|
@ -603,6 +607,43 @@ void elasticsearch_plugin_impl::populateESstruct()
|
|||
es.query = "";
|
||||
}
|
||||
|
||||
void elasticsearch_plugin_impl::init_program_options(const boost::program_options::variables_map& options)
|
||||
{
|
||||
if (options.count("elasticsearch-node-url")) {
|
||||
_elasticsearch_node_url = options["elasticsearch-node-url"].as<std::string>();
|
||||
}
|
||||
if (options.count("elasticsearch-bulk-replay")) {
|
||||
_elasticsearch_bulk_replay = options["elasticsearch-bulk-replay"].as<uint32_t>();
|
||||
}
|
||||
if (options.count("elasticsearch-bulk-sync")) {
|
||||
_elasticsearch_bulk_sync = options["elasticsearch-bulk-sync"].as<uint32_t>();
|
||||
}
|
||||
if (options.count("elasticsearch-visitor")) {
|
||||
_elasticsearch_visitor = options["elasticsearch-visitor"].as<bool>();
|
||||
}
|
||||
if (options.count("elasticsearch-basic-auth")) {
|
||||
_elasticsearch_basic_auth = options["elasticsearch-basic-auth"].as<std::string>();
|
||||
}
|
||||
if (options.count("elasticsearch-index-prefix")) {
|
||||
_elasticsearch_index_prefix = options["elasticsearch-index-prefix"].as<std::string>();
|
||||
}
|
||||
if (options.count("elasticsearch-operation-object")) {
|
||||
_elasticsearch_operation_object = options["elasticsearch-operation-object"].as<bool>();
|
||||
}
|
||||
if (options.count("elasticsearch-start-es-after-block")) {
|
||||
_elasticsearch_start_es_after_block = options["elasticsearch-start-es-after-block"].as<uint32_t>();
|
||||
}
|
||||
if (options.count("elasticsearch-operation-string")) {
|
||||
_elasticsearch_operation_string = options["elasticsearch-operation-string"].as<bool>();
|
||||
}
|
||||
if (options.count("elasticsearch-mode")) {
|
||||
const auto option_number = options["elasticsearch-mode"].as<uint16_t>();
|
||||
if(option_number > mode::all)
|
||||
FC_THROW_EXCEPTION(graphene::chain::plugin_exception, "Elasticsearch mode not valid");
|
||||
_elasticsearch_mode = static_cast<mode>(options["elasticsearch-mode"].as<uint16_t>());
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace detail
|
||||
|
||||
elasticsearch_plugin::elasticsearch_plugin() :
|
||||
|
|
@ -655,42 +696,12 @@ void elasticsearch_plugin::plugin_set_program_options(
|
|||
|
||||
void elasticsearch_plugin::plugin_initialize(const boost::program_options::variables_map& options)
|
||||
{
|
||||
ilog("elasticsearch ACCOUNT HISTORY: plugin_initialize() begin");
|
||||
|
||||
my->_oho_index = database().add_index< primary_index< operation_history_index > >();
|
||||
database().add_index< primary_index< account_transaction_history_index > >();
|
||||
|
||||
if (options.count("elasticsearch-node-url")) {
|
||||
my->_elasticsearch_node_url = options["elasticsearch-node-url"].as<std::string>();
|
||||
}
|
||||
if (options.count("elasticsearch-bulk-replay")) {
|
||||
my->_elasticsearch_bulk_replay = options["elasticsearch-bulk-replay"].as<uint32_t>();
|
||||
}
|
||||
if (options.count("elasticsearch-bulk-sync")) {
|
||||
my->_elasticsearch_bulk_sync = options["elasticsearch-bulk-sync"].as<uint32_t>();
|
||||
}
|
||||
if (options.count("elasticsearch-visitor")) {
|
||||
my->_elasticsearch_visitor = options["elasticsearch-visitor"].as<bool>();
|
||||
}
|
||||
if (options.count("elasticsearch-basic-auth")) {
|
||||
my->_elasticsearch_basic_auth = options["elasticsearch-basic-auth"].as<std::string>();
|
||||
}
|
||||
if (options.count("elasticsearch-index-prefix")) {
|
||||
my->_elasticsearch_index_prefix = options["elasticsearch-index-prefix"].as<std::string>();
|
||||
}
|
||||
if (options.count("elasticsearch-operation-object")) {
|
||||
my->_elasticsearch_operation_object = options["elasticsearch-operation-object"].as<bool>();
|
||||
}
|
||||
if (options.count("elasticsearch-start-es-after-block")) {
|
||||
my->_elasticsearch_start_es_after_block = options["elasticsearch-start-es-after-block"].as<uint32_t>();
|
||||
}
|
||||
if (options.count("elasticsearch-operation-string")) {
|
||||
my->_elasticsearch_operation_string = options["elasticsearch-operation-string"].as<bool>();
|
||||
}
|
||||
if (options.count("elasticsearch-mode")) {
|
||||
const auto option_number = options["elasticsearch-mode"].as<uint16_t>();
|
||||
if(option_number > mode::all)
|
||||
FC_THROW_EXCEPTION(graphene::chain::plugin_exception, "Elasticsearch mode not valid");
|
||||
my->_elasticsearch_mode = static_cast<mode>(options["elasticsearch-mode"].as<uint16_t>());
|
||||
}
|
||||
my->init_program_options( options );
|
||||
|
||||
if(my->_elasticsearch_mode != mode::only_query) {
|
||||
if (my->_elasticsearch_mode == mode::all && !my->_elasticsearch_operation_string)
|
||||
|
|
@ -714,14 +725,14 @@ void elasticsearch_plugin::plugin_initialize(const boost::program_options::varia
|
|||
|
||||
graphene::utilities::checkESVersion7OrAbove(es, my->is_es_version_7_or_above);
|
||||
|
||||
ilog("elasticsearch ACCOUNT HISTORY: plugin_initialize() begin");
|
||||
ilog("elasticsearch ACCOUNT HISTORY: plugin_initialize() end");
|
||||
}
|
||||
|
||||
void elasticsearch_plugin::plugin_startup()
|
||||
{
|
||||
// Nothing to do
|
||||
|
||||
{
|
||||
ilog("elasticsearch ACCOUNT HISTORY: plugin_startup() begin");
|
||||
// Nothing to do
|
||||
ilog("elasticsearch ACCOUNT HISTORY: plugin_startup() end");
|
||||
}
|
||||
|
||||
operation_history_object elasticsearch_plugin::get_operation_by_id(operation_history_id_type id)
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@ class es_objects_plugin_impl
|
|||
bool genesis();
|
||||
void remove_from_database(object_id_type id, std::string index);
|
||||
|
||||
friend class graphene::es_objects::es_objects_plugin;
|
||||
|
||||
private:
|
||||
es_objects_plugin& _self;
|
||||
std::string _es_objects_elasticsearch_url = "http://localhost:9200/";
|
||||
std::string _es_objects_auth = "";
|
||||
|
|
@ -102,6 +105,7 @@ class es_objects_plugin_impl
|
|||
private:
|
||||
template<typename T>
|
||||
void prepareTemplate(T blockchain_object, string index_name);
|
||||
void init_program_options(const boost::program_options::variables_map& options);
|
||||
};
|
||||
|
||||
bool es_objects_plugin_impl::genesis()
|
||||
|
|
@ -570,6 +574,72 @@ es_objects_plugin_impl::~es_objects_plugin_impl()
|
|||
}
|
||||
return;
|
||||
}
|
||||
void es_objects_plugin_impl::init_program_options(const boost::program_options::variables_map& options)
|
||||
{
|
||||
if (options.count("es-objects-elasticsearch-url")) {
|
||||
_es_objects_elasticsearch_url = options["es-objects-elasticsearch-url"].as<std::string>();
|
||||
}
|
||||
if (options.count("es-objects-auth")) {
|
||||
_es_objects_auth = options["es-objects-auth"].as<std::string>();
|
||||
}
|
||||
if (options.count("es-objects-bulk-replay")) {
|
||||
_es_objects_bulk_replay = options["es-objects-bulk-replay"].as<uint32_t>();
|
||||
}
|
||||
if (options.count("es-objects-bulk-sync")) {
|
||||
_es_objects_bulk_sync = options["es-objects-bulk-sync"].as<uint32_t>();
|
||||
}
|
||||
if (options.count("es-objects-proposals")) {
|
||||
_es_objects_proposals = options["es-objects-proposals"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-accounts")) {
|
||||
_es_objects_accounts = options["es-objects-accounts"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-assets")) {
|
||||
_es_objects_assets = options["es-objects-assets"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-balances")) {
|
||||
_es_objects_balances = options["es-objects-balances"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-limit-orders")) {
|
||||
_es_objects_limit_orders = options["es-objects-limit-orders"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-asset-bitasset")) {
|
||||
_es_objects_asset_bitasset = options["es-objects-asset-bitasset"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-account-role")) {
|
||||
_es_objects_balances = options["es-objects-account-role"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-committee-member")) {
|
||||
_es_objects_balances = options["es-objects-committee-member"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-nft")) {
|
||||
_es_objects_balances = options["es-objects-nft"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-son")) {
|
||||
_es_objects_balances = options["es-objects-son"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-transaction")) {
|
||||
_es_objects_balances = options["es-objects-transaction"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-vesting-balance")) {
|
||||
_es_objects_balances = options["es-objects-vesting-balance"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-witness")) {
|
||||
_es_objects_balances = options["es-objects-witness"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-worker")) {
|
||||
_es_objects_balances = options["es-objects-worker"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-index-prefix")) {
|
||||
_es_objects_index_prefix = options["es-objects-index-prefix"].as<std::string>();
|
||||
}
|
||||
if (options.count("es-objects-keep-only-current")) {
|
||||
_es_objects_keep_only_current = options["es-objects-keep-only-current"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-start-es-after-block")) {
|
||||
_es_objects_start_es_after_block = options["es-objects-start-es-after-block"].as<uint32_t>();
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace detail
|
||||
|
||||
|
|
@ -630,69 +700,9 @@ void es_objects_plugin::plugin_set_program_options(
|
|||
|
||||
void es_objects_plugin::plugin_initialize(const boost::program_options::variables_map& options)
|
||||
{
|
||||
if (options.count("es-objects-elasticsearch-url")) {
|
||||
my->_es_objects_elasticsearch_url = options["es-objects-elasticsearch-url"].as<std::string>();
|
||||
}
|
||||
if (options.count("es-objects-auth")) {
|
||||
my->_es_objects_auth = options["es-objects-auth"].as<std::string>();
|
||||
}
|
||||
if (options.count("es-objects-bulk-replay")) {
|
||||
my->_es_objects_bulk_replay = options["es-objects-bulk-replay"].as<uint32_t>();
|
||||
}
|
||||
if (options.count("es-objects-bulk-sync")) {
|
||||
my->_es_objects_bulk_sync = options["es-objects-bulk-sync"].as<uint32_t>();
|
||||
}
|
||||
if (options.count("es-objects-proposals")) {
|
||||
my->_es_objects_proposals = options["es-objects-proposals"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-accounts")) {
|
||||
my->_es_objects_accounts = options["es-objects-accounts"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-assets")) {
|
||||
my->_es_objects_assets = options["es-objects-assets"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-balances")) {
|
||||
my->_es_objects_balances = options["es-objects-balances"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-limit-orders")) {
|
||||
my->_es_objects_limit_orders = options["es-objects-limit-orders"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-asset-bitasset")) {
|
||||
my->_es_objects_asset_bitasset = options["es-objects-asset-bitasset"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-account-role")) {
|
||||
my->_es_objects_balances = options["es-objects-account-role"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-committee-member")) {
|
||||
my->_es_objects_balances = options["es-objects-committee-member"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-nft")) {
|
||||
my->_es_objects_balances = options["es-objects-nft"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-son")) {
|
||||
my->_es_objects_balances = options["es-objects-son"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-transaction")) {
|
||||
my->_es_objects_balances = options["es-objects-transaction"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-vesting-balance")) {
|
||||
my->_es_objects_balances = options["es-objects-vesting-balance"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-witness")) {
|
||||
my->_es_objects_balances = options["es-objects-witness"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-worker")) {
|
||||
my->_es_objects_balances = options["es-objects-worker"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-index-prefix")) {
|
||||
my->_es_objects_index_prefix = options["es-objects-index-prefix"].as<std::string>();
|
||||
}
|
||||
if (options.count("es-objects-keep-only-current")) {
|
||||
my->_es_objects_keep_only_current = options["es-objects-keep-only-current"].as<bool>();
|
||||
}
|
||||
if (options.count("es-objects-start-es-after-block")) {
|
||||
my->_es_objects_start_es_after_block = options["es-objects-start-es-after-block"].as<uint32_t>();
|
||||
}
|
||||
ilog("elasticsearch OBJECTS: plugin_initialize() begin");
|
||||
|
||||
my->init_program_options( options );
|
||||
|
||||
database().applied_block.connect([this](const signed_block &b) {
|
||||
if(b.block_num() == 1 && my->_es_objects_start_es_after_block == 0) {
|
||||
|
|
@ -736,13 +746,14 @@ void es_objects_plugin::plugin_initialize(const boost::program_options::variable
|
|||
|
||||
graphene::utilities::checkESVersion7OrAbove(es, my->is_es_version_7_or_above);
|
||||
|
||||
ilog("elasticsearch OBJECTS: plugin_initialize() begin");
|
||||
ilog("elasticsearch OBJECTS: plugin_initialize() end");
|
||||
}
|
||||
|
||||
void es_objects_plugin::plugin_startup()
|
||||
{
|
||||
{
|
||||
ilog("elasticsearch OBJECTS: plugin_startup() begin");
|
||||
// Nothing to do
|
||||
ilog("elasticsearch OBJECTS: plugin_startup() begin");
|
||||
ilog("elasticsearch OBJECTS: plugin_startup() end");
|
||||
}
|
||||
|
||||
} }
|
||||
Loading…
Reference in a new issue