9 #define BOOST_BIND_GLOBAL_PLACEHOLDERS 10 #include <boost/asio/ssl.hpp> 15 #include <boost/thread/mutex.hpp> 20 class FailbackPollerService;
23 #include "gpudb/Avro.hpp" 59 class GPUdb :
private boost::noncopyable
68 #ifndef GPUDB_NO_HTTPS 93 #ifndef GPUDB_NO_HTTPS 115 #ifndef GPUDB_NO_HTTPS 116 boost::asio::ssl::context* m_sslContext;
117 bool m_bypassSslCertCheck;
120 std::string m_username;
121 std::string m_password;
122 std::string m_oauthToken;
123 std::string m_primaryUrl;
125 bool m_disableFailover;
126 bool m_disableAutoDiscovery;
127 size_t m_threadCount;
128 avro::ExecutorPtr m_executor;
129 std::map<std::string, std::string> m_httpHeaders;
191 GPUdb(
const HttpUrl& url,
const Options& options = Options());
208 GPUdb(
const std::string& url,
const Options& options = Options());
221 GPUdb(
const std::vector<HttpUrl>& urls,
const Options& options = Options());
235 GPUdb(
const std::vector<std::string>& urls,
const Options& options = Options());
243 const std::vector<HttpUrl>&
getUrls()
const;
245 const std::vector<HttpUrl>&
getHmUrls()
const;
247 #ifndef GPUDB_NO_HTTPS 275 long execute(
const std::string& sql);
286 long execute(
const std::string& sql,
const std::string& parameters);
298 long execute(
const std::string& sql,
const std::string& parameters,
299 const std::map<std::string, std::string>& options);
301 template<
typename T>
long execute(
const std::string& sql,
const std::vector<T>& parameters);
302 template<
typename T>
long execute(
const std::string& sql,
const std::vector<T>& parameters,
303 const std::map<std::string, std::string>& options);
333 const std::string& value );
357 template<
typename TRequest,
typename TResponse>
359 const TRequest& request,
361 const bool enableCompression =
false)
const 363 std::vector<uint8_t> requestBytes;
366 avro::encode(requestBytes, request);
368 catch (
const std::exception& ex )
377 submitRequestRaw(url, requestBytes, gpudbResponse, enableCompression);
381 avro::decode(response, gpudbResponse.
data);
383 catch (
const std::exception& ex )
387 <<
"'; please ensure that the client API matches the server API version." );
393 template<
typename TRequest,
typename TResponse>
395 const TRequest& request,
397 const bool enableCompression =
false)
const 399 std::vector<uint8_t> requestBytes;
402 avro::encode(requestBytes, request);
404 catch (
const std::exception& ex )
413 submitRequestRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
417 avro::decode(response, gpudbResponse.
data);
419 catch (
const std::exception& ex )
423 <<
"'; please ensure that the client API matches the server API version." );
430 template<
typename TRequest,
typename TResponse>
432 const TRequest& request,
434 const bool enableCompression =
false)
const 436 submitRequest( (std::string) endpoint, request, response, enableCompression );
454 template<
typename TRequest,
typename TResponse>
456 const TRequest& request,
458 const bool enableCompression =
false)
const 461 std::vector<uint8_t> requestBytes;
464 avro::encode(requestBytes, request);
466 catch (
const std::exception& ex )
475 submitRequestToHostManagerRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
479 avro::decode(response, gpudbResponse.
data);
481 catch (
const std::exception& ex )
485 <<
"'; please ensure that the client API matches the server API version." );
505 template<
typename TRequest,
typename TResponse>
507 const TRequest& request,
509 const bool enableCompression =
false)
const 518 void addKnownType(
const std::string& typeId,
const avro::DecoderPtr& decoder);
527 void addKnownType(
const std::string& typeId,
const std::string& schemaString)
529 addKnownType(typeId, avro::createDecoder<T>(schemaString));
533 void addKnownType(
const std::string& typeId, const ::avro::ValidSchema& schema)
560 static const std::string API_VERSION;
562 static const std::string FAILOVER_TRIGGER_MESSAGES[];
563 static const std::string PROTECTED_HEADERS[];
564 static const std::string HA_SYNCHRONICITY_MODE_VALUES[];
566 static const size_t NUM_TRIGGER_MESSAGES;
568 mutable std::vector<HttpUrl> m_urls;
569 mutable std::vector<HttpUrl> m_hmUrls;
570 std::string m_primaryUrlStr;
572 mutable std::vector<size_t> m_urlIndices;
573 mutable boost::mutex m_urlMutex;
574 mutable size_t m_currentUrl;
576 #ifndef GPUDB_NO_HTTPS 577 boost::asio::ssl::context* m_sslContext;
580 std::string m_username;
581 std::string m_password;
582 std::string m_oauthToken;
583 std::string m_authorization;
585 bool m_disableFailover;
586 bool m_bypassSslCertCheck;
587 bool m_disableAutoDiscovery;
588 size_t m_threadCount;
589 avro::ExecutorPtr m_executor;
590 std::map<std::string, std::string> m_httpHeaders;
595 mutable std::map<std::string, avro::DecoderPtr> m_knownTypes;
596 mutable boost::mutex m_knownTypesMutex;
606 void removeProtectedHttpHeaders();
609 void handlePrimaryURL();
611 const std::string createAuthorizationHeader()
const;
613 void getAuthorizationFromHttpHeaders();
616 static HASynchronicityMode findHASyncModeByValue(
const std::vector<std::string>& values,
const std::string value);
619 void getHAringHeadNodeAddresses();
620 bool isKineticaRunning(
const std::string& primaryURL)
const;
623 void updateHostManagerUrls();
624 void setHostManagerPort(uint16_t value);
631 void randomizeURLs()
const;
639 const HttpUrl* getUrlPointer()
const;
640 const HttpUrl* getHmUrlPointer()
const;
643 bool checkFailbackConditions()
const;
648 void initHttpRequest(
HttpRequest& httpRequest)
const;
649 void submitRequestRaw(
const std::string& endpoint,
650 const std::vector<uint8_t>& request,
652 const bool enableCompression)
const;
653 void submitRequestToHostManagerRaw(
const std::string& endpoint,
654 const std::vector<uint8_t>& request,
656 const bool enableCompression)
const;
657 void submitRequestRaw(
const HttpUrl& url,
658 const std::vector<uint8_t>& request,
660 const bool enableCompression,
661 const bool throwOnError =
true)
const;
664 avro::DecoderPtr getDecoder(
const std::string& typeId)
const;
665 void setDecoderIfMissing(
const std::string& typeId,
666 const std::string& label,
667 const std::string& schemaString,
668 const std::map<std::string, std::vector<std::string> >& properties)
const;
Options & setSslContext(boost::asio::ssl::context *value)
void addKnownType(const std::string &typeId, const avro::DecoderPtr &decoder)
std::string getPassword() const
Do NOT synchronize any endpoint call.
void addKnownTypeFromTable(const std::string &tableName, const ::avro::ValidSchema &schema)
Options & setHttpHeaders(const std::map< std::string, std::string > &value)
boost::asio::ssl::context * getSslContext() const
std::string getUsername() const
TResponse & submitRequest(const HttpUrl &url, const TRequest &request, TResponse &response, const bool enableCompression=false) const
HASynchronicityMode
A enumeration of high-availability synchronicity override modes.
static const std::string DB_OFFLINE_ERROR_MESSAGE
GPUdb(const HttpUrl &url, const Options &options=Options())
Pass a single HttpURL and options to instantiate a GPUdb object.
const std::vector< HttpUrl > & getUrls() const
void updateHostManagerPort()
Update the host manager port by inquiring the server.
#define GPUDB_STREAM_TO_STRING(...)
static const std::string HEADER_AUTHORIZATION
Headers used internally; MUST add each of them to PROTECTED_HEADERS in the .cpp file.
No override; defer to the HA process for synchronizing endpoints (which has different logic for diffe...
void addKnownType(const std::string &typeId)
bool getBypassSslCertCheck() const
void addKnownTypeFromTable(const std::string &tableName)
size_t getThreadCount() const
TResponse & submitRequest(const std::string &endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
avro::ExecutorPtr getExecutor() const
long execute(const std::string &sql)
This method is used to execute a SQL statement (e.g., DML, DDL).
const std::vector< HttpUrl > & getHmUrls() const
const std::string & getPrimaryURL() const
Return a string containing the URL for the primary cluster; empty string otherwise.
bool getUseSnappy() const
static const std::string HEADER_CONTENT_LENGTH
bool getDisableAutoDiscovery() const
Options & setHostManagerPort(const uint16_t value)
Sends a http request directly to each cluster, executes the query locally, and waits for the response...
const std::map< std::string, std::string > & getHttpHeaders() const
size_t getThreadCount() const
Explicitly do NOT replicate across the HA cluster.
bool getUseSnappy() const
static const std::string DB_CONNECTION_RESET_ERROR_MESSAGE
Special error messages indicating that a connection failure happened (generally should trigger a high...
static const std::string HEADER_HA_SYNC_MODE
size_t getTimeout() const
Queues a request to RMQ for each cluster, executes the query locally, and returns to the user.
std::string getPrimaryUrl() const
Return the URL of the primary cluster, if any (empty string delineates that none was set)
Options & setUsername(const std::string &value)
HASynchronicityMode getHASyncMode() const
static const std::string DB_EXITING_ERROR_MESSAGE
boost::asio::ssl::context * getSslContext() const
uint16_t getHostManagerPort() const
Options & setDisableFailover(const bool value)
void addKnownTypeFromTable(const std::string &tableName, const avro::DecoderPtr &decoder)
void addHttpHeader(const std::string &header, const std::string &value)
Adds an HTTP header to the map of additional HTTP headers to send to GPUdb with each request.
Options & setOauthToken(const std::string &value)
void addKnownType(const std::string &typeId, const ::avro::ValidSchema &schema)
Options & setPrimaryUrl(const std::string &value)
Set the URL for the primary cluster.
const HttpUrl & getHmUrl() const
static const std::string DB_HM_OFFLINE_ERROR_MESSAGE
static std::string getApiVersion()
Options & setBypassSslCertCheck(const bool value)
Options & setExecutor(const avro::ExecutorPtr value)
TResponse & submitRequestToHostManager(const char *endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
Submit an HTTP request to the host manager.
void setHASyncMode(HASynchronicityMode mode)
Sets the high-availability synchronization mode which will override the default mode.
std::map< std::string, std::string > & getHttpHeaders()
Get the HTTP headers (will include the high-availability synchronicity override header)
const std::string & getPassword() const
static const int64_t END_OF_SET
Options & setTimeout(const size_t value)
const std::string & getOauthToken() const
static const std::string HEADER_CONTENT_TYPE
size_t getTimeout() const
The wrapper used by the GPUdb server for all endpoint responses.
Options & setThreadCount(const size_t value)
Options & setDisableAutoDiscovery(const bool value)
void addKnownTypeFromTable(const std::string &tableName, const std::string &schemaString)
bool getBypassSslCertCheck() const
std::vector< uint8_t > data
const HttpUrl & getUrl() const
std::string getOauthToken() const
static const std::string DB_CONNECTION_REFUSED_ERROR_MESSAGE
Synchronize all endpoint calls.
Options & addHttpHeader(const std::string &header, const std::string &value)
static const std::string DB_SYSTEM_LIMITED_ERROR_MESSAGE
Options & setUseSnappy(const bool value)
TResponse & submitRequest(const char *endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
bool getDisableFailover() const
void removeHttpHeader(const std::string &header)
Removes the given HTTP header from the map of additional HTTP headers to send to GPUdb with each requ...
Options & setPassword(const std::string &value)
TResponse & submitRequestToHostManager(const std::string &endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
Submit an HTTP request to the host manager.
void addKnownType(const std::string &typeId, const std::string &schemaString)
const std::string & getUsername() const
avro::ExecutorPtr getExecutor() const