feat: Adaptervertrag mit Dienststeuerung und Version (Studio, Ollama, llama.cpp, Attrappe; #1198)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -24,6 +24,10 @@ pub struct MockConfig {
|
||||
pub vram_mb: u64,
|
||||
pub ram_mb: u64,
|
||||
pub artifacts: Vec<DiscoveredArtifact>,
|
||||
/// Wenn gesetzt, meldet die Attrappe einen steuerbaren Dienst mit dieser Einheit (→ #1198).
|
||||
pub dienst_einheit: Option<String>,
|
||||
/// Version, die die Attrappe meldet.
|
||||
pub version: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for MockConfig {
|
||||
@ -34,6 +38,8 @@ impl Default for MockConfig {
|
||||
vram_mb: 1024,
|
||||
ram_mb: 512,
|
||||
artifacts: Vec::new(),
|
||||
dienst_einheit: None,
|
||||
version: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,6 +49,8 @@ pub struct MockEngine {
|
||||
next_id: AtomicU64,
|
||||
starts: AtomicUsize,
|
||||
alive: Mutex<HashMap<u64, bool>>,
|
||||
/// Aufrufe der Dienststeuerung in der Reihenfolge („stop“, „restart“).
|
||||
dienst_aufrufe: Mutex<Vec<&'static str>>,
|
||||
}
|
||||
|
||||
impl MockEngine {
|
||||
@ -52,9 +60,15 @@ impl MockEngine {
|
||||
next_id: AtomicU64::new(1),
|
||||
starts: AtomicUsize::new(0),
|
||||
alive: Mutex::new(HashMap::new()),
|
||||
dienst_aufrufe: Mutex::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Aufrufe der Dienststeuerung, für Tests.
|
||||
pub fn dienst_aufrufe(&self) -> Vec<&'static str> {
|
||||
self.dienst_aufrufe.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
/// Wie oft `start` aufgerufen wurde (auch gescheiterte Starts).
|
||||
pub fn start_count(&self) -> usize {
|
||||
self.starts.load(Ordering::SeqCst)
|
||||
@ -75,6 +89,35 @@ impl MockEngine {
|
||||
|
||||
#[async_trait]
|
||||
impl Engine for MockEngine {
|
||||
fn dienst(&self) -> crate::types::Dienst {
|
||||
match &self.config.dienst_einheit {
|
||||
Some(einheit) => crate::types::Dienst::Systemd {
|
||||
einheit: einheit.clone(),
|
||||
},
|
||||
None => crate::types::Dienst::Keiner,
|
||||
}
|
||||
}
|
||||
|
||||
async fn dienst_stoppen(&self) -> Result<()> {
|
||||
if self.config.dienst_einheit.is_none() {
|
||||
return Err(AdapterError::Stop("kein Dienst".to_string()));
|
||||
}
|
||||
self.dienst_aufrufe.lock().unwrap().push("stop");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn dienst_neustarten(&self) -> Result<()> {
|
||||
if self.config.dienst_einheit.is_none() {
|
||||
return Err(AdapterError::Stop("kein Dienst".to_string()));
|
||||
}
|
||||
self.dienst_aufrufe.lock().unwrap().push("restart");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn version(&self) -> Option<String> {
|
||||
self.config.version.clone()
|
||||
}
|
||||
|
||||
fn describe(&self) -> EngineInfo {
|
||||
EngineInfo {
|
||||
name: "mock".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user