Skip to content

Commit

Permalink
Fix template generation issue in Mac (#2421)
Browse files Browse the repository at this point in the history
* Revert "Path fix for macos (#2413)"

This reverts commit fb1bee4.

* fix max issue

---------

Co-authored-by: ROSHAN SAHU <[email protected]>
  • Loading branch information
sahuroshan and ROSHAN SAHU authored Oct 24, 2024
1 parent 1aa9164 commit 0107dcf
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/Microsoft.SqlTools.Migration/MigrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,15 +611,33 @@ internal async Task HandleGetArmTemplateRequest(
{
try
{
Logger.Verbose("request received in toolsservice");
ProvisioningScriptServiceProvider provider = new ProvisioningScriptServiceProvider();
string searchPattern = $"*{targetType}-Baseline*.json";
string skuRecommendationReportFilePath = Directory.GetFiles(SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath, searchPattern).FirstOrDefault();
Logger.Verbose($"Logging report file path -- {skuRecommendationReportFilePath}");
List<SkuRecommendationResult> recommendations = ExtractSkuRecommendationReportAction.ExtractSkuRecommendationsFromReport(skuRecommendationReportFilePath);
Logger.Verbose($"recommendations generated-- {recommendations.Count}");

// Save the current Console.Out
var originalOut = Console.Out;
List<SkuRecommendationResult> recommendations;
try
{
// Redirect Console.Out to a null stream (no output)
using (var nullWriter = new StreamWriter(Stream.Null))
{
Console.SetOut(nullWriter);

/* This call was adding some console messages in the response hence the API call was failing in MacOS
* setting Console.Out to a null stream so that this call does not add any random messages to response.*/
recommendations = ExtractSkuRecommendationReportAction.ExtractSkuRecommendationsFromReport(skuRecommendationReportFilePath);
}
}
finally
{
// Restore the original Console.Out
Console.SetOut(originalOut);
}


List<SqlArmTemplate> templateList = provider.GenerateProvisioningScript(recommendations);
Logger.Verbose($"ARM templates generated-- {templateList.Count}");
List<string> armTemplates = new List<string>();
foreach (SqlArmTemplate template in templateList)
{
Expand All @@ -628,17 +646,13 @@ internal async Task HandleGetArmTemplateRequest(
Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Culture = CultureInfo.InvariantCulture }
);
Logger.Verbose($"Logging ARM templates -- {jsonOutput}");
armTemplates.Add(jsonOutput);
}
Logger.Verbose($"sending response -- {armTemplates.Count}");
await requestContext.SendResult(armTemplates);
}
catch (Exception e)
{
await requestContext.SendError(e.ToString());
Logger.Verbose($"inside catch block -- ");
await requestContext.SendError(e.ToString());
}
}

Expand Down

0 comments on commit 0107dcf

Please sign in to comment.