mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -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:
@@ -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
|
/// SQL instance requirements, representing an aggregated view of the performance requirements of the source instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SqlInstanceRequirements InstanceRequirements { get; set; }
|
public SqlInstanceRequirements InstanceRequirements { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// File paths where the recommendation reports were saved
|
||||||
|
/// </summary>
|
||||||
|
public List<string> SkuRecommendationReportPaths { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GetSkuRecommendationsRequest
|
public class GetSkuRecommendationsRequest
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration.Contracts
|
|||||||
/// Contains the raw assessment response
|
/// Contains the raw assessment response
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ISqlMigrationAssessmentModel RawAssessmentResult { get; set; }
|
public ISqlMigrationAssessmentModel RawAssessmentResult { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// File path where the assessment report was saved
|
||||||
|
/// </summary>
|
||||||
|
public string AssessmentReportPath { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ using Microsoft.SqlServer.Migration.SkuRecommendation.Contracts.Exceptions;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.SqlServer.Migration.SkuRecommendation.Contracts.Models.Environment;
|
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
|
namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||||
{
|
{
|
||||||
@@ -269,6 +271,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
|||||||
hostRequirements: new SqlServerHostRequirements() { NICCount = 1 });
|
hostRequirements: new SqlServerHostRequirements() { NICCount = 1 });
|
||||||
|
|
||||||
SkuRecommendationServiceProvider provider = new SkuRecommendationServiceProvider(new AzureSqlSkuBillingServiceProvider());
|
SkuRecommendationServiceProvider provider = new SkuRecommendationServiceProvider(new AzureSqlSkuBillingServiceProvider());
|
||||||
|
List<string> skuRecommendationReportPaths = new List<string>();
|
||||||
|
|
||||||
// generate SQL DB recommendations, if applicable
|
// generate SQL DB recommendations, if applicable
|
||||||
List<SkuRecommendationResult> sqlDbResults = new List<SkuRecommendationResult>();
|
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
|
// generate SQL MI recommendations, if applicable
|
||||||
@@ -329,6 +340,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
|||||||
NegativeJustifications = null,
|
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
|
// generate SQL VM recommendations, if applicable
|
||||||
@@ -358,6 +377,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
|||||||
NegativeJustifications = null,
|
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
|
GetSkuRecommendationsResult results = new GetSkuRecommendationsResult
|
||||||
@@ -365,7 +392,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
|||||||
SqlDbRecommendationResults = sqlDbResults,
|
SqlDbRecommendationResults = sqlDbResults,
|
||||||
SqlMiRecommendationResults = sqlMiResults,
|
SqlMiRecommendationResults = sqlMiResults,
|
||||||
SqlVmRecommendationResults = sqlVmResults,
|
SqlVmRecommendationResults = sqlVmResults,
|
||||||
InstanceRequirements = req
|
InstanceRequirements = req,
|
||||||
|
SkuRecommendationReportPaths = skuRecommendationReportPaths
|
||||||
};
|
};
|
||||||
|
|
||||||
await requestContext.SendResult(results);
|
await requestContext.SendResult(results);
|
||||||
@@ -409,7 +437,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
|||||||
SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath = Path.GetDirectoryName(Logger.LogFileFullPath);
|
SqlAssessmentConfiguration.ReportsAndLogsRootFolderPath = Path.GetDirectoryName(Logger.LogFileFullPath);
|
||||||
DmaEngine engine = new DmaEngine(connectionStrings);
|
DmaEngine engine = new DmaEngine(connectionStrings);
|
||||||
ISqlMigrationAssessmentModel contextualizedAssessmentResult = await engine.GetTargetAssessmentResultsListWithCheck(System.Threading.CancellationToken.None);
|
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;
|
var server = (contextualizedAssessmentResult.Servers.Count > 0) ? ParseServerAssessmentInfo(contextualizedAssessmentResult.Servers[0], engine) : null;
|
||||||
return new MigrationAssessmentResult()
|
return new MigrationAssessmentResult()
|
||||||
{
|
{
|
||||||
@@ -417,7 +448,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
|||||||
Errors = ParseAssessmentError(contextualizedAssessmentResult.Errors),
|
Errors = ParseAssessmentError(contextualizedAssessmentResult.Errors),
|
||||||
StartTime = contextualizedAssessmentResult.StartedOn.ToString(),
|
StartTime = contextualizedAssessmentResult.StartedOn.ToString(),
|
||||||
EndedTime = contextualizedAssessmentResult.EndedOn.ToString(),
|
EndedTime = contextualizedAssessmentResult.EndedOn.ToString(),
|
||||||
RawAssessmentResult = contextualizedAssessmentResult
|
RawAssessmentResult = contextualizedAssessmentResult,
|
||||||
|
AssessmentReportPath = assessmentReportFullPath
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user