提交 4342b747 编写于 作者: G groot

add test client


Former-commit-id: cebc4c2bfaec125003e0b6e60534e69514796fd7
上级 194dcc14
......@@ -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)
......
......@@ -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
......@@ -9,6 +9,11 @@ aux_source_directory(config config_files)
aux_source_directory(server server_files)
aux_source_directory(utils utils_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}
......@@ -20,6 +25,7 @@ add_executable(vecwise_engine_server
${config_files}
${server_files}
${utils_files}
${service_files}
${VECWISE_THIRD_PARTY_BUILD}/include/easylogging++.cc
)
......@@ -28,5 +34,7 @@ set(dependency_libs
yaml-cpp
boost_system
boost_filesystem
thrift
pthread
)
target_link_libraries(vecwise_engine_server ${dependency_libs})
\ No newline at end of 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) {
......
......@@ -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();
}
}
......
......@@ -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);
}
}
}
......
......@@ -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;
};
}
......
/*******************************************************************************
* 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();
}
}
}
}
\ No newline at end of file
/*******************************************************************************
* 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();
};
}
}
}
/*******************************************************************************
* 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);
}
\ No newline at end of file
此差异已折叠。
此差异已折叠。
// 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;
}
/**
* 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() {
}
/**
* 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
此差异已折叠。
此差异已折叠。
......@@ -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) {
......
......@@ -24,7 +24,6 @@ void SignalUtil::HandleSignal(int signum){
server_ptr->Stop();
exit(0);
}
default:{
SignalUtil::PrintStacktrace();
......
#-------------------------------------------------------------------------------
# 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})
////////////////////////////////////////////////////////////////////////////////
// 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");
}
\ No newline at end of file
/*******************************************************************************
* 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) {
}
}
}
}
/*******************************************************************************
* 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);
};
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册