diff --git a/src/Microsoft.SqlTools.ServiceLayer/Migration/Contracts/GetSkuRecommendationsRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/Migration/Contracts/GetSkuRecommendationsRequest.cs index 51566758..dca4e34d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Migration/Contracts/GetSkuRecommendationsRequest.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Migration/Contracts/GetSkuRecommendationsRequest.cs @@ -88,6 +88,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration.Contracts /// SQL instance requirements, representing an aggregated view of the performance requirements of the source instance /// public SqlInstanceRequirements InstanceRequirements { get; set; } + + /// + /// File paths where the recommendation reports were saved + /// + public List SkuRecommendationReportPaths { get; set; } } public class GetSkuRecommendationsRequest diff --git a/src/Microsoft.SqlTools.ServiceLayer/Migration/Contracts/MigrationAssessmentsRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/Migration/Contracts/MigrationAssessmentsRequest.cs index fb1e5b17..4dccb6b2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Migration/Contracts/MigrationAssessmentsRequest.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Migration/Contracts/MigrationAssessmentsRequest.cs @@ -36,6 +36,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration.Contracts /// Contains the raw assessment response /// public ISqlMigrationAssessmentModel RawAssessmentResult { get; set; } + /// + /// File path where the assessment report was saved + /// + public string AssessmentReportPath { get; set; } } /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Migration/MigrationService.cs b/src/Microsoft.SqlTools.ServiceLayer/Migration/MigrationService.cs index b36a3aaf..8345be43 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Migration/MigrationService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Migration/MigrationService.cs @@ -32,6 +32,8 @@ using Microsoft.SqlServer.Migration.SkuRecommendation.Contracts.Exceptions; using Newtonsoft.Json; using System.Reflection; using Microsoft.SqlServer.Migration.SkuRecommendation.Contracts.Models.Environment; +using Microsoft.SqlServer.Migration.SkuRecommendation.Models; +using Microsoft.SqlServer.Migration.SkuRecommendation.Utils; namespace Microsoft.SqlTools.ServiceLayer.Migration { @@ -269,6 +271,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration hostRequirements: new SqlServerHostRequirements() { NICCount = 1 }); SkuRecommendationServiceProvider provider = new SkuRecommendationServiceProvider(new AzureSqlSkuBillingServiceProvider()); + List skuRecommendationReportPaths = new List(); // generate SQL DB recommendations, if applicable List sqlDbResults = new List(); @@ -301,6 +304,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration }); } } + + SkuRecommendationReport sqlDbReport = new SkuRecommendationReport( + new Dictionary> {{ req, sqlDbResults }}, + AzureSqlTargetPlatform.AzureSqlDatabase.ToString()); + var sqlDbRecommendationReportFileName = String.Format("SkuRecommendationReport-AzureSqlDatabase-{0}", DateTime.UtcNow.ToString("yyyyMMddHH-mmss", CultureInfo.InvariantCulture)); + var sqlDbRecommendationReportFullPath = Path.Combine(SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath, sqlDbRecommendationReportFileName); + ExportRecommendationResultsAction.ExportRecommendationResults(sqlDbReport, SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath, false, sqlDbRecommendationReportFileName); + skuRecommendationReportPaths.Add(sqlDbRecommendationReportFullPath + ".html"); } // generate SQL MI recommendations, if applicable @@ -329,6 +340,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration NegativeJustifications = null, }); } + + SkuRecommendationReport sqlMiReport = new SkuRecommendationReport( + new Dictionary> { { req, sqlMiResults } }, + AzureSqlTargetPlatform.AzureSqlManagedInstance.ToString()); + var sqlMiRecommendationReportFileName = String.Format("SkuRecommendationReport-AzureSqlManagedInstance-{0}", DateTime.UtcNow.ToString("yyyyMMddHH-mmss", CultureInfo.InvariantCulture)); + var sqlMiRecommendationReportFullPath = Path.Combine(SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath, sqlMiRecommendationReportFileName); + ExportRecommendationResultsAction.ExportRecommendationResults(sqlMiReport, SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath, false, sqlMiRecommendationReportFileName); + skuRecommendationReportPaths.Add(sqlMiRecommendationReportFullPath + ".html"); } // generate SQL VM recommendations, if applicable @@ -358,6 +377,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration NegativeJustifications = null, }); } + + SkuRecommendationReport sqlVmReport = new SkuRecommendationReport( + new Dictionary> { { req, sqlVmResults } }, + AzureSqlTargetPlatform.AzureSqlVirtualMachine.ToString()); + var sqlVmRecommendationReportFileName = String.Format("SkuRecommendationReport-AzureSqlVirtualMachine-{0}", DateTime.UtcNow.ToString("yyyyMMddHH-mmss", CultureInfo.InvariantCulture)); + var sqlVmRecommendationReportFullPath = Path.Combine(SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath, sqlVmRecommendationReportFileName); + ExportRecommendationResultsAction.ExportRecommendationResults(sqlVmReport, SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath, false, sqlVmRecommendationReportFileName); + skuRecommendationReportPaths.Add(sqlVmRecommendationReportFullPath + ".html"); } GetSkuRecommendationsResult results = new GetSkuRecommendationsResult @@ -365,7 +392,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration SqlDbRecommendationResults = sqlDbResults, SqlMiRecommendationResults = sqlMiResults, SqlVmRecommendationResults = sqlVmResults, - InstanceRequirements = req + InstanceRequirements = req, + SkuRecommendationReportPaths = skuRecommendationReportPaths }; await requestContext.SendResult(results); @@ -409,7 +437,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath = Path.GetDirectoryName(Logger.LogFileFullPath); DmaEngine engine = new DmaEngine(connectionStrings); ISqlMigrationAssessmentModel contextualizedAssessmentResult = await engine.GetTargetAssessmentResultsListWithCheck(System.Threading.CancellationToken.None); - engine.SaveAssessmentResultsToJson(contextualizedAssessmentResult, false); + var assessmentReportFileName = String.Format("SqlAssessmentReport-{0}.json", DateTime.UtcNow.ToString("yyyyMMddHH-mmss", CultureInfo.InvariantCulture)); + var assessmentReportFullPath = Path.Combine(SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath, assessmentReportFileName); + engine.SaveAssessmentResultsToJson(contextualizedAssessmentResult, false, assessmentReportFullPath); + var server = (contextualizedAssessmentResult.Servers.Count > 0) ? ParseServerAssessmentInfo(contextualizedAssessmentResult.Servers[0], engine) : null; return new MigrationAssessmentResult() { @@ -417,7 +448,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration Errors = ParseAssessmentError(contextualizedAssessmentResult.Errors), StartTime = contextualizedAssessmentResult.StartedOn.ToString(), EndedTime = contextualizedAssessmentResult.EndedOn.ToString(), - RawAssessmentResult = contextualizedAssessmentResult + RawAssessmentResult = contextualizedAssessmentResult, + AssessmentReportPath = assessmentReportFullPath }; }