Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added endpoint for fetching all notebook jobs #834

Merged
merged 23 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0548b14
Added endpoint for fetching all notebook jobs
Jul 10, 2019
e93875b
Refractored NotebookJobInfo to AgentNotebookInfo to make it more cons…
Jul 10, 2019
f712b14
Added Notebook History endpoint in contracts.
Jul 11, 2019
16ff3e6
Added Create, Update, Delete notebook endpoints. Also added separate …
Jul 12, 2019
598b91e
AgentNotebookInfo is now derived from AgentJobInfo
Jul 13, 2019
e05e3a3
added fetch noteook history endpoint
aasimkhan30 Jul 15, 2019
b81d721
Added fetching materialized notebook endpoint
aasimkhan30 Jul 18, 2019
32be5ac
Added code for cleaning up the directory
aasimkhan30 Jul 18, 2019
b0a9fbf
Added create notebook api
aasimkhan30 Aug 2, 2019
05503eb
Added Update and delete notebook job
aasimkhan30 Aug 3, 2019
d06d027
Fixed notebook history API
aasimkhan30 Aug 6, 2019
ff74e7b
Added last run info to the script and template folder
aasimkhan30 Aug 6, 2019
7602f7e
Added execute database feature for notebook Jobs
aasimkhan30 Aug 10, 2019
0fa8005
Merge branch 'master' of https://github.com/microsoft/sqltoolsservice…
aasimkhan30 Aug 12, 2019
98ef5c8
SQL commands are now using sqlparameters to prevent
aasimkhan30 Aug 13, 2019
e025516
Changed rundate and runtime to string to preserve
aasimkhan30 Aug 13, 2019
42651dd
integration test for agentnotebooks api
aasimkhan30 Aug 13, 2019
d56a0ea
Made some changes mentioned in PR
aasimkhan30 Aug 13, 2019
fc71b39
Refactored the code, removed enpoint logic from the notebook handler and
aasimkhan30 Aug 16, 2019
2e2da19
Merge branch 'master' of https://github.com/microsoft/sqltoolsservice…
aasimkhan30 Aug 16, 2019
cf95619
changes select statements, fixed a bug in the test job cleanup
aasimkhan30 Aug 16, 2019
256e483
added notebook_error column in notebook history select statement
aasimkhan30 Aug 19, 2019
19442dc
Added get template notebook endpoint
aasimkhan30 Aug 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
305 changes: 293 additions & 12 deletions src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,37 @@ public static AgentJobInfo ConvertToAgentJobInfo(JobProperties job)
};
}

public static AgentNotebookInfo ConvertToAgentNotebookInfo(JobProperties job)
{
return new AgentNotebookInfo(){
Name = job.Name,
Description = job.Description,
CurrentExecutionStatus = (Contracts.JobExecutionStatus) job.CurrentExecutionStatus,
LastRunOutcome = (Contracts.CompletionResult) job.LastRunOutcome,
CurrentExecutionStep = job.CurrentExecutionStep,
Enabled = job.Enabled,
HasTarget = job.HasTarget,
HasSchedule = job.HasSchedule,
HasStep = job.HasStep,
Runnable = job.Runnable,
Category = job.Category,
CategoryId = job.CategoryID,
CategoryType = job.CategoryType,
LastRun = job.LastRun != null ? job.LastRun.ToString() : string.Empty,
NextRun = job.NextRun != null ? job.NextRun.ToString() : string.Empty,
JobId = job.JobID != null ? job.JobID.ToString() : null,
OperatorToEmail = job.OperatorToEmail,
OperatorToPage = job.OperatorToPage,
StartStepId = job.StartStepID,
EmailLevel = job.EmailLevel,
PageLevel = job.PageLevel,
EventLogLevel = job.EventLogLevel,
DeleteLevel = job.DeleteLevel,
Owner = job.Owner
};

}

