Added delete materialized run endpoints (#858)

* Added endpoint for fetching all notebook jobs

* Refractored NotebookJobInfo to AgentNotebookInfo to make it more consistent with the rest of the codebase

* Added Notebook History endpoint in contracts.

* Added Create, Update, Delete notebook endpoints. Also added separate fetch template, materialized notebook endpoints. This will make the Notebook Request and Notebook History responses lighter.

* AgentNotebookInfo is now derived from AgentJobInfo

* added fetch noteook history endpoint

* Added fetching materialized notebook endpoint

* Added code for cleaning up the directory

* Added create notebook api

* Added Update and delete notebook job

* Fixed notebook history API

* Added last run info to the script and template folder

* Added execute database feature for notebook Jobs

* SQL commands are now using sqlparameters to prevent
any injection attacks

* Changed rundate and runtime to string to preserve
leading zeros

* integration test for agentnotebooks api

* Made some changes mentioned in PR

* Refactored the code, removed enpoint logic from the notebook handler and
wrote test cases

* changes select statements, fixed a bug in the test job cleanup
and fixed other stuff mentioned in the PR.

* added notebook_error column in notebook history select statement

* Added get template notebook endpoint

* Added renaming and pinning notebook runs

* made tables names caps to handle servers with case sensitive queries

* made some changes to the enpoint points paths

* Added delete materialized notebooks endpoints

* Fixed a bug in delete, rename and pin apis where
requests from multiple clients with materializedID = 0
could have resulted in multiple rows getting created
on notebooks.nb_materialized table.

* fixed a merge conflict

* Made some changes mentioned in the PR
This commit is contained in:
Aasim Khan
2019-09-04 10:34:28 -07:00
committed by GitHub
parent 89623c1ae8
commit 8a12802fb9
4 changed files with 181 additions and 64 deletions

View File

@@ -131,7 +131,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
this.ServiceHost.SetRequestHandler(UpdateAgentNotebookRequest.Type, HandleUpdateAgentNotebookRequest);
this.ServiceHost.SetRequestHandler(UpdateAgentNotebookRunPinRequest.Type, HandleUpdateAgentNotebookRunPinRequest);
this.ServiceHost.SetRequestHandler(UpdateAgentNotebookRunNameRequest.Type, HandleUpdateAgentNotebookRunNameRequest);
this.ServiceHost.SetRequestHandler(DeleteNotebookMaterializedRequest.Type, HandleDeleteNotebookMaterializedRequest);
serviceHost.RegisterShutdownTask(async (shutdownParams, shutdownRequestContext) =>
{
@@ -1265,7 +1265,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
parameters.OwnerUri,
out connInfo);
result = GetAgentNotebookHistories(
result = await GetAgentNotebookHistories(
connInfo,
parameters.JobId,
parameters.JobName,
@@ -1320,7 +1320,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
result.NotebookTemplate = AgentNotebookHelper.GetTemplateNotebook(connInfo, parameters.JobId, parameters.TargetDatabase).Result;
result.NotebookTemplate = await AgentNotebookHelper.GetTemplateNotebook(connInfo, parameters.JobId, parameters.TargetDatabase);
result.Success = true;
}
catch (Exception e)
@@ -1426,7 +1426,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
// Calling update helper function
await AgentNotebookHelper.UpdateMaterializedNotebookName(
connInfo,
parameters.MaterializedId,
parameters.agentNotebookHistory,
parameters.TargetDatabase,
parameters.MaterializedNotebookName);
result.Success = true;
@@ -1455,7 +1455,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
// Calling update helper function
await AgentNotebookHelper.UpdateMaterializedNotebookPin(
connInfo,
parameters.MaterializedId,
parameters.agentNotebookHistory,
parameters.TargetDatabase,
parameters.MaterializedNotebookPin);
result.Success = true;
@@ -1470,7 +1470,36 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
});
}
public AgentNotebookHistoryResult GetAgentNotebookHistories(
internal async Task HandleDeleteNotebookMaterializedRequest(DeleteNotebookMaterializedParams parameters, RequestContext<ResultStatus> requestContext)
{
await Task.Run(async () =>
{
var result = new ResultStatus();
try
{
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
// Calling update helper function
await AgentNotebookHelper.DeleteMaterializedNotebook(
connInfo,
parameters.agentNotebookHistory,
parameters.TargetDatabase);
result.Success = true;
}
catch (Exception e)
{
result.Success = false;
result.ErrorMessage = e.ToString();
}
await requestContext.SendResult(result);
});
}
public async Task<AgentNotebookHistoryResult> GetAgentNotebookHistories
(
ConnectionInfo connInfo,
string jobId,
string jobName,
@@ -1519,7 +1548,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
var jobHistories = AgentUtilities.ConvertToAgentNotebookHistoryInfo(logEntries, job, steps);
// fetching notebook part of histories
Dictionary<string, DataRow> notebookHistoriesDict = new Dictionary<string, DataRow>();
DataTable materializedNotebookTable = AgentNotebookHelper.GetAgentNotebookHistories(connInfo, jobId, targetDatabase).Result;
DataTable materializedNotebookTable = await AgentNotebookHelper.GetAgentNotebookHistories(connInfo, jobId, targetDatabase);
foreach (DataRow materializedNotebookRow in materializedNotebookTable.Rows)
{
string materializedRunDateTime = materializedNotebookRow["run_date"].ToString() + materializedNotebookRow["run_time"].ToString();
@@ -1537,8 +1566,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
notebookHistory.MaterializedNotebookErrorInfo = notebookHistoriesDict[jobRuntime]["notebook_error"] as string;
notebookHistory.MaterializedNotebookName = notebookHistoriesDict[jobRuntime]["notebook_name"] as string;
notebookHistory.MaterializedNotebookPin = (bool)notebookHistoriesDict[jobRuntime]["pin"];
notebookHistory.MaterializedNotebookDeleted = (bool)notebookHistoriesDict[jobRuntime]["is_deleted"];
}
if (notebookHistory.MaterializedNotebookDeleted)
{
continue;
}
notebookHistories.Add(notebookHistory);
}
result.Histories = notebookHistories.ToArray();
tlog.CloseReader();