diff options
16 files changed, 589 insertions, 327 deletions
diff --git a/contrib/native/client/CMakeLists.txt b/contrib/native/client/CMakeLists.txt index 7b54b00fd..ddb151917 100644 --- a/contrib/native/client/CMakeLists.txt +++ b/contrib/native/client/CMakeLists.txt @@ -116,8 +116,11 @@ if(MSVC) add_definitions(-DUSE_STATIC_LIB) else() add_definitions(-DBOOST_ALL_DYN_LINK) + #suppress boost warnings (clang, gcc) + add_definitions ("-Wno-unused-local-typedefs") endif() + # Find Protobufs find_package(Protobuf REQUIRED ) include_directories(${PROTOBUF_INCLUDE_DIR}) diff --git a/contrib/native/client/src/clientlib/CMakeLists.txt b/contrib/native/client/src/clientlib/CMakeLists.txt index 343bb4d8c..6124fc898 100644 --- a/contrib/native/client/src/clientlib/CMakeLists.txt +++ b/contrib/native/client/src/clientlib/CMakeLists.txt @@ -20,14 +20,17 @@ set (CLIENTLIB_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/decimalUtils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drillConfig.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drillClient.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drillClientImpl.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drillError.cpp ${CMAKE_CURRENT_SOURCE_DIR}/fieldmeta.cpp ${CMAKE_CURRENT_SOURCE_DIR}/metadata.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/recordBatch.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rpcMessage.cpp ${CMAKE_CURRENT_SOURCE_DIR}/errmsgs.cpp ${CMAKE_CURRENT_SOURCE_DIR}/logger.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/recordBatch.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rpcMessage.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/userProperties.cpp ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/saslAuthenticatorImpl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/zookeeperClient.cpp) diff --git a/contrib/native/client/src/clientlib/drillClient.cpp b/contrib/native/client/src/clientlib/drillClient.cpp index 8eb909b49..429a17886 100644 --- a/contrib/native/client/src/clientlib/drillClient.cpp +++ b/contrib/native/client/src/clientlib/drillClient.cpp @@ -17,25 +17,19 @@ */ #include <stdlib.h> -#include <boost/assign.hpp> #include "drill/common.hpp" #include "drill/drillClient.hpp" #include "drill/fieldmeta.hpp" #include "drill/recordBatch.hpp" +#include "drill/userProperties.hpp" #include "drillClientImpl.hpp" +#include "env.h" #include "errmsgs.hpp" #include "logger.hpp" #include "Types.pb.h" namespace Drill{ -DrillClientError* DrillClientError::getErrorObject(const exec::shared::DrillPBError& e){ - std::string s=Drill::getMessage(ERR_QRY_FAILURE, e.message().c_str()); - DrillClientError* err=NULL; - err=new DrillClientError(QRY_FAILURE, QRY_ERROR_START+QRY_FAILURE, s); - return err; -} - DrillClientInitializer::DrillClientInitializer(){ GOOGLE_PROTOBUF_VERIFY_VERSION; srand(time(NULL)); @@ -45,151 +39,6 @@ DrillClientInitializer::~DrillClientInitializer(){ google::protobuf::ShutdownProtobufLibrary(); } -// Initialize static member of DrillClientConfig -logLevel_t DrillClientConfig::s_logLevel=LOG_ERROR; -const char* DrillClientConfig::s_saslPluginPath = NULL; -uint64_t DrillClientConfig::s_bufferLimit=MAX_MEM_ALLOC_SIZE; -int32_t DrillClientConfig::s_socketTimeout=0; -int32_t DrillClientConfig::s_handshakeTimeout=5; -int32_t DrillClientConfig::s_queryTimeout=180; -int32_t DrillClientConfig::s_heartbeatFrequency=15; // 15 seconds -std::string DrillClientConfig::s_clientName(DRILL_CONNECTOR_NAME); -std::string DrillClientConfig::s_applicationName; - -boost::mutex DrillClientConfig::s_mutex; - -DrillClientConfig::DrillClientConfig(){ - // Do not initialize logging. The Logger object is static and may - // not have been initialized yet - //initLogging(NULL); -} - -DrillClientConfig::~DrillClientConfig(){ -} - -void DrillClientConfig::initLogging(const char* path){ - getLogger().init(path); -} - -void DrillClientConfig::setLogLevel(logLevel_t l){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - s_logLevel=l; - getLogger().m_level=l; - //boost::log::core::get()->set_filter(boost::log::trivial::severity >= s_logLevel); -} - -void DrillClientConfig::setSaslPluginPath(const char *path){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - s_saslPluginPath = path; -} - -const char* DrillClientConfig::getSaslPluginPath(){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - return s_saslPluginPath; -} - -void DrillClientConfig::setBufferLimit(uint64_t l){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - s_bufferLimit=l; -} - -uint64_t DrillClientConfig::getBufferLimit(){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - return s_bufferLimit; -} - -void DrillClientConfig::setSocketTimeout(int32_t t){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - s_socketTimeout=t; -} - -void DrillClientConfig::setHandshakeTimeout(int32_t t){ - if (t > 0) { - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - s_handshakeTimeout = t; - } -} - -void DrillClientConfig::setQueryTimeout(int32_t t){ - if (t>0){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - s_queryTimeout=t; - } -} - -void DrillClientConfig::setHeartbeatFrequency(int32_t t){ - if (t>=0){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - s_heartbeatFrequency=t; - } -} - -int32_t DrillClientConfig::getSocketTimeout(){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - return s_socketTimeout; -} - -int32_t DrillClientConfig::getHandshakeTimeout(){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - return s_handshakeTimeout; -} - -int32_t DrillClientConfig::getQueryTimeout(){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - return s_queryTimeout; -} - -int32_t DrillClientConfig::getHeartbeatFrequency(){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - return s_heartbeatFrequency; -} - -logLevel_t DrillClientConfig::getLogLevel(){ - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - return s_logLevel; -} - -const std::string& DrillClientConfig::getClientName() { - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - return s_clientName; -} - -void DrillClientConfig::setClientName(const std::string& name) { - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - s_clientName = name; -} - -const std::string& DrillClientConfig::getApplicationName() { - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - return s_applicationName; -} - -void DrillClientConfig::setApplicationName(const std::string& name) { - boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); - s_applicationName = name; -} - -//Using boost assign to initialize maps. -const std::map<std::string, uint32_t> DrillUserProperties::USER_PROPERTIES=boost::assign::map_list_of - ( USERPROP_USERNAME, USERPROP_FLAGS_SERVERPROP|USERPROP_FLAGS_USERNAME|USERPROP_FLAGS_STRING ) - ( USERPROP_PASSWORD, USERPROP_FLAGS_SERVERPROP|USERPROP_FLAGS_PASSWORD) - ( USERPROP_SCHEMA, USERPROP_FLAGS_SERVERPROP|USERPROP_FLAGS_STRING) - ( USERPROP_IMPERSONATION_TARGET, USERPROP_FLAGS_SERVERPROP|USERPROP_FLAGS_STRING) - ( USERPROP_AUTH_MECHANISM, USERPROP_FLAGS_STRING) - ( USERPROP_SERVICE_NAME, USERPROP_FLAGS_STRING) - ( USERPROP_SERVICE_HOST, USERPROP_FLAGS_STRING) - ( USERPROP_USESSL, USERPROP_FLAGS_BOOLEAN|USERPROP_FLAGS_SSLPROP) - ( USERPROP_FILEPATH, USERPROP_FLAGS_STRING|USERPROP_FLAGS_SSLPROP|USERPROP_FLAGS_FILEPATH) - ( USERPROP_FILENAME, USERPROP_FLAGS_STRING|USERPROP_FLAGS_SSLPROP|USERPROP_FLAGS_FILENAME) - ( USERPROP_SASL_ENCRYPT, USERPROP_FLAGS_STRING) -; - -bool DrillUserProperties::validate(std::string& err){ - bool ret=true; - //We can add additional validation for any params here - return ret; -} - RecordIterator::~RecordIterator(){ if(m_pColDefs!=NULL){ for(std::vector<Drill::FieldMetadata*>::iterator it=m_pColDefs->begin(); diff --git a/contrib/native/client/src/clientlib/drillClientImpl.cpp b/contrib/native/client/src/clientlib/drillClientImpl.cpp index 1ccc29fb4..39ac847c6 100644 --- a/contrib/native/client/src/clientlib/drillClientImpl.cpp +++ b/contrib/native/client/src/clientlib/drillClientImpl.cpp @@ -536,19 +536,9 @@ bool DrillClientImpl::clientNeedsEncryption(const DrillUserProperties* userPrope return needsEncryption; } - // Loop through the property to find USERPROP_SASL_ENCRYPT and it's value - for (size_t i = 0; i < userProperties->size(); i++) { - const std::string key = userProperties->keyAt(i); - std::string value = userProperties->valueAt(i); - - if(USERPROP_SASL_ENCRYPT == key) { - boost::algorithm::to_lower(value); - - if(0 == value.compare("true")) { - needsEncryption = true; - } - } - } + std::string val; + needsEncryption = userProperties->isPropSet(USERPROP_SASL_ENCRYPT) && + boost::iequals(userProperties->getProp(USERPROP_SASL_ENCRYPT, val), "true") ; return needsEncryption; } @@ -581,33 +571,33 @@ connectionStatus_t DrillClientImpl::validateHandshake(DrillUserProperties* prope exec::user::UserProperties* userProperties = u2b.mutable_properties(); std::map<char,int>::iterator it; - for(size_t i=0; i<properties->size(); i++){ - std::map<std::string,uint32_t>::const_iterator it=DrillUserProperties::USER_PROPERTIES.find(properties->keyAt(i)); + for (std::map<std::string,std::string>::const_iterator propIter=properties->begin(); propIter!=properties->end(); ++propIter){ + std::string currKey=propIter->first; + std::string currVal=propIter->second; + std::map<std::string,uint32_t>::const_iterator it=DrillUserProperties::USER_PROPERTIES.find(currKey); if(it==DrillUserProperties::USER_PROPERTIES.end()){ - DRILL_MT_LOG(DRILL_LOG(LOG_INFO) << "Connection property ("<< properties->keyAt(i) + DRILL_MT_LOG(DRILL_LOG(LOG_INFO) << "Connection property ("<< currKey << ") is unknown" << std::endl;) - exec::user::Property* connProp = userProperties->add_properties(); - connProp->set_key(properties->keyAt(i)); - connProp->set_value(properties->valueAt(i)); - + connProp->set_key(currKey); + connProp->set_value(currVal); continue; } if(IS_BITSET((*it).second,USERPROP_FLAGS_SERVERPROP)){ exec::user::Property* connProp = userProperties->add_properties(); - connProp->set_key(properties->keyAt(i)); - connProp->set_value(properties->valueAt(i)); + connProp->set_key(currKey); + connProp->set_value(currVal); //Username(but not the password) also needs to be set in UserCredentials if(IS_BITSET((*it).second,USERPROP_FLAGS_USERNAME)){ exec::shared::UserCredentials* creds = u2b.mutable_credentials(); - username=properties->valueAt(i); + username=currVal; creds->set_user_name(username); //u2b.set_credentials(&creds); } if(IS_BITSET((*it).second,USERPROP_FLAGS_PASSWORD)){ - DRILL_MT_LOG(DRILL_LOG(LOG_INFO) << properties->keyAt(i) << ": ********** " << std::endl;) + DRILL_MT_LOG(DRILL_LOG(LOG_INFO) << currKey << ": ********** " << std::endl;) }else{ - DRILL_MT_LOG(DRILL_LOG(LOG_INFO) << properties->keyAt(i) << ":" << properties->valueAt(i) << std::endl;) + DRILL_MT_LOG(DRILL_LOG(LOG_INFO) << currKey << ":" << currVal << std::endl;) } }// Server properties } @@ -2725,10 +2715,13 @@ connectionStatus_t PooledDrillClientImpl::validateHandshake(DrillUserProperties* // Keep a copy of the user properties if(props!=NULL){ m_pUserProperties = boost::shared_ptr<DrillUserProperties>(new DrillUserProperties); - for(size_t i=0; i<props->size(); i++){ + //for(size_t i=0; i<props->size(); i++){ + for(std::map<std::string, std::string>::const_iterator propIter = props->begin(); propIter != props->end(); ++propIter){ + std::string currKey=propIter->first; + std::string currVal=propIter->second; m_pUserProperties->setProperty( - props->keyAt(i), - props->valueAt(i) + currKey, + currVal ); } } diff --git a/contrib/native/client/src/clientlib/drillClientImpl.hpp b/contrib/native/client/src/clientlib/drillClientImpl.hpp index efa4e6641..dacc2c30a 100644 --- a/contrib/native/client/src/clientlib/drillClientImpl.hpp +++ b/contrib/native/client/src/clientlib/drillClientImpl.hpp @@ -41,8 +41,9 @@ #include <boost/asio/deadline_timer.hpp> #include <boost/function.hpp> #include <boost/thread.hpp> - #include "drill/drillClient.hpp" +#include "drill/drillConfig.hpp" +#include "drill/drillError.hpp" #include "drill/preparedStatement.hpp" #include "collectionsImpl.hpp" #include "metadata.hpp" diff --git a/contrib/native/client/src/clientlib/drillConfig.cpp b/contrib/native/client/src/clientlib/drillConfig.cpp new file mode 100644 index 000000000..abaa79aff --- /dev/null +++ b/contrib/native/client/src/clientlib/drillConfig.cpp @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "drill/common.hpp" +#include "drill/drillConfig.hpp" +#include "env.h" +#include "logger.hpp" + +namespace Drill{ + +// Initialize static member of DrillClientConfig +logLevel_t DrillClientConfig::s_logLevel=LOG_ERROR; +uint64_t DrillClientConfig::s_bufferLimit=MAX_MEM_ALLOC_SIZE; +int32_t DrillClientConfig::s_socketTimeout=0; +int32_t DrillClientConfig::s_handshakeTimeout=5; +int32_t DrillClientConfig::s_queryTimeout=180; +int32_t DrillClientConfig::s_heartbeatFrequency=15; // 15 seconds +const char* DrillClientConfig::s_saslPluginPath = NULL; +std::string DrillClientConfig::s_clientName(DRILL_CONNECTOR_NAME); +std::string DrillClientConfig::s_applicationName; + + +boost::mutex DrillClientConfig::s_mutex; + +DrillClientConfig::DrillClientConfig(){ + // Do not initialize logging. The Logger object is static and may + // not have been initialized yet + //initLogging(NULL); +} + +DrillClientConfig::~DrillClientConfig(){ +} + +void DrillClientConfig::initLogging(const char* path){ + getLogger().init(path); +} + +void DrillClientConfig::setLogLevel(logLevel_t l){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + s_logLevel=l; + getLogger().m_level=l; +} + +void DrillClientConfig::setBufferLimit(uint64_t l){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + s_bufferLimit=l; +} + +uint64_t DrillClientConfig::getBufferLimit(){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + return s_bufferLimit; +} + +void DrillClientConfig::setSocketTimeout(int32_t t){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + s_socketTimeout=t; +} + +void DrillClientConfig::setHandshakeTimeout(int32_t t){ + if (t > 0) { + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + s_handshakeTimeout = t; + } +} + +void DrillClientConfig::setQueryTimeout(int32_t t){ + if (t>0){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + s_queryTimeout=t; + } +} + +void DrillClientConfig::setHeartbeatFrequency(int32_t t){ + if (t>0){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + s_heartbeatFrequency=t; + } +} + +int32_t DrillClientConfig::getSocketTimeout(){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + return s_socketTimeout; +} + +int32_t DrillClientConfig::getHandshakeTimeout(){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + return s_handshakeTimeout; +} + +int32_t DrillClientConfig::getQueryTimeout(){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + return s_queryTimeout; +} + +int32_t DrillClientConfig::getHeartbeatFrequency(){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + return s_heartbeatFrequency; +} + +logLevel_t DrillClientConfig::getLogLevel(){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + return s_logLevel; +} + +void DrillClientConfig::setSaslPluginPath(const char *path){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + s_saslPluginPath = path; +} + +const char* DrillClientConfig::getSaslPluginPath(){ + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + return s_saslPluginPath; +} + +const std::string& DrillClientConfig::getClientName() { + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + return s_clientName; +} + +void DrillClientConfig::setClientName(const std::string& name) { + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + s_clientName = name; +} + +const std::string& DrillClientConfig::getApplicationName() { + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + return s_applicationName; +} + +void DrillClientConfig::setApplicationName(const std::string& name) { + boost::lock_guard<boost::mutex> configLock(DrillClientConfig::s_mutex); + s_applicationName = name; +} + +} // namespace Drill diff --git a/contrib/native/client/src/clientlib/drillError.cpp b/contrib/native/client/src/clientlib/drillError.cpp new file mode 100644 index 000000000..046eb5330 --- /dev/null +++ b/contrib/native/client/src/clientlib/drillError.cpp @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "drill/drillError.hpp" +#include "errmsgs.hpp" +#include "logger.hpp" +#include "UserBitShared.pb.h" + +namespace exec{ + namespace shared{ + class DrillPBError; + }; +}; + +namespace Drill{ + +DrillClientError* DrillClientError::getErrorObject(const exec::shared::DrillPBError& e){ + std::string s=Drill::getMessage(ERR_QRY_FAILURE, e.message().c_str()); + DrillClientError* err=NULL; + err=new DrillClientError(QRY_FAILURE, QRY_ERROR_START+QRY_FAILURE, s); + return err; +} + + +} // namespace Drill diff --git a/contrib/native/client/src/clientlib/saslAuthenticatorImpl.cpp b/contrib/native/client/src/clientlib/saslAuthenticatorImpl.cpp index c5dc3aced..78f99b619 100644 --- a/contrib/native/client/src/clientlib/saslAuthenticatorImpl.cpp +++ b/contrib/native/client/src/clientlib/saslAuthenticatorImpl.cpp @@ -20,6 +20,7 @@ #include <algorithm> #include <boost/algorithm/string.hpp> #include <boost/assign.hpp> +#include "drill/userProperties.hpp" #include "saslAuthenticatorImpl.hpp" #include "drillClientImpl.hpp" @@ -123,10 +124,11 @@ int SaslAuthenticatorImpl::init(const std::vector<std::string>& mechanisms, exec std::string authMechanismToUse; std::string serviceName; std::string serviceHost; - for (size_t i = 0; i < m_pUserProperties->size(); i++) { - const std::string key = m_pUserProperties->keyAt(i); - const std::string value = m_pUserProperties->valueAt(i); - + for (std::map<std::string, std::string>::const_iterator it=m_pUserProperties->begin(); + it!=m_pUserProperties->end(); + ++it){ + const std::string key = it->first; + const std::string value = it->second; if (USERPROP_SERVICE_HOST == key) { serviceHost = value; } else if (USERPROP_SERVICE_NAME == key) { diff --git a/contrib/native/client/src/clientlib/userProperties.cpp b/contrib/native/client/src/clientlib/userProperties.cpp new file mode 100644 index 000000000..07497ef55 --- /dev/null +++ b/contrib/native/client/src/clientlib/userProperties.cpp @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <boost/assign.hpp> +#include "drill/userProperties.hpp" + +namespace Drill{ + +//Using boost assign to initialize maps. +const std::map<std::string, uint32_t> DrillUserProperties::USER_PROPERTIES=boost::assign::map_list_of + ( USERPROP_USERNAME, USERPROP_FLAGS_SERVERPROP|USERPROP_FLAGS_USERNAME|USERPROP_FLAGS_STRING ) + ( USERPROP_PASSWORD, USERPROP_FLAGS_SERVERPROP|USERPROP_FLAGS_PASSWORD) + ( USERPROP_SCHEMA, USERPROP_FLAGS_SERVERPROP|USERPROP_FLAGS_STRING) + ( USERPROP_IMPERSONATION_TARGET, USERPROP_FLAGS_SERVERPROP|USERPROP_FLAGS_STRING) + ( USERPROP_AUTH_MECHANISM, USERPROP_FLAGS_STRING) + ( USERPROP_SERVICE_NAME, USERPROP_FLAGS_STRING) + ( USERPROP_SERVICE_HOST, USERPROP_FLAGS_STRING) + ( USERPROP_USESSL, USERPROP_FLAGS_BOOLEAN|USERPROP_FLAGS_SSLPROP) + ( USERPROP_CERTFILEPATH, USERPROP_FLAGS_STRING|USERPROP_FLAGS_SSLPROP|USERPROP_FLAGS_FILEPATH) + ( USERPROP_SASL_ENCRYPT, USERPROP_FLAGS_STRING) +; + +bool DrillUserProperties::validate(std::string& err){ + bool ret=true; + //We can add additional validation for any params here + return ret; +} + +} // namespace Drill diff --git a/contrib/native/client/src/clientlib/utils.cpp b/contrib/native/client/src/clientlib/utils.cpp index 11aa2c272..137be6521 100644 --- a/contrib/native/client/src/clientlib/utils.cpp +++ b/contrib/native/client/src/clientlib/utils.cpp @@ -21,6 +21,7 @@ #include "utils.hpp" #include "logger.hpp" #include "drill/common.hpp" +#include "drill/drillConfig.hpp" #if defined _WIN32 || defined _WIN64 //Windows header files redefine 'max' diff --git a/contrib/native/client/src/clientlib/zookeeperClient.cpp b/contrib/native/client/src/clientlib/zookeeperClient.cpp index 535bebcad..cd2ac0055 100644 --- a/contrib/native/client/src/clientlib/zookeeperClient.cpp +++ b/contrib/native/client/src/clientlib/zookeeperClient.cpp @@ -18,6 +18,7 @@ #include <boost/bind.hpp> #include <drill/drillClient.hpp> +#include <drill/drillConfig.hpp> #include "zookeeperClient.hpp" #include "errmsgs.hpp" @@ -158,6 +159,10 @@ int ZookeeperClient::getEndPoint(const std::string& drillbit, exec::DrillbitEndp drillServiceInstance.ParseFromArray(buffer, buffer_len); endpoint=drillServiceInstance.endpoint(); + if(p_zh!=NULL && m_state==ZOO_CONNECTED_STATE){ + DRILL_LOG(LOG_TRACE) << drillServiceInstance.DebugString() << std::endl; + } + return 0; } diff --git a/contrib/native/client/src/include/drill/drillClient.hpp b/contrib/native/client/src/include/drill/drillClient.hpp index f09d7f5ec..ceaf50d43 100644 --- a/contrib/native/client/src/include/drill/drillClient.hpp +++ b/contrib/native/client/src/include/drill/drillClient.hpp @@ -35,9 +35,12 @@ namespace exec{ namespace Drill{ //struct UserServerEndPoint; +class DrillClientConfig; +class DrillClientError; class DrillClientImplBase; class DrillClientImpl; class DrillClientQueryResult; +class DrillUserProperties; class FieldMetadata; class PreparedStatement; class RecordBatch; @@ -49,23 +52,6 @@ enum QueryType{ PHYSICAL = 3 }; -class DECLSPEC_DRILL_CLIENT DrillClientError{ - public: - static const uint32_t CONN_ERROR_START = 100; - static const uint32_t QRY_ERROR_START = 200; - - DrillClientError(uint32_t s, uint32_t e, char* m){status=s; errnum=e; msg=m;}; - DrillClientError(uint32_t s, uint32_t e, std::string m){status=s; errnum=e; msg=m;}; - - static DrillClientError* getErrorObject(const exec::shared::DrillPBError& e); - - // To get the error number we add a error range start number to - // the status code returned (either status_t or connectionStatus_t) - uint32_t status; // could be either status_t or connectionStatus_t - uint32_t errnum; - std::string msg; -}; - // Only one instance of this class exists. A static member of DrillClientImpl; class DECLSPEC_DRILL_CLIENT DrillClientInitializer{ public: @@ -73,127 +59,6 @@ class DECLSPEC_DRILL_CLIENT DrillClientInitializer{ ~DrillClientInitializer(); }; -// Only one instance of this class exists. A static member of DrillClientImpl; -class DECLSPEC_DRILL_CLIENT DrillClientConfig{ - public: - DrillClientConfig(); - ~DrillClientConfig(); - static void initLogging(const char* path); - static void setLogLevel(logLevel_t l); - static void setSaslPluginPath(const char* path); - static const char* getSaslPluginPath(); - static void setBufferLimit(uint64_t l); - static uint64_t getBufferLimit(); - static void setSocketTimeout(int32_t l); - static void setHandshakeTimeout(int32_t l); - static void setQueryTimeout(int32_t l); - static void setHeartbeatFrequency(int32_t l); - static int32_t getSocketTimeout(); - static int32_t getHandshakeTimeout(); - static int32_t getQueryTimeout(); - static int32_t getHeartbeatFrequency(); - static logLevel_t getLogLevel(); - - /** - * Return the client name sent to the server when connecting - * - * @return the current client name - */ - static const std::string& getClientName(); - - /** - * Set the client name to be sent to the server when connecting. - * - * Only new connections will use the new value. Existing connections - * will be left unchanged. - * - * @param name the name to be send to the server - */ - static void setClientName(const std::string& name); - - /** - * Return the application name sent to the server when connecting - * - * @return the current application name - */ - static const std::string& getApplicationName(); - - /** - * Set the application name to be sent to the server when connecting. - * - * Only new connections will use the new value. Existing connections - * will be left unchanged. - * - * @param name the name to be send to the server - */ - static void setApplicationName(const std::string& name); - - - - private: - // The logging level - static logLevel_t s_logLevel; - // The total amount of memory to be allocated by an instance of DrillClient. - // For future use. Currently, not enforced. - static uint64_t s_bufferLimit; - - static const char* s_saslPluginPath; - - /** - * DrillClient configures timeout (in seconds) in a fine granularity. - * Disabled by setting the value to zero. - * - * s_socketTimout: (default 0) - * set SO_RCVTIMEO and SO_SNDTIMEO socket options and place a - * timeout on socket receives and sends. It is disabled by default. - * - * s_handshakeTimeout: (default 5) - * place a timeout on validating handshake. When an endpoint (host:port) - * is reachable but drillbit hangs or running another service. It will - * avoid the client hanging. - * - * s_queryTimeout: (default 180) - * place a timeout on waiting result of querying. - * - * s_heartbeatFrequency: (default 30) - * Seconds of idle activity after which a heartbeat is sent to the drillbit - */ - static int32_t s_socketTimeout; - static int32_t s_handshakeTimeout; - static int32_t s_queryTimeout; - static int32_t s_heartbeatFrequency; - static boost::mutex s_mutex; - - // The client name (default to DRILL_CONNECTOR_NAME) - static std::string s_clientName; - // The application name (default to <empty>) - static std::string s_applicationName; -}; - - -class DECLSPEC_DRILL_CLIENT DrillUserProperties{ - public: - static const std::map<std::string, uint32_t> USER_PROPERTIES; - - DrillUserProperties(){}; - - void setProperty( const std::string& propName, const std::string& propValue){ - std::pair< std::string, std::string> in = make_pair(propName, propValue); - m_properties.push_back(in); - } - - size_t size() const { return m_properties.size(); } - - const std::string& keyAt(size_t i) const { return m_properties.at(i).first; } - - const std::string& valueAt(size_t i) const { return m_properties.at(i).second; } - - bool validate(std::string& err); - - private: - std::vector< std::pair< std::string, std::string> > m_properties; -}; - /* * Handle to the Query submitted for execution. * */ @@ -1248,7 +1113,7 @@ class DECLSPEC_DRILL_CLIENT DrillClient{ */ DEPRECATED connectionStatus_t connect(const char* connectStr, const char* defaultSchema=NULL); - /* + /* * Connect the client to a Drillbit using connection string and a set of user properties. * The connection string format can be found in comments of * [DRILL-780](https://issues.apache.org/jira/browse/DRILL-780) diff --git a/contrib/native/client/src/include/drill/drillConfig.hpp b/contrib/native/client/src/include/drill/drillConfig.hpp new file mode 100644 index 000000000..669267d86 --- /dev/null +++ b/contrib/native/client/src/include/drill/drillConfig.hpp @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef DRILL_CONFIG_H +#define DRILL_CONFIG_H + +#include "drill/common.hpp" +#include <boost/thread.hpp> + + + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef DRILL_CLIENT_EXPORTS + #define DECLSPEC_DRILL_CLIENT __declspec(dllexport) + #else + #ifdef USE_STATIC_LIBDRILL + #define DECLSPEC_DRILL_CLIENT + #else + #define DECLSPEC_DRILL_CLIENT __declspec(dllimport) + #endif + #endif +#else + #if __GNUC__ >= 4 + #define DECLSPEC_DRILL_CLIENT __attribute__ ((visibility ("default"))) + #else + #define DECLSPEC_DRILL_CLIENT + #endif +#endif + +namespace exec{ + namespace shared{ + class DrillPBError; + }; +}; + +namespace Drill{ + +// Only one instance of this class exists. A static member of DrillClientImpl; + +class DECLSPEC_DRILL_CLIENT DrillClientConfig{ + public: + DrillClientConfig(); + ~DrillClientConfig(); + static void initLogging(const char* path); + static void setLogLevel(logLevel_t l); + static void setSaslPluginPath(const char* path); + static const char* getSaslPluginPath(); + static void setBufferLimit(uint64_t l); + static uint64_t getBufferLimit(); + static void setSocketTimeout(int32_t l); + static void setHandshakeTimeout(int32_t l); + static void setQueryTimeout(int32_t l); + static void setHeartbeatFrequency(int32_t l); + static int32_t getSocketTimeout(); + static int32_t getHandshakeTimeout(); + static int32_t getQueryTimeout(); + static int32_t getHeartbeatFrequency(); + static logLevel_t getLogLevel(); + /** + * Return the client name sent to the server when connecting + * + * @return the current client name + */ + static const std::string& getClientName(); + + /** + * Set the client name to be sent to the server when connecting. + * + * Only new connections will use the new value. Existing connections + * will be left unchanged. + * + * @param name the name to be send to the server + */ + static void setClientName(const std::string& name); + + /** + * Return the application name sent to the server when connecting + * + * @return the current application name + */ + static const std::string& getApplicationName(); + + /** + * Set the application name to be sent to the server when connecting. + * + * Only new connections will use the new value. Existing connections + * will be left unchanged. + * + * @param name the name to be send to the server + */ + static void setApplicationName(const std::string& name); + + + private: + // The logging level + static logLevel_t s_logLevel; + // The total amount of memory to be allocated by an instance of DrillClient. + // For future use. Currently, not enforced. + static uint64_t s_bufferLimit; + + static const char* s_saslPluginPath; + + /** + * DrillClient configures timeout (in seconds) in a fine granularity. + * Disabled by setting the value to zero. + * + * s_socketTimout: (default 0) + * set SO_RCVTIMEO and SO_SNDTIMEO socket options and place a + * timeout on socket receives and sends. It is disabled by default. + * + * s_handshakeTimeout: (default 5) + * place a timeout on validating handshake. When an endpoint (host:port) + * is reachable but drillbit hangs or running another service. It will + * avoid the client hanging. + * + * s_queryTimeout: (default 180) + * place a timeout on waiting result of querying. + * + * s_heartbeatFrequency: (default 30) + * Seconds of idle activity after which a heartbeat is sent to the drillbit + */ + static int32_t s_socketTimeout; + static int32_t s_handshakeTimeout; + static int32_t s_queryTimeout; + static int32_t s_heartbeatFrequency; + static boost::mutex s_mutex; + // The client name (default to DRILL_CONNECTOR_NAME) + static std::string s_clientName; + // The application name (default to <empty>) + static std::string s_applicationName; +}; + + + +} // namespace Drill + +#endif diff --git a/contrib/native/client/src/include/drill/drillError.hpp b/contrib/native/client/src/include/drill/drillError.hpp new file mode 100644 index 000000000..072df1c31 --- /dev/null +++ b/contrib/native/client/src/include/drill/drillError.hpp @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef DRILL_ERROR_H +#define DRILL_ERROR_H + +#include "drill/common.hpp" + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef DRILL_CLIENT_EXPORTS + #define DECLSPEC_DRILL_CLIENT __declspec(dllexport) + #else + #ifdef USE_STATIC_LIBDRILL + #define DECLSPEC_DRILL_CLIENT + #else + #define DECLSPEC_DRILL_CLIENT __declspec(dllimport) + #endif + #endif +#else + #if __GNUC__ >= 4 + #define DECLSPEC_DRILL_CLIENT __attribute__ ((visibility ("default"))) + #else + #define DECLSPEC_DRILL_CLIENT + #endif +#endif + +namespace exec{ + namespace shared{ + class DrillPBError; + }; +}; + +namespace Drill{ + +class DECLSPEC_DRILL_CLIENT DrillClientError{ + public: + static const uint32_t CONN_ERROR_START = 100; + static const uint32_t QRY_ERROR_START = 200; + + DrillClientError(uint32_t s, uint32_t e, char* m){status=s; errnum=e; msg=m;}; + DrillClientError(uint32_t s, uint32_t e, std::string m){status=s; errnum=e; msg=m;}; + //copy ctor + DrillClientError(const DrillClientError& err){status=err.status; errnum=err.errnum; msg=err.msg;}; + + static DrillClientError* getErrorObject(const exec::shared::DrillPBError& e); + + // To get the error number we add a error range start number to + // the status code returned (either status_t or connectionStatus_t) + uint32_t status; // could be either status_t or connectionStatus_t + uint32_t errnum; + std::string msg; +}; + +} // namespace Drill + +#endif diff --git a/contrib/native/client/src/include/drill/drillc.hpp b/contrib/native/client/src/include/drill/drillc.hpp index c8593f599..21a18e7d8 100644 --- a/contrib/native/client/src/include/drill/drillc.hpp +++ b/contrib/native/client/src/include/drill/drillc.hpp @@ -20,10 +20,13 @@ #define DRILL_CLIENT_ALL_H #include "drill/common.hpp" +#include "drill/drillConfig.hpp" +#include "drill/drillError.hpp" #include "drill/drillClient.hpp" #include "drill/fieldmeta.hpp" #include "drill/preparedStatement.hpp" #include "drill/recordBatch.hpp" +#include "drill/userProperties.hpp" #include "drill/protobuf/Types.pb.h" #endif diff --git a/contrib/native/client/src/include/drill/userProperties.hpp b/contrib/native/client/src/include/drill/userProperties.hpp new file mode 100644 index 000000000..3490dce7a --- /dev/null +++ b/contrib/native/client/src/include/drill/userProperties.hpp @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef USER_PROPERTIES_H +#define USER_PROPERTIES_H + +#include <map> +#include "drill/common.hpp" + +namespace Drill{ + +class DECLSPEC_DRILL_CLIENT DrillUserProperties{ + public: + static const std::map<std::string, uint32_t> USER_PROPERTIES; + + DrillUserProperties(){}; + + void setProperty( const std::string& propName, const std::string& propValue){ + std::pair< std::string, std::string> in = make_pair(propName, propValue); + m_properties.insert(in); + } + + size_t size() const { return m_properties.size(); } + + //const std::string& keyAt(size_t i) const { return m_properties.at(i).first; } + + //const std::string& valueAt(size_t i) const { return m_properties.at(i).second; } + + const bool isPropSet(const std::string& key) const{ + bool isSet=true; + auto f= m_properties.find(key); + if(f==m_properties.end()){ + isSet=false; + } + return isSet; + } + const std::string& getProp(const std::string& key, std::string& value) const{ + auto f= m_properties.find(key); + if(f!=m_properties.end()){ + value=f->second; + } + return value; + } + + bool validate(std::string& err); + + std::map<std::string,std::string>::const_iterator begin() const{ + return m_properties.begin(); + } + + std::map<std::string,std::string>::const_iterator end() const{ + return m_properties.end(); + } + + private: + std::map< std::string, std::string > m_properties; +}; + + +} // namespace Drill +#endif // USER_PROPERTIES_H + |