Add Agent Job and Job Step request handlers (#635)

* Stage changes

* Fix update job request handler

* WIP

* Additional agent handler updates

* Setup agent job step create test

* Fix Step update handler
This commit is contained in:
Karl Burtram
2018-06-13 10:02:25 -07:00
committed by GitHub
parent 7c1f78a678
commit 8dda34c95a
52 changed files with 705 additions and 619 deletions

View File

@@ -0,0 +1,71 @@
//
// 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.Threading.Tasks;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Agent;
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Moq;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
{
public class AgentJobStepTests
{
/// <summary>
/// TestHandleCreateAgentJobStepRequest
/// </summary>
[Fact]
public async Task TestHandleCreateAgentJobStepRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
// setup
var service = new AgentService();
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
var job = AgentTestUtils.GetTestJobInfo();
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
await AgentTestUtils.CreateAgentJob(service, connectionResult, job);
var stepInfo = AgentTestUtils.GetTestJobStepInfo(connectionResult, job);
// test
await AgentTestUtils.CreateAgentJobStep(service, connectionResult, stepInfo);
// cleanup
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
}
}
/// <summary>
/// TestHandleUpdateAgentJobStepRequest
/// </summary>
[Fact]
public async Task TestHandleUpdateAgentJobStepRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
// setup
var service = new AgentService();
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
var job = AgentTestUtils.GetTestJobInfo();
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
await AgentTestUtils.CreateAgentJob(service, connectionResult, job);
var stepInfo = AgentTestUtils.GetTestJobStepInfo(connectionResult, job);
await AgentTestUtils.CreateAgentJobStep(service, connectionResult, stepInfo);
// test
stepInfo.Script = "SELECT * FROM sys.objects";
await AgentTestUtils.UpdateAgentJobStep(service, connectionResult, stepInfo);
// cleanup
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
}
}
}
}

View File

@@ -10,6 +10,7 @@ using Microsoft.SqlTools.ServiceLayer.Agent;
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Moq;
using Xunit;
@@ -20,68 +21,66 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
/// <summary>
/// TestHandleCreateAgentJobRequest
/// </summary>
//[Fact]
[Fact]
public async Task TestHandleCreateAgentJobRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
var createContext = new Mock<RequestContext<CreateAgentJobResult>>();
// setup
var service = new AgentService();
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
await service.HandleCreateAgentJobRequest(new CreateAgentJobParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Job = new AgentJobInfo()
{
Name = "Test Job",
Owner = "sa",
Description = "Test job description",
CurrentExecutionStatus = 1,
LastRunOutcome = 1,
CurrentExecutionStep = "Step 1",
Enabled = false,
HasTarget = false,
HasSchedule = false,
HasStep = false,
Runnable = true,
Category = "Cateory 1",
CategoryId = 1,
CategoryType = 1,
LastRun = "today",
NextRun = "tomorrow",
JobId = Guid.NewGuid().ToString()
}
}, createContext.Object);
createContext.VerifyAll();
var job = AgentTestUtils.GetTestJobInfo();
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
// test
await AgentTestUtils.CreateAgentJob(service, connectionResult, job);
// cleanup
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
}
}
/// <summary>
/// TestHandleCreateAgentJobStepRequest
/// TestHandleUpdateAgentJobRequest
/// </summary>
//[Fact]
public async Task TestHandleCreateAgentJobStepRequest()
[Fact]
public async Task TestHandleUpdateAgentJobRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
var createContext = new Mock<RequestContext<CreateAgentJobStepResult>>();
// setup
var service = new AgentService();
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
await service.HandleCreateAgentJobStepRequest(new CreateAgentJobStepParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Step = new AgentJobStepInfo()
{
// JobId = Guid.NewGuid().ToString(),
Script = @"c:\xplat\test.sql",
ScriptName = "Test Script",
var job = AgentTestUtils.GetTestJobInfo();
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
await AgentTestUtils.CreateAgentJob(service, connectionResult, job);
}
}, createContext.Object);
createContext.VerifyAll();
// test
await AgentTestUtils.UpdateAgentJob(service, connectionResult, job);
// cleanup
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
}
}
/// <summary>
/// TestHandleDeleteAgentJobRequest
/// </summary>
[Fact]
public async Task TestHandleDeleteAgentJobRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
// setup
var service = new AgentService();
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
var job = AgentTestUtils.GetTestJobInfo();
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
await AgentTestUtils.CreateAgentJob(service, connectionResult, job);
// test
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
}
}
}
}

