feat(agent): unify oracle driver
This commit is contained in:
1 parent
415d53e8dc
commit
edf9dd88e3
11 files changed
+139
-90
No files matched your search
@@ -359,8 +359,6 @@ const driverProfiles: Record<
|
|||||||
},
|
},
|
||||||
sqlserver: { type: "sqlserver", port: 1433, user: "sa", label: "SQL Server", icon: "sqlserver" },
|
sqlserver: { type: "sqlserver", port: 1433, user: "sa", label: "SQL Server", icon: "sqlserver" },
|
||||||
oracle: { type: "oracle", port: 1521, user: "system", label: "Oracle", icon: "oracle" },
|
oracle: { type: "oracle", port: 1521, user: "system", label: "Oracle", icon: "oracle" },
|
||||||
"oracle-legacy": { type: "oracle", port: 1521, user: "system", label: "Oracle Legacy", icon: "oracle" },
|
|
||||||
"oracle-10g": { type: "oracle", port: 1521, user: "system", label: "Oracle 10g", icon: "oracle" },
|
|
||||||
elasticsearch: {
|
elasticsearch: {
|
||||||
type: "elasticsearch",
|
type: "elasticsearch",
|
||||||
port: 9200,
|
port: 9200,
|
||||||
@@ -474,6 +472,7 @@ const driverProfiles: Record<
|
|||||||
};
|
};
|
||||||
|
|
||||||
function profileForConfig(config: ConnectionConfig) {
|
function profileForConfig(config: ConnectionConfig) {
|
||||||
|
if (config.db_type === "oracle") return "oracle";
|
||||||
if (config.driver_profile && driverProfiles[config.driver_profile]) {
|
if (config.driver_profile && driverProfiles[config.driver_profile]) {
|
||||||
if (config.driver_profile === "oceanbase-oracle") return "oceanbase";
|
if (config.driver_profile === "oceanbase-oracle") return "oceanbase";
|
||||||
return config.driver_profile;
|
return config.driver_profile;
|
||||||
@@ -707,8 +706,6 @@ const iconTypeMap: Record<string, string> = {
|
|||||||
clickhouse: "clickhouse",
|
clickhouse: "clickhouse",
|
||||||
sqlserver: "sqlserver",
|
sqlserver: "sqlserver",
|
||||||
oracle: "oracle",
|
oracle: "oracle",
|
||||||
"oracle-legacy": "oracle",
|
|
||||||
"oracle-10g": "oracle",
|
|
||||||
elasticsearch: "elasticsearch",
|
elasticsearch: "elasticsearch",
|
||||||
mariadb: "mariadb",
|
mariadb: "mariadb",
|
||||||
tidb: "tidb",
|
tidb: "tidb",
|
||||||
@@ -2600,20 +2597,6 @@ function openExternalUrl(url: string) {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="form.db_type === 'oracle'" class="grid grid-cols-4 items-center gap-4">
|
|
||||||
<Label class="text-right text-xs">{{ t("connection.version") }}</Label>
|
|
||||||
<Select :model-value="selectedType === 'oracle-legacy' || selectedType === 'oracle-10g' ? selectedType : 'oracle'" @update:model-value="(val) => applyProfile(String(val), true)">
|
|
||||||
<SelectTrigger class="col-span-3 h-8 text-sm">
|
|
||||||
<SelectValue />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
<SelectItem value="oracle">Oracle 19c+</SelectItem>
|
|
||||||
<SelectItem value="oracle-legacy">Oracle 11g-19c</SelectItem>
|
|
||||||
<SelectItem value="oracle-10g">Oracle 10g</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="form.db_type === 'oracle'" class="grid grid-cols-4 items-center gap-4">
|
<div v-if="form.db_type === 'oracle'" class="grid grid-cols-4 items-center gap-4">
|
||||||
<Label class="text-right text-xs">SYSDBA</Label>
|
<Label class="text-right text-xs">SYSDBA</Label>
|
||||||
<label class="col-span-3 flex items-center gap-2 cursor-pointer">
|
<label class="col-span-3 flex items-center gap-2 cursor-pointer">
|
||||||
|
|||||||
@@ -6,8 +6,13 @@ export interface AgentDriverInstallState {
|
|||||||
installed: boolean;
|
installed: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function agentDriverInstallKey(dbType: DatabaseType | undefined, driverProfile?: string): string | undefined {
|
||||||
|
if (dbType === "oracle") return "oracle";
|
||||||
|
return driverProfile && driverProfile !== dbType ? driverProfile : dbType;
|
||||||
|
}
|
||||||
|
|
||||||
export function showAgentDriverInstallHint(dbType: DatabaseType | undefined, drivers: readonly AgentDriverInstallState[], driverProfile?: string): boolean {
|
export function showAgentDriverInstallHint(dbType: DatabaseType | undefined, drivers: readonly AgentDriverInstallState[], driverProfile?: string): boolean {
|
||||||
if (!supportsDriverManagement(dbType)) return false;
|
if (!supportsDriverManagement(dbType)) return false;
|
||||||
const driverKey = driverProfile && driverProfile !== dbType ? driverProfile : dbType;
|
const driverKey = agentDriverInstallKey(dbType, driverProfile);
|
||||||
return drivers.find((driver) => driver.db_type === driverKey)?.installed !== true;
|
return drivers.find((driver) => driver.db_type === driverKey)?.installed !== true;
|
||||||
}
|
}
|
||||||
@@ -271,18 +271,6 @@
|
|||||||
"metadataConnectionScoped": false,
|
"metadataConnectionScoped": false,
|
||||||
"skipTcpProbe": true,
|
"skipTcpProbe": true,
|
||||||
"defaultPort": 1521,
|
"defaultPort": 1521,
|
||||||
"driverProfiles": [
|
|
||||||
{
|
|
||||||
"profile": "oracle-legacy",
|
|
||||||
"label": "Oracle Legacy",
|
|
||||||
"agentKey": "oracle-legacy"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"profile": "oracle-10g",
|
|
||||||
"label": "Oracle 10g",
|
|
||||||
"agentKey": "oracle-10g"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"supportLevel": "operate",
|
"supportLevel": "operate",
|
||||||
"capabilities": {
|
"capabilities": {
|
||||||
"queryExecution": true,
|
"queryExecution": true,
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ pub struct AgentDriverProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ORACLE_PROFILES: &[AgentDriverProfile] = &[
|
const ORACLE_PROFILES: &[AgentDriverProfile] = &[
|
||||||
AgentDriverProfile { profile: "oracle-legacy", key: "oracle-legacy", label: "Oracle Legacy", store_visible: true },
|
AgentDriverProfile { profile: "oracle-legacy", key: "oracle", label: "Oracle", store_visible: false },
|
||||||
AgentDriverProfile { profile: "oracle-10g", key: "oracle-10g", label: "Oracle 10g", store_visible: true },
|
AgentDriverProfile { profile: "oracle-10g", key: "oracle", label: "Oracle", store_visible: false },
|
||||||
];
|
];
|
||||||
|
|
||||||
const GBASE_PROFILES: &[AgentDriverProfile] =
|
const GBASE_PROFILES: &[AgentDriverProfile] =
|
||||||
|
|||||||
@@ -193,18 +193,13 @@ pub fn oracle_error_with_driver_hint(config: &ConnectionConfig, err: &str) -> St
|
|||||||
if config.db_type != DatabaseType::Oracle {
|
if config.db_type != DatabaseType::Oracle {
|
||||||
return err.to_string();
|
return err.to_string();
|
||||||
}
|
}
|
||||||
if matches!(config.driver_profile.as_deref(), Some("oracle-legacy" | "oracle-10g")) {
|
|
||||||
return err.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
let normalized = err.to_lowercase();
|
let normalized = err.to_lowercase();
|
||||||
if !normalized.contains("ora-12541") && !err.contains("没有监听程序") {
|
if !normalized.contains("ora-12541") && !err.contains("没有监听程序") {
|
||||||
return err.to_string();
|
return err.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
format!(
|
format!("{err}\n\nOracle listener was not reachable. If the host and port are correct, try switching between Service Name and SID.")
|
||||||
"{err}\n\nOracle listener was not reachable with the current driver. If the host and port are correct, try switching Version to Oracle 11g-19c or Oracle 10g."
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn oracle_alternate_connect_configs(config: &ConnectionConfig, err: &str) -> Vec<ConnectionConfig> {
|
pub fn oracle_alternate_connect_configs(config: &ConnectionConfig, err: &str) -> Vec<ConnectionConfig> {
|
||||||
@@ -356,11 +351,7 @@ pub fn oracle_auth_fallback_profiles(config: &ConnectionConfig, err: &str) -> Ve
|
|||||||
if !normalized.contains("ora-28040") && !normalized.contains("no matching authentication protocol") {
|
if !normalized.contains("ora-28040") && !normalized.contains("no matching authentication protocol") {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
match config.driver_profile.as_deref() {
|
Vec::new()
|
||||||
Some("oracle-10g") => Vec::new(),
|
|
||||||
Some("oracle-legacy") => vec!["oracle-10g"],
|
|
||||||
_ => vec!["oracle-legacy", "oracle-10g"],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn oracle_alternate_connect_config(config: &ConnectionConfig, err: &str) -> Option<ConnectionConfig> {
|
pub fn oracle_alternate_connect_config(config: &ConnectionConfig, err: &str) -> Option<ConnectionConfig> {
|
||||||
@@ -632,17 +623,17 @@ mod tests {
|
|||||||
let hinted = oracle_error_with_driver_hint(&cfg, err);
|
let hinted = oracle_error_with_driver_hint(&cfg, err);
|
||||||
|
|
||||||
assert!(hinted.starts_with(err));
|
assert!(hinted.starts_with(err));
|
||||||
assert!(hinted.contains("Oracle 11g-19c"));
|
assert!(hinted.contains("Service Name"));
|
||||||
assert!(hinted.contains("Oracle 10g"));
|
assert!(hinted.contains("SID"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn oracle_listener_error_hint_skips_legacy_profiles_and_other_databases() {
|
fn oracle_listener_error_hint_skips_other_databases() {
|
||||||
let err = "Agent RPC error (-1): ORA-12541: TNS:no listener";
|
let err = "Agent RPC error (-1): ORA-12541: TNS:no listener";
|
||||||
let mut cfg = config(DatabaseType::Oracle, Some("ORCL"));
|
let mut cfg = config(DatabaseType::Oracle, Some("ORCL"));
|
||||||
cfg.driver_profile = Some("oracle-legacy".to_string());
|
cfg.driver_profile = Some("oracle-legacy".to_string());
|
||||||
|
|
||||||
assert_eq!(oracle_error_with_driver_hint(&cfg, err), err);
|
assert!(oracle_error_with_driver_hint(&cfg, err).contains("Service Name"));
|
||||||
|
|
||||||
cfg.db_type = DatabaseType::OceanbaseOracle;
|
cfg.db_type = DatabaseType::OceanbaseOracle;
|
||||||
cfg.driver_profile = None;
|
cfg.driver_profile = None;
|
||||||
@@ -762,20 +753,14 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn oracle_auth_errors_use_legacy_then_10g_fallbacks() {
|
fn oracle_auth_errors_do_not_switch_driver_profiles() {
|
||||||
let mut cfg = config(DatabaseType::Oracle, Some("ORCL"));
|
let mut cfg = config(DatabaseType::Oracle, Some("ORCL"));
|
||||||
cfg.driver_profile = Some("oracle".to_string());
|
cfg.driver_profile = Some("oracle".to_string());
|
||||||
|
|
||||||
assert_eq!(
|
assert!(oracle_auth_fallback_profiles(&cfg, "ORA-28040: No matching authentication protocol").is_empty());
|
||||||
oracle_auth_fallback_profiles(&cfg, "ORA-28040: No matching authentication protocol"),
|
|
||||||
vec!["oracle-legacy", "oracle-10g"]
|
|
||||||
);
|
|
||||||
|
|
||||||
cfg.driver_profile = Some("oracle-legacy".to_string());
|
cfg.driver_profile = Some("oracle-legacy".to_string());
|
||||||
assert_eq!(
|
assert!(oracle_auth_fallback_profiles(&cfg, "ORA-28040: No matching authentication protocol").is_empty());
|
||||||
oracle_auth_fallback_profiles(&cfg, "ORA-28040: No matching authentication protocol"),
|
|
||||||
vec!["oracle-10g"]
|
|
||||||
);
|
|
||||||
|
|
||||||
cfg.driver_profile = Some("oracle-10g".to_string());
|
cfg.driver_profile = Some("oracle-10g".to_string());
|
||||||
assert!(oracle_auth_fallback_profiles(&cfg, "ORA-28040: No matching authentication protocol").is_empty());
|
assert!(oracle_auth_fallback_profiles(&cfg, "ORA-28040: No matching authentication protocol").is_empty());
|
||||||
|
|||||||
@@ -153,11 +153,8 @@ mod tests {
|
|||||||
async fn runtime_gateway_resolves_profile_specific_keys() {
|
async fn runtime_gateway_resolves_profile_specific_keys() {
|
||||||
let manager = test_manager("profile-key");
|
let manager = test_manager("profile-key");
|
||||||
|
|
||||||
assert_eq!(AgentManager::db_type_to_agent_key(&DatabaseType::Oracle, Some("oracle-10g")), Some("oracle-10g"));
|
assert_eq!(AgentManager::db_type_to_agent_key(&DatabaseType::Oracle, Some("oracle-10g")), Some("oracle"));
|
||||||
assert_eq!(
|
assert_eq!(AgentManager::db_type_to_agent_key(&DatabaseType::Oracle, Some("oracle-legacy")), Some("oracle"));
|
||||||
AgentManager::db_type_to_agent_key(&DatabaseType::Oracle, Some("oracle-legacy")),
|
|
||||||
Some("oracle-legacy")
|
|
||||||
);
|
|
||||||
assert_eq!(AgentManager::db_type_to_agent_key(&DatabaseType::Oracle, None), Some("oracle"));
|
assert_eq!(AgentManager::db_type_to_agent_key(&DatabaseType::Oracle, None), Some("oracle"));
|
||||||
assert_eq!(AgentManager::db_type_to_agent_key(&DatabaseType::Gbase, Some("gbase8s")), Some("gbase8s"));
|
assert_eq!(AgentManager::db_type_to_agent_key(&DatabaseType::Gbase, Some("gbase8s")), Some("gbase8s"));
|
||||||
assert_eq!(AgentManager::db_type_to_agent_key(&DatabaseType::Gbase, None), Some("gbase"));
|
assert_eq!(AgentManager::db_type_to_agent_key(&DatabaseType::Gbase, None), Some("gbase"));
|
||||||
@@ -220,7 +217,10 @@ pub struct DriverInfo {
|
|||||||
pub version: String,
|
pub version: String,
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub min_app_version: String,
|
pub min_app_version: String,
|
||||||
pub jar: ArtifactInfo,
|
#[serde(default)]
|
||||||
|
pub jar: Option<ArtifactInfo>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub native: std::collections::HashMap<String, ArtifactInfo>,
|
||||||
#[serde(default = "default_jre_key")]
|
#[serde(default = "default_jre_key")]
|
||||||
pub jre: String,
|
pub jre: String,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ pub async fn spawn_connection_client(
|
|||||||
db_type: &DatabaseType,
|
db_type: &DatabaseType,
|
||||||
driver_profile: Option<&str>,
|
driver_profile: Option<&str>,
|
||||||
) -> Result<AgentDriverClient, String> {
|
) -> Result<AgentDriverClient, String> {
|
||||||
let key = db_type_to_agent_key(db_type, driver_profile)
|
let keys = runtime_agent_key_candidates(db_type, driver_profile)
|
||||||
.ok_or_else(|| format!("{:?} is not an agent-driven database type", db_type))?;
|
.ok_or_else(|| format!("{:?} is not an agent-driven database type", db_type))?;
|
||||||
spawn_client_for_key(manager, key).await
|
spawn_first_available_client(manager, &keys).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn call_daemon<T: DeserializeOwned + Send + 'static>(
|
pub async fn call_daemon<T: DeserializeOwned + Send + 'static>(
|
||||||
@@ -45,9 +45,9 @@ pub async fn call_daemon<T: DeserializeOwned + Send + 'static>(
|
|||||||
method: &str,
|
method: &str,
|
||||||
params: serde_json::Value,
|
params: serde_json::Value,
|
||||||
) -> Result<T, String> {
|
) -> Result<T, String> {
|
||||||
let key = db_type_to_agent_key(db_type, driver_profile)
|
let keys = runtime_agent_key_candidates(db_type, driver_profile)
|
||||||
.ok_or_else(|| format!("{:?} is not an agent-driven database type", db_type))?
|
.ok_or_else(|| format!("{:?} is not an agent-driven database type", db_type))?;
|
||||||
.to_string();
|
let key = first_installed_agent_key(manager, &keys).unwrap_or(keys[0]).to_string();
|
||||||
|
|
||||||
let mut daemons = manager.daemons.lock().await;
|
let mut daemons = manager.daemons.lock().await;
|
||||||
|
|
||||||
@@ -80,6 +80,36 @@ pub async fn call_daemon_method<T: DeserializeOwned + Send + 'static>(
|
|||||||
call_daemon(manager, db_type, driver_profile, method.as_str(), params).await
|
call_daemon(manager, db_type, driver_profile, method.as_str(), params).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn runtime_agent_key_candidates(db_type: &DatabaseType, driver_profile: Option<&str>) -> Option<Vec<&'static str>> {
|
||||||
|
let primary = db_type_to_agent_key(db_type, driver_profile)?;
|
||||||
|
if *db_type == DatabaseType::Oracle {
|
||||||
|
return match driver_profile {
|
||||||
|
Some("oracle-legacy") => Some(vec![primary, "oracle-legacy"]),
|
||||||
|
Some("oracle-10g") => Some(vec![primary, "oracle-10g"]),
|
||||||
|
_ => Some(vec![primary]),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Some(vec![primary])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn first_installed_agent_key<'a>(manager: &AgentManager, keys: &'a [&'static str]) -> Option<&'a str> {
|
||||||
|
keys.iter().copied().find(|key| manager.is_driver_installed(key))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn spawn_first_available_client(
|
||||||
|
manager: &AgentManager,
|
||||||
|
keys: &[&'static str],
|
||||||
|
) -> Result<AgentDriverClient, String> {
|
||||||
|
let mut last_error = None;
|
||||||
|
for key in keys {
|
||||||
|
match spawn_client_for_key(manager, key).await {
|
||||||
|
Ok(client) => return Ok(client),
|
||||||
|
Err(err) => last_error = Some(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(last_error.unwrap_or_else(|| "No agent driver candidates available".to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
async fn spawn_client_for_key(manager: &AgentManager, key: &str) -> Result<AgentDriverClient, String> {
|
async fn spawn_client_for_key(manager: &AgentManager, key: &str) -> Result<AgentDriverClient, String> {
|
||||||
let state = manager.load_state();
|
let state = manager.load_state();
|
||||||
let jre_key = state.installed_drivers.get(key).map(|driver| driver.jre.as_str()).unwrap_or(DEFAULT_JRE_KEY);
|
let jre_key = state.installed_drivers.get(key).map(|driver| driver.jre.as_str()).unwrap_or(DEFAULT_JRE_KEY);
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ pub fn build_agent_list(am: &AgentManager, registry: Option<&AgentRegistry>) ->
|
|||||||
db_type: key.to_string(),
|
db_type: key.to_string(),
|
||||||
label: label.to_string(),
|
label: label.to_string(),
|
||||||
version: remote.map(|r| r.version.clone()).unwrap_or_default(),
|
version: remote.map(|r| r.version.clone()).unwrap_or_default(),
|
||||||
size: remote.map(|r| r.jar.size).unwrap_or(0),
|
size: remote.and_then(driver_download_artifact).map(|artifact| artifact.size).unwrap_or(0),
|
||||||
installed,
|
installed,
|
||||||
installed_version: local.map(|l| l.version.clone()),
|
installed_version: local.map(|l| l.version.clone()),
|
||||||
update_available: match (local, remote) {
|
update_available: match (local, remote) {
|
||||||
@@ -95,6 +95,10 @@ pub fn build_agent_list(am: &AgentManager, registry: Option<&AgentRegistry>) ->
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn driver_download_artifact(driver: &crate::agent_manager::DriverInfo) -> Option<&crate::agent_manager::ArtifactInfo> {
|
||||||
|
driver.native.get(AgentManager::current_platform()).or(driver.jar.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
fn installed_jre_version<'a>(state: &'a crate::agent_manager::AgentState, jre_key: &str) -> Option<&'a String> {
|
fn installed_jre_version<'a>(state: &'a crate::agent_manager::AgentState, jre_key: &str) -> Option<&'a String> {
|
||||||
state
|
state
|
||||||
.jre_versions
|
.jre_versions
|
||||||
@@ -102,6 +106,21 @@ fn installed_jre_version<'a>(state: &'a crate::agent_manager::AgentState, jre_ke
|
|||||||
.or_else(|| (jre_key == DEFAULT_JRE_KEY).then_some(state.jre_version.as_ref()).flatten())
|
.or_else(|| (jre_key == DEFAULT_JRE_KEY).then_some(state.jre_version.as_ref()).flatten())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn mark_executable(path: &Path) -> Result<(), String> {
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
let mut permissions = std::fs::metadata(path).map_err(|err| err.to_string())?.permissions();
|
||||||
|
permissions.set_mode(0o755);
|
||||||
|
std::fs::set_permissions(path, permissions).map_err(|err| err.to_string())?;
|
||||||
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
{
|
||||||
|
let _ = path;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn jre_needs_install(am: &AgentManager, registry: &AgentRegistry, jre_key: &str) -> bool {
|
pub fn jre_needs_install(am: &AgentManager, registry: &AgentRegistry, jre_key: &str) -> bool {
|
||||||
let state = am.load_state();
|
let state = am.load_state();
|
||||||
if state.java_runtime.mode != JavaRuntimeMode::Managed {
|
if state.java_runtime.mode != JavaRuntimeMode::Managed {
|
||||||
@@ -352,7 +371,10 @@ async fn install_agent_driver_from_registry(
|
|||||||
return Err(format!("Unknown driver type: {db_type}"));
|
return Err(format!("Unknown driver type: {db_type}"));
|
||||||
};
|
};
|
||||||
let jre_key = &driver.jre;
|
let jre_key = &driver.jre;
|
||||||
let needs_jre = jre_needs_install(am, registry, jre_key);
|
let native_artifact = driver.native.get(AgentManager::current_platform());
|
||||||
|
let jar_artifact = driver.jar.as_ref();
|
||||||
|
let requires_java_runtime = native_artifact.is_none();
|
||||||
|
let needs_jre = requires_java_runtime && jre_needs_install(am, registry, jre_key);
|
||||||
|
|
||||||
if needs_jre {
|
if needs_jre {
|
||||||
let jre_info =
|
let jre_info =
|
||||||
@@ -391,8 +413,17 @@ async fn install_agent_driver_from_registry(
|
|||||||
std::fs::remove_file(&jre_archive).ok();
|
std::fs::remove_file(&jre_archive).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
let jar_path = am.driver_jar_path(db_type);
|
let (artifact, target_path) = if let Some(native) = native_artifact {
|
||||||
progress(AgentProgressEvent::transfer("driver", 0, driver.jar.size).with_batch(
|
(native, am.driver_native_path(db_type))
|
||||||
|
} else if let Some(jar) = jar_artifact {
|
||||||
|
(jar, am.driver_jar_path(db_type))
|
||||||
|
} else {
|
||||||
|
return Err(format!("No driver artifact available for {db_type}"));
|
||||||
|
};
|
||||||
|
if let Some(parent) = target_path.parent() {
|
||||||
|
std::fs::create_dir_all(parent).map_err(|err| format!("Failed to create driver directory: {err}"))?;
|
||||||
|
}
|
||||||
|
progress(AgentProgressEvent::transfer("driver", 0, artifact.size).with_batch(
|
||||||
Some(db_type),
|
Some(db_type),
|
||||||
current,
|
current,
|
||||||
total_drivers,
|
total_drivers,
|
||||||
@@ -401,20 +432,28 @@ async fn install_agent_driver_from_registry(
|
|||||||
am,
|
am,
|
||||||
progress,
|
progress,
|
||||||
"driver",
|
"driver",
|
||||||
&driver.jar.url,
|
&artifact.url,
|
||||||
&github_url_to_r2_path(&driver.jar.url, "driver"),
|
&github_url_to_r2_path(&artifact.url, "driver"),
|
||||||
&jar_path,
|
&target_path,
|
||||||
driver.jar.size,
|
artifact.size,
|
||||||
Some(CacheIdentity::Driver { db_type, version: &driver.version }),
|
Some(CacheIdentity::Driver { db_type, version: &driver.version }),
|
||||||
Some(db_type),
|
Some(db_type),
|
||||||
current,
|
current,
|
||||||
total_drivers,
|
total_drivers,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
if native_artifact.is_some() {
|
||||||
|
mark_executable(&target_path)?;
|
||||||
|
std::fs::remove_file(am.driver_jar_path(db_type)).ok();
|
||||||
|
} else {
|
||||||
|
std::fs::remove_file(am.driver_native_path(db_type)).ok();
|
||||||
|
}
|
||||||
|
|
||||||
let mut local_state = am.load_state();
|
let mut local_state = am.load_state();
|
||||||
if let Some(jre_info) = registry.resolve_jre(jre_key) {
|
if requires_java_runtime {
|
||||||
local_state.jre_versions.insert(jre_key.clone(), jre_info.version.clone());
|
if let Some(jre_info) = registry.resolve_jre(jre_key) {
|
||||||
|
local_state.jre_versions.insert(jre_key.clone(), jre_info.version.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
local_state.installed_drivers.insert(
|
local_state.installed_drivers.insert(
|
||||||
db_type.to_string(),
|
db_type.to_string(),
|
||||||
@@ -715,13 +754,16 @@ pub fn import_offline_zip(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let driver_entries: Vec<(String, String)> = (0..archive.len())
|
let driver_entries: Vec<(String, String, bool)> = (0..archive.len())
|
||||||
.filter_map(|i| {
|
.filter_map(|i| {
|
||||||
let entry = archive.by_index(i).ok()?;
|
let entry = archive.by_index(i).ok()?;
|
||||||
let name = entry.name().to_string();
|
let name = entry.name().to_string();
|
||||||
if name.starts_with("drivers/") && name.ends_with(".jar") {
|
if name.starts_with("drivers/") && name.ends_with(".jar") {
|
||||||
let db_type = extract_db_type_from_filename(&name)?;
|
let db_type = extract_db_type_from_filename(&name)?;
|
||||||
Some((db_type, name))
|
Some((db_type, name, false))
|
||||||
|
} else if name.starts_with("drivers/") {
|
||||||
|
let db_type = db_type_for_native_offline_entry(®istry, platform, &name)?;
|
||||||
|
Some((db_type, name, true))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -762,7 +804,7 @@ pub fn import_offline_zip(
|
|||||||
result.jre_installed.push(jre_key.clone());
|
result.jre_installed.push(jre_key.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (db_type, entry_name) in &driver_entries {
|
for (db_type, entry_name, is_native) in &driver_entries {
|
||||||
current += 1;
|
current += 1;
|
||||||
|
|
||||||
if let Some(remote_driver) = registry.drivers.get(db_type) {
|
if let Some(remote_driver) = registry.drivers.get(db_type) {
|
||||||
@@ -784,13 +826,19 @@ pub fn import_offline_zip(
|
|||||||
label: agent_catalog::label_for_key(db_type).unwrap_or(db_type).to_string(),
|
label: agent_catalog::label_for_key(db_type).unwrap_or(db_type).to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let jar_path = am.driver_jar_path(db_type);
|
let driver_path = if *is_native { am.driver_native_path(db_type) } else { am.driver_jar_path(db_type) };
|
||||||
if let Some(parent) = jar_path.parent() {
|
if let Some(parent) = driver_path.parent() {
|
||||||
std::fs::create_dir_all(parent).map_err(|e| e.to_string())?;
|
std::fs::create_dir_all(parent).map_err(|e| e.to_string())?;
|
||||||
}
|
}
|
||||||
let mut entry = archive.by_name(entry_name).map_err(|e| format!("Failed to read {entry_name}: {e}"))?;
|
let mut entry = archive.by_name(entry_name).map_err(|e| format!("Failed to read {entry_name}: {e}"))?;
|
||||||
let mut out = std::fs::File::create(&jar_path).map_err(|e| format!("Failed to write driver JAR: {e}"))?;
|
let mut out = std::fs::File::create(&driver_path).map_err(|e| format!("Failed to write driver: {e}"))?;
|
||||||
std::io::copy(&mut entry, &mut out).map_err(|e| format!("Failed to copy driver JAR: {e}"))?;
|
std::io::copy(&mut entry, &mut out).map_err(|e| format!("Failed to copy driver: {e}"))?;
|
||||||
|
if *is_native {
|
||||||
|
mark_executable(&driver_path)?;
|
||||||
|
std::fs::remove_file(am.driver_jar_path(db_type)).ok();
|
||||||
|
} else {
|
||||||
|
std::fs::remove_file(am.driver_native_path(db_type)).ok();
|
||||||
|
}
|
||||||
|
|
||||||
let version = registry.drivers.get(db_type).map(|d| d.version.clone()).unwrap_or_else(|| "local".to_string());
|
let version = registry.drivers.get(db_type).map(|d| d.version.clone()).unwrap_or_else(|| "local".to_string());
|
||||||
let jre_key =
|
let jre_key =
|
||||||
@@ -836,6 +884,15 @@ fn extract_db_type_from_filename(name: &str) -> Option<String> {
|
|||||||
Some(db_type.to_string())
|
Some(db_type.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn db_type_for_native_offline_entry(registry: &AgentRegistry, platform: &str, name: &str) -> Option<String> {
|
||||||
|
let filename = name.rsplit('/').next()?;
|
||||||
|
registry.drivers.iter().find_map(|(db_type, driver)| {
|
||||||
|
let artifact = driver.native.get(platform)?;
|
||||||
|
let artifact_filename = artifact.url.rsplit('/').next()?;
|
||||||
|
(artifact_filename == filename).then(|| db_type.clone())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn extract_tar_gz(archive: &Path, dest: &Path) -> Result<(), String> {
|
fn extract_tar_gz(archive: &Path, dest: &Path) -> Result<(), String> {
|
||||||
std::fs::create_dir_all(dest).map_err(|e| e.to_string())?;
|
std::fs::create_dir_all(dest).map_err(|e| e.to_string())?;
|
||||||
let status = std::process::Command::new("tar")
|
let status = std::process::Command::new("tar")
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ fn registry_with_driver(db_type: &str, version: &str, jre: &str) -> AgentRegistr
|
|||||||
label: db_type.to_string(),
|
label: db_type.to_string(),
|
||||||
min_app_version: "0.1.0".to_string(),
|
min_app_version: "0.1.0".to_string(),
|
||||||
jre: jre.to_string(),
|
jre: jre.to_string(),
|
||||||
jar: ArtifactInfo { url: format!("https://example.com/dbx-agent-{db_type}.jar"), size: 42 },
|
jar: Some(ArtifactInfo { url: format!("https://example.com/dbx-agent-{db_type}.jar"), size: 42 }),
|
||||||
|
native: std::collections::HashMap::new(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
AgentRegistry { jre: None, jres: std::collections::HashMap::new(), drivers }
|
AgentRegistry { jre: None, jres: std::collections::HashMap::new(), drivers }
|
||||||
|
|||||||
@@ -112,8 +112,8 @@ fn maps_agent_database_types_to_driver_keys() {
|
|||||||
assert_eq!(agent_key(&DatabaseType::Oracle, None), Some("oracle"));
|
assert_eq!(agent_key(&DatabaseType::Oracle, None), Some("oracle"));
|
||||||
assert_eq!(agent_key(&DatabaseType::Databend, None), Some("databend"));
|
assert_eq!(agent_key(&DatabaseType::Databend, None), Some("databend"));
|
||||||
assert_eq!(agent_key(&DatabaseType::InfluxDb, None), Some("influxdb"));
|
assert_eq!(agent_key(&DatabaseType::InfluxDb, None), Some("influxdb"));
|
||||||
assert_eq!(agent_key(&DatabaseType::Oracle, Some("oracle-legacy")), Some("oracle-legacy"));
|
assert_eq!(agent_key(&DatabaseType::Oracle, Some("oracle-legacy")), Some("oracle"));
|
||||||
assert_eq!(agent_key(&DatabaseType::Oracle, Some("oracle-10g")), Some("oracle-10g"));
|
assert_eq!(agent_key(&DatabaseType::Oracle, Some("oracle-10g")), Some("oracle"));
|
||||||
assert_eq!(agent_key(&DatabaseType::Postgres, None), None);
|
assert_eq!(agent_key(&DatabaseType::Postgres, None), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ test("does not show agent driver install hints for built-in database types", ()
|
|||||||
assert.equal(showAgentDriverInstallHint("mysql", [{ db_type: "informix", installed: false }]), false);
|
assert.equal(showAgentDriverInstallHint("mysql", [{ db_type: "informix", installed: false }]), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("uses the selected Oracle driver profile for install hints", () => {
|
test("uses the unified Oracle driver for legacy Oracle profiles", () => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
showAgentDriverInstallHint(
|
showAgentDriverInstallHint(
|
||||||
"oracle",
|
"oracle",
|
||||||
@@ -33,7 +33,7 @@ test("uses the selected Oracle driver profile for install hints", () => {
|
|||||||
],
|
],
|
||||||
"oracle-10g",
|
"oracle-10g",
|
||||||
),
|
),
|
||||||
false,
|
true,
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
showAgentDriverInstallHint(
|
showAgentDriverInstallHint(
|
||||||
|
|||||||
Reference in new issue
Block a user