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
86 #ifndef GPUDB_NO_HTTPS
104 #ifndef GPUDB_NO_HTTPS
105 boost::asio::ssl::context* m_sslContext;
108 std::string m_username;
109 std::string m_password;
110 std::string m_primaryUrl;
112 size_t m_threadCount;
113 avro::ExecutorPtr m_executor;
114 std::map<std::string, std::string> m_httpHeaders;
174 GPUdb(
const HttpUrl& url,
const Options& options = Options());
193 GPUdb(
const std::string& url,
const Options& options = Options());
208 GPUdb(
const std::vector<HttpUrl>& urls,
const Options& options = Options());
224 GPUdb(
const std::vector<std::string>& urls,
const Options& options = Options());
232 const std::vector<HttpUrl>&
getUrls()
const;
234 const std::vector<HttpUrl>&
getHmUrls()
const;
236 #ifndef GPUDB_NO_HTTPS
282 const std::string& value );
306 template<
typename TRequest,
typename TResponse>
308 const TRequest& request,
310 const bool enableCompression =
false)
const
312 std::vector<uint8_t> requestBytes;
315 avro::encode(requestBytes, request);
317 catch (
const std::exception& ex )
326 submitRequestRaw(url, requestBytes, gpudbResponse, enableCompression);
330 avro::decode(response, gpudbResponse.
data);
332 catch (
const std::exception& ex )
336 <<
"'; please ensure that the client API matches the server API version." );
342 template<
typename TRequest,
typename TResponse>
344 const TRequest& request,
346 const bool enableCompression =
false)
const
348 std::vector<uint8_t> requestBytes;
351 avro::encode(requestBytes, request);
353 catch (
const std::exception& ex )
362 submitRequestRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
366 avro::decode(response, gpudbResponse.
data);
368 catch (
const std::exception& ex )
372 <<
"'; please ensure that the client API matches the server API version." );
379 template<
typename TRequest,
typename TResponse>
381 const TRequest& request,
383 const bool enableCompression =
false)
const
385 submitRequest( (std::string) endpoint, request, response, enableCompression );
403 template<
typename TRequest,
typename TResponse>
405 const TRequest& request,
407 const bool enableCompression =
false)
const
410 std::vector<uint8_t> requestBytes;
413 avro::encode(requestBytes, request);
415 catch (
const std::exception& ex )
424 submitRequestToHostManagerRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
428 avro::decode(response, gpudbResponse.
data);
430 catch (
const std::exception& ex )
434 <<
"'; please ensure that the client API matches the server API version." );
454 template<
typename TRequest,
typename TResponse>
456 const TRequest& request,
458 const bool enableCompression =
false)
const
467 void addKnownType(
const std::string& typeId,
const avro::DecoderPtr& decoder);
476 void addKnownType(
const std::string& typeId,
const std::string& schemaString)
478 addKnownType(typeId, avro::createDecoder<T>(schemaString));
482 void addKnownType(
const std::string& typeId, const ::avro::ValidSchema& schema)
509 static const std::string API_VERSION;
511 static const std::string FAILOVER_TRIGGER_MESSAGES[];
512 static const std::string PROTECTED_HEADERS[];
513 static const std::string HA_SYNCHRONICITY_MODE_VALUES[];
515 static const size_t NUM_TRIGGER_MESSAGES;
517 mutable std::vector<HttpUrl> m_urls;
518 mutable std::vector<HttpUrl> m_hmUrls;
519 std::string m_primaryUrlStr;
521 mutable std::vector<size_t> m_urlIndices;
522 mutable boost::mutex m_urlMutex;
523 mutable size_t m_currentUrl;
525 #ifndef GPUDB_NO_HTTPS
526 boost::asio::ssl::context* m_sslContext;
529 std::string m_username;
530 std::string m_password;
531 std::string m_authorization;
533 size_t m_threadCount;
534 avro::ExecutorPtr m_executor;
535 std::map<std::string, std::string> m_httpHeaders;
540 mutable std::map<std::string, avro::DecoderPtr> m_knownTypes;
541 mutable boost::mutex m_knownTypesMutex;
550 void handlePrimaryURL();
553 void getHAringHeadNodeAdresses();
556 void updateHostManagerUrls();
557 void setHostManagerPort(uint16_t value);
564 void randomizeURLs()
const;
572 const HttpUrl* getUrlPointer()
const;
573 const HttpUrl* getHmUrlPointer()
const;
580 void initHttpRequest(
HttpRequest& httpRequest)
const;
581 void submitRequestRaw(
const std::string& endpoint,
582 const std::vector<uint8_t>& request,
584 const bool enableCompression)
const;
585 void submitRequestToHostManagerRaw(
const std::string& endpoint,
586 const std::vector<uint8_t>& request,
588 const bool enableCompression)
const;
589 void submitRequestRaw(
const HttpUrl& url,
590 const std::vector<uint8_t>& request,
592 const bool enableCompression,
593 const bool throwOnError =
true)
const;
596 avro::DecoderPtr getDecoder(
const std::string& typeId)
const;
597 void setDecoderIfMissing(
const std::string& typeId,
598 const std::string& label,
599 const std::string& schemaString,
600 const std::map<std::string, std::vector<std::string> >& properties)
const;
const HttpUrl & getHmUrl() 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.
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
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
size_t getThreadCount() const
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...
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 & 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)
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