BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
elasticsearch.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 oxarbitrage, and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 #include <cstddef>
26 #include <string>
27 #include <vector>
28 
29 #include <curl/curl.h>
30 #include <fc/time.hpp>
31 #include <fc/variant_object.hpp>
32 
33 size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp);
34 
35 namespace graphene { namespace utilities {
36 
37  class ES {
38  public:
39  CURL *curl;
40  std::vector <std::string> bulk_lines;
41  std::string elasticsearch_url;
42  std::string index_prefix;
43  std::string auth;
44  std::string endpoint;
45  std::string query;
46  };
47  class CurlRequest {
48  public:
49  CURL *handler;
50  std::string url;
51  std::string type;
52  std::string auth;
53  std::string query;
54  };
55 
56  bool SendBulk(ES&& es);
57  const std::vector<std::string> createBulk(const fc::mutable_variant_object& bulk_header, std::string&& data);
58  bool checkES(ES& es);
59  const std::string simpleQuery(ES& es);
60  bool deleteAll(ES& es);
61  bool handleBulkResponse(long http_code, const std::string& CurlReadBuffer);
62  const std::string getEndPoint(ES& es);
63  const std::string generateIndexName(const fc::time_point_sec& block_date, const std::string& _elasticsearch_index_prefix);
64  const std::string doCurl(CurlRequest& curl);
65  const std::string joinBulkLines(const std::vector<std::string>& bulk);
66  long getResponseCode(CURL *handler);
67 
68 } } // end namespace graphene::utilities
long getResponseCode(CURL *handler)
bool handleBulkResponse(long http_code, const std::string &CurlReadBuffer)
Definition: api.cpp:56
size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
bool SendBulk(ES &&es)
const std::string doCurl(CurlRequest &curl)
const std::vector< std::string > createBulk(const fc::mutable_variant_object &bulk_header, std::string &&data)
const std::string simpleQuery(ES &es)
bool deleteAll(ES &es)
bool checkES(ES &es)
const std::string getEndPoint(ES &es)
const std::string joinBulkLines(const std::vector< std::string > &bulk)
const std::string generateIndexName(const fc::time_point_sec &block_date, const std::string &_elasticsearch_index_prefix)
std::vector< std::string > bulk_lines
An order-perserving dictionary of variant&#39;s.