mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Initial admin and DR services. (#329)
* Add initial services for admin, tasks, and DR * Fix up some of the contract interfaces * Make fields public to allow Json.Net to work * Fix a couple issues in backup contracts
This commit is contained in:
66
src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs
Normal file
66
src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.Hosting.Protocol;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Admin.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Datasource admin task service class
|
||||||
|
/// </summary>
|
||||||
|
public class AdminService
|
||||||
|
{
|
||||||
|
private static readonly Lazy<AdminService> instance = new Lazy<AdminService>(() => new AdminService());
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default, parameterless constructor.
|
||||||
|
/// </summary>
|
||||||
|
internal AdminService()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the singleton instance object
|
||||||
|
/// </summary>
|
||||||
|
public static AdminService Instance
|
||||||
|
{
|
||||||
|
get { return instance.Value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the service instance
|
||||||
|
/// </summary>
|
||||||
|
public void InitializeService(ServiceHost serviceHost)
|
||||||
|
{
|
||||||
|
serviceHost.SetRequestHandler(CreateDatabaseRequest.Type, HandleCreateDatabaseRequest);
|
||||||
|
serviceHost.SetRequestHandler(CreateLoginRequest.Type, HandleCreateLoginRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles a create database request
|
||||||
|
/// </summary>
|
||||||
|
internal static async Task HandleCreateDatabaseRequest(
|
||||||
|
CreateDatabaseParams databaseParams,
|
||||||
|
RequestContext<CreateDatabaseResponse> requestContext)
|
||||||
|
{
|
||||||
|
await requestContext.SendResult(new CreateDatabaseResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles a create login request
|
||||||
|
/// </summary>
|
||||||
|
internal static async Task HandleCreateLoginRequest(
|
||||||
|
CreateLoginParams loginParams,
|
||||||
|
RequestContext<CreateLoginResponse> requestContext)
|
||||||
|
{
|
||||||
|
await requestContext.SendResult(new CreateLoginResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.Admin.Contracts
|
||||||
|
{
|
||||||
|
public class CreateDatabaseParams
|
||||||
|
{
|
||||||
|
public string OwnerUri { get; set; }
|
||||||
|
|
||||||
|
public DatabaseInfo DatabaseInfo { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateDatabaseResponse
|
||||||
|
{
|
||||||
|
public bool Result { get; set; }
|
||||||
|
|
||||||
|
public int TaskId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateDatabaseRequest
|
||||||
|
{
|
||||||
|
public static readonly
|
||||||
|
RequestType<CreateDatabaseParams, CreateDatabaseResponse> Type =
|
||||||
|
RequestType<CreateDatabaseParams, CreateDatabaseResponse>.Create("admin/createdatabase");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.Admin.Contracts
|
||||||
|
{
|
||||||
|
public class CreateLoginParams
|
||||||
|
{
|
||||||
|
public string OwnerUri { get; set; }
|
||||||
|
|
||||||
|
public LoginInfo DatabaseInfo { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateLoginResponse
|
||||||
|
{
|
||||||
|
public bool Result { get; set; }
|
||||||
|
|
||||||
|
public int TaskId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateLoginRequest
|
||||||
|
{
|
||||||
|
public static readonly
|
||||||
|
RequestType<CreateLoginParams, CreateLoginResponse> Type =
|
||||||
|
RequestType<CreateLoginParams, CreateLoginResponse>.Create("admin/createlogin");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.Admin.Contracts
|
||||||
|
{
|
||||||
|
public class DatabaseInfo
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.Admin.Contracts
|
||||||
|
{
|
||||||
|
public class LoginInfo
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
|
||||||
|
{
|
||||||
|
public class BackupInfo
|
||||||
|
{
|
||||||
|
public string BackupType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
|
||||||
|
{
|
||||||
|
public class BackupParams
|
||||||
|
{
|
||||||
|
public string OwnerUri { get; set; }
|
||||||
|
|
||||||
|
public BackupInfo BackupInfo { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BackupResponse
|
||||||
|
{
|
||||||
|
public bool Result { get; set; }
|
||||||
|
|
||||||
|
public int TaskId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BackupRequest
|
||||||
|
{
|
||||||
|
public static readonly
|
||||||
|
RequestType<BackupParams, BackupResponse> Type =
|
||||||
|
RequestType<BackupParams, BackupResponse>.Create("disasterrecovery/backup");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.Hosting.Protocol;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
|
||||||
|
{
|
||||||
|
public class DisasterRecoveryService
|
||||||
|
{
|
||||||
|
private static readonly Lazy<DisasterRecoveryService> instance = new Lazy<DisasterRecoveryService>(() => new DisasterRecoveryService());
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default, parameterless constructor.
|
||||||
|
/// </summary>
|
||||||
|
internal DisasterRecoveryService()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the singleton instance object
|
||||||
|
/// </summary>
|
||||||
|
public static DisasterRecoveryService Instance
|
||||||
|
{
|
||||||
|
get { return instance.Value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the service instance
|
||||||
|
/// </summary>
|
||||||
|
public void InitializeService(ServiceHost serviceHost )
|
||||||
|
{
|
||||||
|
serviceHost.SetRequestHandler(BackupRequest.Type, HandleBackupRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles a backup request
|
||||||
|
/// </summary>
|
||||||
|
internal static async Task HandleBackupRequest(
|
||||||
|
BackupParams backupParams,
|
||||||
|
RequestContext<BackupResponse> requestContext)
|
||||||
|
{
|
||||||
|
await requestContext.SendResult(new BackupResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,12 +6,14 @@ using Microsoft.SqlTools.Credentials;
|
|||||||
using Microsoft.SqlTools.Extensibility;
|
using Microsoft.SqlTools.Extensibility;
|
||||||
using Microsoft.SqlTools.Hosting;
|
using Microsoft.SqlTools.Hosting;
|
||||||
using Microsoft.SqlTools.Hosting.Protocol;
|
using Microsoft.SqlTools.Hosting.Protocol;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery;
|
||||||
using Microsoft.SqlTools.ServiceLayer.EditData;
|
using Microsoft.SqlTools.ServiceLayer.EditData;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Metadata;
|
using Microsoft.SqlTools.ServiceLayer.Metadata;
|
||||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
|
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Scripting;
|
using Microsoft.SqlTools.ServiceLayer.Scripting;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
@@ -85,6 +87,12 @@ namespace Microsoft.SqlTools.ServiceLayer
|
|||||||
ScriptingService.Instance.InitializeService(serviceHost);
|
ScriptingService.Instance.InitializeService(serviceHost);
|
||||||
serviceProvider.RegisterSingleService(ScriptingService.Instance);
|
serviceProvider.RegisterSingleService(ScriptingService.Instance);
|
||||||
|
|
||||||
|
AdminService.Instance.InitializeService(serviceHost);
|
||||||
|
serviceProvider.RegisterSingleService(AdminService.Instance);
|
||||||
|
|
||||||
|
DisasterRecoveryService.Instance.InitializeService(serviceHost);
|
||||||
|
serviceProvider.RegisterSingleService(DisasterRecoveryService.Instance);
|
||||||
|
|
||||||
InitializeHostedServices(serviceProvider, serviceHost);
|
InitializeHostedServices(serviceProvider, serviceHost);
|
||||||
serviceHost.ServiceProvider = serviceProvider;
|
serviceHost.ServiceProvider = serviceProvider;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.TaskServices.Contracts
|
||||||
|
{
|
||||||
|
|
||||||
|
public class ListTasksParams
|
||||||
|
{
|
||||||
|
bool ListActiveTasksOnly { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ListTasksResponse
|
||||||
|
{
|
||||||
|
TaskInfo[] Tasks { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ListTasksRequest
|
||||||
|
{
|
||||||
|
public static readonly
|
||||||
|
RequestType<ListTasksParams, ListTasksResponse> Type =
|
||||||
|
RequestType<ListTasksParams, ListTasksResponse>.Create("tasks/listtasks");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.TaskServices.Contracts
|
||||||
|
{
|
||||||
|
public enum TaskState
|
||||||
|
{
|
||||||
|
NotStarted = 0,
|
||||||
|
Running = 1,
|
||||||
|
Complete = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TaskInfo
|
||||||
|
{
|
||||||
|
public int TaskId { get; set; }
|
||||||
|
|
||||||
|
public TaskState State { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.Hosting.Protocol;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.TaskServices.Contracts;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
||||||
|
{
|
||||||
|
public class TaskService
|
||||||
|
{
|
||||||
|
private static readonly Lazy<TaskService> instance = new Lazy<TaskService>(() => new TaskService());
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default, parameterless constructor.
|
||||||
|
/// </summary>
|
||||||
|
internal TaskService()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the singleton instance object
|
||||||
|
/// </summary>
|
||||||
|
public static TaskService Instance
|
||||||
|
{
|
||||||
|
get { return instance.Value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the service instance
|
||||||
|
/// </summary>
|
||||||
|
public void InitializeService(ServiceHost serviceHost, SqlToolsContext context)
|
||||||
|
{
|
||||||
|
serviceHost.SetRequestHandler(ListTasksRequest.Type, HandleListTasksRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles a list tasks request
|
||||||
|
/// </summary>
|
||||||
|
internal static async Task HandleListTasksRequest(
|
||||||
|
ListTasksParams listTasksParams,
|
||||||
|
RequestContext<ListTasksResponse> requestContext)
|
||||||
|
{
|
||||||
|
await requestContext.SendResult(new ListTasksResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Admin
|
||||||
|
{
|
||||||
|
public class CreateDatabaseTests
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Admin
|
||||||
|
{
|
||||||
|
public class CreateLoginTests
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.DisasterRecovery
|
||||||
|
{
|
||||||
|
public class BackupTests
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user