feat: add preference sorting and multi-ok DC prioritization in replication pipeline
This commit is contained in:
@@ -225,6 +225,7 @@ function Get-NetAppActiveDc {
|
||||
|
||||
$srvIp = if ($ds.server_ip) { $ds.server_ip } else { "" }
|
||||
$srvType = if ($ds.server_type) { $ds.server_type } elseif ($ds.type) { $ds.type } else { "dc" }
|
||||
$srvPref = if ($ds.preference) { $ds.preference.ToString().ToLower() } else { "regular" }
|
||||
$srvState = if ($ds.state) { $ds.state } elseif ($ds.status) { $ds.status } else { "unknown" }
|
||||
$srvNode = if ($ds.node -and $ds.node.name) { $ds.node.name }
|
||||
elseif ($ds.node) { $ds.node.ToString() } else { "node-01" }
|
||||
@@ -234,6 +235,7 @@ function Get-NetAppActiveDc {
|
||||
ServerName = $srvName
|
||||
ServerIp = $srvIp
|
||||
ServerType = $srvType
|
||||
Preference = $srvPref
|
||||
State = $srvState
|
||||
Node = $srvNode
|
||||
Domain = $srvDomain
|
||||
@@ -243,11 +245,25 @@ function Get-NetAppActiveDc {
|
||||
}
|
||||
}
|
||||
|
||||
# 1순위: 상태가 "ok", "active", "up" 이면서 type이 DC인 서버
|
||||
$bestMatch = $discoveredList | Where-Object {
|
||||
# OK 상태인 DC 후보군 추출
|
||||
$okDcList = @($discoveredList | Where-Object {
|
||||
($_.State -like "*ok*" -or $_.State -like "*up*" -or $_.State -like "*active*") -and
|
||||
($_.ServerType -like "*dc*" -or $_.ServerType -like "*primary*")
|
||||
} | Select-Object -First 1
|
||||
})
|
||||
|
||||
# OK 상태인 고유 DC FQDN 목록
|
||||
$allOkDcNames = @($okDcList | Select-Object -ExpandProperty ServerName -Unique)
|
||||
|
||||
# 1순위: OK 상태 중 Preference 가중치 정렬 (preferred: 1, favored: 2, regular: 3)
|
||||
$sortedOkDcs = @($okDcList | Sort-Object -Property @{
|
||||
Expression = {
|
||||
if ($_.Preference -eq "preferred") { 1 }
|
||||
elseif ($_.Preference -eq "favored") { 2 }
|
||||
else { 3 }
|
||||
}
|
||||
})
|
||||
|
||||
$bestMatch = if ($sortedOkDcs.Count -gt 0) { $sortedOkDcs[0] } else { $null }
|
||||
|
||||
# 2순위: 상태 무관 DC 타입 서버
|
||||
if (-not $bestMatch) {
|
||||
@@ -265,6 +281,7 @@ function Get-NetAppActiveDc {
|
||||
return [PSCustomObject]@{
|
||||
ActiveDC = $bestMatch.ServerName
|
||||
ActiveDcIp = $bestMatch.ServerIp
|
||||
Preference = $bestMatch.Preference
|
||||
Node = $bestMatch.Node
|
||||
SvmName = $bestMatch.SvmName
|
||||
Status = "OK (Active Connected)"
|
||||
@@ -273,6 +290,8 @@ function Get-NetAppActiveDc {
|
||||
IsLive = $true
|
||||
DiscoveryMethod = "ONTAP REST API (/api/protocols/cifs/domains)"
|
||||
DiscoveredServerCount= $discoveredList.Count
|
||||
OkCount = $allOkDcNames.Count
|
||||
AllOkDcs = $allOkDcNames
|
||||
AllDiscoveredServers = $discoveredList.ToArray()
|
||||
}
|
||||
}
|
||||
@@ -321,6 +340,7 @@ function Get-NetAppActiveDc {
|
||||
return [PSCustomObject]@{
|
||||
ActiveDC = "dc04.corp.local"
|
||||
ActiveDcIp = "10.20.1.14"
|
||||
Preference = "preferred"
|
||||
Node = "ontap-node-02"
|
||||
SvmName = if ($svm) { $svm } else { "svm_cifs_prod01" }
|
||||
Status = "OK (Simulated Active Binding)"
|
||||
@@ -329,10 +349,12 @@ function Get-NetAppActiveDc {
|
||||
IsLive = $false
|
||||
DiscoveryMethod = "ONTAP Domain Discovery (Simulated)"
|
||||
DiscoveredServerCount= 2
|
||||
OkCount = 2
|
||||
AllOkDcs = @("dc04.corp.local", "dc01.corp.local")
|
||||
FallbackReason = if ($attemptErrors.Count -gt 0) { ($attemptErrors -join "; ") } else { "Live mode not configured" }
|
||||
AllDiscoveredServers = @(
|
||||
[PSCustomObject]@{ ServerName = "dc04.corp.local"; ServerIp = "10.20.1.14"; ServerType = "ms_dc"; State = "ok"; Node = "ontap-node-02"; SvmName = "svm_cifs_prod01" },
|
||||
[PSCustomObject]@{ ServerName = "dc01.corp.local"; ServerIp = "10.10.1.11"; ServerType = "ms_dc"; State = "ok"; Node = "ontap-node-01"; SvmName = "svm_cifs_prod01" }
|
||||
[PSCustomObject]@{ ServerName = "dc04.corp.local"; ServerIp = "10.20.1.14"; ServerType = "ms_dc"; Preference = "preferred"; State = "ok"; Node = "ontap-node-02"; SvmName = "svm_cifs_prod01" },
|
||||
[PSCustomObject]@{ ServerName = "dc01.corp.local"; ServerIp = "10.10.1.11"; ServerType = "ms_dc"; Preference = "favored"; State = "ok"; Node = "ontap-node-01"; SvmName = "svm_cifs_prod01" }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user