add test client

Former-commit-id: af73a98aad00251fa5432d39e092ee950fe2db2b
pull/191/head
groot 2019-04-16 12:03:33 +08:00 committed by xj.lin
parent a25a7a24a7
commit 2a850821b5
23 changed files with 6640 additions and 29 deletions

View File

@ -59,6 +59,7 @@ link_directories(${VECWISE_THIRD_PARTY_BUILD}/lib)
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
add_subdirectory(src)
add_subdirectory(test_client)
if (BUILD_UNIT_TEST)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unittest)

View File

@ -30,5 +30,13 @@ Set config in cpp/conf/server_config.yaml
Then luanch server with config:
cd [build output path]/src
vecwise_engine_server -c [sourcecode path]/cpp/conf/server_config.yaml
### Luanch test_client(only for debug)
Client use same config file with server:
cd [build output path]/test_client
test_client -c [sourcecode path]/cpp/conf/server_config.yaml

View File

@ -10,6 +10,11 @@ aux_source_directory(server server_files)
aux_source_directory(utils utils_files)
aux_source_directory(wrapper wrapper_files)
set(service_files
thrift/gen-cpp/VecService.cpp
thrift/gen-cpp/VectorService_constants.cpp
thrift/gen-cpp/VectorService_types.cpp)
set(vecwise_engine_src
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${cache_files}
@ -24,7 +29,11 @@ add_executable(vecwise_engine_server
${config_files}
${server_files}
${utils_files}
<<<<<<< f0f0e4c6c70323464d2e3bb4834e942bdbe2c868
${wrapper_files}
=======
${service_files}
>>>>>>> add test client
${VECWISE_THIRD_PARTY_BUILD}/include/easylogging++.cc
)
@ -33,5 +42,7 @@ set(dependency_libs
yaml-cpp
boost_system
boost_filesystem
thrift
pthread
)
target_link_libraries(vecwise_engine_server ${dependency_libs} ${cuda_library})

View File

@ -47,10 +47,11 @@ main(int argc, char *argv[]) {
app_name = argv[0];
// if(argc < 5) {
// print_help(app_name);
// return EXIT_FAILURE;
// }
if(argc < 2) {
print_help(app_name);
printf("Vecwise engine server exit...\n");
return EXIT_FAILURE;
}
int value;
while ((value = getopt_long(argc, argv, "c:p:dh", long_options, &option_index)) != -1) {

View File

@ -5,11 +5,13 @@
////////////////////////////////////////////////////////////////////////////////
#include "Server.h"
#include "ServerConfig.h"
#include "ServiceWrapper.h"
#include "utils/CommonUtil.h"
#include "utils/SignalUtil.h"
#include "utils/TimeRecorder.h"
#include "utils/LogUtil.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
@ -157,9 +159,8 @@ Server::Start() {
signal(SIGHUP, SignalUtil::HandleSignal);
signal(SIGTERM, SignalUtil::HandleSignal);
StartService();
CommonUtil::PrintInfo("Vecwise server is running...");
StartService();
} catch(std::exception& ex){
std::string info = "Vecwise server encounter exception: " + std::string(ex.what());
@ -216,12 +217,12 @@ Server::LoadConfig() {
void
Server::StartService() {
ServiceWrapper::StartService();
}
void
Server::StopService() {
ServiceWrapper::StopService();
}
}

View File

@ -17,9 +17,6 @@ namespace zilliz {
namespace vecwise {
namespace server {
static const std::string CONFIG_ADDRESS = "address";
static const std::string CONFIG_PORT = "port";
ServerConfig&
ServerConfig::GetInstance() {
static ServerConfig config;
@ -79,18 +76,6 @@ ServerConfig::GetConfig(const std::string& name) {
return root_node.GetChild(name);
}
std::string
ServerConfig::GetServerAddress() const {
ConfigNode server_config = GetConfig(CONFIG_SERVER);
return server_config.GetValue(CONFIG_ADDRESS);
}
std::string
ServerConfig::GetServerPort() const {
ConfigNode server_config = GetConfig(CONFIG_SERVER);
return server_config.GetValue(CONFIG_PORT);
}
}
}

View File

@ -15,8 +15,16 @@ namespace vecwise {
namespace server {
static const std::string CONFIG_SERVER = "server_config";
static const std::string CONFIG_SERVER_ADDRESS = "address";
static const std::string CONFIG_SERVER_PORT = "port";
static const std::string CONFIG_SERVER_PROTOCOL = "transfer_protocol";
static const std::string CONFIG_SERVER_MODE = "server_mode";
static const std::string CONFIG_LOG = "log_config";
static const std::string CONFIG_CACHE = "cache_config";
static const std::string CONFIG_CACHE_CAPACITY = "cache_capacity";
class ServerConfig {
public:
static ServerConfig &GetInstance();
@ -26,9 +34,6 @@ class ServerConfig {
ConfigNode GetConfig(const std::string& name) const;
ConfigNode& GetConfig(const std::string& name);
std::string GetServerAddress() const;
std::string GetServerPort() const;
};
}

View File

@ -0,0 +1,152 @@
/*******************************************************************************
* Copyright (Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#include "ServiceWrapper.h"
#include "ServerConfig.h"
#include "utils/CommonUtil.h"
#include "thrift/gen-cpp/VecService.h"
#include "thrift/gen-cpp/VectorService_types.h"
#include "thrift/gen-cpp/VectorService_constants.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/server/TThreadPoolServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/concurrency/PosixThreadFactory.h>
#include <thread>
namespace zilliz {
namespace vecwise {
namespace server {
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using namespace ::apache::thrift::concurrency;
class VecServiceHandler : virtual public VecServiceIf {
public:
VecServiceHandler() {
// Your initialization goes here
}
/**
* group interfaces
*
* @param group
*/
void add_group(const VecGroup& group) {
// Your implementation goes here
printf("add_group\n");
}
void get_group(VecGroup& _return, const std::string& group_id) {
// Your implementation goes here
printf("get_group\n");
}
void del_group(const std::string& group_id) {
// Your implementation goes here
printf("del_group\n");
}
/**
* vector interfaces
*
*
* @param group_id
* @param tensor
*/
int64_t add_vector(const std::string& group_id, const VecTensor& tensor) {
// Your implementation goes here
printf("add_vector\n");
}
void add_vector_batch(VecTensorIdList& _return, const std::string& group_id, const VecTensorList& tensor_list) {
// Your implementation goes here
printf("add_vector_batch\n");
}
/**
* search interfaces
* if time_range_list is empty, engine will search without time limit
*
* @param group_id
* @param top_k
* @param tensor
* @param time_range_list
*/
void search_vector(VecSearchResult& _return, const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecTimeRangeList& time_range_list) {
// Your implementation goes here
printf("search_vector\n");
}
void search_vector_batch(VecSearchResultList& _return, const std::string& group_id, const int64_t top_k, const VecTensorList& tensor_list, const VecTimeRangeList& time_range_list) {
// Your implementation goes here
printf("search_vector_batch\n");
}
};
static ::apache::thrift::stdcxx::shared_ptr<TServer> s_server;
void ServiceWrapper::StartService() {
if(s_server != nullptr){
StopService();
}
ServerConfig &config = ServerConfig::GetInstance();
ConfigNode server_config = config.GetConfig(CONFIG_SERVER);
std::string address = server_config.GetValue(CONFIG_SERVER_ADDRESS, "127.0.0.1");
int32_t port = server_config.GetInt32Value(CONFIG_SERVER_PORT, 33001);
std::string protocol = server_config.GetValue(CONFIG_SERVER_PROTOCOL, "binary");
std::string mode = server_config.GetValue(CONFIG_SERVER_MODE, "thread_pool");
::apache::thrift::stdcxx::shared_ptr<VecServiceHandler> handler(new VecServiceHandler());
::apache::thrift::stdcxx::shared_ptr<TProcessor> processor(new VecServiceProcessor(handler));
if(mode == "simple") {
::apache::thrift::stdcxx::shared_ptr<TServerTransport> serverTransport(new TServerSocket(address, port));
::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
s_server.reset(new TSimpleServer(processor, serverTransport, transportFactory, protocolFactory));
s_server->serve();
} else if(mode == "thread_pool") {
::apache::thrift::stdcxx::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
::apache::thrift::stdcxx::shared_ptr<ThreadManager> threadManager(ThreadManager::newSimpleThreadManager(1));
::apache::thrift::stdcxx::shared_ptr<PosixThreadFactory> threadFactory(new PosixThreadFactory());
threadManager->threadFactory(threadFactory);
threadManager->start();
s_server.reset(new TThreadPoolServer(processor, serverTransport, transportFactory, protocolFactory, threadManager));
s_server->serve();
} else {
CommonUtil::PrintError("Server mode: " + mode + " is not supported currently");
}
}
void ServiceWrapper::StopService() {
auto stop_server_worker = [&]{
if(s_server != nullptr) {
s_server->stop();
}
};
std::shared_ptr<std::thread> stop_thread = std::make_shared<std::thread>(stop_server_worker);
stop_thread->join();
}
}
}
}

View File

@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#pragma once
#include "utils/Error.h"
#include <cstdint>
#include <string>
namespace zilliz {
namespace vecwise {
namespace server {
class ServiceWrapper {
public:
static void StartService();
static void StopService();
};
}
}
}

View File

@ -0,0 +1,90 @@
/*******************************************************************************
* Copyright (Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
enum VecErrCode {
SUCCESS = 0,
ILLEGAL_ARGUMENT,
GROUP_NOT_EXISTS,
ILLEGAL_TIME_RANGE,
ILLEGAL_VECTOR_DIMENSION,
OUT_OF_MEMORY,
}
exception VecException {
1: VecErrCode code;
2: string reason;
}
struct VecGroup {
1: string id;
2: i32 dimension;
3: i32 index_type;
}
struct VecTensor {
2: list<double> tensor;
}
struct VecTensorList {
1: list<VecTensor> tensor_list;
}
struct VecTensorIdList {
1: list<i64> id_list;
}
struct VecSearchResult {
1: list<i64> id_list;
}
struct VecSearchResultList {
1: list<VecSearchResult> result_list;
}
struct VecDateTime {
1: i32 year;
2: i32 month;
3: i32 day;
4: i32 hour;
5: i32 minute;
6: i32 second;
}
struct VecTimeRange {
1: VecDateTime time_begin;
2: bool begine_closed;
3: VecDateTime time_end;
4: bool end_closed;
}
struct VecTimeRangeList {
1: list<VecTimeRange> range_list;
}
service VecService {
/**
* group interfaces
*/
void add_group(2: VecGroup group) throws(1: VecException e);
VecGroup get_group(2: string group_id) throws(1: VecException e);
void del_group(2: string group_id) throws(1: VecException e);
/**
* vector interfaces
*
*/
i64 add_vector(2: string group_id, 3: VecTensor tensor) throws(1: VecException e);
VecTensorIdList add_vector_batch(2: string group_id, 3: VecTensorList tensor_list) throws(1: VecException e);
/**
* search interfaces
* if time_range_list is empty, engine will search without time limit
*/
VecSearchResult search_vector(2: string group_id, 3: i64 top_k, 4: VecTensor tensor, 5: VecTimeRangeList time_range_list) throws(1: VecException e);
VecSearchResultList search_vector_batch(2: string group_id, 3: i64 top_k, 4: VecTensorList tensor_list, 5: VecTimeRangeList time_range_list) throws(1: VecException e);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
// This autogenerated skeleton file illustrates how to build a server.
// You should copy it to another filename to avoid overwriting it.
#include "VecService.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
class VecServiceHandler : virtual public VecServiceIf {
public:
VecServiceHandler() {
// Your initialization goes here
}
/**
* group interfaces
*
* @param group
*/
void add_group(const VecGroup& group) {
// Your implementation goes here
printf("add_group\n");
}
void get_group(VecGroup& _return, const std::string& group_id) {
// Your implementation goes here
printf("get_group\n");
}
void del_group(const std::string& group_id) {
// Your implementation goes here
printf("del_group\n");
}
/**
* vector interfaces
*
*
* @param group_id
* @param tensor
*/
int64_t add_vector(const std::string& group_id, const VecTensor& tensor) {
// Your implementation goes here
printf("add_vector\n");
}
void add_vector_batch(VecTensorIdList& _return, const std::string& group_id, const VecTensorList& tensor_list) {
// Your implementation goes here
printf("add_vector_batch\n");
}
/**
* search interfaces
* if time_range_list is empty, engine will search without time limit
*
* @param group_id
* @param top_k
* @param tensor
* @param time_range_list
*/
void search_vector(VecSearchResult& _return, const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecTimeRangeList& time_range_list) {
// Your implementation goes here
printf("search_vector\n");
}
void search_vector_batch(VecSearchResultList& _return, const std::string& group_id, const int64_t top_k, const VecTensorList& tensor_list, const VecTimeRangeList& time_range_list) {
// Your implementation goes here
printf("search_vector_batch\n");
}
};
int main(int argc, char **argv) {
int port = 9090;
::apache::thrift::stdcxx::shared_ptr<VecServiceHandler> handler(new VecServiceHandler());
::apache::thrift::stdcxx::shared_ptr<TProcessor> processor(new VecServiceProcessor(handler));
::apache::thrift::stdcxx::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();
return 0;
}

View File

@ -0,0 +1,17 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
#include "VectorService_constants.h"
const VectorServiceConstants g_VectorService_constants;
VectorServiceConstants::VectorServiceConstants() {
}

View File

@ -0,0 +1,24 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
#ifndef VectorService_CONSTANTS_H
#define VectorService_CONSTANTS_H
#include "VectorService_types.h"
class VectorServiceConstants {
public:
VectorServiceConstants();
};
extern const VectorServiceConstants g_VectorService_constants;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,548 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
#ifndef VectorService_TYPES_H
#define VectorService_TYPES_H
#include <iosfwd>
#include <thrift/Thrift.h>
#include <thrift/TApplicationException.h>
#include <thrift/TBase.h>
#include <thrift/protocol/TProtocol.h>
#include <thrift/transport/TTransport.h>
#include <thrift/stdcxx.h>
struct VecErrCode {
enum type {
SUCCESS = 0,
ILLEGAL_ARGUMENT = 1,
GROUP_NOT_EXISTS = 2,
ILLEGAL_TIME_RANGE = 3,
ILLEGAL_VECTOR_DIMENSION = 4,
OUT_OF_MEMORY = 5
};
};
extern const std::map<int, const char*> _VecErrCode_VALUES_TO_NAMES;
std::ostream& operator<<(std::ostream& out, const VecErrCode::type& val);
class VecException;
class VecGroup;
class VecTensor;
class VecTensorList;
class VecTensorIdList;
class VecSearchResult;
class VecSearchResultList;
class VecDateTime;
class VecTimeRange;
class VecTimeRangeList;
typedef struct _VecException__isset {
_VecException__isset() : code(false), reason(false) {}
bool code :1;
bool reason :1;
} _VecException__isset;
class VecException : public ::apache::thrift::TException {
public:
VecException(const VecException&);
VecException& operator=(const VecException&);
VecException() : code((VecErrCode::type)0), reason() {
}
virtual ~VecException() throw();
VecErrCode::type code;
std::string reason;
_VecException__isset __isset;
void __set_code(const VecErrCode::type val);
void __set_reason(const std::string& val);
bool operator == (const VecException & rhs) const
{
if (!(code == rhs.code))
return false;
if (!(reason == rhs.reason))
return false;
return true;
}
bool operator != (const VecException &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecException & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
mutable std::string thriftTExceptionMessageHolder_;
const char* what() const throw();
};
void swap(VecException &a, VecException &b);
std::ostream& operator<<(std::ostream& out, const VecException& obj);
typedef struct _VecGroup__isset {
_VecGroup__isset() : id(false), dimension(false), index_type(false) {}
bool id :1;
bool dimension :1;
bool index_type :1;
} _VecGroup__isset;
class VecGroup : public virtual ::apache::thrift::TBase {
public:
VecGroup(const VecGroup&);
VecGroup& operator=(const VecGroup&);
VecGroup() : id(), dimension(0), index_type(0) {
}
virtual ~VecGroup() throw();
std::string id;
int32_t dimension;
int32_t index_type;
_VecGroup__isset __isset;
void __set_id(const std::string& val);
void __set_dimension(const int32_t val);
void __set_index_type(const int32_t val);
bool operator == (const VecGroup & rhs) const
{
if (!(id == rhs.id))
return false;
if (!(dimension == rhs.dimension))
return false;
if (!(index_type == rhs.index_type))
return false;
return true;
}
bool operator != (const VecGroup &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecGroup & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
};
void swap(VecGroup &a, VecGroup &b);
std::ostream& operator<<(std::ostream& out, const VecGroup& obj);
typedef struct _VecTensor__isset {
_VecTensor__isset() : tensor(false) {}
bool tensor :1;
} _VecTensor__isset;
class VecTensor : public virtual ::apache::thrift::TBase {
public:
VecTensor(const VecTensor&);
VecTensor& operator=(const VecTensor&);
VecTensor() {
}
virtual ~VecTensor() throw();
std::vector<double> tensor;
_VecTensor__isset __isset;
void __set_tensor(const std::vector<double> & val);
bool operator == (const VecTensor & rhs) const
{
if (!(tensor == rhs.tensor))
return false;
return true;
}
bool operator != (const VecTensor &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecTensor & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
};
void swap(VecTensor &a, VecTensor &b);
std::ostream& operator<<(std::ostream& out, const VecTensor& obj);
typedef struct _VecTensorList__isset {
_VecTensorList__isset() : tensor_list(false) {}
bool tensor_list :1;
} _VecTensorList__isset;
class VecTensorList : public virtual ::apache::thrift::TBase {
public:
VecTensorList(const VecTensorList&);
VecTensorList& operator=(const VecTensorList&);
VecTensorList() {
}
virtual ~VecTensorList() throw();
std::vector<VecTensor> tensor_list;
_VecTensorList__isset __isset;
void __set_tensor_list(const std::vector<VecTensor> & val);
bool operator == (const VecTensorList & rhs) const
{
if (!(tensor_list == rhs.tensor_list))
return false;
return true;
}
bool operator != (const VecTensorList &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecTensorList & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
};
void swap(VecTensorList &a, VecTensorList &b);
std::ostream& operator<<(std::ostream& out, const VecTensorList& obj);
typedef struct _VecTensorIdList__isset {
_VecTensorIdList__isset() : id_list(false) {}
bool id_list :1;
} _VecTensorIdList__isset;
class VecTensorIdList : public virtual ::apache::thrift::TBase {
public:
VecTensorIdList(const VecTensorIdList&);
VecTensorIdList& operator=(const VecTensorIdList&);
VecTensorIdList() {
}
virtual ~VecTensorIdList() throw();
std::vector<int64_t> id_list;
_VecTensorIdList__isset __isset;
void __set_id_list(const std::vector<int64_t> & val);
bool operator == (const VecTensorIdList & rhs) const
{
if (!(id_list == rhs.id_list))
return false;
return true;
}
bool operator != (const VecTensorIdList &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecTensorIdList & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
};
void swap(VecTensorIdList &a, VecTensorIdList &b);
std::ostream& operator<<(std::ostream& out, const VecTensorIdList& obj);
typedef struct _VecSearchResult__isset {
_VecSearchResult__isset() : id_list(false) {}
bool id_list :1;
} _VecSearchResult__isset;
class VecSearchResult : public virtual ::apache::thrift::TBase {
public:
VecSearchResult(const VecSearchResult&);
VecSearchResult& operator=(const VecSearchResult&);
VecSearchResult() {
}
virtual ~VecSearchResult() throw();
std::vector<int64_t> id_list;
_VecSearchResult__isset __isset;
void __set_id_list(const std::vector<int64_t> & val);
bool operator == (const VecSearchResult & rhs) const
{
if (!(id_list == rhs.id_list))
return false;
return true;
}
bool operator != (const VecSearchResult &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecSearchResult & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
};
void swap(VecSearchResult &a, VecSearchResult &b);
std::ostream& operator<<(std::ostream& out, const VecSearchResult& obj);
typedef struct _VecSearchResultList__isset {
_VecSearchResultList__isset() : result_list(false) {}
bool result_list :1;
} _VecSearchResultList__isset;
class VecSearchResultList : public virtual ::apache::thrift::TBase {
public:
VecSearchResultList(const VecSearchResultList&);
VecSearchResultList& operator=(const VecSearchResultList&);
VecSearchResultList() {
}
virtual ~VecSearchResultList() throw();
std::vector<VecSearchResult> result_list;
_VecSearchResultList__isset __isset;
void __set_result_list(const std::vector<VecSearchResult> & val);
bool operator == (const VecSearchResultList & rhs) const
{
if (!(result_list == rhs.result_list))
return false;
return true;
}
bool operator != (const VecSearchResultList &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecSearchResultList & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
};
void swap(VecSearchResultList &a, VecSearchResultList &b);
std::ostream& operator<<(std::ostream& out, const VecSearchResultList& obj);
typedef struct _VecDateTime__isset {
_VecDateTime__isset() : year(false), month(false), day(false), hour(false), minute(false), second(false) {}
bool year :1;
bool month :1;
bool day :1;
bool hour :1;
bool minute :1;
bool second :1;
} _VecDateTime__isset;
class VecDateTime : public virtual ::apache::thrift::TBase {
public:
VecDateTime(const VecDateTime&);
VecDateTime& operator=(const VecDateTime&);
VecDateTime() : year(0), month(0), day(0), hour(0), minute(0), second(0) {
}
virtual ~VecDateTime() throw();
int32_t year;
int32_t month;
int32_t day;
int32_t hour;
int32_t minute;
int32_t second;
_VecDateTime__isset __isset;
void __set_year(const int32_t val);
void __set_month(const int32_t val);
void __set_day(const int32_t val);
void __set_hour(const int32_t val);
void __set_minute(const int32_t val);
void __set_second(const int32_t val);
bool operator == (const VecDateTime & rhs) const
{
if (!(year == rhs.year))
return false;
if (!(month == rhs.month))
return false;
if (!(day == rhs.day))
return false;
if (!(hour == rhs.hour))
return false;
if (!(minute == rhs.minute))
return false;
if (!(second == rhs.second))
return false;
return true;
}
bool operator != (const VecDateTime &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecDateTime & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
};
void swap(VecDateTime &a, VecDateTime &b);
std::ostream& operator<<(std::ostream& out, const VecDateTime& obj);
typedef struct _VecTimeRange__isset {
_VecTimeRange__isset() : time_begin(false), begine_closed(false), time_end(false), end_closed(false) {}
bool time_begin :1;
bool begine_closed :1;
bool time_end :1;
bool end_closed :1;
} _VecTimeRange__isset;
class VecTimeRange : public virtual ::apache::thrift::TBase {
public:
VecTimeRange(const VecTimeRange&);
VecTimeRange& operator=(const VecTimeRange&);
VecTimeRange() : begine_closed(0), end_closed(0) {
}
virtual ~VecTimeRange() throw();
VecDateTime time_begin;
bool begine_closed;
VecDateTime time_end;
bool end_closed;
_VecTimeRange__isset __isset;
void __set_time_begin(const VecDateTime& val);
void __set_begine_closed(const bool val);
void __set_time_end(const VecDateTime& val);
void __set_end_closed(const bool val);
bool operator == (const VecTimeRange & rhs) const
{
if (!(time_begin == rhs.time_begin))
return false;
if (!(begine_closed == rhs.begine_closed))
return false;
if (!(time_end == rhs.time_end))
return false;
if (!(end_closed == rhs.end_closed))
return false;
return true;
}
bool operator != (const VecTimeRange &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecTimeRange & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
};
void swap(VecTimeRange &a, VecTimeRange &b);
std::ostream& operator<<(std::ostream& out, const VecTimeRange& obj);
typedef struct _VecTimeRangeList__isset {
_VecTimeRangeList__isset() : range_list(false) {}
bool range_list :1;
} _VecTimeRangeList__isset;
class VecTimeRangeList : public virtual ::apache::thrift::TBase {
public:
VecTimeRangeList(const VecTimeRangeList&);
VecTimeRangeList& operator=(const VecTimeRangeList&);
VecTimeRangeList() {
}
virtual ~VecTimeRangeList() throw();
std::vector<VecTimeRange> range_list;
_VecTimeRangeList__isset __isset;
void __set_range_list(const std::vector<VecTimeRange> & val);
bool operator == (const VecTimeRangeList & rhs) const
{
if (!(range_list == rhs.range_list))
return false;
return true;
}
bool operator != (const VecTimeRangeList &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecTimeRangeList & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
};
void swap(VecTimeRangeList &a, VecTimeRangeList &b);
std::ostream& operator<<(std::ostream& out, const VecTimeRangeList& obj);
#endif

View File

@ -33,12 +33,12 @@ namespace fs = boost::filesystem;
void CommonUtil::PrintInfo(const std::string& info){
SERVER_LOG_INFO << info;
// std::cout << info << std::endl;
std::cout << "Info:" << info << std::endl;
}
void CommonUtil::PrintError(const std::string& info){
SERVER_LOG_ERROR << info;
// std::cout << info << std::endl;
std::cout << "Error:" << info << std::endl;
}
bool CommonUtil::GetSystemMemInfo(unsigned long &totalMem, unsigned long &freeMem) {

View File

@ -24,7 +24,6 @@ void SignalUtil::HandleSignal(int signum){
server_ptr->Stop();
exit(0);
}
default:{
SignalUtil::PrintStacktrace();

View File

@ -0,0 +1,42 @@
#-------------------------------------------------------------------------------
# Copyright (Zilliz) - All Rights Reserved
# Unauthorized copying of this file, via any medium is strictly prohibited.
# Proprietary and confidential.
#-------------------------------------------------------------------------------
include_directories(../src)
aux_source_directory(./src client_src)
aux_source_directory(../src/config config_files)
set(util_files
../src/utils/CommonUtil.cpp
../src/utils/LogUtil.cpp
../src/utils/TimeRecorder.cpp)
set(service_files
../src/thrift/gen-cpp/VecService.cpp
../src/thrift/gen-cpp/VectorService_constants.cpp
../src/thrift/gen-cpp/VectorService_types.cpp)
add_executable(test_client
./main.cpp
${client_src}
${service_files}
${config_files}
${util_files}
${VECWISE_THIRD_PARTY_BUILD}/include/easylogging++.cc)
link_directories(
"${CMAKE_BINARY_DIR}/lib"
"${VECWISE_THIRD_PARTY_BUILD}/lib"
)
set(client_libs
yaml-cpp
boost_system
boost_filesystem
thrift
pthread)
target_link_libraries(test_client ${client_libs})

74
cpp/test_client/main.cpp Normal file
View File

@ -0,0 +1,74 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include <getopt.h>
#include <libgen.h>
#include <cstring>
#include <string>
#include <easylogging++.h>
#include "src/ClientApp.h"
INITIALIZE_EASYLOGGINGPP
void print_help(const std::string &app_name);
int
main(int argc, char *argv[]) {
printf("Client start...\n");
std::string app_name = basename(argv[0]);
static struct option long_options[] = {{"conf_file", required_argument, 0, 'c'},
{"help", no_argument, 0, 'h'},
{NULL, 0, 0, 0}};
int option_index = 0;
std::string config_filename;
app_name = argv[0];
if(argc < 2) {
print_help(app_name);
printf("Client exit...\n");
return EXIT_FAILURE;
}
int value;
while ((value = getopt_long(argc, argv, "c:p:dh", long_options, &option_index)) != -1) {
switch (value) {
case 'c': {
char *config_filename_ptr = strdup(optarg);
config_filename = config_filename_ptr;
free(config_filename_ptr);
printf("Loading configuration from: %s\n", config_filename.c_str());
break;
}
case 'h':
print_help(app_name);
return EXIT_SUCCESS;
case '?':
print_help(app_name);
return EXIT_FAILURE;
default:
print_help(app_name);
break;
}
}
zilliz::vecwise::client::ClientApp app;
app.Run(config_filename);
printf("Client exit...\n");
return 0;
}
void
print_help(const std::string &app_name) {
printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
printf(" Options:\n");
printf(" -h --help Print this help\n");
printf(" -c --conf_file filename Read configuration from the file\n");
printf("\n");
}

View File

@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#include "ClientApp.h"
namespace zilliz {
namespace vecwise {
namespace client {
void ClientApp::Run(const std::string &config_file) {
}
}
}
}

View File

@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#pragma once
#include <string>
namespace zilliz {
namespace vecwise {
namespace client {
class ClientApp {
public:
void Run(const std::string& config_file);
};
}
}
}