View File

@@ -3,16 +3,138 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Threading.Tasks;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Agent;
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Moq;
using static Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility.LiveConnectionHelper;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
{
public static class AgentTestUtils
{
internal static AgentJobStepInfo GetTestJobStepInfo(
TestConnectionResult connectionResult,
AgentJobInfo job,
string stepName = "Test Job Step1")
{
return new AgentJobStepInfo()
{
Id = 1,
JobName = job.Name,
StepName = stepName,
SubSystem = "T-SQL",
Script = "SELECT @@VERSION",
DatabaseName = connectionResult.ConnectionInfo.ConnectionDetails.DatabaseName,
DatabaseUserName = connectionResult.ConnectionInfo.ConnectionDetails.UserName,
Server = connectionResult.ConnectionInfo.ConnectionDetails.ServerName
};
}
internal static AgentJobInfo GetTestJobInfo()
{
return new AgentJobInfo()
{
Name = "Test Job",
Owner = "sa",
Description = "Test job description",
CurrentExecutionStatus = 1,
LastRunOutcome = 1,
CurrentExecutionStep = "Step 1",
Enabled = false,
HasTarget = false,
HasSchedule = false,
HasStep = false,
Runnable = true,
Category = "Cateory 1",
CategoryId = 1,
CategoryType = 1,
LastRun = "today",
NextRun = "tomorrow",
JobId = Guid.NewGuid().ToString()
};
}
internal static async Task CreateAgentJob(
AgentService service,
TestConnectionResult connectionResult,
AgentJobInfo job)
{
var context = new Mock<RequestContext<CreateAgentJobResult>>();
await service.HandleCreateAgentJobRequest(new CreateAgentJobParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Job = job
}, context.Object);
context.VerifyAll();
}
internal static async Task UpdateAgentJob(
AgentService service,
TestConnectionResult connectionResult,
AgentJobInfo job)
{
job.Description = "Update job description";
var context = new Mock<RequestContext<UpdateAgentJobResult>>();
await service.HandleUpdateAgentJobRequest(new UpdateAgentJobParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Job = job
}, context.Object);
context.VerifyAll();
}
internal static async Task DeleteAgentJob(
AgentService service,
TestConnectionResult connectionResult,
AgentJobInfo job,
bool verify = true)
{
var context = new Mock<RequestContext<ResultStatus>>();
await service.HandleDeleteAgentJobRequest(new DeleteAgentJobParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Job = job
}, context.Object);
if (verify)
{
context.VerifyAll();
}
}
internal static async Task CreateAgentJobStep(
AgentService service,
TestConnectionResult connectionResult,
AgentJobStepInfo stepInfo)
{
var context = new Mock<RequestContext<CreateAgentJobStepResult>>();
await service.HandleCreateAgentJobStepRequest(new CreateAgentJobStepParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Step = stepInfo
}, context.Object);
context.VerifyAll();
}
internal static async Task UpdateAgentJobStep(
AgentService service,
TestConnectionResult connectionResult,
AgentJobStepInfo stepInfo)
{
var context = new Mock<RequestContext<UpdateAgentJobStepResult>>();
await service.HandleUpdateAgentJobStepRequest(new UpdateAgentJobStepParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Step = stepInfo
}, context.Object);
context.VerifyAll();
}
internal static async Task<AgentAlertInfo[]> GetAgentAlerts(string connectionUri)
{
var requestParams = new AgentAlertsParams()

View File

@@ -17,6 +17,7 @@ using Microsoft.SqlTools.ServiceLayer.DisasterRecovery;
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts;
using Microsoft.SqlTools.ServiceLayer.FileBrowser;
using Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts;
using Microsoft.SqlTools.ServiceLayer.Management;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;

View File

@@ -12,6 +12,7 @@ using Microsoft.SqlTools.ServiceLayer.DisasterRecovery;
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts;
using Microsoft.SqlTools.ServiceLayer.FileBrowser;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
using Microsoft.SqlTools.ServiceLayer.Management;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DisasterRecovery