Skip to content

Commit ad0e236

Browse files
adding fallback logic for retrievng values from deployment output
1 parent 7967733 commit ad0e236

File tree

2 files changed

+157
-9
lines changed

2 files changed

+157
-9
lines changed

infra/scripts/Selecting-Team-Config-And-Data.ps1

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,70 @@ function Get-ValuesFromAzDeployment {
214214
return $true
215215
}
216216

217+
function Get-ValuesUsingSolutionSuffix {
218+
Write-Host "Getting values from resource naming convention using solution suffix..."
219+
220+
# Get the solution suffix from resource group tags
221+
$solutionSuffix = az group show --name $ResourceGroup --query "tags.SolutionSuffix" -o tsv
222+
if (-not $solutionSuffix) {
223+
Write-Host "Error: Could not find SolutionSuffix tag in resource group."
224+
return $false
225+
}
226+
227+
Write-Host "Found solution suffix: $solutionSuffix"
228+
229+
# Reconstruct resource names using same naming convention as Bicep
230+
$script:storageAccount = "st$solutionSuffix" -replace '-', '' # Remove dashes like Bicep does
231+
$script:aiSearch = "srch-$solutionSuffix"
232+
$containerAppName = "ca-$solutionSuffix"
233+
234+
# Query dynamic value (backend URL) from Container App
235+
Write-Host "Querying backend URL from Container App..."
236+
$backendFqdn = az containerapp show `
237+
--name $containerAppName `
238+
--resource-group $ResourceGroup `
239+
--query "properties.configuration.ingress.fqdn" `
240+
-o tsv 2>$null
241+
242+
if (-not $backendFqdn) {
243+
Write-Host "Error: Could not get Container App FQDN. Container App may not be deployed yet."
244+
return $false
245+
}
246+
247+
$script:backendUrl = "https://$backendFqdn"
248+
249+
# Hardcoded container names (These don't follow the suffix pattern in Bicep, hence need to be changed here if changed in Bicep)
250+
$script:blobContainerForRetailCustomer = "retail-dataset-customer"
251+
$script:blobContainerForRetailOrder = "retail-dataset-order"
252+
$script:blobContainerForRFPSummary = "rfp-summary-dataset"
253+
$script:blobContainerForRFPRisk = "rfp-risk-dataset"
254+
$script:blobContainerForRFPCompliance = "rfp-compliance-dataset"
255+
$script:blobContainerForContractSummary = "contract-summary-dataset"
256+
$script:blobContainerForContractRisk = "contract-risk-dataset"
257+
$script:blobContainerForContractCompliance = "contract-compliance-dataset"
258+
259+
# Hardcoded index names (These don't follow the suffix pattern in Bicep, hence need to be changed here if changed in Bicep)
260+
$script:aiSearchIndexForRetailCustomer = "macae-retail-customer-index"
261+
$script:aiSearchIndexForRetailOrder = "macae-retail-order-index"
262+
$script:aiSearchIndexForRFPSummary = "macae-rfp-summary-index"
263+
$script:aiSearchIndexForRFPRisk = "macae-rfp-risk-index"
264+
$script:aiSearchIndexForRFPCompliance = "macae-rfp-compliance-index"
265+
$script:aiSearchIndexForContractSummary = "contract-summary-doc-index"
266+
$script:aiSearchIndexForContractRisk = "contract-risk-doc-index"
267+
$script:aiSearchIndexForContractCompliance = "contract-compliance-doc-index"
268+
269+
$script:directoryPath = "data/agent_teams"
270+
271+
# Validate that we got all critical values
272+
if (-not $script:storageAccount -or -not $script:aiSearch -or -not $script:backendUrl) {
273+
Write-Host "Error: Failed to reconstruct all required resource names."
274+
return $false
275+
}
276+
277+
Write-Host "Successfully reconstructed values from resource naming convention."
278+
return $true
279+
}
280+
217281
# Main script execution with cleanup handling
218282
try {
219283
# Authenticate with Azure
@@ -301,14 +365,24 @@ if (-not $ResourceGroup) {
301365
exit 1
302366
}
303367
} else {
304-
# Resource group provided - use deployment outputs
368+
# Resource group provided - try deployment outputs first, then fallback to naming convention
305369
Write-Host "Resource group provided: $ResourceGroup"
306370

307371
if (-not (Get-ValuesFromAzDeployment)) {
308-
Write-Host "Failed to get values from deployment outputs."
309-
exit 1
372+
Write-Host ""
373+
Write-Host "Warning: Could not retrieve values from deployment outputs (deployment may be deleted)."
374+
Write-Host "Attempting fallback method: reconstructing values from resource naming convention..."
375+
Write-Host ""
376+
377+
if (-not (Get-ValuesUsingSolutionSuffix)) {
378+
Write-Host ""
379+
Write-Host "Error: Both methods failed to retrieve configuration values."
380+
Write-Host "Please ensure:"
381+
Write-Host " 1. The deployment exists and has a DeploymentName tag, OR"
382+
Write-Host " 2. The resource group has a SolutionSuffix tag"
383+
exit 1
384+
}
310385
}
311-
}
312386

313387
# Interactive Use Case Selection
314388
Write-Host ""
@@ -787,12 +861,11 @@ if($useCaseSelection -eq "2" -or $useCaseSelection -eq "all" -or $useCaseSelecti
787861
Write-Host "Python script to index data for Retail Customer Satisfaction successfully executed."
788862
}
789863

