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 guonix |
17 | * \date Dec 2020 |
18 | * \brief |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include "meta_service.h" |
24 | |
25 | namespace proxima { |
26 | namespace be { |
27 | namespace meta { |
28 | |
29 | //! Predefined class |
30 | class MetaAgent; |
31 | //! Alias Pointer for MetaAgent |
32 | using MetaAgentPtr = std::shared_ptr<MetaAgent>; |
33 | |
34 | |
35 | /*! |
36 | * MetaAgent for meta management |
37 | */ |
38 | class MetaAgent { |
39 | public: |
40 | //! Create one MetaAgent instance |
41 | static MetaAgentPtr Create(const std::string &uri); |
42 | |
43 | //! Create MetaAgent from MetaService instance |
44 | static MetaAgentPtr Create(const MetaServicePtr &); |
45 | |
46 | public: |
47 | //! Destructor |
48 | virtual ~MetaAgent() = default; |
49 | |
50 | public: |
51 | //! Get Meta Service Instance |
52 | virtual MetaServicePtr get_service() const = 0; |
53 | |
54 | public: |
55 | //! Init Meta Agent |
56 | virtual int init() = 0; |
57 | |
58 | //! Clean up object |
59 | virtual int cleanup() = 0; |
60 | |
61 | //! Start background service |
62 | virtual int start() = 0; |
63 | |
64 | //! Stop background service |
65 | virtual int stop() = 0; |
66 | |
67 | public: |
68 | //! Reload meta service |
69 | virtual int reload() = 0; |
70 | |
71 | //! Create collection, 0 for success, otherwise failed, write the details |
72 | // of collection to @param meta if meta not nullptr. |
73 | //! @param, input parameter |
74 | //! @meta, output parameter |
75 | virtual int create_collection(const CollectionBase ¶m, |
76 | CollectionMetaPtr *meta) = 0; |
77 | |
78 | //! Update collection, 0 for success, otherwise failed, write the details |
79 | // of collection to @param meta if meta not nullptr. |
80 | //! @param, input parameter |
81 | //! @meta, output parameter |
82 | virtual int update_collection(const CollectionBase ¶m, |
83 | CollectionMetaPtr *meta) = 0; |
84 | |
85 | //! Update the status of current used collection |
86 | virtual int update_status(const std::string &collection_name, |
87 | CollectionStatus status) = 0; |
88 | |
89 | //! Enable collection |
90 | virtual int enable_collection(const std::string &collection, |
91 | uint32_t revision) = 0; |
92 | |
93 | //! Suspend reading requests of collection |
94 | virtual int suspend_collection_read(const std::string &collection_name) = 0; |
95 | |
96 | //! Resume reading requests of collection |
97 | virtual int resume_collection_read(const std::string &collection_name) = 0; |
98 | |
99 | //! Suspend writing requests of collection |
100 | virtual int suspend_collection_write(const std::string &collection_name) = 0; |
101 | |
102 | //! Resume writing requests of collection |
103 | virtual int resume_collection_write(const std::string &collection_name) = 0; |
104 | |
105 | //! Delete collection |
106 | virtual int delete_collection(const std::string &collection) = 0; |
107 | |
108 | //! Retrieve collections |
109 | virtual int list_collections(CollectionMetaPtrList *collections) const = 0; |
110 | |
111 | //! Retrieve collection history by name |
112 | virtual int get_collection_history( |
113 | const std::string &name, CollectionMetaPtrList *collections) const = 0; |
114 | |
115 | //! Retrieve collection by name |
116 | virtual CollectionMetaPtr get_collection(const std::string &name) const = 0; |
117 | |
118 | //! Check collection exists |
119 | virtual bool exist_collection(const std::string &name) const = 0; |
120 | }; |
121 | |
122 | |
123 | } // namespace meta |
124 | } // namespace be |
125 | } // namespace proxima |
126 | |