8 #include <boost/asio/ssl.hpp>
13 #include <boost/thread/mutex.hpp>
20 #include "gpudb/Avro.hpp"
56 class GPUdb :
private boost::noncopyable
65 #ifndef GPUDB_NO_HTTPS
89 #ifndef GPUDB_NO_HTTPS
110 #ifndef GPUDB_NO_HTTPS
111 boost::asio::ssl::context* m_sslContext;
112 bool m_bypassSslCertCheck;
115 std::string m_username;
116 std::string m_password;
117 std::string m_primaryUrl;
119 bool m_disableFailover;
120 bool m_disableAutoDiscovery;
121 size_t m_threadCount;
122 avro::ExecutorPtr m_executor;
123 std::map<std::string, std::string> m_httpHeaders;
185 GPUdb(
const HttpUrl& url,
const Options& options = Options());
204 GPUdb(
const std::string& url,
const Options& options = Options());
219 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
294 const std::string& value );
318 template<
typename TRequest,
typename TResponse>
320 const TRequest& request,
322 const bool enableCompression =
false)
const
324 std::vector<uint8_t> requestBytes;
327 avro::encode(requestBytes, request);
329 catch (
const std::exception& ex )
338 submitRequestRaw(url, requestBytes, gpudbResponse, enableCompression);
342 avro::decode(response, gpudbResponse.
data);
344 catch (
const std::exception& ex )
348 <<
"'; please ensure that the client API matches the server API version." );
354 template<
typename TRequest,
typename TResponse>
356 const TRequest& request,
358 const bool enableCompression =
false)
const
360 std::vector<uint8_t> requestBytes;
363 avro::encode(requestBytes, request);
365 catch (
const std::exception& ex )
374 submitRequestRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
378 avro::decode(response, gpudbResponse.
data);
380 catch (
const std::exception& ex )
384 <<
"'; please ensure that the client API matches the server API version." );
391 template<
typename TRequest,
typename TResponse>
393 const TRequest& request,
395 const bool enableCompression =
false)
const
397 submitRequest( (std::string) endpoint, request, response, enableCompression );
415 template<
typename TRequest,
typename TResponse>
417 const TRequest& request,
419 const bool enableCompression =
false)
const
422 std::vector<uint8_t> requestBytes;
425 avro::encode(requestBytes, request);
427 catch (
const std::exception& ex )
436 submitRequestToHostManagerRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
440 avro::decode(response, gpudbResponse.
data);
442 catch (
const std::exception& ex )
446 <<
"'; please ensure that the client API matches the server API version." );
466 template<
typename TRequest,
typename TResponse>
468 const TRequest& request,
470 const bool enableCompression =
false)
const
479 void addKnownType(
const std::string& typeId,
const avro::DecoderPtr& decoder);
488 void addKnownType(
const std::string& typeId,
const std::string& schemaString)
490 addKnownType(typeId, avro::createDecoder<T>(schemaString));
494 void addKnownType(
const std::string& typeId, const ::avro::ValidSchema& schema)
521 static const std::string API_VERSION;
523 static const std::string FAILOVER_TRIGGER_MESSAGES[];
524 static const std::string PROTECTED_HEADERS[];
525 static const std::string HA_SYNCHRONICITY_MODE_VALUES[];
527 static const size_t NUM_TRIGGER_MESSAGES;
529 mutable std::vector<HttpUrl> m_urls;
530 mutable std::vector<HttpUrl> m_hmUrls;
531 std::string m_primaryUrlStr;
533 mutable std::vector<size_t> m_urlIndices;
534 mutable boost::mutex m_urlMutex;
535 mutable size_t m_currentUrl;
537 #ifndef GPUDB_NO_HTTPS
538 boost::asio::ssl::context* m_sslContext;
541 std::string m_username;
542 std::string m_password;
543 std::string m_authorization;
545 bool m_disableFailover;
546 bool m_bypassSslCertCheck;
547 bool m_disableAutoDiscovery;
548 size_t m_threadCount;
549 avro::ExecutorPtr m_executor;
550 std::map<std::string, std::string> m_httpHeaders;
555 mutable std::map<std::string, avro::DecoderPtr> m_knownTypes;
556 mutable boost::mutex m_knownTypesMutex;
565 void handlePrimaryURL();
568 void getHAringHeadNodeAddresses();
571 void updateHostManagerUrls();
572 void setHostManagerPort(uint16_t value);
579 void randomizeURLs()
const;
587 const HttpUrl* getUrlPointer()
const;
588 const HttpUrl* getHmUrlPointer()
const;
595 void initHttpRequest(
HttpRequest& httpRequest)
const;
596 void submitRequestRaw(
const std::string& endpoint,
597 const std::vector<uint8_t>& request,
599 const bool enableCompression)
const;
600 void submitRequestToHostManagerRaw(
const std::string& endpoint,
601 const std::vector<uint8_t>& request,
603 const bool enableCompression)
const;
604 void submitRequestRaw(
const HttpUrl& url,
605 const std::vector<uint8_t>& request,
607 const bool enableCompression,
608 const bool throwOnError =
true)
const;
611 avro::DecoderPtr getDecoder(
const std::string& typeId)
const;
612 void setDecoderIfMissing(
const std::string& typeId,
613 const std::string& label,
614 const std::string& schemaString,
615 const std::map<std::string, std::vector<std::string> >& properties)
const;
const HttpUrl & getHmUrl() const
bool getBypassSslCertCheck() const
Options & setSslContext(boost::asio::ssl::context *value)
void addKnownType(const std::string &typeId, const avro::DecoderPtr &decoder)
void addKnownTypeFromTable(const std::string &tableName, const ::avro::ValidSchema &schema)
Options & setHttpHeaders(const std::map< std::string, std::string > &value)
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.
void updateHostManagerPort()
Update the host manager port by inquiring the server.
bool getBypassSslCertCheck() const
std::string getPrimaryUrl() const
Return the URL of the primary cluster, if any (empty string delineates that none was set) ...
#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.
void addKnownType(const std::string &typeId)
void addKnownTypeFromTable(const std::string &tableName)
TResponse & submitRequest(const HttpUrl &url, const TRequest &request, TResponse &response, const bool enableCompression=false) const
const std::string & getPassword() const
TResponse & submitRequestToHostManager(const std::string &endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
Submit an HTTP request to the host manager.
const std::vector< HttpUrl > & getUrls() const
bool getDisableAutoDiscovery() const
static const std::string HEADER_CONTENT_LENGTH
Options & setHostManagerPort(const uint16_t value)
const std::vector< HttpUrl > & getHmUrls() const
avro::ExecutorPtr getExecutor() 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
std::string getPassword() const
TResponse & submitRequestToHostManager(const char *endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
Submit an HTTP request to the host manager.
Options & setUsername(const std::string &value)
static const std::string DB_EXITING_ERROR_MESSAGE
const std::map< std::string, std::string > & getHttpHeaders() const
Options & setDisableFailover(const bool value)
size_t getThreadCount() const
void addKnownTypeFromTable(const std::string &tableName, const avro::DecoderPtr &decoder)
bool getDisableFailover() const
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...
TResponse & submitRequest(const std::string &endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
const std::string & getUsername() const
void addKnownType(const std::string &typeId, const ::avro::ValidSchema &schema)
uint16_t getHostManagerPort() const
size_t getThreadCount() const
Options & setPrimaryUrl(const std::string &value)
Set the URL for the primary cluster.
boost::asio::ssl::context * getSslContext() 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)
size_t getTimeout() const
void setHASyncMode(HASynchronicityMode mode)
Some setters
std::map< std::string, std::string > & getHttpHeaders()
Get the HTTP headers (will include the high-availability synchronicity override header) ...
std::string getUsername() const
HASynchronicityMode getHASyncMode() const
static const int64_t END_OF_SET
boost::asio::ssl::context * getSslContext() const
TResponse & submitRequest(const char *endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
Options & setTimeout(const size_t value)
avro::ExecutorPtr getExecutor() const
static const std::string HEADER_CONTENT_TYPE
const HttpUrl & getUrl() const
Some getters
A set of output parameters forendpoint /gpudbresponse}.
Options & setThreadCount(const size_t value)
Options & setDisableAutoDiscovery(const bool value)
void addKnownTypeFromTable(const std::string &tableName, const std::string &schemaString)
bool getUseSnappy() const
std::vector< uint8_t > data
static const std::string DB_CONNECTION_REFUSED_ERROR_MESSAGE
const std::string & getPrimaryURL() const
Return a string containing the URL for the primary cluster; empty string otherwise.
Options & addHttpHeader(const std::string &header, const std::string &value)
static const std::string DB_SYSTEM_LIMITED_ERROR_MESSAGE
Options & setUseSnappy(const bool value)
size_t getTimeout() 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)
void addKnownType(const std::string &typeId, const std::string &schemaString)
bool getUseSnappy() const