internal static AgentJobStep ConvertToAgentJobStep(JobStep step, LogSourceJobHistory.LogEntryJobHistory logEntry, string jobId)
{
AgentJobStepInfo stepInfo = new AgentJobStepInfo();
Expand Down Expand Up @@ -120,6 +151,7 @@ internal static AgentJobStepInfo ConvertToAgentJobStepInfo(JobStep step, string
stepInfo.ProxyName = step.ProxyName;
return stepInfo;
}


internal static AgentScheduleInfo ConvertToAgentScheduleInfo(JobSchedule schedule)
{
Expand Down Expand Up @@ -221,5 +253,47 @@ public static List<AgentJobHistoryInfo> ConvertToAgentJobHistoryInfo(List<ILogEn
}
return jobs;
}

public static List<AgentNotebookHistoryInfo> ConvertToAgentNotebookHistoryInfo(List<ILogEntry> logEntries, DataRow jobRow, JobStepCollection steps)
{
List<AgentNotebookHistoryInfo> jobs = new List<AgentNotebookHistoryInfo>();
// get all the values for a job history
foreach (ILogEntry entry in logEntries)
{
// Make a new AgentJobHistoryInfo object
var jobHistoryInfo = new AgentNotebookHistoryInfo();
jobHistoryInfo.InstanceId = Convert.ToInt32(jobRow[UrnInstanceID], System.Globalization.CultureInfo.InvariantCulture);
jobHistoryInfo.JobId = (Guid) jobRow[UrnJobId];
var logEntry = entry as LogSourceJobHistory.LogEntryJobHistory;
jobHistoryInfo.RunStatus = entry.Severity == SeverityClass.Error ? 0 : 1;
jobHistoryInfo.SqlMessageId = logEntry.SqlMessageID;
jobHistoryInfo.Message = logEntry.Message;
jobHistoryInfo.StepId = logEntry.StepID;
jobHistoryInfo.StepName = logEntry.StepName;
jobHistoryInfo.SqlSeverity = logEntry.SqlSeverity;
jobHistoryInfo.JobName = logEntry.JobName;
jobHistoryInfo.RunDate = entry.PointInTime;
jobHistoryInfo.RunDuration = logEntry.Duration;
jobHistoryInfo.OperatorEmailed = logEntry.OperatorEmailed;
jobHistoryInfo.OperatorNetsent = logEntry.OperatorNetsent;
jobHistoryInfo.OperatorPaged = logEntry.OperatorPaged;
jobHistoryInfo.RetriesAttempted = logEntry.RetriesAttempted;
jobHistoryInfo.Server = logEntry.Server;

// Add steps to the job if any
var jobSteps = new List<AgentJobStep>();
foreach (LogSourceJobHistory.LogEntryJobHistory subEntry in entry.SubEntries)
{
if (steps.Contains(subEntry.StepName))
{
var jobId = jobRow[UrnJobId].ToString();
jobSteps.Add(AgentUtilities.ConvertToAgentJobStep(steps.ItemById(Convert.ToInt32(subEntry.StepID)), logEntry, jobId));
}
}
jobHistoryInfo.Steps = jobSteps.ToArray();
jobs.Add(jobHistoryInfo);
}
return jobs;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ public class AgentJobStep
public CompletionResult runStatus;
public AgentJobStepInfo stepDetails;
}

/// <summary>
/// a class for storing various properties of a agent notebook history
/// </summary>
public class AgentNotebookHistoryInfo : AgentJobHistoryInfo
{
public int MaterializedNotebookId { get; set; }
public int MaterializedNotebookErrorFlag { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove or rename to ...ErrorCode

public string MaterializedNotebookErrorInfo { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check other classes for naming conventions, but I think this would be something like ErrorMessage

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ public class AgentJobInfo
public AgentScheduleInfo[] JobSchedules { get; set; }
public AgentAlertInfo[] Alerts { get; set; }
}

/// <summary>
/// a class for storing variour properties of notebook Jobs
/// </summary>
public class AgentNotebookInfo : AgentJobInfo
{
public string TemplateId { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding comments of these properties describing they are..specifically the distinction between Target and Execution databases, etc.

public string TargetDatabase { get; set; }
public string LastRunNotebookError { get; set; }
public string ExecuteDatabase { get; set; }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
//
// 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 Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Microsoft.SqlTools.Utility;

namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
{
/// <summary>
aasimkhan30 marked this conversation as resolved.
Show resolved Hide resolved
/// SQL Agent Notebooks activity parameters
/// </summary>
public class AgentNotebooksParams : GeneralRequestDetails
{
public string OwnerUri { get; set; }

}

/// <summary>
/// SQL Agent Notebook activity result
/// </summary>
public class AgentNotebooksResult : ResultStatus
{
public AgentNotebookInfo[] Notebooks { get; set; }
}

/// <summary>
/// SQL Agent Notebook request type
/// </summary>
public class AgentNotebooksRequest
{
/// <summary>
/// Request definition
/// </summary>
public static readonly
RequestType<AgentNotebooksParams, AgentNotebooksResult> Type =
RequestType<AgentNotebooksParams, AgentNotebooksResult>.Create("agent/notebooks");
}

/// <summary>
/// SQL Agent Notebook history parameters
/// </summary>
public class AgentNotebookHistoryParams : GeneralRequestDetails
{
public string OwnerUri { get; set; }
public string JobId { get; set; }
public string TargetDatabase { get; set; }
public string JobName { get; set; }
}

/// <summary>
/// SQL Agent Notebook history results
/// </summary>
public class AgentNotebookHistoryResult : ResultStatus
{
public AgentNotebookHistoryInfo[] Histories { get; set; }
public AgentJobStepInfo[] Steps { get; set; }

public AgentScheduleInfo[] Schedules { get; set; }
}

/// <summary>
/// SQL Agent Notebook history request type
/// <summary>
public class AgentNotebookHistoryRequest
{
/// <summary>
/// Request definition
/// </summary>
public static readonly
RequestType<AgentNotebookHistoryParams, AgentNotebookHistoryResult> Type =
RequestType<AgentNotebookHistoryParams, AgentNotebookHistoryResult>.Create("agent/notebookhistory");
}

/// <summary>
/// SQL Agent create Notebook params
/// </summary>
public class CreateAgentNotebookParams : TaskRequestDetails
{
public string OwnerUri { get; set; }
public AgentNotebookInfo Notebook { get; set; }
public string TemplateFilePath { get; set; }
}

/// <summary>
/// SQL Agent create Notebook result
/// </summary>
public class CreateAgentNotebookResult : ResultStatus
{
public AgentNotebookInfo Job { get; set; }
}

/// <summary>
/// SQL Agent create Notebook request type
/// </summary>
public class CreateAgentNotebookRequest
aasimkhan30 marked this conversation as resolved.
Show resolved Hide resolved
{
public static readonly
RequestType<CreateAgentNotebookParams, CreateAgentNotebookResult> Type =
RequestType<CreateAgentNotebookParams, CreateAgentNotebookResult>.Create("agent/createnotebook");
}

/// <summary>
/// SQL Agent update Notebook params
/// </summary>
public class UpdateAgentNotebookParams : TaskRequestDetails
{
public string OwnerUri { get; set; }
public string OriginalNotebookName { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just OriginalName is fine?

public AgentNotebookInfo Notebook { get; set; }
public string TemplateFilePath { get; set; }
}

/// <summary>
/// SQL Agent update Notebook result
/// </summary>
public class UpdateAgentNotebookResult : ResultStatus
{
}

/// <summary>
/// SQL Agent update Notebook request type
/// </summary>
public class UpdateAgentNotebookRequest
{
/// <summary>
/// Request definition
/// </summary>
public static readonly
RequestType<UpdateAgentNotebookParams, UpdateAgentNotebookResult> Type =
RequestType<UpdateAgentNotebookParams, UpdateAgentNotebookResult>.Create("agent/updatenotebook");
}

/// <summary>
/// SQL Agent delete Notebook params
/// </summary>
public class DeleteAgentNotebookParams : TaskRequestDetails
{
public string OwnerUri { get; set; }
public AgentNotebookInfo Notebook { get; set; }
}

/// <summary>
/// SQL Agent delete Notebook request type
/// </summary>
public class DeleteAgentNotebookRequest
{
/// <summary>
/// Request definition
/// </summary>
public static readonly
RequestType<DeleteAgentNotebookParams, ResultStatus> Type =
RequestType<DeleteAgentNotebookParams, ResultStatus>.Create("agent/deletenotebook");
}

/// <summary>
/// SQL Agent Notebook materialized params
/// </summary>
public class AgentNotebookMaterializedParams : TaskRequestDetails
{
public string OwnerUri { get; set; }
public string TargetDatabase { get; set; }
public int NotebookMaterializedId { get; set; }
}

/// <summary>
/// SQL Agent Notebook materialized result
/// </summary>
public class AgentNotebookMaterializedResult : ResultStatus
{
public string NotebookMaterialized { get; set; }
}

/// <summary>
/// SQL Agent Notebook materialized request type
/// </summary>
public class AgentNotebookMaterializedRequest
{
public static readonly
RequestType<AgentNotebookMaterializedParams, AgentNotebookMaterializedResult> Type =
RequestType<AgentNotebookMaterializedParams, AgentNotebookMaterializedResult>.Create("agent/notebookmaterialized");
}

/// <summary>
/// SQL Agent Notebook templates params
/// </summary>
public class AgentNotebookTemplateParams : TaskRequestDetails
{
public string OwnerUri { get; set; }
public string JobId { get; set; }
public string TargetDatabase { get; set; }

}

/// <summary>
/// SQL Agent Notebook templates results
/// </summary>
public class AgentNotebookTemplateResult : ResultStatus
{
public string NotebookTemplate { get; set; }
}

/// <summary>
/// SQL Agent Notebook templates request type
/// </summary>
public class AgentNotebookTemplateRequest
{
public static readonly
RequestType<AgentNotebookTemplateParams, AgentNotebookTemplateResult> Type =
RequestType<AgentNotebookTemplateParams, AgentNotebookTemplateResult>.Create("agent/notebooktemplate");
}
}
Loading