Skip to content

Commit

Permalink
mk-sql: do not detect instances if detection is disabled
Browse files Browse the repository at this point in the history
Change-Id: I0939195b05dcf2f426b649d0eac7e50800a7011d
  • Loading branch information
s-kipnis committed Jan 8, 2025
1 parent e98b554 commit fe80421
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions packages/host/mk-sql/src/ms_sql/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ async fn find_working_instances(
ms_sql: &config::ms_sql::Config,
environment: &Env,
) -> Result<Vec<SqlInstance>> {
let builders = find_allowed_instance_builders(ms_sql).await?;
let builders = find_all_instance_builders(ms_sql).await?;
if builders.is_empty() {
log::warn!("Found NO allowed SQL server instances");
return Ok(Vec::new());
Expand All @@ -2033,32 +2033,21 @@ async fn find_working_instances(
.collect::<Vec<SqlInstance>>())
}

async fn find_allowed_instance_builders(
ms_sql: &config::ms_sql::Config,
) -> Result<Vec<SqlInstanceBuilder>> {
let builders = find_all_instance_builders(ms_sql).await?;
Ok(builders
.into_iter()
.filter(|i| ms_sql.is_instance_allowed(&i.get_name()))
.collect::<Vec<SqlInstanceBuilder>>())
}

pub async fn find_all_instance_builders(
ms_sql: &config::ms_sql::Config,
) -> Result<Vec<SqlInstanceBuilder>> {
let found = find_detectable_instance_builders(ms_sql).await;
log::info!(
"Found {} instances by discovery: [ {} ]",
found.len(),
found
.iter()
.map(|i| format!("{}", i.get_name()))
.collect::<Vec<_>>()
.join(", ")
);

let detected = if ms_sql.discovery().detect() {
found
let builders = detect_instance_builders(ms_sql).await;
log::info!(
"Found {} instances by discovery: [ {} ]",
builders.len(),
builders
.iter()
.map(|i| format!("{}", i.get_name()))
.collect::<Vec<_>>()
.join(", ")
);
builders
} else {
ms_sql
.discovery()
Expand Down Expand Up @@ -2086,9 +2075,7 @@ pub async fn find_all_instance_builders(
}

/// find instances described in the config but not detected by the discovery
async fn find_detectable_instance_builders(
ms_sql: &config::ms_sql::Config,
) -> Vec<SqlInstanceBuilder> {
async fn detect_instance_builders(ms_sql: &config::ms_sql::Config) -> Vec<SqlInstanceBuilder> {
obtain_instance_builders(&ms_sql.endpoint(), &[], ms_sql.discovery())
.await
.unwrap_or_else(|e| {
Expand Down

0 comments on commit fe80421

Please sign in to comment.