1 | /** |
2 | * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | |
16 | * \author Haichao.chc |
17 | * \date Oct 2020 |
18 | * \brief Implementation of pb service interface, it will be registered |
19 | * to http/grpc server for rpc service |
20 | */ |
21 | |
22 | #pragma once |
23 | |
24 | #include <brpc/server.h> |
25 | #include "admin/admin_agent.h" |
26 | #include "agent/index_agent.h" |
27 | #include "proto/proxima_be.pb.h" |
28 | #include "query/query_agent.h" |
29 | |
30 | namespace proxima { |
31 | namespace be { |
32 | namespace server { |
33 | |
34 | class ProximaRequestHandler : public proto::ProximaService, |
35 | public proto::HttpProximaService { |
36 | public: |
37 | ProximaRequestHandler(const agent::IndexAgentPtr &index_agent, |
38 | const query::QueryAgentPtr &query_agent, |
39 | const admin::AdminAgentPtr &admin_agent); |
40 | |
41 | ~ProximaRequestHandler() = default; |
42 | |
43 | public: |
44 | void create_collection(::google::protobuf::RpcController *controller, |
45 | const proto::CollectionConfig *request, |
46 | proto::Status *response, |
47 | ::google::protobuf::Closure *done) override; |
48 | |
49 | |
50 | void drop_collection(::google::protobuf::RpcController *controller, |
51 | const proto::CollectionName *request, |
52 | proto::Status *response, |
53 | ::google::protobuf::Closure *done) override; |
54 | |
55 | void describe_collection(::google::protobuf::RpcController *controller, |
56 | const proto::CollectionName *request, |
57 | proto::DescribeCollectionResponse *response, |
58 | ::google::protobuf::Closure *done) override; |
59 | |
60 | void list_collections(::google::protobuf::RpcController *controller, |
61 | const proto::ListCondition *request, |
62 | proto::ListCollectionsResponse *response, |
63 | ::google::protobuf::Closure *done) override; |
64 | |
65 | void stats_collection(::google::protobuf::RpcController *controller, |
66 | const proto::CollectionName *request, |
67 | proto::StatsCollectionResponse *response, |
68 | ::google::protobuf::Closure *done) override; |
69 | |
70 | void write(::google::protobuf::RpcController *controller, |
71 | const proto::WriteRequest *request, proto::Status *response, |
72 | ::google::protobuf::Closure *done) override; |
73 | |
74 | void query(::google::protobuf::RpcController *controller, |
75 | const proto::QueryRequest *request, proto::QueryResponse *response, |
76 | ::google::protobuf::Closure *done) override; |
77 | |
78 | void get_document_by_key(::google::protobuf::RpcController *controller, |
79 | const proto::GetDocumentRequest *request, |
80 | proto::GetDocumentResponse *response, |
81 | ::google::protobuf::Closure *done) override; |
82 | |
83 | void get_version(::google::protobuf::RpcController *controller, |
84 | const proto::GetVersionRequest *request, |
85 | proto::GetVersionResponse *response, |
86 | ::google::protobuf::Closure *done) override; |
87 | |
88 | |
89 | public: |
90 | // Restful apis from HttpProximaService |
91 | void collection(::google::protobuf::RpcController *controller, |
92 | const proto::HttpRequest *request, |
93 | proto::HttpResponse *response, |
94 | ::google::protobuf::Closure *done) override; |
95 | |
96 | void stats_collection(::google::protobuf::RpcController *controller, |
97 | const proto::HttpRequest *request, |
98 | proto::HttpResponse *response, |
99 | ::google::protobuf::Closure *done) override; |
100 | |
101 | void write(::google::protobuf::RpcController *controller, |
102 | const proto::HttpRequest *request, proto::HttpResponse *response, |
103 | ::google::protobuf::Closure *done) override; |
104 | |
105 | void query(::google::protobuf::RpcController *controller, |
106 | const proto::HttpRequest *request, proto::HttpResponse *response, |
107 | ::google::protobuf::Closure *done) override; |
108 | |
109 | void get_document_by_key(::google::protobuf::RpcController *controller, |
110 | const proto::HttpRequest *request, |
111 | proto::HttpResponse *response, |
112 | ::google::protobuf::Closure *done) override; |
113 | |
114 | void list_collections(::google::protobuf::RpcController *controller, |
115 | const proto::HttpRequest *request, |
116 | proto::HttpResponse *response, |
117 | ::google::protobuf::Closure *done) override; |
118 | |
119 | void get_version(::google::protobuf::RpcController *controller, |
120 | const proto::HttpRequest *request, |
121 | proto::HttpResponse *response, |
122 | ::google::protobuf::Closure *done) override; |
123 | |
124 | public: |
125 | void set_version(const std::string &val) { |
126 | version_ = val; |
127 | } |
128 | |
129 | private: |
130 | int write_impl(const proto::WriteRequest &request, proto::Status *response); |
131 | |
132 | void create_collection(brpc::Controller *controller); |
133 | |
134 | void drop_collection(brpc::Controller *controller); |
135 | |
136 | void describe_collection(brpc::Controller *controller); |
137 | |
138 | int parse_collection(brpc::Controller *controller, std::string *collection); |
139 | |
140 | private: |
141 | std::string version_{}; |
142 | agent::IndexAgentPtr index_agent_{}; |
143 | query::QueryAgentPtr query_agent_{}; |
144 | admin::AdminAgentPtr admin_agent_{}; |
145 | }; |
146 | |
147 | } // end namespace server |
148 | } // namespace be |
149 | } // end namespace proxima |
150 | |