mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
refactor: 拆分 gateway 单体为独立 crate,新增 systemd 部署方案
将 gateway 内部的 model-fetch、provider-transport、scheduler-core、 usage-runtime、video-tasks-core 模块提取为独立 crate;重构 gateway 内部模块结构(state/router/cache/data/query 等);移除大量遗留模块 文件;新增 systemd 二进制部署骨架及相关文档;更新前端 usage 相关 API 和组件。
This commit is contained in:
19
apps/aether-gateway/src/cache/auth_api_key_last_used.rs
vendored
Normal file
19
apps/aether-gateway/src/cache/auth_api_key_last_used.rs
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use aether_cache::ExpiringMap;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct AuthApiKeyLastUsedCache {
|
||||
entries: ExpiringMap<String, ()>,
|
||||
}
|
||||
|
||||
impl AuthApiKeyLastUsedCache {
|
||||
pub(crate) fn should_touch(&self, api_key_id: &str, ttl: Duration, max_entries: usize) -> bool {
|
||||
let key = api_key_id.to_string();
|
||||
if self.entries.contains_fresh(&key, ttl) {
|
||||
return false;
|
||||
}
|
||||
self.entries.insert(key, (), ttl, max_entries);
|
||||
true
|
||||
}
|
||||
}
|
||||
31
apps/aether-gateway/src/cache/auth_context.rs
vendored
Normal file
31
apps/aether-gateway/src/cache/auth_context.rs
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use aether_cache::ExpiringMap;
|
||||
|
||||
use crate::control::GatewayControlAuthContext;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct AuthContextCache {
|
||||
entries: ExpiringMap<String, GatewayControlAuthContext>,
|
||||
}
|
||||
|
||||
impl AuthContextCache {
|
||||
pub(crate) fn get_fresh(
|
||||
&self,
|
||||
cache_key: &str,
|
||||
ttl: Duration,
|
||||
) -> Option<GatewayControlAuthContext> {
|
||||
self.entries.get_fresh(&cache_key.to_string(), ttl)
|
||||
}
|
||||
|
||||
pub(crate) fn insert(
|
||||
&self,
|
||||
cache_key: String,
|
||||
auth_context: GatewayControlAuthContext,
|
||||
ttl: Duration,
|
||||
max_entries: usize,
|
||||
) {
|
||||
self.entries
|
||||
.insert(cache_key, auth_context, ttl, max_entries);
|
||||
}
|
||||
}
|
||||
18
apps/aether-gateway/src/cache/direct_plan_bypass.rs
vendored
Normal file
18
apps/aether-gateway/src/cache/direct_plan_bypass.rs
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use aether_cache::ExpiringMap;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct DirectPlanBypassCache {
|
||||
entries: ExpiringMap<String, ()>,
|
||||
}
|
||||
|
||||
impl DirectPlanBypassCache {
|
||||
pub(crate) fn should_skip(&self, cache_key: &str, ttl: Duration) -> bool {
|
||||
self.entries.contains_fresh(&cache_key.to_string(), ttl)
|
||||
}
|
||||
|
||||
pub(crate) fn mark(&self, cache_key: String, ttl: Duration, max_entries: usize) {
|
||||
self.entries.insert(cache_key, (), ttl, max_entries);
|
||||
}
|
||||
}
|
||||
9
apps/aether-gateway/src/cache/mod.rs
vendored
Normal file
9
apps/aether-gateway/src/cache/mod.rs
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
mod auth_api_key_last_used;
|
||||
mod auth_context;
|
||||
mod direct_plan_bypass;
|
||||
mod scheduler_affinity;
|
||||
|
||||
pub(crate) use auth_api_key_last_used::AuthApiKeyLastUsedCache;
|
||||
pub(crate) use auth_context::AuthContextCache;
|
||||
pub(crate) use direct_plan_bypass::DirectPlanBypassCache;
|
||||
pub(crate) use scheduler_affinity::{SchedulerAffinityCache, SchedulerAffinityTarget};
|
||||
34
apps/aether-gateway/src/cache/scheduler_affinity.rs
vendored
Normal file
34
apps/aether-gateway/src/cache/scheduler_affinity.rs
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use aether_cache::ExpiringMap;
|
||||
pub(crate) use aether_scheduler_core::SchedulerAffinityTarget;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct SchedulerAffinityCache {
|
||||
entries: ExpiringMap<String, SchedulerAffinityTarget>,
|
||||
}
|
||||
|
||||
impl SchedulerAffinityCache {
|
||||
pub(crate) fn get_fresh(
|
||||
&self,
|
||||
cache_key: &str,
|
||||
ttl: Duration,
|
||||
) -> Option<SchedulerAffinityTarget> {
|
||||
self.entries.get_fresh(&cache_key.to_string(), ttl)
|
||||
}
|
||||
|
||||
#[cfg_attr(not(test), allow(dead_code))]
|
||||
pub(crate) fn insert(
|
||||
&self,
|
||||
cache_key: String,
|
||||
target: SchedulerAffinityTarget,
|
||||
ttl: Duration,
|
||||
max_entries: usize,
|
||||
) {
|
||||
self.entries.insert(cache_key, target, ttl, max_entries);
|
||||
}
|
||||
|
||||
pub(crate) fn remove(&self, cache_key: &str) -> Option<SchedulerAffinityTarget> {
|
||||
self.entries.remove(&cache_key.to_string())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user