提交 a0faf1a7 编写于 作者: B BossZou 提交者: Jin Hai

Add http server (#956)

* refactoring(create_table done)

* refactoring

* refactor server delivery (insert done)

* refactoring server module (count_table done)

* server refactor done

* cmake pass

* refactor server module done.

* set grpc response status correctly

* format done.

* fix redefine ErrorMap()

* optimize insert reducing ids data copy

* optimize grpc request with reducing data copy

* clang format

* [skip ci] Refactor server module done. update changlog. prepare for PR

* remove explicit and change int32_t to int64_t

* add web server

* [skip ci] add license in web module

* modify header include & comment oatpp environment config

* add port configure & create table in handler

* modify web url

* simple url complation done & add swagger

* make sure web url

* web functionality done. debuging

* add web unittest

* web test pass

* add web server port

* add web server port in template

* update unittest cmake file

* change web server default port to 19121

* rename method in web module & unittest pass

* add search case in unittest for web module

* rename some variables

* fix bug

* unittest pass

* web prepare

* fix cmd bug(check server status)

* update changlog

* add web port validate & default set

* clang-format pass

* add web port test in unittest

* add CORS & redirect root to swagger ui

* add web status

* web table method func cascade test pass

* add config url in web module

* modify thirdparty cmake to avoid building oatpp test

* clang format

* update changlog

* add constants in web module

* reserve Config.cpp

* fix constants reference bug

* replace web server with async module

* modify component to support async

* format

* developing controller & add test clent into unittest

* add web port into demo/server_config

* modify thirdparty cmake to allow build test

* remove  unnecessary comment

* add endpoint info in controller

* finish web test(bug here)

* clang format

* add web test cpp to lint exclusions

* check null field in GetConfig

* add macro RETURN STATUS DTo

* fix cmake conflict

* fix crash when exit server

* remove surplus comments & add http param check

* add uri /docs to direct swagger

* format

* change cmd to system

* add default value & unittest in web module

* add macros to judge if GPU supported

* add macros in unit & add default in index dto & print error message when bind http port fail

* format (fix #788)

* fix cors bug (not completed)

* comment cors

* change web framework to simple api

* comments optimize

* change to simple API

* remove comments in controller.hpp

* remove EP_COMMON_CMAKE_ARGS in oatpp and oatpp-swagger

* add ep cmake args to sqlite

* clang-format

* change a format

* test pass

* change name to

* fix compiler issue(oatpp-swagger depend on oatpp)

* add & in start_server.h

* specify lib location with oatpp and oatpp-swagger

* add comments

* add swagger definition

* [skip ci] change http method options status code

* remove oatpp swagger(fix #970)

* remove comments

* check Start web behavior

* add default to cpu_cache_capacity

* remove swagger component.hpp & /docs url

* remove /docs info

* remove /docs in unittest

* remove space in test rpc

* remove repeate info in CHANGLOG

* change cache_insert_data default value as a constant

* [skip ci] Fix some broken links (#960)

* [skip ci] Fix broken link

* [skip ci] Fix broken link

* [skip ci] Fix broken link

* [skip ci] Fix broken links

* fix issue 373 (#964)

* fix issue 373

* Adjustment format

* Adjustment format

* Adjustment format

* change readme

* #966 update NOTICE.md (#967)

* remove comments

* check Start web behavior

* add default to cpu_cache_capacity

* remove swagger component.hpp & /docs url

* remove /docs info

* remove /docs in unittest

* remove space in test rpc

* remove repeate info in CHANGLOG

* change cache_insert_data default value as a constant

* adjust web port cofig place

* rename web_port variable

* set advanced config name add DEFAULT
Co-authored-by: Njielinxu <52057195+jielinxu@users.noreply.github.com>
Co-authored-by: NJackLCL <53512883+JackLCL@users.noreply.github.com>
Co-authored-by: NCai Yudong <yudong.cai@zilliz.com>
上级 c787b84d
......@@ -18,6 +18,7 @@ Please mark all change in change log and use the issue from GitHub
- \#766 - If partition tag is similar, wrong partition is searched
- \#771 - Add server build commit info interface
- \#759 - Put C++ sdk out of milvus/core
- \#788 - Add web server into server module
- \#813 - Add push mode for prometheus monitor
- \#815 - Support MinIO storage
- \#910 - Change Milvus c++ standard to c++17
......
......@@ -7,4 +7,5 @@
*SqliteMetaImpl.cpp
*src/grpc*
*thirdparty*
*milvus/include*
\ No newline at end of file
*milvus/include*
*unittest/server/test_web.cpp
\ No newline at end of file
......@@ -91,6 +91,8 @@ define_option(MILVUS_WITH_FIU "Build with fiu" OFF)
define_option(MILVUS_WITH_AWS "Build with aws" ON)
define_option(MILVUS_WITH_OATPP "Build with oatpp" ON)
#----------------------------------------------------------------------
set_option_category("Test and benchmark")
......
......@@ -28,7 +28,8 @@ set(MILVUS_THIRDPARTY_DEPENDENCIES
ZLIB
Opentracing
fiu
AWS)
AWS
oatpp)
message(STATUS "Using ${MILVUS_DEPENDENCY_SOURCE} approach to find dependencies")
......@@ -64,6 +65,8 @@ macro(build_dependency DEPENDENCY_NAME)
build_opentracing()
elseif ("${DEPENDENCY_NAME}" STREQUAL "fiu")
build_fiu()
elseif ("${DEPENDENCY_NAME}" STREQUAL "oatpp")
build_oatpp()
elseif("${DEPENDENCY_NAME}" STREQUAL "AWS")
build_aws()
else ()
......@@ -330,6 +333,13 @@ else ()
"https://gitee.com/quicksilver/libfiu/repository/archive/${FIU_VERSION}.zip")
endif ()
if (DEFINED ENV{MILVUS_OATPP_URL})
set(MILVUS_OATPP_URL "$ENV{MILVUS_OATPP_URL}")
else ()
# set(OATPP_SOURCE_URL "https://github.com/oatpp/oatpp/archive/${OATPP_VERSION}.tar.gz")
set(OATPP_SOURCE_URL "https://github.com/BossZou/oatpp/archive/master.zip")
endif ()
if (DEFINED ENV{MILVUS_AWS_URL})
set(AWS_SOURCE_URL "$ENV{MILVUS_AWS_URL}")
else ()
......@@ -973,7 +983,6 @@ endif ()
# ----------------------------------------------------------------------
# fiu
macro(build_fiu)
message(STATUS "Building FIU-${FIU_VERSION} from source")
set(FIU_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/fiu_ep-prefix/src/fiu_ep")
......@@ -1013,6 +1022,53 @@ resolve_dependency(fiu)
get_target_property(FIU_INCLUDE_DIR fiu INTERFACE_INCLUDE_DIRECTORIES)
include_directories(SYSTEM ${FIU_INCLUDE_DIR})
# ----------------------------------------------------------------------
# oatpp
macro(build_oatpp)
message(STATUS "Building oatpp-${OATPP_VERSION} from source")
set(OATPP_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/oatpp_ep-prefix/src/oatpp_ep")
set(OATPP_STATIC_LIB "${OATPP_PREFIX}/lib/oatpp-${OATPP_VERSION}/${CMAKE_STATIC_LIBRARY_PREFIX}oatpp${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(OATPP_INCLUDE_DIR "${OATPP_PREFIX}/include/oatpp-${OATPP_VERSION}/oatpp")
set(OATPP_DIR_SRC "${OATPP_PREFIX}/src")
set(OATPP_DIR_LIB "${OATPP_PREFIX}/lib")
set(OATPP_CMAKE_ARGS
"-DCMAKE_INSTALL_PREFIX=${OATPP_PREFIX}"
-DCMAKE_INSTALL_LIBDIR=lib
-DBUILD_SHARED_LIBS=OFF
-DOATPP_BUILD_TESTS=OFF
)
externalproject_add(oatpp_ep
URL
${OATPP_SOURCE_URL}
${EP_LOG_OPTIONS}
CMAKE_ARGS
${OATPP_CMAKE_ARGS}
BUILD_COMMAND
${MAKE}
${MAKE_BUILD_ARGS}
BUILD_BYPRODUCTS
${OATPP_STATIC_LIB}
)
file(MAKE_DIRECTORY "${OATPP_INCLUDE_DIR}")
add_library(oatpp STATIC IMPORTED)
set_target_properties(oatpp
PROPERTIES IMPORTED_LOCATION "${OATPP_STATIC_LIB}"
INTERFACE_INCLUDE_DIRECTORIES "${OATPP_INCLUDE_DIR}")
add_dependencies(oatpp oatpp_ep)
endmacro()
if (MILVUS_WITH_OATPP)
resolve_dependency(oatpp)
get_target_property(OATPP_INCLUDE_DIR oatpp INTERFACE_INCLUDE_DIRECTORIES)
include_directories(SYSTEM ${OATPP_INCLUDE_DIR})
endif ()
# ----------------------------------------------------------------------
# aws
macro(build_aws)
......
......@@ -29,11 +29,15 @@ version: 0.1
#----------------------+------------------------------------------------------------+------------+-----------------+
# time_zone | Use UTC-x or UTC+x to specify a time zone. | Timezone | UTC+8 |
#----------------------+------------------------------------------------------------+------------+-----------------+
# web_port | Port that Milvus web server monitors. | Integer | 19121 |
# | Port range (1024, 65535) | | |
#----------------------+------------------------------------------------------------+------------+-----------------+
server_config:
address: 0.0.0.0
port: 19530
deploy_mode: single
time_zone: UTC+8
web_port: 19121
#----------------------+------------------------------------------------------------+------------+-----------------+
# DataBase Config | Description | Type | Default |
......
......@@ -29,11 +29,15 @@ version: 0.1
#----------------------+------------------------------------------------------------+------------+-----------------+
# time_zone | Use UTC-x or UTC+x to specify a time zone. | Timezone | UTC+8 |
#----------------------+------------------------------------------------------------+------------+-----------------+
# web_port | Port that Milvus web server monitors. | Integer | 19121 |
# | Port range (1024, 65535) | | |
#----------------------+------------------------------------------------------------+------------+-----------------+
server_config:
address: 0.0.0.0
port: 19530
deploy_mode: single
time_zone: UTC+8
web_port: 19121
#----------------------+------------------------------------------------------------+------------+-----------------+
# DataBase Config | Description | Type | Default |
......
......@@ -29,11 +29,15 @@ version: 0.1
#----------------------+------------------------------------------------------------+------------+-----------------+
# time_zone | Use UTC-x or UTC+x to specify a time zone. | Timezone | UTC+8 |
#----------------------+------------------------------------------------------------+------------+-----------------+
# web_port | Port that Milvus web server monitors. | Integer | 19121 |
# | Port range (1024, 65535) | | |
#----------------------+------------------------------------------------------------+------------+-----------------+
server_config:
address: 0.0.0.0
port: 19530
deploy_mode: single
time_zone: UTC+8
web_port: 19121
#----------------------+------------------------------------------------------------+------------+-----------------+
# DataBase Config | Description | Type | Default |
......
......@@ -92,6 +92,19 @@ set(grpc_server_files
${grpc_interceptor_files}
)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/web_impl/handler web_handler_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/web_impl/component web_conponent_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/web_impl/controller web_controller_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/web_impl/dto web_dto_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/web_impl web_impl_files)
set(web_server_files
${web_handler_files}
${web_conponent_files}
${web_controller_files}
${web_dto_files}
${web_impl_files}
)
aux_source_directory(${MILVUS_ENGINE_SRC}/storage storage_main_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/storage/file storage_file_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/storage/s3 storage_s3_files)
......@@ -247,6 +260,7 @@ set(server_libs
milvus_engine
metrics
tracing
oatpp
)
add_executable(milvus_server
......@@ -256,6 +270,7 @@ add_executable(milvus_server
${server_files}
${grpc_server_files}
${grpc_service_files}
${web_server_files}
${server_context_files}
${utils_files}
${tracing_files}
......
......@@ -88,6 +88,9 @@ Config::ValidateConfig() {
std::string server_time_zone;
CONFIG_CHECK(GetServerConfigTimeZone(server_time_zone));
std::string server_web_port;
CONFIG_CHECK(GetServerConfigWebPort(server_web_port));
/* db config */
std::string db_backend_url;
CONFIG_CHECK(GetDBConfigBackendUrl(db_backend_url));
......@@ -194,6 +197,7 @@ Config::ResetDefaultConfig() {
CONFIG_CHECK(SetServerConfigPort(CONFIG_SERVER_PORT_DEFAULT));
CONFIG_CHECK(SetServerConfigDeployMode(CONFIG_SERVER_DEPLOY_MODE_DEFAULT));
CONFIG_CHECK(SetServerConfigTimeZone(CONFIG_SERVER_TIME_ZONE_DEFAULT));
CONFIG_CHECK(SetServerConfigWebPort(CONFIG_SERVER_WEB_PORT_DEFAULT));
/* db config */
CONFIG_CHECK(SetDBConfigBackendUrl(CONFIG_DB_BACKEND_URL_DEFAULT));
......@@ -404,6 +408,23 @@ Config::CheckServerConfigTimeZone(const std::string& value) {
return Status::OK();
}
Status
Config::CheckServerConfigWebPort(const std::string& value) {
if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
std::string msg =
"Invalid web server port: " + value + ". Possible reason: server_config.web_port is not a number.";
return Status(SERVER_INVALID_ARGUMENT, msg);
} else {
int32_t port = std::stoi(value);
if (!(port > 1024 && port < 65535)) {
std::string msg = "Invalid web server port: " + value +
". Possible reason: server_config.web_port is not in range [1025, 65534].";
return Status(SERVER_INVALID_ARGUMENT, msg);
}
}
return Status::OK();
}
/* DB config */
Status
Config::CheckDBConfigBackendUrl(const std::string& value) {
......@@ -668,6 +689,7 @@ Config::CheckEngineConfigOmpThreadNum(const std::string& value) {
}
#ifdef MILVUS_GPU_VERSION
Status
Config::CheckEngineConfigGpuSearchThreshold(const std::string& value) {
if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
......@@ -789,6 +811,7 @@ Config::CheckGpuResourceConfigBuildIndexResources(const std::vector<std::string>
return Status::OK();
}
#endif
////////////////////////////////////////////////////////////////////////////////
......@@ -890,6 +913,12 @@ Config::GetServerConfigTimeZone(std::string& value) {
return CheckServerConfigTimeZone(value);
}
Status
Config::GetServerConfigWebPort(std::string& value) {
value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_WEB_PORT, CONFIG_SERVER_WEB_PORT_DEFAULT);
return CheckServerConfigWebPort(value);
}
/* DB config */
Status
Config::GetDBConfigBackendUrl(std::string& value) {
......@@ -1051,6 +1080,7 @@ Config::GetEngineConfigOmpThreadNum(int64_t& value) {
}
#ifdef MILVUS_GPU_VERSION
Status
Config::GetEngineConfigGpuSearchThreshold(int64_t& value) {
std::string str =
......@@ -1140,6 +1170,7 @@ Config::GetGpuResourceConfigBuildIndexResources(std::vector<int64_t>& value) {
}
return Status::OK();
}
#endif
/* tracing config */
......@@ -1183,6 +1214,12 @@ Config::SetServerConfigTimeZone(const std::string& value) {
return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, value);
}
Status
Config::SetServerConfigWebPort(const std::string& value) {
CONFIG_CHECK(CheckServerConfigWebPort(value));
return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_WEB_PORT, value);
}
/* db config */
Status
Config::SetDBConfigBackendUrl(const std::string& value) {
......@@ -1309,6 +1346,7 @@ Config::SetEngineConfigOmpThreadNum(const std::string& value) {
}
#ifdef MILVUS_GPU_VERSION
/* gpu resource config */
Status
Config::SetEngineConfigGpuSearchThreshold(const std::string& value) {
CONFIG_CHECK(CheckEngineConfigGpuSearchThreshold(value));
......
......@@ -49,6 +49,8 @@ static const char* CONFIG_SERVER_DEPLOY_MODE = "deploy_mode";
static const char* CONFIG_SERVER_DEPLOY_MODE_DEFAULT = "single";
static const char* CONFIG_SERVER_TIME_ZONE = "time_zone";
static const char* CONFIG_SERVER_TIME_ZONE_DEFAULT = "UTC+8";
static const char* CONFIG_SERVER_WEB_PORT = "web_port";
static const char* CONFIG_SERVER_WEB_PORT_DEFAULT = "19121";
/* db config */
static const char* CONFIG_DB = "db_config";
......@@ -176,6 +178,8 @@ class Config {
CheckServerConfigDeployMode(const std::string& value);
Status
CheckServerConfigTimeZone(const std::string& value);
Status
CheckServerConfigWebPort(const std::string& value);
/* db config */
Status
......@@ -262,6 +266,8 @@ class Config {
GetServerConfigDeployMode(std::string& value);
Status
GetServerConfigTimeZone(std::string& value);
Status
GetServerConfigWebPort(std::string& value);
/* db config */
Status
......@@ -346,6 +352,8 @@ class Config {
SetServerConfigDeployMode(const std::string& value);
Status
SetServerConfigTimeZone(const std::string& value);
Status
SetServerConfigWebPort(const std::string& value);
/* db config */
Status
......
......@@ -26,6 +26,7 @@
#include "server/Config.h"
#include "server/DBWrapper.h"
#include "server/grpc_impl/GrpcServer.h"
#include "server/web_impl/WebServer.h"
#include "src/version.h"
#include "storage/s3/S3ClientWrapper.h"
#include "tracing/TracerUtil.h"
......@@ -264,12 +265,14 @@ Server::StartService() {
scheduler::StartSchedulerService();
DBWrapper::GetInstance().StartService();
grpc::GrpcServer::GetInstance().Start();
web::WebServer::GetInstance().Start();
storage::S3ClientWrapper::GetInstance().StartService();
}
void
Server::StopService() {
storage::S3ClientWrapper::GetInstance().StopService();
web::WebServer::GetInstance().Stop();
grpc::GrpcServer::GetInstance().Stop();
DBWrapper::GetInstance().StopService();
scheduler::StopSchedulerService();
......
......@@ -18,7 +18,7 @@
#pragma once
#include "server/delivery/request/BaseRequest.h"
#include "src/utils/Status.h"
#include "utils/Status.h"
#include <memory>
#include <string>
......
......@@ -57,26 +57,28 @@ RequestScheduler::Start() {
void
RequestScheduler::Stop() {
if (stopped_) {
if (stopped_ && request_groups_.empty() && execute_threads_.empty()) {
return;
}
SERVER_LOG_INFO << "Scheduler gonna stop...";
{
std::lock_guard<std::mutex> lock(queue_mtx_);
for (auto iter : request_groups_) {
for (auto& iter : request_groups_) {
if (iter.second != nullptr) {
iter.second->Put(nullptr);
}
}
}
for (auto iter : execute_threads_) {
for (auto& iter : execute_threads_) {
if (iter == nullptr)
continue;
iter->join();
}
request_groups_.clear();
execute_threads_.clear();
stopped_ = true;
SERVER_LOG_INFO << "Scheduler stopped";
}
......
......@@ -49,9 +49,9 @@ ShowPartitionsRequest::OnExecute() {
}
std::vector<engine::meta::TableSchema> schema_array;
auto statuts = DBWrapper::DB()->ShowPartitions(table_name_, schema_array);
if (!statuts.ok()) {
return statuts;
status = DBWrapper::DB()->ShowPartitions(table_name_, schema_array);
if (!status.ok()) {
return status;
}
for (auto& schema : schema_array) {
......
......@@ -23,6 +23,7 @@
#include "server/grpc_impl/GrpcRequestHandler.h"
#include "tracing/TextMapCarrier.h"
#include "tracing/TracerUtil.h"
#include "utils/Log.h"
#include "utils/TimeRecorder.h"
namespace milvus {
......
......@@ -103,9 +103,8 @@ GrpcServer::StartService() {
builder.SetDefaultCompressionAlgorithm(GRPC_COMPRESS_STREAM_GZIP);
builder.SetDefaultCompressionLevel(GRPC_COMPRESS_LEVEL_NONE);
RequestHandler handler;
GrpcRequestHandler service(opentracing::Tracer::Global());
service.RegisterRequestHandler(handler);
service.RegisterRequestHandler(RequestHandler());
builder.AddListeningPort(server_address, ::grpc::InsecureServerCredentials());
builder.RegisterService(&service);
......
// 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.
#pragma once
namespace milvus {
namespace server {
namespace web {
////////////////////////////////////////////////////
static const char* CORS_KEY_METHODS = "Access-Control-Allow-Methods";
static const char* CORS_KEY_ORIGIN = "Access-Control-Allow-Origin";
static const char* CORS_KEY_HEADERS = "Access-Control-Allow-Headers";
static const char* CORS_KEY_AGE = "Access-Control-Max-Age";
static const char* CORS_VALUE_METHODS = "GET, POST, PUT, OPTIONS, DELETE";
static const char* CORS_VALUE_ORIGIN = "*";
static const char* CORS_VALUE_HEADERS =
"DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range, Authorization";
static const char* CORS_VALUE_AGE = "1728000";
////////////////////////////////////////////////////
static const char* NAME_ENGINE_TYPE_FLAT = "FLAT";
static const char* NAME_ENGINE_TYPE_IVFFLAT = "IVFFLAT";
static const char* NAME_ENGINE_TYPE_IVFSQ8 = "IVFSQ8";
static const char* NAME_ENGINE_TYPE_IVFSQ8H = "IVFSQ8H";
static const char* NAME_ENGINE_TYPE_RNSG = "RNSG";
static const char* NAME_ENGINE_TYPE_IVFPQ = "IVFPQ";
static const char* NAME_METRIC_TYPE_L2 = "L2";
static const char* NAME_METRIC_TYPE_IP = "IP";
////////////////////////////////////////////////////
static const char* KEY_TABLE_TABLE_NAME = "table_name";
static const char* KEY_TABLE_DIMENSION = "dimension";
static const char* KEY_TABLE_INDEX_FILE_SIZE = "index_file_size";
static const char* KEY_TABLE_INDEX_METRIC_TYPE = "metric_type";
static const char* KEY_TABLE_COUNT = "count";
static const char* KEY_INDEX_INDEX_TYPE = "index_type";
static const char* KEY_INDEX_NLIST = "nlist";
static const char* KEY_PARTITION_NAME = "partition_name";
static const char* KEY_PARTITION_TAG = "partition_tag";
////////////////////////////////////////////////////
static const int64_t VALUE_TABLE_INDEX_FILE_SIZE_DEFAULT = 1024;
static const char* VALUE_TABLE_METRIC_TYPE_DEFAULT = "L2";
static const char* VALUE_PARTITION_TAG_DEFAULT = "";
static const char* VALUE_INDEX_INDEX_TYPE_DEFAULT = NAME_ENGINE_TYPE_FLAT;
static const int64_t VALUE_INDEX_NLIST_DEFAULT = 16384;
static const int64_t VALUE_CONFIG_CPU_CACHE_CAPACITY_DEFAULT = 4;
static const bool VALUE_CONFIG_CACHE_INSERT_DATA_DEFAULT = false;
} // namespace web
} // namespace server
} // namespace milvus
// 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.
#pragma once
#include <string>
#include <unordered_map>
#include <oatpp/core/data/mapping/type/Object.hpp>
#include "db/engine/ExecutionEngine.h"
#include "server/web_impl/Constants.h"
namespace milvus {
namespace server {
namespace web {
using OString = oatpp::data::mapping::type::String;
using OInt64 = oatpp::data::mapping::type::Int64;
using OFloat32 = oatpp::data::mapping::type::Float32;
template <class T>
using OList = oatpp::data::mapping::type::List<T>;
using OQueryParams = oatpp::web::protocol::http::QueryParams;
enum StatusCode : int {
SUCCESS = 0,
UNEXPECTED_ERROR = 1,
CONNECT_FAILED = 2, // reserved.
PERMISSION_DENIED = 3,
TABLE_NOT_EXISTS = 4, // DB_NOT_FOUND || TABLE_NOT_EXISTS
ILLEGAL_ARGUMENT = 5,
ILLEGAL_RANGE = 6,
ILLEGAL_DIMENSION = 7,
ILLEGAL_INDEX_TYPE = 8,
ILLEGAL_TABLE_NAME = 9,
ILLEGAL_TOPK = 10,
ILLEGAL_ROWRECORD = 11,
ILLEGAL_VECTOR_ID = 12,
ILLEGAL_SEARCH_RESULT = 13,
FILE_NOT_FOUND = 14,
META_FAILED = 15,
CACHE_FAILED = 16,
CANNOT_CREATE_FOLDER = 17,
CANNOT_CREATE_FILE = 18,
CANNOT_DELETE_FOLDER = 19,
CANNOT_DELETE_FILE = 20,
BUILD_INDEX_ERROR = 21,
ILLEGAL_NLIST = 22,
ILLEGAL_METRIC_TYPE = 23,
OUT_OF_MEMORY = 24,
// HTTP status code
PATH_PARAM_LOSS = 31,
QUERY_PARAM_LOSS = 32,
BODY_FIELD_LOSS = 33,
};
static const std::unordered_map<engine::EngineType, std::string> IndexMap = {
{engine::EngineType::FAISS_IDMAP, NAME_ENGINE_TYPE_FLAT},
{engine::EngineType::FAISS_IVFFLAT, NAME_ENGINE_TYPE_IVFFLAT},
{engine::EngineType::FAISS_IVFSQ8, NAME_ENGINE_TYPE_IVFSQ8},
{engine::EngineType::FAISS_IVFSQ8H, NAME_ENGINE_TYPE_IVFSQ8H},
{engine::EngineType::NSG_MIX, NAME_ENGINE_TYPE_RNSG},
{engine::EngineType::FAISS_PQ, NAME_ENGINE_TYPE_IVFPQ},
};
static const std::unordered_map<std::string, engine::EngineType> IndexNameMap = {
{NAME_ENGINE_TYPE_FLAT, engine::EngineType::FAISS_IDMAP},
{NAME_ENGINE_TYPE_IVFFLAT, engine::EngineType::FAISS_IVFFLAT},
{NAME_ENGINE_TYPE_IVFSQ8, engine::EngineType::FAISS_IVFSQ8},
{NAME_ENGINE_TYPE_IVFSQ8H, engine::EngineType::FAISS_IVFSQ8H},
{NAME_ENGINE_TYPE_RNSG, engine::EngineType::NSG_MIX},
{NAME_ENGINE_TYPE_IVFPQ, engine::EngineType::FAISS_PQ},
};
static const std::unordered_map<engine::MetricType, std::string> MetricMap = {
{engine::MetricType::L2, NAME_METRIC_TYPE_L2},
{engine::MetricType::IP, NAME_METRIC_TYPE_IP},
};
static const std::unordered_map<std::string, engine::MetricType> MetricNameMap = {
{NAME_METRIC_TYPE_L2, engine::MetricType::L2},
{NAME_METRIC_TYPE_IP, engine::MetricType::IP},
};
} // namespace web
} // namespace server
} // namespace milvus
// 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 <chrono>
#include <oatpp/network/server/Server.hpp>
#include "server/web_impl/WebServer.h"
#include "server/web_impl/controller/WebController.hpp"
#include "server/Config.h"
namespace milvus {
namespace server {
namespace web {
void
WebServer::Start() {
if (nullptr == thread_ptr_) {
thread_ptr_ = std::make_shared<std::thread>(&WebServer::StartService, this);
}
}
void
WebServer::Stop() {
StopService();
if (thread_ptr_ != nullptr) {
thread_ptr_->join();
thread_ptr_ = nullptr;
}
}
Status
WebServer::StartService() {
oatpp::base::Environment::init();
Config& config = Config::GetInstance();
std::string port;
Status status;
status = config.GetServerConfigWebPort(port);
{
AppComponent components = AppComponent(std::stoi(port));
auto user_controller = WebController::createShared();
/* create ApiControllers and add endpoints to router */
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
user_controller->addEndpointsToRouter(router);
/* Get connection handler component */
OATPP_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, connection_handler);
/* Get connection provider component */
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connection_provider);
/* create server */
auto server = oatpp::network::server::Server(connection_provider, connection_handler);
std::thread stop_thread([&server, this] {
while (!this->try_stop_.load()) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
server.stop();
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, client_provider);
client_provider->getConnection();
});
// start synchronously
server.run();
connection_handler->stop();
stop_thread.join();
}
oatpp::base::Environment::destroy();
return Status::OK();
}
Status
WebServer::StopService() {
try_stop_.store(true);
return Status::OK();
}
} // namespace web
} // namespace server
} // namespace milvus
// 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.
#pragma once
#include <atomic>
#include <memory>
#include <string>
#include <thread>
#include <oatpp/network/server/Server.hpp>
#include "server/web_impl/component/AppComponent.hpp"
#include "utils/Status.h"
namespace milvus {
namespace server {
namespace web {
class WebServer {
public:
static WebServer&
GetInstance() {
static WebServer web_server;
return web_server;
}
void
Start();
void
Stop();
private:
WebServer() {
try_stop_.store(false);
}
~WebServer() = default;
Status
StartService();
Status
StopService();
private:
std::atomic_bool try_stop_;
std::shared_ptr<std::thread> thread_ptr_;
};
} // namespace web
} // namespace server
} // namespace milvus
// 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.
#pragma once
#include <oatpp/parser/json/mapping/Serializer.hpp>
#include <oatpp/parser/json/mapping/Deserializer.hpp>
#include <oatpp/web/server/HttpRouter.hpp>
#include <oatpp/network/client/SimpleTCPConnectionProvider.hpp>
#include <oatpp/network/server/SimpleTCPConnectionProvider.hpp>
#include <oatpp/parser/json/mapping/ObjectMapper.hpp>
#include <oatpp/core/macro/component.hpp>
#include "server/web_impl/handler/WebRequestHandler.h"
namespace milvus {
namespace server {
namespace web {
class AppComponent {
public:
explicit AppComponent(int port) : port_(port) {
}
private:
const int port_;
public:
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, server_connection_provider_)
([this] {
try {
return oatpp::network::server::SimpleTCPConnectionProvider::createShared(this->port_);
} catch (std::exception& e) {
std::string error_msg = "Cannot bind http port " + std::to_string(this->port_) +
". Check if the port is already used";
std::cout << error_msg << std::endl;
throw std::runtime_error(error_msg);
}
}());
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, client_connection_provider_)
([this] {
return oatpp::network::client::SimpleTCPConnectionProvider::createShared("localhost", this->port_);
}());
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, http_router_)([] {
return oatpp::web::server::HttpRouter::createShared();
}());
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, server_connection_handler_)([] {
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // get Router component
return oatpp::web::server::HttpConnectionHandler::createShared(router);
}());
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, api_object_mapper_)([] {
auto serializerConfig = oatpp::parser::json::mapping::Serializer::Config::createShared();
auto deserializerConfig = oatpp::parser::json::mapping::Deserializer::Config::createShared();
deserializerConfig->allowUnknownFields = false;
return oatpp::parser::json::mapping::ObjectMapper::createShared(serializerConfig,
deserializerConfig);
}());
};
} //namespace web
} //namespace server
} //namespace milvus
此差异已折叠。
// 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.
#pragma once
#include "server/web_impl/dto/Dto.h"
namespace milvus {
namespace server {
namespace web {
#include OATPP_CODEGEN_BEGIN(DTO)
class CommandDto: public oatpp::data::mapping::type::Object {
DTO_INIT(CommandDto, Object)
DTO_FIELD(String, reply, "reply");
};
class CmdFieldsDto : public OObject {
DTO_INIT(CmdFieldsDto, Object)
DTO_FIELD(Fields<String>::ObjectWrapper, reply);
};
#include OATPP_CODEGEN_END(DTO)
} // namespace web
} // namespace server
} // namespace milvus
\ No newline at end of file
// 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.
#pragma once
#include "server/web_impl/Constants.h"
#include "server/web_impl/dto/Dto.h"
namespace milvus {
namespace server {
namespace web {
#include OATPP_CODEGEN_BEGIN(DTO)
class AdvancedConfigDto : public OObject {
DTO_INIT(AdvancedConfigDto, Object);
DTO_FIELD(Int64, cpu_cache_capacity) = VALUE_CONFIG_CPU_CACHE_CAPACITY_DEFAULT;
DTO_FIELD(Boolean, cache_insert_data) = VALUE_CONFIG_CACHE_INSERT_DATA_DEFAULT;
DTO_FIELD(Int64, use_blas_threshold) = 1100;
#ifdef MILVUS_GPU_VERSION
DTO_FIELD(Int64, gpu_search_threshold) = 1000;
#endif
};
class GPUConfigDto : public OObject {
DTO_INIT(GPUConfigDto, Object);
DTO_FIELD(Boolean, enable) = true;
DTO_FIELD(Int64, cache_capacity) = 1;
DTO_FIELD(List<String>::ObjectWrapper, search_resources);
DTO_FIELD(List<String>::ObjectWrapper, build_index_resources);
};
#include OATPP_CODEGEN_END(DTO)
} // namespace web
} // namespace server
} // namespace milvus
// 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.
#pragma once
#include "server/web_impl/dto/Dto.h"
namespace milvus {
namespace server {
namespace web {
#include OATPP_CODEGEN_BEGIN(DTO)
class DeviceInfoDto : public OObject {
DTO_INIT(DeviceInfoDto, Object);
DTO_FIELD(Int64, memory);
};
class DevicesDto : public OObject {
DTO_INIT(DevicesDto, Object);
DTO_FIELD(DeviceInfoDto::ObjectWrapper, cpu);
DTO_FIELD(Fields<DeviceInfoDto::ObjectWrapper>::ObjectWrapper, gpus);
};
#include OATPP_CODEGEN_END(DTO)
} // namespace web
} // namespace server
} // namespace milvus
// 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.
#pragma once
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp"
namespace milvus {
namespace server {
namespace web {
using OObject = oatpp::data::mapping::type::Object;
}
} // namespace server
} // namespace milvus
// 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.
#pragma once
#include "server/web_impl/dto/Dto.h"
#include "server/web_impl/dto/StatusDto.hpp"
#include "server/web_impl/Constants.h"
namespace milvus {
namespace server {
namespace web {
#include OATPP_CODEGEN_BEGIN(DTO)
class IndexRequestDto : public oatpp::data::mapping::type::Object {
DTO_INIT(IndexRequestDto, Object)
DTO_FIELD(String, index_type) = VALUE_INDEX_INDEX_TYPE_DEFAULT;
DTO_FIELD(Int64, nlist) = VALUE_INDEX_NLIST_DEFAULT;
};
using IndexDto = IndexRequestDto;
#include OATPP_CODEGEN_END(DTO)
} // namespace web
} // namespace server
} // namespace milvus
// 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.
#pragma once
#include "server/web_impl/dto/Dto.h"
#include "server/web_impl/dto/StatusDto.hpp"
namespace milvus {
namespace server {
namespace web {
#include OATPP_CODEGEN_BEGIN(DTO)
class PartitionRequestDto : public oatpp::data::mapping::type::Object {
DTO_INIT(PartitionRequestDto, Object)
DTO_FIELD(String, partition_name);
DTO_FIELD(String, partition_tag);
};
using PartitionFieldsDto = PartitionRequestDto;
class PartitionListDto : public oatpp::data::mapping::type::Object {
DTO_INIT(PartitionListDto, Object)
DTO_FIELD(List<PartitionFieldsDto::ObjectWrapper>::ObjectWrapper, partitions);
};
#include OATPP_CODEGEN_END(DTO)
} // namespace web
} // namespace server
} // namespace milvus
// 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.
#pragma once
#include "server/web_impl/dto/Dto.h"
namespace milvus {
namespace server {
namespace web {
#include OATPP_CODEGEN_BEGIN(DTO)
class StatusDto: public oatpp::data::mapping::type::Object {
DTO_INIT(StatusDto, Object)
DTO_FIELD(String, message) = "Success";
DTO_FIELD(Int64, code) = 0;
};
#include OATPP_CODEGEN_END(DTO)
} // namespace web
} // namespace server
} // namespace milvus
// 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.
#pragma once
#include "server/web_impl/dto/Dto.h"
#include "server/web_impl/dto/StatusDto.hpp"
#include "server/web_impl/Constants.h"
namespace milvus {
namespace server {
namespace web {
#include OATPP_CODEGEN_BEGIN(DTO)
class TableRequestDto : public oatpp::data::mapping::type::Object {
DTO_INIT(TableRequestDto, Object)
DTO_FIELD(String, table_name, "table_name");
DTO_FIELD(Int64, dimension, "dimension");
DTO_FIELD(Int64, index_file_size, "index_file_size") = VALUE_TABLE_INDEX_FILE_SIZE_DEFAULT;
DTO_FIELD(String, metric_type, "metric_type") = VALUE_TABLE_METRIC_TYPE_DEFAULT;
};
class TableFieldsDto : public oatpp::data::mapping::type::Object {
DTO_INIT(TableFieldsDto, Object)
DTO_FIELD(String, table_name);
DTO_FIELD(Int64, dimension);
DTO_FIELD(Int64, index_file_size);
DTO_FIELD(String, metric_type);
DTO_FIELD(Int64, count);
DTO_FIELD(String, index);
DTO_FIELD(Int64, nlist);
};
class TableListDto : public OObject {
DTO_INIT(TableListDto, Object)
DTO_FIELD(List<String>::ObjectWrapper, table_names);
};
class TableListFieldsDto : public OObject {
DTO_INIT(TableListFieldsDto, Object)
DTO_FIELD(List<TableFieldsDto::ObjectWrapper>::ObjectWrapper, tables);
DTO_FIELD(Int64, count);
};
class TablesResponseDto : public OObject {
DTO_INIT(TablesResponseDto, Object)
DTO_FIELD(TableListFieldsDto::ObjectWrapper, tables_fields);
DTO_FIELD(Int64, page_num);
};
#include OATPP_CODEGEN_END(DTO)
} // namespace web
} // namespace server
} // namespace milvus
\ No newline at end of file
// 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.
#pragma once
#include "server/web_impl/dto/Dto.h"
#include "server/web_impl/Constants.h"
namespace milvus {
namespace server {
namespace web {
#include OATPP_CODEGEN_BEGIN(DTO)
class RowRecordDto : public oatpp::data::mapping::type::Object {
DTO_INIT(RowRecordDto, Object)
DTO_FIELD(List<Float32>::ObjectWrapper, record);
};
class RecordsDto : public oatpp::data::mapping::type::Object {
DTO_INIT(RecordsDto, Object)
DTO_FIELD(List<RowRecordDto::ObjectWrapper>::ObjectWrapper, records);
};
class SearchRequestDto : public OObject {
DTO_INIT(SearchRequestDto, Object)
DTO_FIELD(Int64, topk);
DTO_FIELD(Int64, nprobe);
DTO_FIELD(List<String>::ObjectWrapper, tags);
DTO_FIELD(List<String>::ObjectWrapper, file_ids);
DTO_FIELD(List<List<Float32>::ObjectWrapper>::ObjectWrapper, records);
};
class InsertRequestDto : public oatpp::data::mapping::type::Object {
DTO_INIT(InsertRequestDto, Object)
DTO_FIELD(String, tag) = VALUE_PARTITION_TAG_DEFAULT;
DTO_FIELD(List<List<Float32>::ObjectWrapper>::ObjectWrapper, records);
DTO_FIELD(List<Int64>::ObjectWrapper, ids);
};
class VectorIdsDto : public oatpp::data::mapping::type::Object {
DTO_INIT(VectorIdsDto, Object)
DTO_FIELD(List<String>::ObjectWrapper, ids);
};
class ResultDto : public oatpp::data::mapping::type::Object {
DTO_INIT(ResultDto, Object)
// DTO_FIELD(Int64, num);
DTO_FIELD(String, id);
DTO_FIELD(String, dit, "distance");
};
class RowResultsDto : public OObject {
DTO_INIT(RowResultsDto, Object)
// DTO_FIELD(List<ResultDto::ObjectWrapper>::ObjectWrapper, );
};
class TopkResultsDto : public OObject {
DTO_INIT(TopkResultsDto, Object);
DTO_FIELD(Int64, num);
DTO_FIELD(List<List<ResultDto::ObjectWrapper>::ObjectWrapper>::ObjectWrapper, results);
};
#include OATPP_CODEGEN_END(DTO)
} // namespace web
} // namespace server
} // namespace milvus
此差异已折叠。
// 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.
#pragma once
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <opentracing/mocktracer/tracer.h>
#include <oatpp/web/server/api/ApiController.hpp>
#include <oatpp/core/data/mapping/type/Object.hpp>
#include <oatpp/core/macro/codegen.hpp>
#include "server/web_impl/Types.h"
#include "server/web_impl/dto/CmdDto.hpp"
#include "server/web_impl/dto/ConfigDto.hpp"
#include "server/web_impl/dto/DevicesDto.hpp"
#include "server/web_impl/dto/IndexDto.hpp"
#include "server/web_impl/dto/PartitionDto.hpp"
#include "server/web_impl/dto/TableDto.hpp"
#include "server/web_impl/dto/VectorDto.hpp"
#include "server/context/Context.h"
#include "server/delivery/RequestHandler.h"
#include "utils/Status.h"
namespace milvus {
namespace server {
namespace web {
#define RETURN_STATUS_DTO(STATUS_CODE, MESSAGE) \
do { \
auto status_dto = StatusDto::createShared(); \
status_dto->code = (STATUS_CODE); \
status_dto->message = (MESSAGE); \
return status_dto; \
} while (false);
#define ASSIGN_RETURN_STATUS_DTO(STATUS) \
do { \
int code; \
if (0 != (STATUS).code()) { \
code = WebErrorMap((STATUS).code()); \
} else { \
code = 0; \
} \
RETURN_STATUS_DTO(code, (STATUS).message().c_str()) \
} while (false);
StatusCode
WebErrorMap(ErrorCode code);
class WebRequestHandler {
private:
std::shared_ptr<Context>
GenContextPtr(const std::string& context_str) {
auto context_ptr = std::make_shared<Context>("dummy_request_id");
opentracing::mocktracer::MockTracerOptions tracer_options;
auto mock_tracer =
std::shared_ptr<opentracing::Tracer>{new opentracing::mocktracer::MockTracer{std::move(tracer_options)}};
auto mock_span = mock_tracer->StartSpan("mock_span");
auto trace_context = std::make_shared<milvus::tracing::TraceContext>(mock_span);
context_ptr->SetTraceContext(trace_context);
return context_ptr;
}
public:
WebRequestHandler() {
context_ptr_ = GenContextPtr("Web Handler");
}
Status
GetTaleInfo(const std::shared_ptr<Context>& context, const std::string& table_name,
std::map<std::string, std::string>& table_info);
StatusDto::ObjectWrapper
GetDevices(DevicesDto::ObjectWrapper& devices);
StatusDto::ObjectWrapper
GetAdvancedConfig(AdvancedConfigDto::ObjectWrapper& config);
StatusDto::ObjectWrapper
SetAdvancedConfig(const AdvancedConfigDto::ObjectWrapper& config);
#ifdef MILVUS_GPU_VERSION
StatusDto::ObjectWrapper
GetGpuConfig(GPUConfigDto::ObjectWrapper& gpu_config_dto);
StatusDto::ObjectWrapper
SetGpuConfig(const GPUConfigDto::ObjectWrapper& gpu_config_dto);
#endif
StatusDto::ObjectWrapper
CreateTable(const TableRequestDto::ObjectWrapper& table_schema);
StatusDto::ObjectWrapper
GetTable(const OString& table_name, const OQueryParams& query_params, TableFieldsDto::ObjectWrapper& schema_dto);
StatusDto::ObjectWrapper
ShowTables(const OInt64& offset, const OInt64& page_size, TableListFieldsDto::ObjectWrapper& table_list_dto);
StatusDto::ObjectWrapper
DropTable(const OString& table_name);
StatusDto::ObjectWrapper
CreateIndex(const OString& table_name, const IndexRequestDto::ObjectWrapper& index_param);
StatusDto::ObjectWrapper
GetIndex(const OString& table_name, IndexDto::ObjectWrapper& index_dto);
StatusDto::ObjectWrapper
DropIndex(const OString& table_name);
StatusDto::ObjectWrapper
CreatePartition(const OString& table_name, const PartitionRequestDto::ObjectWrapper& param);
StatusDto::ObjectWrapper
ShowPartitions(const OInt64& offset, const OInt64& page_size, const OString& table_name,
PartitionListDto::ObjectWrapper& partition_list_dto);
StatusDto::ObjectWrapper
DropPartition(const OString& table_name, const OString& tag);
StatusDto::ObjectWrapper
Insert(const OString& table_name, const InsertRequestDto::ObjectWrapper& param,
VectorIdsDto::ObjectWrapper& ids_dto);
StatusDto::ObjectWrapper
Search(const OString& table_name, const SearchRequestDto::ObjectWrapper& search_request,
TopkResultsDto::ObjectWrapper& results_dto);
StatusDto::ObjectWrapper
Cmd(const OString& cmd, CommandDto::ObjectWrapper& cmd_dto);
WebRequestHandler&
RegisterRequestHandler(const RequestHandler& handler) {
request_handler_ = handler;
}
private:
std::shared_ptr<Context> context_ptr_;
RequestHandler request_handler_;
};
} // namespace web
} // namespace server
} // namespace milvus
......@@ -11,6 +11,7 @@ GRPC_VERSION=master
ZLIB_VERSION=v1.2.11
OPENTRACING_VERSION=v1.5.1
FIU_VERSION=1.00
OATPP_VERSION=0.19.11
AWS_VERSION=1.7.250
# vim: set filetype=sh:
......@@ -74,6 +74,19 @@ set(grpc_server_files
${grpc_interceptor_files}
)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/web_impl/handler web_handler_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/web_impl/component web_conponent_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/web_impl/controller web_controller_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/web_impl/dto web_dto_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/web_impl web_impl_files)
set(web_server_files
${web_handler_files}
${web_conponent_files}
${web_controller_files}
${web_dto_files}
${web_impl_files}
)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/delivery server_delivery_impl_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/server/delivery/request server_delivery_request_files)
set(server_delivery_files
......
......@@ -21,6 +21,7 @@ set(test_files
${CMAKE_CURRENT_SOURCE_DIR}/test_cache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_config.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_rpc.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_web.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_util.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp)
......@@ -48,6 +49,7 @@ set(server_test_files
${grpc_server_files}
${grpc_service_files}
${server_delivery_files}
${web_server_files}
${util_files}
${entry_file}
${test_files}
......@@ -60,13 +62,15 @@ set(grpc_lib
grpc++
grpc
grpc_protobuf
grpc_protoc)
grpc_protoc
)
target_link_libraries(test_server
knowhere
stdc++
${grpc_lib}
${unittest_libs}
oatpp
)
install(TARGETS test_server DESTINATION unittest)
......@@ -135,6 +135,11 @@ TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) {
ASSERT_TRUE(config.GetServerConfigPort(str_val).ok());
ASSERT_TRUE(str_val == server_port);
std::string web_port = "19999";
ASSERT_TRUE(config.SetServerConfigWebPort(web_port).ok());
ASSERT_TRUE(config.GetServerConfigWebPort(str_val).ok());
ASSERT_TRUE(str_val == web_port);
std::string server_mode = "cluster_readonly";
ASSERT_TRUE(config.SetServerConfigDeployMode(server_mode).ok());
ASSERT_TRUE(config.GetServerConfigDeployMode(str_val).ok());
......@@ -479,6 +484,10 @@ TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) {
ASSERT_FALSE(config.SetServerConfigPort("a").ok());
ASSERT_FALSE(config.SetServerConfigPort("99999").ok());
ASSERT_FALSE(config.SetServerConfigWebPort("a").ok());
ASSERT_FALSE(config.SetServerConfigWebPort("99999").ok());
ASSERT_FALSE(config.SetServerConfigWebPort("-1").ok());
ASSERT_FALSE(config.SetServerConfigDeployMode("cluster").ok());
ASSERT_FALSE(config.SetServerConfigTimeZone("GM").ok());
......
......@@ -231,7 +231,7 @@ TEST_F(RpcHandlerTest, INSERT_TEST) {
ASSERT_EQ(vector_ids.vector_id_array_size(), VECTOR_COUNT);
// insert vectors with wrong dim
std::vector<float > record_wrong_dim(TABLE_DIM - 1, 0.5f);
std::vector<float> record_wrong_dim(TABLE_DIM - 1, 0.5f);
::milvus::grpc::RowRecord* grpc_record = request.add_row_record_array();
CopyRowRecord(grpc_record, record_wrong_dim);
handler->Insert(&context, &request, &vector_ids);
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册