mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-26 01:25:42 -05:00
Akma/login migrations (#1728)
In this PR, we make the appropriate backend service changes in order to enable the login migrations feature in the SQL migration extension. Changes include: updating the Microsoft.SqlServer.Migration.Login NuGet version to the latest version adding a new request handler for StartLoginMigrations calls, which makes the appropriate calls to the login NuGet adding ExtensionMethod helper to properly combine exception maps login migration nuget calls Co-authored-by: Akshay Mata <akma@microsoft.com>
This commit is contained in:
@@ -24,6 +24,7 @@ using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.Migration.Contracts;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using Microsoft.SqlServer.Migration.Logins;
|
||||
using Microsoft.SqlServer.Migration.SkuRecommendation.Aggregation;
|
||||
using Microsoft.SqlServer.Migration.SkuRecommendation.Models.Sql;
|
||||
using Microsoft.SqlServer.Migration.SkuRecommendation;
|
||||
@@ -39,8 +40,12 @@ using Microsoft.SqlServer.Migration.SkuRecommendation.ElasticStrategy.AzureSqlMa
|
||||
using Microsoft.SqlServer.Migration.SkuRecommendation.ElasticStrategy.AzureSqlDatabase;
|
||||
using Microsoft.SqlServer.Migration.SkuRecommendation.Models;
|
||||
using Microsoft.SqlServer.Migration.SkuRecommendation.Utils;
|
||||
using Microsoft.SqlServer.DataCollection.Common.Contracts.OperationsInfrastructure;
|
||||
using System.Threading;
|
||||
using Microsoft.SqlServer.Migration.Logins.Contracts;
|
||||
using Microsoft.SqlServer.Migration.Assessment.Common.Models;
|
||||
using Microsoft.SqlServer.Migration.Assessment.Common.Utils;
|
||||
using Microsoft.SqlTools.ServiceLayer.Migration.Utils;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||
{
|
||||
@@ -121,6 +126,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||
this.ServiceHost.SetRequestHandler(StopPerfDataCollectionRequest.Type, HandleStopPerfDataCollectionRequest);
|
||||
this.ServiceHost.SetRequestHandler(RefreshPerfDataCollectionRequest.Type, HandleRefreshPerfDataCollectionRequest);
|
||||
this.ServiceHost.SetRequestHandler(GetSkuRecommendationsRequest.Type, HandleGetSkuRecommendationsRequest);
|
||||
this.ServiceHost.SetRequestHandler(StartLoginMigrationRequest.Type, HandleStartLoginMigration);
|
||||
this.ServiceHost.SetRequestHandler(ValidateLoginMigrationRequest.Type, HandleValidateLoginMigration);
|
||||
this.ServiceHost.SetRequestHandler(MigrateLoginsRequest.Type, HandleMigrateLogins);
|
||||
this.ServiceHost.SetRequestHandler(EstablishUserMappingRequest.Type, HandleEstablishUserMapping);
|
||||
this.ServiceHost.SetRequestHandler(MigrateServerRolesAndSetPermissionsRequest.Type, HandleMigrateServerRolesAndSetPermissions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -325,6 +335,231 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task HandleStartLoginMigration(
|
||||
StartLoginMigrationParams parameters,
|
||||
RequestContext<LoginMigrationResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ILoginsMigration loginMigration = new LoginsMigration(parameters.SourceConnectionString, parameters.TargetConnectionString,
|
||||
null, parameters.LoginList, parameters.AADDomainName);
|
||||
|
||||
IDictionary<string, IEnumerable<ReportableException>> exceptionMap = new Dictionary<string, IEnumerable<ReportableException>>();
|
||||
|
||||
exceptionMap.AddExceptions( await loginMigration.StartValidations(CancellationToken.None) );
|
||||
exceptionMap.AddExceptions( await loginMigration.MigrateLogins(CancellationToken.None) );
|
||||
exceptionMap.AddExceptions( loginMigration.MigrateServerRoles(CancellationToken.None) );
|
||||
exceptionMap.AddExceptions( loginMigration.EstablishUserMapping(CancellationToken.None) );
|
||||
exceptionMap.AddExceptions( await loginMigration.EstablishServerRoleMapping(CancellationToken.None) );
|
||||
exceptionMap.AddExceptions( loginMigration.SetLoginPermissions(CancellationToken.None) );
|
||||
exceptionMap.AddExceptions( loginMigration.SetServerRolePermissions(CancellationToken.None) );
|
||||
|
||||
LoginMigrationResult results = new LoginMigrationResult()
|
||||
{
|
||||
ExceptionMap = exceptionMap
|
||||
};
|
||||
|
||||
await requestContext.SendResult(results);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task HandleValidateLoginMigration(
|
||||
StartLoginMigrationParams parameters,
|
||||
RequestContext<LoginMigrationResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ILoginsMigration loginMigration = new LoginsMigration(parameters.SourceConnectionString, parameters.TargetConnectionString,
|
||||
null, parameters.LoginList, parameters.AADDomainName);
|
||||
|
||||
IDictionary<string, IEnumerable<ReportableException>> exceptionMap = new Dictionary<string, IEnumerable<ReportableException>>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
exceptionMap.AddExceptions( await loginMigration.StartValidations(CancellationToken.None) );
|
||||
stopWatch.Stop();
|
||||
TimeSpan elapsedTime = stopWatch.Elapsed;
|
||||
|
||||
LoginMigrationResult results = new LoginMigrationResult()
|
||||
{
|
||||
ExceptionMap = exceptionMap,
|
||||
CompletedStep = LoginMigrationStep.StartValidations,
|
||||
ElapsedTime = MigrationServiceHelper.FormatTimeSpan(elapsedTime)
|
||||
|
||||
};
|
||||
|
||||
await requestContext.SendResult(results);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task HandleMigrateLogins(
|
||||
StartLoginMigrationParams parameters,
|
||||
RequestContext<LoginMigrationResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ILoginsMigration loginMigration = new LoginsMigration(parameters.SourceConnectionString, parameters.TargetConnectionString,
|
||||
null, parameters.LoginList, parameters.AADDomainName);
|
||||
|
||||
IDictionary<string, IEnumerable<ReportableException>> exceptionMap = new Dictionary<string, IEnumerable<ReportableException>>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
exceptionMap.AddExceptions( await loginMigration.StartValidations(CancellationToken.None) );
|
||||
exceptionMap.AddExceptions( await loginMigration.MigrateLogins(CancellationToken.None) );
|
||||
stopWatch.Stop();
|
||||
TimeSpan elapsedTime = stopWatch.Elapsed;
|
||||
|
||||
LoginMigrationResult results = new LoginMigrationResult()
|
||||
{
|
||||
ExceptionMap = exceptionMap,
|
||||
CompletedStep = LoginMigrationStep.MigrateLogins,
|
||||
ElapsedTime = MigrationServiceHelper.FormatTimeSpan(elapsedTime)
|
||||
};
|
||||
|
||||
await requestContext.SendResult(results);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task HandleEstablishUserMapping(
|
||||
StartLoginMigrationParams parameters,
|
||||
RequestContext<LoginMigrationResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ILoginsMigration loginMigration = new LoginsMigration(parameters.SourceConnectionString, parameters.TargetConnectionString,
|
||||
null, parameters.LoginList, parameters.AADDomainName);
|
||||
|
||||
IDictionary<string, IEnumerable<ReportableException>> exceptionMap = new Dictionary<string, IEnumerable<ReportableException>>();
|
||||
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
exceptionMap.AddExceptions( await loginMigration.StartValidations(CancellationToken.None) );
|
||||
exceptionMap.AddExceptions( loginMigration.EstablishUserMapping(CancellationToken.None) );
|
||||
stopWatch.Stop();
|
||||
TimeSpan elapsedTime = stopWatch.Elapsed;
|
||||
|
||||
LoginMigrationResult results = new LoginMigrationResult()
|
||||
{
|
||||
ExceptionMap = exceptionMap,
|
||||
CompletedStep = LoginMigrationStep.EstablishUserMapping,
|
||||
ElapsedTime = MigrationServiceHelper.FormatTimeSpan(elapsedTime)
|
||||
};
|
||||
|
||||
await requestContext.SendResult(results);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task HandleMigrateServerRolesAndSetPermissions(
|
||||
StartLoginMigrationParams parameters,
|
||||
RequestContext<LoginMigrationResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ILoginsMigration loginMigration = new LoginsMigration(parameters.SourceConnectionString, parameters.TargetConnectionString,
|
||||
null, parameters.LoginList, parameters.AADDomainName);
|
||||
|
||||
IDictionary<string, IEnumerable<ReportableException>> exceptionMap = new Dictionary<string, IEnumerable<ReportableException>>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
exceptionMap.AddExceptions(await loginMigration.StartValidations(CancellationToken.None));
|
||||
stopWatch.Stop();
|
||||
TimeSpan elapsedTime = stopWatch.Elapsed;
|
||||
|
||||
await this.ServiceHost.SendEvent(
|
||||
LoginMigrationNotification.Type,
|
||||
new LoginMigrationResult()
|
||||
{
|
||||
ExceptionMap = exceptionMap,
|
||||
CompletedStep = LoginMigrationStep.StartValidations,
|
||||
ElapsedTime = MigrationServiceHelper.FormatTimeSpan(elapsedTime)
|
||||
});
|
||||
|
||||
stopWatch.Restart();
|
||||
exceptionMap.AddExceptions(loginMigration.MigrateServerRoles(CancellationToken.None));
|
||||
stopWatch.Stop();
|
||||
elapsedTime = stopWatch.Elapsed;
|
||||
|
||||
await this.ServiceHost.SendEvent(
|
||||
LoginMigrationNotification.Type,
|
||||
new LoginMigrationResult()
|
||||
{
|
||||
ExceptionMap = exceptionMap,
|
||||
CompletedStep = LoginMigrationStep.MigrateServerRoles,
|
||||
ElapsedTime = MigrationServiceHelper.FormatTimeSpan(elapsedTime)
|
||||
});
|
||||
|
||||
stopWatch.Restart();
|
||||
exceptionMap.AddExceptions(await loginMigration.EstablishServerRoleMapping(CancellationToken.None));
|
||||
stopWatch.Stop();
|
||||
elapsedTime = stopWatch.Elapsed;
|
||||
|
||||
await this.ServiceHost.SendEvent(
|
||||
LoginMigrationNotification.Type,
|
||||
new LoginMigrationResult()
|
||||
{
|
||||
ExceptionMap = exceptionMap,
|
||||
CompletedStep = LoginMigrationStep.EstablishServerRoleMapping,
|
||||
ElapsedTime = MigrationServiceHelper.FormatTimeSpan(elapsedTime)
|
||||
});
|
||||
|
||||
stopWatch.Restart();
|
||||
exceptionMap.AddExceptions(loginMigration.SetLoginPermissions(CancellationToken.None));
|
||||
stopWatch.Stop();
|
||||
elapsedTime = stopWatch.Elapsed;
|
||||
|
||||
await this.ServiceHost.SendEvent(
|
||||
LoginMigrationNotification.Type,
|
||||
new LoginMigrationResult()
|
||||
{
|
||||
ExceptionMap = exceptionMap,
|
||||
CompletedStep = LoginMigrationStep.SetLoginPermissions,
|
||||
ElapsedTime = MigrationServiceHelper.FormatTimeSpan(elapsedTime)
|
||||
});
|
||||
|
||||
stopWatch.Restart();
|
||||
exceptionMap.AddExceptions(loginMigration.SetServerRolePermissions(CancellationToken.None));
|
||||
stopWatch.Stop();
|
||||
elapsedTime = stopWatch.Elapsed;
|
||||
|
||||
await this.ServiceHost.SendEvent(
|
||||
LoginMigrationNotification.Type,
|
||||
new LoginMigrationResult()
|
||||
{
|
||||
ExceptionMap = exceptionMap,
|
||||
CompletedStep = LoginMigrationStep.SetServerRolePermissions,
|
||||
ElapsedTime = MigrationServiceHelper.FormatTimeSpan(elapsedTime)
|
||||
});
|
||||
|
||||
LoginMigrationResult results = new LoginMigrationResult()
|
||||
{
|
||||
ExceptionMap = exceptionMap,
|
||||
CompletedStep = LoginMigrationStep.SetServerRolePermissions,
|
||||
ElapsedTime = MigrationServiceHelper.FormatTimeSpan(elapsedTime)
|
||||
};
|
||||
|
||||
await requestContext.SendResult(results);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal RecommendationResultSet GenerateBaselineRecommendations(SqlInstanceRequirements req, GetSkuRecommendationsParams parameters) {
|
||||
RecommendationResultSet resultSet = new RecommendationResultSet();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user