mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-23 17:24:12 -05:00
[SQL Migration] Enable saving assessment/recommendation reports (#1613)
* Implement save assessment report * Implement save recommendation report * Remove unnecessary content files after updating NuGet version
This commit is contained in:
@@ -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<string> skuRecommendationReportPaths = new List<string>();
|
||||
|
||||
// generate SQL DB recommendations, if applicable
|
||||
List<SkuRecommendationResult> sqlDbResults = new List<SkuRecommendationResult>();
|
||||
@@ -301,6 +304,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
SkuRecommendationReport sqlDbReport = new SkuRecommendationReport(
|
||||
new Dictionary<SqlInstanceRequirements, List<SkuRecommendationResult>> {{ 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<SqlInstanceRequirements, List<SkuRecommendationResult>> { { 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<SqlInstanceRequirements, List<SkuRecommendationResult>> { { 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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user