7 #include <boost/asio/ssl.hpp> 12 #include <boost/thread/mutex.hpp> 19 #include "gpudb/Avro.hpp" 55 class GPUdb :
private boost::noncopyable
64 #ifndef GPUDB_NO_HTTPS 78 #ifndef GPUDB_NO_HTTPS 94 #ifndef GPUDB_NO_HTTPS 95 boost::asio::ssl::context* m_sslContext;
98 std::string m_username;
99 std::string m_password;
101 size_t m_threadCount;
102 avro::ExecutorPtr m_executor;
103 std::map<std::string, std::string> m_httpHeaders;
119 const std::vector<HttpUrl>&
getUrls()
const;
121 const std::vector<HttpUrl>&
getHmUrls()
const;
123 #ifndef GPUDB_NO_HTTPS 138 template<
typename TRequest,
typename TResponse>
140 const TRequest& request,
142 const bool enableCompression =
false)
const 144 std::vector<uint8_t> requestBytes;
145 avro::encode(requestBytes, request);
147 submitRequestRaw(url, requestBytes, gpudbResponse, enableCompression);
148 avro::decode(response, gpudbResponse.
data);
152 template<
typename TRequest,
typename TResponse>
154 const TRequest& request,
156 const bool enableCompression =
false)
const 158 std::vector<uint8_t> requestBytes;
159 avro::encode(requestBytes, request);
161 submitRequestRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
162 avro::decode(response, gpudbResponse.
data);
166 template<
typename TRequest,
typename TResponse>
168 const TRequest& request,
170 const bool enableCompression =
false)
const 172 submitRequest( (std::string) endpoint, request, response, enableCompression );
190 template<
typename TRequest,
typename TResponse>
192 const TRequest& request,
194 const bool enableCompression =
false)
const 197 std::vector<uint8_t> requestBytes;
198 avro::encode(requestBytes, request);
200 submitRequestToHostManagerRaw(endpoint, requestBytes, gpudbResponse, enableCompression);
201 avro::decode(response, gpudbResponse.
data);
219 template<
typename TRequest,
typename TResponse>
221 const TRequest& request,
223 const bool enableCompression =
false)
const 232 void addKnownType(
const std::string& typeId,
const avro::DecoderPtr& decoder);
241 void addKnownType(
const std::string& typeId,
const std::string& schemaString)
243 addKnownType(typeId, avro::createDecoder<T>(schemaString));
247 void addKnownType(
const std::string& typeId, const ::avro::ValidSchema& schema)
273 static const std::string API_VERSION;
275 std::vector<HttpUrl> m_urls;
276 std::vector<HttpUrl> m_hmUrls;
277 mutable boost::mutex m_urlMutex;
278 mutable size_t m_currentUrl;
279 mutable size_t m_currentHmUrl;
281 #ifndef GPUDB_NO_HTTPS 282 boost::asio::ssl::context* m_sslContext;
285 std::string m_username;
286 std::string m_password;
287 std::string m_authorization;
289 size_t m_threadCount;
290 avro::ExecutorPtr m_executor;
291 std::map<std::string, std::string> m_httpHeaders;
294 mutable std::map<std::string, avro::DecoderPtr> m_knownTypes;
295 mutable boost::mutex m_knownTypesMutex;
298 const HttpUrl* getUrlPointer()
const;
299 const HttpUrl* getHmUrlPointer()
const;
304 void initHttpRequest(
HttpRequest& httpRequest)
const;
305 void submitRequestRaw(
const std::string& endpoint,
306 const std::vector<uint8_t>& request,
308 const bool enableCompression)
const;
309 void submitRequestToHostManagerRaw(
const std::string& endpoint,
310 const std::vector<uint8_t>& request,
312 const bool enableCompression)
const;
313 void submitRequestRaw(
const HttpUrl& url,
314 const std::vector<uint8_t>& request,
316 const bool enableCompression,
317 const bool throwOnError =
true)
const;
320 avro::DecoderPtr getDecoder(
const std::string& typeId)
const;
321 void setDecoderIfMissing(
const std::string& typeId,
322 const std::string& label,
323 const std::string& schemaString,
324 const std::map<std::string, std::vector<std::string> >& properties)
const;
327 void createHostManagerUrl(
const HttpUrl& url, uint16_t hostManagerPort );
328 void createHostManagerUrls(
const std::vector<HttpUrl>& urls, uint16_t hostManagerPort );
Options & setSslContext(boost::asio::ssl::context *value)
void addKnownType(const std::string &typeId, const avro::DecoderPtr &decoder)
std::string getPassword() const
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
GPUdb(const HttpUrl &url, const Options &options=Options())
const std::vector< HttpUrl > & getUrls() const
void updateHostManagerPort()
Update the host manager port by inquiring the server.
void addKnownType(const std::string &typeId)
void addKnownTypeFromTable(const std::string &tableName)
TResponse & submitRequest(const std::string &endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
avro::ExecutorPtr getExecutor() const
const std::vector< HttpUrl > & getHmUrls() const
Options & setHostManagerPort(const uint16_t value)
size_t getThreadCount() const
bool getUseSnappy() const
size_t getTimeout() const
Options & setUsername(const std::string &value)
uint16_t getHostManagerPort() const
void addKnownTypeFromTable(const std::string &tableName, const avro::DecoderPtr &decoder)
void addKnownType(const std::string &typeId, const ::avro::ValidSchema &schema)
const HttpUrl & getHmUrl() const
static std::string getApiVersion()
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.
std::map< std::string, std::string > & getHttpHeaders()
static const int64_t END_OF_SET
Options & setTimeout(const size_t value)
A set of output parameters forendpoint /gpudbresponse}.
Options & setThreadCount(const size_t value)
void addKnownTypeFromTable(const std::string &tableName, const std::string &schemaString)
std::vector< uint8_t > data
const HttpUrl & getUrl() const
Some getters.
Options & addHttpHeader(const std::string &header, const std::string &value)
Options & setUseSnappy(const bool value)
TResponse & submitRequest(const char *endpoint, const TRequest &request, TResponse &response, const bool enableCompression=false) const
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)