bios_basic/spi.rs
1//! SPI (Service Provider Interface) module
2//!
3//! SPI (服务提供接口) 模块
4//!
5//! The SPI in BIOS is used to provide different scenario-oriented capabilities.
6//! These capabilities are abstracted into standardized service interfaces for other modules to call.
7//! Based on these standardized service interfaces, different backend implementations can be extended and interfaced.
8//!
9//! BIOS中的SPI用于提供面向不同场景的能力。这些能力抽象成标准化的服务接口,供其他模块调用。基于这些标准化的服务接口,可扩展对接不同的后端实现。
10//!
11//! # Example of invoke flow: full-text search service / 调用流程举例:全文搜索服务:
12//!
13//! ```text
14//! +------------------+
15//! +-----------+ +----------+ +-+backend-postgresql|
16//! | spi-basic | |spi-search+----+ +------------------+--+
17//! +-----+-----+ +----+-----+ +-+backend-elasticsearch|
18//! 1. Init domain | | +---------------------+
19//! | | 2. Init special entity
20//! | |
21//! | | 3. Init special API
22//! 4. Init common API | |
23//! | |
24//! +----------+ | |
25//! ---->|Common API+---> | |
26//! +----------+ | |
27//! 5. Add backend service | |
28//! (POST /ci/manage/bs) | |
29//! | | +-----------+
30//! 6. Add cert to tenant/app | | <---+Special API|<----
31//! (PUT /:id/rel/:app_tenant_id) | | +-----------+
32//! | | 7. Request some apis
33//! | |
34//! 8. Init and return backend client | |
35//! (spi_funs) | |
36//! | | 9. Call client to execute request
37//! | |
38//! | | 10. Response data
39//! | |
40//! ```
41//!
42//! # Key design:
43//! 1. Reuse RBUM's ability
44//! 1. Each SPI service has a ``rbum_domain`` for initializing domain objects.
45//! For example, the ``rbum_domain=spi-search`` of spi-search
46//! 1. Each SPI service has one or more backend implementations,
47//! each corresponding to a ``rbum_kind``. Different SPI services can share the same ``rbum_kind``.
48//! For example, the ``rbum_kind=spi-bs-pg`` and ``rbum_kind=spi-bs-es`` of spi-search
49//! 1. Each SPI backend implementation can have multiple connections, corresponding to ``rbum_item and extended spi_bs``.
50//! For example, multiple connections can be specified for ``spi-bs-pg`` of spi-search
51//! 1. The connection information of each SPI backend implementation is stored in ``rbum_cert``
52//! 1. The binding relationship between each SPI backend implementation and the corresponding tenant or application must be bound before use,
53//! and the binding relationship is stored in ``rbum_rel``, with the tag as ``spi_ident``
54//! 1. No request authentication is done.
55//! The SPI service trusts the authentication information carried by the request (``ak`` in ``TardisContext``, corresponding to the Id of the tenant or application).
56//! The authentication logic will be implemented uniformly by the gateway
57//! 1. Delayed initialization.
58//! The backend implementation of each SPI service is initialized (client generated) only when called for the first time to reduce resource consumption at startup.
59//! See [`crate::spi::spi_funs::SpiBsInst`] for details
60//!
61//! # 关键设计:
62//! 1. 复用RBUM的能力
63//! 1. 每个SPI服务都有一个``rbum_domain``,用于初始化领域对象。 如:spi-search的 ``rbum_domain=spi-search``
64//! 1. 每个SPI服务有一个或多个后端实现,每个后端实现对应一个``rbum_kind``。不同的SPI服务可以共用相同的``rbum_kind``。如:spi-search的 ``rbum_kind=spi-bs-pg`` 和 ``rbum_kind=spi-bs-es``
65//! 1. 每个SPI的后端实现可以有多个,对应于``rbum_item及扩展的spi_bs``。如可以为spi-search的``spi-bs-pg``指定多个连接
66//! 1. 每个SPI后端实现的连接信息存储于``rbum_cert``
67//! 1. 每个SPI后端实现的要绑定给对应的租户或应用后才能使用,绑定关系存储于``rbum_rel``,tag为``spi_ident``
68//! 1. 不做请求认证。SPI服务信任请求带来的认证信息(``TardisContext``中的``ak``,对应于租户或应用的Id)。认证的逻辑将由网关统一实现
69//! 1. 延时初始化。SPI服务的每个后端实现只有在第一次调用时才会初始化(生成client),以减少启动时的资源消耗。详见 [`crate::spi::spi_funs::SpiBsInst`]
70
71pub mod api;
72
73mod domain;
74pub mod dto;
75pub mod macros;
76
77pub mod serv;
78pub mod spi_constants;
79pub mod spi_funs;
80pub mod spi_initializer;