790-
Write-Host "Script executed successfully. Sample Data Processed Successfully."
791-
792864
if ($isTeamConfigFailed -or $isSampleDataFailed) {
793865
Write-Host "`nOne or more tasks failed. Please check the error messages above."
794866
exit 1
795867
} else {
868+
Write-Host "`nScript executed successfully. Sample Data Processed Successfully."
796869
if($useCaseSelection -eq "1"-or $useCaseSelection -eq "2" -or $useCaseSelection -eq "5" -or $useCaseSelection -eq "all" -or $useCaseSelection -eq "6"){
797870
Write-Host "`nTeam configuration upload and sample data processing completed successfully."
798871
}else {

infra/scripts/selecting_team_config_and_data.sh

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,70 @@ function get_values_from_az_deployment() {
232232
return 0
233233
}
234234

235+
function get_values_using_solution_suffix() {
236+
echo "Getting values from resource naming convention using solution suffix..."
237+
238+
# Get the solution suffix from resource group tags
239+
solutionSuffix=$(az group show --name "$ResourceGroup" --query "tags.SolutionSuffix" -o tsv)
240+
if [[ -z "$solutionSuffix" ]]; then
241+
echo "Error: Could not find SolutionSuffix tag in resource group."
242+
return 1
243+
fi
244+
245+
echo "Found solution suffix: $solutionSuffix"
246+
247+
# Reconstruct resource names using same naming convention as Bicep
248+
storageAccount=$(echo "st${solutionSuffix}" | tr -d '-') # Remove dashes like Bicep does
249+
aiSearch="srch-${solutionSuffix}"
250+
containerAppName="ca-${solutionSuffix}"
251+
252+
# Query dynamic value (backend URL) from Container App
253+
echo "Querying backend URL from Container App..."
254+
backendFqdn=$(az containerapp show \
255+
--name "$containerAppName" \
256+
--resource-group "$ResourceGroup" \
257+
--query "properties.configuration.ingress.fqdn" \
258+
-o tsv 2>/dev/null)
259+
260+
if [[ -z "$backendFqdn" ]]; then
261+
echo "Error: Could not get Container App FQDN. Container App may not be deployed yet."
262+
return 1
263+
fi
264+
265+
backendUrl="https://${backendFqdn}"
266+
267+
# Hardcoded container names (These don't follow the suffix pattern in Bicep, hence need to be changed here if changed in Bicep)
268+
blobContainerForRetailCustomer="retail-dataset-customer"
269+
blobContainerForRetailOrder="retail-dataset-order"
270+
blobContainerForRFPSummary="rfp-summary-dataset"
271+
blobContainerForRFPRisk="rfp-risk-dataset"
272+
blobContainerForRFPCompliance="rfp-compliance-dataset"
273+
blobContainerForContractSummary="contract-summary-dataset"
274+
blobContainerForContractRisk="contract-risk-dataset"
275+
blobContainerForContractCompliance="contract-compliance-dataset"
276+
277+
# Hardcoded index names (These don't follow the suffix pattern in Bicep, hence need to be changed here if changed in Bicep)
278+
aiSearchIndexForRetailCustomer="macae-retail-customer-index"
279+
aiSearchIndexForRetailOrder="macae-retail-order-index"
280+
aiSearchIndexForRFPSummary="macae-rfp-summary-index"
281+
aiSearchIndexForRFPRisk="macae-rfp-risk-index"
282+
aiSearchIndexForRFPCompliance="macae-rfp-compliance-index"
283+
aiSearchIndexForContractSummary="contract-summary-doc-index"
284+
aiSearchIndexForContractRisk="contract-risk-doc-index"
285+
aiSearchIndexForContractCompliance="contract-compliance-doc-index"
286+
287+
directoryPath="data/agent_teams"
288+
289+
# Validate that we got all critical values
290+
if [[ -z "$storageAccount" || -z "$aiSearch" || -z "$backendUrl" ]]; then
291+
echo "Error: Failed to reconstruct all required resource names."
292+
return 1
293+
fi
294+
295+
echo "Successfully reconstructed values from resource naming convention."
296+
return 0
297+
}
298+
235299
# Authenticate with Azure
236300
if az account show &> /dev/null; then
237301
echo "Already authenticated with Azure."
@@ -314,12 +378,23 @@ if [[ -z "$ResourceGroup" ]]; then
314378
exit 1
315379
fi
316380
else
317-
# Resource group provided - use deployment outputs
381+
# Resource group provided - use deployment outputs, then fallback to naming convention
318382
echo "Resource group provided: $ResourceGroup"
319383

320384
if ! get_values_from_az_deployment; then
321-
echo "Failed to get values from deployment outputs."
322-
exit 1
385+
echo ""
386+
echo "Warning: Could not retrieve values from deployment outputs (deployment may be deleted)."
387+
echo "Attempting fallback method: reconstructing values from resource naming convention..."
388+
echo ""
389+
390+
if ! get_values_using_solution_suffix; then
391+
echo ""
392+
echo "Error: Both methods failed to retrieve configuration values."
393+
echo "Please ensure:"
394+
echo " 1. The deployment exists and has a DeploymentName tag, OR"
395+
echo " 2. The resource group has a SolutionSuffix tag"
396+
exit 1
397+
fi
323398
fi
324399
fi
325400

0 commit comments

Comments
 (0)