#237 Move generateIndexName(...) from util to ES plugin

This commit is contained in:
Vladislav Dobromyslov 2022-01-20 04:23:35 -04:00
parent d04e0c1c99
commit 694fcf00f3
4 changed files with 26 additions and 23 deletions

View file

@ -22,6 +22,7 @@
* THE SOFTWARE.
*/
#include <boost/algorithm/string.hpp>
#include <graphene/elasticsearch/elasticsearch_plugin.hpp>
#include <graphene/chain/impacted.hpp>
#include <graphene/chain/account_evaluator.hpp>
@ -33,6 +34,15 @@ namespace graphene { namespace elasticsearch {
namespace detail
{
const std::string generateIndexName(const fc::time_point_sec& block_date, const std::string& _elasticsearch_index_prefix)
{
auto block_date_string = block_date.to_iso_string();
std::vector<std::string> parts;
boost::split(parts, block_date_string, boost::is_any_of("-"));
std::string index_name = _elasticsearch_index_prefix + parts[0] + "-" + parts[1];
return index_name;
}
class elasticsearch_plugin_impl
{
public:
@ -107,7 +117,7 @@ elasticsearch_plugin_impl::~elasticsearch_plugin_impl()
bool elasticsearch_plugin_impl::update_account_histories( const signed_block& b )
{
checkState(b.timestamp);
index_name = graphene::utilities::generateIndexName(b.timestamp, _elasticsearch_index_prefix);
index_name = generateIndexName(b.timestamp, _elasticsearch_index_prefix);
graphene::chain::database& db = database();
const vector<optional< operation_history_object > >& hist = db.get_applied_operations();
@ -710,7 +720,7 @@ void elasticsearch_plugin::plugin_initialize(const boost::program_options::varia
void elasticsearch_plugin::plugin_startup()
{
// Nothing to do
ilog("elasticsearch ACCOUNT HISTORY: plugin_startup() begin");
}

View file

@ -24,7 +24,6 @@
#include <graphene/utilities/elasticsearch.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string.hpp>
#include <fc/log/logger.hpp>
#include <fc/io/json.hpp>
@ -182,15 +181,6 @@ const std::string getEndPoint(ES& es)
return doCurl(curl_request);
}
const std::string generateIndexName(const fc::time_point_sec& block_date, const std::string& _elasticsearch_index_prefix)
{
auto block_date_string = block_date.to_iso_string();
std::vector<std::string> parts;
boost::split(parts, block_date_string, boost::is_any_of("-"));
std::string index_name = _elasticsearch_index_prefix + parts[0] + "-" + parts[1];
return index_name;
}
const std::string doCurl(CurlRequest& curl)
{
std::string CurlReadBuffer;

View file

@ -62,7 +62,6 @@ namespace graphene { namespace utilities {
bool deleteAll(ES& es);
bool handleBulkResponse(long http_code, const std::string& CurlReadBuffer);
const std::string getEndPoint(ES& es);
const std::string generateIndexName(const fc::time_point_sec& block_date, const std::string& _elasticsearch_index_prefix);
const std::string doCurl(CurlRequest& curl);
const std::string joinBulkLines(const std::vector<std::string>& bulk);
long getResponseCode(CURL *handler);

View file

@ -38,6 +38,10 @@ using namespace graphene::chain;
using namespace graphene::chain::test;
using namespace graphene::app;
const std::string g_es_url = "http://localhost:9200/";
const std::string g_es_index_prefix = "peerplays-";
const std::string g_es_ppobjects_prefix = "ppobjects-";
BOOST_FIXTURE_TEST_SUITE( elasticsearch_tests, database_fixture )
BOOST_AUTO_TEST_CASE(elasticsearch_account_history) {
@ -48,8 +52,8 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) {
graphene::utilities::ES es;
es.curl = curl;
es.elasticsearch_url = "http://localhost:9200/";
es.index_prefix = "peerplays-";
es.elasticsearch_url = g_es_url;
es.index_prefix = g_es_index_prefix;
//es.auth = "elastic:changeme";
// delete all first
@ -114,7 +118,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) {
// check the visitor data
auto block_date = db.head_block_time();
std::string index_name = graphene::utilities::generateIndexName(block_date, "peerplays-");
std::string index_name = g_es_index_prefix + block_date.to_iso_string().substr( 0, 7 ); // yyyy-mm
es.endpoint = index_name + "/_doc/2.9.12"; // we know last op is a transfer of amount 300
res = graphene::utilities::getEndPoint(es);
@ -137,8 +141,8 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) {
graphene::utilities::ES es;
es.curl = curl;
es.elasticsearch_url = "http://localhost:9200/";
es.index_prefix = "ppobjects-";
es.elasticsearch_url = g_es_url;
es.index_prefix = g_es_ppobjects_prefix;
//es.auth = "elastic:changeme";
// delete all first
@ -192,11 +196,11 @@ BOOST_AUTO_TEST_CASE(elasticsearch_suite) {
graphene::utilities::ES es;
es.curl = curl;
es.elasticsearch_url = "http://localhost:9200/";
es.index_prefix = "peerplays-";
es.elasticsearch_url = g_es_url;
es.index_prefix = g_es_index_prefix;
auto delete_account_history = graphene::utilities::deleteAll(es);
fc::usleep(fc::milliseconds(1000));
es.index_prefix = "ppobjects-";
es.index_prefix = g_es_ppobjects_prefix;
auto delete_objects = graphene::utilities::deleteAll(es);
fc::usleep(fc::milliseconds(1000));
@ -218,8 +222,8 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) {
graphene::utilities::ES es;
es.curl = curl;
es.elasticsearch_url = "http://localhost:9200/";
es.index_prefix = "peerplays-";
es.elasticsearch_url = g_es_url;
es.index_prefix = g_es_index_prefix;
auto delete_account_history = graphene::utilities::deleteAll(es);