9 #define BOOST_BIND_GLOBAL_PLACEHOLDERS 10 #include <boost/asio/ssl.hpp> 15 #include <boost/thread/mutex.hpp> 22 #include "gpudb/Avro.hpp" 58 class GPUdb :
private boost::noncopyable
67 #ifndef GPUDB_NO_HTTPS 92 #ifndef GPUDB_NO_HTTPS 114 #ifndef GPUDB_NO_HTTPS 115 boost::asio::ssl::context* m_sslContext;
116 bool m_bypassSslCertCheck;
119 std::string m_username;
120 std::string m_password;
121 std::string m_oauthToken;
122 std::string m_primaryUrl;
124 bool m_disableFailover;
125 bool m_disableAutoDiscovery;
126 size_t m_threadCount;
127 avro::ExecutorPtr m_executor;
128 std::map<std::string, std::string> m_httpHeaders;
190 GPUdb(
const HttpUrl& url,
const Options& options = Options());
207 GPUdb(
const std::string& url,
const Options& options = Options());
220 GPUdb(
const std::vector<HttpUrl>& urls,
const Options& options = Options());
234 GPUdb(
const std::vector<std::string>& urls,
const Options& options = Options());
242 const std::vector<HttpUrl>&
getUrls()
const;
244 const std::vector<HttpUrl>&
getHmUrls()
const;
246 #ifndef GPUDB_NO_HTTPS 274 long execute(
const std::string& sql);
285 long execute(
const std::string& sql,
const std::string& parameters);
297 long execute(
const std::string& sql,
const std::string& parameters,
298 const std::map<std::string, std::string>& options);
300 template<
typename T>
long execute(
const std::string& sql,
const std::vector<T>& parameters);
301 template<
typename T>
long execute(
const std::string& sql,
const std::vector<T>& parameters,
302 const std::map<std::string, std::string>& options);
332 const std::string& value );
356 template<
typename TRequest,
typename TResponse>
358 const TRequest& request,
360 const bool enableCompression =
false)
const 362 std::vector<uint8_t> requestBytes;
365 avro::encode(requestBytes, request);
367 catch (
const std::exception& ex )
376 submitRequestRaw(url, requestBytes, gpudbResponse, enableCompression);
380 avro::decode(response, gpudbResponse.
data);
382 catch (
const std::exception& ex )
386 <<
"'; please ensure that the client API matches the server API version." );
392 template<
typename TRequest,
typename TResponse>
394 const TRequest& request,
396 const bool enableCompression =
false)
const 398 std::vector<uint8_t> requestBytes;
401 avro::encode(requestBytes, request);
403 catch (
const std::exception& ex )
412 submitRequestRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
416 avro::decode(response, gpudbResponse.
data);
418 catch (
const std::exception& ex )
422 <<
"'; please ensure that the client API matches the server API version." );
429 template<
typename TRequest,
typename TResponse>
431 const TRequest& request,
433 const bool enableCompression =
false)
const 435 submitRequest( (std::string) endpoint, request, response, enableCompression );
453 template<
typename TRequest,
typename TResponse>
455 const TRequest& request,
457 const bool enableCompression =
false)
const 460 std::vector<uint8_t> requestBytes;
463 avro::encode(requestBytes, request);
465 catch (
const std::exception& ex )
474 submitRequestToHostManagerRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
478 avro::decode(response, gpudbResponse.
data);
480 catch (
const std::exception& ex )
484 <<
"'; please ensure that the client API matches the server API version." );
504 template<
typename TRequest,
typename TResponse>
506 const TRequest& request,
508 const bool enableCompression =
false)
const 517 void addKnownType(
const std::string& typeId,
const avro::DecoderPtr& decoder);
526 void addKnownType(
const std::string& typeId,
const std::string& schemaString)
528 addKnownType(typeId, avro::createDecoder<T>(schemaString));
532 void addKnownType(
const std::string& typeId, const ::avro::ValidSchema& schema)
559 static const std::string API_VERSION;
561 static const std::string FAILOVER_TRIGGER_MESSAGES[];
562 static const std::string PROTECTED_HEADERS[];
563 static const std::string HA_SYNCHRONICITY_MODE_VALUES[];
565 static const size_t NUM_TRIGGER_MESSAGES;
567 mutable std::vector<HttpUrl> m_urls;
568 mutable std::vector<HttpUrl> m_hmUrls;
569 std::string m_primaryUrlStr;
571 mutable std::vector<size_t> m_urlIndices;
572 mutable boost::mutex m_urlMutex;
573 mutable size_t m_currentUrl;
575 #ifndef GPUDB_NO_HTTPS 576 boost::asio::ssl::context* m_sslContext;
579 std::string m_username;
580 std::string m_password;
581 std::string m_oauthToken;
582 std::string m_authorization;
584 bool m_disableFailover;
585 bool m_bypassSslCertCheck;
586 bool m_disableAutoDiscovery;
587 size_t m_threadCount;
588 avro::ExecutorPtr m_executor;
589 std::map<std::string, std::string> m_httpHeaders;
594 mutable std::map<std::string, avro::DecoderPtr> m_knownTypes;
595 mutable boost::mutex m_knownTypesMutex;
604 void removeProtectedHttpHeaders();
607 void handlePrimaryURL();
609 const std::string createAuthorizationHeader()
const;
611 void getAuthorizationFromHttpHeaders();
614 static HASynchronicityMode findHASyncModeByValue(
const std::vector<std::string>& values,
const std::string value);
617 void getHAringHeadNodeAddresses();
620 void updateHostManagerUrls();
621 void setHostManagerPort(uint16_t value);
628 void randomizeURLs()
const;
636 const HttpUrl* getUrlPointer()
const;
637 const HttpUrl* getHmUrlPointer()
const;
644 void initHttpRequest(
HttpRequest& httpRequest)
const;
645 void submitRequestRaw(
const std::string& endpoint,
646 const std::vector<uint8_t>& request,
648 const bool enableCompression)
const;
649 void submitRequestToHostManagerRaw(
const std::string& endpoint,
650 const std::vector<uint8_t>& request,
652 const bool enableCompression)
const;
653 void submitRequestRaw(
const HttpUrl& url,
654 const std::vector<uint8_t>& request,
656 const bool enableCompression,
657 const bool throwOnError =
true)
const;
660 avro::DecoderPtr getDecoder(
const std::string& typeId)
const;
661 void setDecoderIfMissing(
const std::string& typeId,
662 const std::string& label,
663 const std::string& schemaString,
664 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