mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Added more options to job changes and elaborated error messages (#775)
* job step type and error message details change * added newline for both environments * checked for inner exceptions * sorted imports
This commit is contained in:
@@ -299,6 +299,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
{
|
{
|
||||||
result.Success = false;
|
result.Success = false;
|
||||||
result.ErrorMessage = e.Message;
|
result.ErrorMessage = e.Message;
|
||||||
|
Exception exception = e.InnerException;
|
||||||
|
while (exception != null)
|
||||||
|
{
|
||||||
|
result.ErrorMessage += Environment.NewLine + "\t" + exception.Message;
|
||||||
|
exception = exception.InnerException;
|
||||||
|
}
|
||||||
await requestContext.SendResult(result);
|
await requestContext.SendResult(result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -920,7 +926,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await ConfigureAgentJobStep(ownerUri, step, configAction, runType);
|
await ConfigureAgentJobStep(ownerUri, step, configAction, runType, jobData, dataContainer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -929,7 +935,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
{
|
{
|
||||||
foreach (AgentScheduleInfo schedule in jobInfo.JobSchedules)
|
foreach (AgentScheduleInfo schedule in jobInfo.JobSchedules)
|
||||||
{
|
{
|
||||||
await ConfigureAgentSchedule(ownerUri, schedule, configAction, runType);
|
await ConfigureAgentSchedule(ownerUri, schedule, configAction, runType, jobData, dataContainer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -939,7 +945,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
foreach (AgentAlertInfo alert in jobInfo.Alerts)
|
foreach (AgentAlertInfo alert in jobInfo.Alerts)
|
||||||
{
|
{
|
||||||
alert.JobId = jobData.Job.JobID.ToString();
|
alert.JobId = jobData.Job.JobID.ToString();
|
||||||
await ConfigureAgentAlert(ownerUri, alert.Name, alert, configAction, runType);
|
await ConfigureAgentAlert(ownerUri, alert.Name, alert, configAction, runType, jobData, dataContainer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -956,7 +962,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
string ownerUri,
|
string ownerUri,
|
||||||
AgentJobStepInfo stepInfo,
|
AgentJobStepInfo stepInfo,
|
||||||
ConfigAction configAction,
|
ConfigAction configAction,
|
||||||
RunType runType)
|
RunType runType,
|
||||||
|
JobData jobData = null,
|
||||||
|
CDataContainer dataContainer = null)
|
||||||
{
|
{
|
||||||
return await Task<Tuple<bool, string>>.Run(() =>
|
return await Task<Tuple<bool, string>>.Run(() =>
|
||||||
{
|
{
|
||||||
@@ -967,9 +975,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
return new Tuple<bool, string>(false, "JobName cannot be null");
|
return new Tuple<bool, string>(false, "JobName cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
JobData jobData;
|
if (jobData == null)
|
||||||
CDataContainer dataContainer;
|
{
|
||||||
CreateJobData(ownerUri, stepInfo.JobName, out dataContainer, out jobData);
|
CreateJobData(ownerUri, stepInfo.JobName, out dataContainer, out jobData);
|
||||||
|
}
|
||||||
|
|
||||||
using (var actions = new JobStepsActions(dataContainer, jobData, stepInfo, configAction))
|
using (var actions = new JobStepsActions(dataContainer, jobData, stepInfo, configAction))
|
||||||
{
|
{
|
||||||
@@ -991,14 +1000,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
string alertName,
|
string alertName,
|
||||||
AgentAlertInfo alert,
|
AgentAlertInfo alert,
|
||||||
ConfigAction configAction,
|
ConfigAction configAction,
|
||||||
RunType runType)
|
RunType runType,
|
||||||
|
JobData jobData = null,
|
||||||
|
CDataContainer dataContainer = null)
|
||||||
{
|
{
|
||||||
return await Task<Tuple<bool, string>>.Run(() =>
|
return await Task<Tuple<bool, string>>.Run(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CDataContainer dataContainer;
|
|
||||||
JobData jobData = null;
|
|
||||||
// If the alert is being created outside of a job
|
// If the alert is being created outside of a job
|
||||||
if (string.IsNullOrWhiteSpace(alert.JobName))
|
if (string.IsNullOrWhiteSpace(alert.JobName))
|
||||||
{
|
{
|
||||||
@@ -1007,9 +1016,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If the alert is being created inside a job
|
if (jobData == null)
|
||||||
CreateJobData(ownerUri, alert.JobName, out dataContainer, out jobData);
|
{
|
||||||
|
// If the alert is being created inside a job
|
||||||
|
CreateJobData(ownerUri, alert.JobName, out dataContainer, out jobData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
STParameters param = new STParameters(dataContainer.Document);
|
STParameters param = new STParameters(dataContainer.Document);
|
||||||
param.SetParam("alert", alertName);
|
param.SetParam("alert", alertName);
|
||||||
@@ -1095,15 +1107,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
string ownerUri,
|
string ownerUri,
|
||||||
AgentScheduleInfo schedule,
|
AgentScheduleInfo schedule,
|
||||||
ConfigAction configAction,
|
ConfigAction configAction,
|
||||||
RunType runType)
|
RunType runType,
|
||||||
|
JobData jobData = null,
|
||||||
|
CDataContainer dataContainer = null)
|
||||||
{
|
{
|
||||||
return await Task<bool>.Run(() =>
|
return await Task<bool>.Run(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
JobData jobData;
|
if (jobData == null)
|
||||||
CDataContainer dataContainer;
|
{
|
||||||
CreateJobData(ownerUri, schedule.JobName, out dataContainer, out jobData);
|
CreateJobData(ownerUri, schedule.JobName, out dataContainer, out jobData);
|
||||||
|
}
|
||||||
|
|
||||||
const string UrnFormatStr = "Server[@Name='{0}']/JobServer[@Name='{0}']/Job[@Name='{1}']/Schedule[@Name='{2}']";
|
const string UrnFormatStr = "Server[@Name='{0}']/JobServer[@Name='{0}']/Job[@Name='{1}']/Schedule[@Name='{2}']";
|
||||||
string serverName = dataContainer.Server.Name.ToUpper();
|
string serverName = dataContainer.Server.Name.ToUpper();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||||
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
||||||
|
|
||||||
@@ -33,8 +34,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
public const string UrnRetriesAttempted = "RetriesAttempted";
|
public const string UrnRetriesAttempted = "RetriesAttempted";
|
||||||
public const string UrnServer = "Server";
|
public const string UrnServer = "Server";
|
||||||
internal const string UrnServerTime = "CurrentDate";
|
internal const string UrnServerTime = "CurrentDate";
|
||||||
|
|
||||||
public static AgentJobInfo ConvertToAgentJobInfo(JobProperties job)
|
public static AgentJobInfo ConvertToAgentJobInfo(JobProperties job)
|
||||||
{
|
{
|
||||||
return new AgentJobInfo
|
return new AgentJobInfo
|
||||||
{
|
{
|
||||||
@@ -217,5 +218,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
}
|
}
|
||||||
return jobs;
|
return jobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AgentSubSystem ConvertToAgentSubSytem(string subSystem)
|
||||||
|
{
|
||||||
|
switch(subSystem)
|
||||||
|
{
|
||||||
|
case ("Transact-SQL script (T-SQL"):
|
||||||
|
return AgentSubSystem.TransactSql;
|
||||||
|
case ("Operating system (CmdExec)"):
|
||||||
|
return AgentSubSystem.CmdExec;
|
||||||
|
case ("PowerShell"):
|
||||||
|
return AgentSubSystem.PowerShell;
|
||||||
|
default:
|
||||||
|
return AgentSubSystem.TransactSql;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -659,10 +659,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
if (jobInfo != null)
|
if (jobInfo != null)
|
||||||
{
|
{
|
||||||
this.currentName = jobInfo.Name;
|
this.currentName = jobInfo.Name;
|
||||||
this.owner = jobInfo.Owner;
|
this.Owner = jobInfo.Owner;
|
||||||
this.description = jobInfo.Description;
|
this.Description = jobInfo.Description;
|
||||||
this.enabled = jobInfo.Enabled;
|
this.Enabled = jobInfo.Enabled;
|
||||||
this.startStepID = jobInfo.StartStepId;
|
this.startStepID = jobInfo.StartStepId;
|
||||||
|
this.Category = ConvertStringToCategory(jobInfo.Category);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -188,6 +188,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SubSystem
|
||||||
|
/// </summary>
|
||||||
|
public AgentSubSystem Subsystem
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.subSystem;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.subSystem = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// indicates whether the job exists on the server
|
/// indicates whether the job exists on the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Agent;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||||
|
|
||||||
@@ -43,6 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
this.data.ID = stepInfo.Id;
|
this.data.ID = stepInfo.Id;
|
||||||
this.data.Name = stepInfo.StepName;
|
this.data.Name = stepInfo.StepName;
|
||||||
this.data.Command = stepInfo.Command;
|
this.data.Command = stepInfo.Command;
|
||||||
|
this.data.Subsystem = AgentUtilities.ConvertToAgentSubSytem(stepInfo.SubSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool DoPreProcessExecution(RunType runType, out ExecutionMode executionResult)
|
protected override bool DoPreProcessExecution(RunType runType, out ExecutionMode executionResult)
|
||||||
|
|||||||
Reference in New Issue
Block a user