feat(agent): add compatible driver handshake
This commit is contained in:
1 parent
9cbca5fc3a
commit
5df7fbf062
5 files changed
+133
-8
No files matched your search
@@ -104,6 +104,14 @@ mod tests {
|
||||
assert!(err.contains("Custom Java runtime does not exist"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stores_configured_app_version_for_agent_handshake() {
|
||||
let dir = std::env::temp_dir().join(format!("dbx-agent-manager-version-{}", uuid::Uuid::new_v4()));
|
||||
let manager = AgentManager::new_with_base_dir_and_app_version(dir, "0.5.13");
|
||||
|
||||
assert_eq!(manager.agent_app_version(), "0.5.13");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolves_system_java_runtime_from_path() {
|
||||
let manager = test_manager("system");
|
||||
@@ -190,6 +198,7 @@ pub struct AgentDriverInfo {
|
||||
|
||||
pub struct AgentManager {
|
||||
base_dir: PathBuf,
|
||||
app_version: String,
|
||||
daemons: Mutex<std::collections::HashMap<String, AgentDriverClient>>,
|
||||
}
|
||||
|
||||
@@ -201,7 +210,12 @@ impl AgentManager {
|
||||
}
|
||||
|
||||
pub fn new_with_base_dir(base_dir: PathBuf) -> Self {
|
||||
let mgr = Self { base_dir, daemons: Mutex::new(std::collections::HashMap::new()) };
|
||||
Self::new_with_base_dir_and_app_version(base_dir, env!("CARGO_PKG_VERSION"))
|
||||
}
|
||||
|
||||
pub fn new_with_base_dir_and_app_version(base_dir: PathBuf, app_version: impl Into<String>) -> Self {
|
||||
let mgr =
|
||||
Self { base_dir, app_version: app_version.into(), daemons: Mutex::new(std::collections::HashMap::new()) };
|
||||
mgr.migrate_legacy_jre();
|
||||
mgr
|
||||
}
|
||||
@@ -218,6 +232,10 @@ impl AgentManager {
|
||||
&self.base_dir
|
||||
}
|
||||
|
||||
pub fn agent_app_version(&self) -> &str {
|
||||
&self.app_version
|
||||
}
|
||||
|
||||
pub fn jre_dir(&self, jre_key: &str) -> PathBuf {
|
||||
self.base_dir.join(format!("jre-{jre_key}"))
|
||||
}
|
||||
@@ -320,7 +338,9 @@ impl AgentManager {
|
||||
|
||||
let java = self.resolve_java_runtime(&state, jre_key)?.to_string_lossy().to_string();
|
||||
let jar = self.driver_jar_path(key).to_string_lossy().to_string();
|
||||
AgentDriverClient::spawn(&java, &jar).await
|
||||
let mut client = AgentDriverClient::spawn(&java, &jar).await?;
|
||||
client.try_optional_handshake(self.agent_app_version()).await;
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
pub async fn call_daemon<T: serde::de::DeserializeOwned + Send + 'static>(
|
||||
@@ -345,7 +365,8 @@ impl AgentManager {
|
||||
}
|
||||
let java = self.resolve_java_runtime(&state, jre_key)?.to_string_lossy().to_string();
|
||||
let jar = self.driver_jar_path(&key).to_string_lossy().to_string();
|
||||
let client = AgentDriverClient::spawn(&java, &jar).await?;
|
||||
let mut client = AgentDriverClient::spawn(&java, &jar).await?;
|
||||
client.try_optional_handshake(self.agent_app_version()).await;
|
||||
daemons.insert(key.clone(), client);
|
||||
}
|
||||
|
||||
@@ -360,6 +381,7 @@ impl AgentManager {
|
||||
let java = self.resolve_java_runtime(&state, jre_key)?.to_string_lossy().to_string();
|
||||
let jar = self.driver_jar_path(&key).to_string_lossy().to_string();
|
||||
let mut new_client = AgentDriverClient::spawn(&java, &jar).await?;
|
||||
new_client.try_optional_handshake(self.agent_app_version()).await;
|
||||
let result = new_client.call::<T>(method, params).await?;
|
||||
daemons.insert(key, new_client);
|
||||
Ok(result)
|
||||
|
||||
Reference in new issue
Block a user