mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-12 04:09:48 +08:00
feat: unify provider scheduling workspace
This commit is contained in:
@@ -62,6 +62,16 @@ pub(crate) async fn maybe_build_local_admin_provider_writes_response(
|
||||
)));
|
||||
}
|
||||
};
|
||||
let routing_group_id = payload
|
||||
.routing_group_id
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.map(str::to_string);
|
||||
if routing_group_id.as_deref() == Some("") {
|
||||
return Ok(Some(build_admin_provider_bad_request_response(
|
||||
"routing_group_id 不能为空",
|
||||
)));
|
||||
}
|
||||
let (record, shift_existing_priorities_from) =
|
||||
match state.build_admin_create_provider_record(payload).await {
|
||||
Ok(record) => record,
|
||||
@@ -69,10 +79,23 @@ pub(crate) async fn maybe_build_local_admin_provider_writes_response(
|
||||
return Ok(Some(build_admin_provider_bad_request_response(message)));
|
||||
}
|
||||
};
|
||||
let Some(created_provider) = state
|
||||
.create_provider_catalog_provider(&record, shift_existing_priorities_from)
|
||||
.await?
|
||||
else {
|
||||
let created = match routing_group_id.as_deref() {
|
||||
Some(group_id) => {
|
||||
state
|
||||
.create_provider_catalog_provider_in_routing_group(
|
||||
&record,
|
||||
shift_existing_priorities_from,
|
||||
group_id,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
None => {
|
||||
state
|
||||
.create_provider_catalog_provider(&record, shift_existing_priorities_from)
|
||||
.await?
|
||||
}
|
||||
};
|
||||
let Some(created_provider) = created else {
|
||||
return Ok(Some(build_admin_providers_data_unavailable_response()));
|
||||
};
|
||||
|
||||
|
||||
@@ -179,6 +179,8 @@ pub(crate) struct AdminCodexResetCreditConsumeRequest {
|
||||
pub(crate) struct AdminProviderCreateRequest {
|
||||
pub(crate) name: String,
|
||||
#[serde(default)]
|
||||
pub(crate) routing_group_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub(crate) provider_type: Option<String>,
|
||||
#[serde(default)]
|
||||
pub(crate) description: Option<String>,
|
||||
|
||||
@@ -420,6 +420,24 @@ impl<'a> AdminAppState<'a> {
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn create_provider_catalog_provider_in_routing_group(
|
||||
&self,
|
||||
provider: &aether_data_contracts::repository::provider_catalog::StoredProviderCatalogProvider,
|
||||
shift_existing_priorities_from: Option<i32>,
|
||||
routing_group_id: &str,
|
||||
) -> Result<
|
||||
Option<aether_data_contracts::repository::provider_catalog::StoredProviderCatalogProvider>,
|
||||
GatewayError,
|
||||
> {
|
||||
self.app
|
||||
.create_provider_catalog_provider_in_routing_group(
|
||||
provider,
|
||||
shift_existing_priorities_from,
|
||||
routing_group_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn update_provider_catalog_provider(
|
||||
&self,
|
||||
provider: &aether_data_contracts::repository::provider_catalog::StoredProviderCatalogProvider,
|
||||
|
||||
@@ -350,6 +350,7 @@ async fn publish_routing_group(
|
||||
.update_routing_group(
|
||||
group_id,
|
||||
UpdateRoutingGroupRecord {
|
||||
expected_version: Some(group.version),
|
||||
version: Some(next_version),
|
||||
updated_at: now,
|
||||
published_at: Some(Some(now)),
|
||||
@@ -455,6 +456,9 @@ fn build_routing_group_update_patch(
|
||||
updated_at: current_unix_secs() as i64,
|
||||
..UpdateRoutingGroupRecord::default()
|
||||
};
|
||||
if let Some(value) = object.get("expected_version") {
|
||||
patch.expected_version = Some(required_i64(value, "expected_version")?);
|
||||
}
|
||||
if let Some(value) = object.get("name") {
|
||||
patch.name = Some(required_string(value, "name")?);
|
||||
}
|
||||
|
||||
@@ -2909,6 +2909,10 @@ mod tests {
|
||||
allowed_keys: vec!["key-other".to_string()],
|
||||
..matching.clone()
|
||||
};
|
||||
let disabled_provider = aether_routing_core::RankingOverlay {
|
||||
disabled_providers: vec!["provider-allowed".to_string()],
|
||||
..matching.clone()
|
||||
};
|
||||
|
||||
assert!(routing_overlay_allows_affinity_target(None, &target));
|
||||
assert!(routing_overlay_allows_affinity_target(
|
||||
@@ -2923,6 +2927,10 @@ mod tests {
|
||||
Some(&wrong_key),
|
||||
&target
|
||||
));
|
||||
assert!(!routing_overlay_allows_affinity_target(
|
||||
Some(&disabled_provider),
|
||||
&target
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user