mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Agent work (WIP) (#597)
* Initial SQL Agent WIP * Fix test build break * wip * wip2 * additonal SQL Agent history parsing code * Fix namespace sorting * Hook up agent\jobs method * fixed agent service tests * added job history handler * Fix broken integration test build * code review refactoring * Added handler for job history request (#586) * fixed agent service tests * added job history handler * code review refactoring * Turn off another failing test * Disable failing test * refactored code * small refactor * code review changes * Feature/agent1 adbist (#592) * fixed agent service tests * added job history handler * code review refactoring * refactored code * small refactor * code review changes * changed constant casing * added handler for job actions * Remove unused code * Remove unused test file * Feature/agent1 adbist (#593) * fixed agent service tests * added job history handler * code review refactoring * refactored code * small refactor * code review changes * changed constant casing * added handler for job actions * Reenable disabled test * cleaned up code * added steps to job history * sort the job history steps * changed error handling for job action
This commit is contained in:
@@ -147,12 +147,41 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
DataTable dt = tuple.Item2;
|
||||
int count = dt.Rows.Count;
|
||||
var agentJobs = new List<AgentJobHistoryInfo>();
|
||||
|
||||
var agentStepMap = new Dictionary<DateTime, List<AgentJobStep>>();
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
var job = dt.Rows[i];
|
||||
agentJobs.Add(JobUtilities.ConvertToAgentJobHistoryInfo(job, sqlConnInfo));
|
||||
if (JobUtilities.IsStep(job, sqlConnInfo))
|
||||
{
|
||||
var agentJobStep = JobUtilities.ConvertToAgentJobStep(job, sqlConnInfo);
|
||||
if (agentStepMap.ContainsKey(agentJobStep.RunDate))
|
||||
{
|
||||
agentStepMap[agentJobStep.RunDate].Add(agentJobStep);
|
||||
}
|
||||
else
|
||||
{
|
||||
var agentJobSteps = new List<AgentJobStep>();
|
||||
agentJobSteps.Add(agentJobStep);
|
||||
agentStepMap[agentJobStep.RunDate] = agentJobSteps;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var agentJobHistoryInfo = JobUtilities.ConvertToAgentJobHistoryInfo(job, sqlConnInfo);
|
||||
agentJobs.Add(agentJobHistoryInfo);
|
||||
}
|
||||
}
|
||||
result.Succeeded = true;
|
||||
foreach (AgentJobHistoryInfo agentJobHistoryInfo in agentJobs)
|
||||
{
|
||||
if (agentStepMap.ContainsKey(agentJobHistoryInfo.RunDate))
|
||||
{
|
||||
var agentStepList = agentStepMap[agentJobHistoryInfo.RunDate].ToList();
|
||||
agentStepList.Sort(delegate (AgentJobStep s1, AgentJobStep s2) { return s1.StepId.CompareTo(s2.StepId); });
|
||||
agentJobHistoryInfo.Steps = agentStepList.ToArray();
|
||||
}
|
||||
}
|
||||
result.Jobs = agentJobs.ToArray();
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
@@ -168,9 +197,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// </summary>
|
||||
internal async Task HandleJobActionRequest(AgentJobActionParams parameters, RequestContext<AgentJobActionResult> requestContext)
|
||||
{
|
||||
var result = new AgentJobActionResult();
|
||||
try
|
||||
{
|
||||
var result = new AgentJobActionResult();
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
@@ -207,7 +236,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
result.Succeeded = false;
|
||||
result.ErrorMessage = e.Message;
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
public string OperatorPaged { get; set; }
|
||||
public int RetriesAttempted { get; set; }
|
||||
public string Server { get; set; }
|
||||
public AgentJobStep[] Steps { get; set; }
|
||||
}
|
||||
|
||||
public class AgentJobStep
|
||||
{
|
||||
public int StepId { get; set; }
|
||||
public string StepName { get; set; }
|
||||
public string Message { get; set; }
|
||||
public DateTime RunDate { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,6 +56,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
};
|
||||
}
|
||||
|
||||
public static bool IsStep(DataRow row, SqlConnectionInfo sqlConnectionInfo)
|
||||
{
|
||||
int stepId = Convert.ToInt32(row[UrnStepID], System.Globalization.CultureInfo.InvariantCulture);
|
||||
return stepId != 0;
|
||||
}
|
||||
|
||||
public static AgentJobHistoryInfo ConvertToAgentJobHistoryInfo(DataRow jobRow, SqlConnectionInfo sqlConnInfo)
|
||||
{
|
||||
// get all the values for a job history
|
||||
@@ -99,8 +105,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
jobHistoryInfo.OperatorPaged = operatorPaged;
|
||||
jobHistoryInfo.RetriesAttempted = retriesAttempted;
|
||||
jobHistoryInfo.Server = server;
|
||||
|
||||
return jobHistoryInfo;
|
||||
}
|
||||
|
||||
public static AgentJobStep ConvertToAgentJobStep(DataRow jobRow, SqlConnectionInfo sqlConnInfo)
|
||||
{
|
||||
int stepId = Convert.ToInt32(jobRow[UrnStepID], System.Globalization.CultureInfo.InvariantCulture);
|
||||
string stepName = Convert.ToString(jobRow[UrnStepName], System.Globalization.CultureInfo.InvariantCulture);
|
||||
string message = Convert.ToString(jobRow[UrnMessage], System.Globalization.CultureInfo.InvariantCulture);
|
||||
DateTime runDate = Convert.ToDateTime(jobRow[UrnRunDate], System.Globalization.CultureInfo.InvariantCulture);
|
||||
AgentJobStep step = new AgentJobStep();
|
||||
step.StepId = stepId;
|
||||
step.StepName = stepName;
|
||||
step.Message = message;
|
||||
step.RunDate = runDate;
|
||||
return step;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user