Added renaming and pinning agent notebook runs (#855)

* 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 enpointpoint paths
This commit is contained in:
Aasim Khan
2019-08-28 18:21:33 -07:00
committed by GitHub
parent 361287a81b
commit 55c82fbcc4
4 changed files with 166 additions and 6 deletions

View File

@@ -263,7 +263,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
materialized_id,
run_time,
run_date,
notebook_error
notebook_error,
pin,
notebook_name
FROM
notebooks.nb_materialized
WHERE JOB_ID = @jobId";
@@ -406,9 +408,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
string notebookDatabaseSetupQueryString =
@"
IF NOT EXISTS (
SELECT schema_name
FROM information_schema.schemata
WHERE schema_name = 'notebooks' )
SELECT SCHEMA_NAME
FROM INFORMATION_SCHEMA.SCHEMATA
WHERE SCHEMA_NAME = 'notebooks' )
BEGIN
EXEC sp_executesql N'CREATE SCHEMA notebooks'
END
@@ -434,7 +436,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
run_time VARCHAR(100),
run_date VARCHAR(100),
notebook NVARCHAR(MAX),
notebook_error NVARCHAR(MAX)
notebook_error NVARCHAR(MAX),
pin BIT NOT NULL DEFAULT 0,
notebook_name NVARCHAR(MAX) NOT NULL default('')
)
END
USE [msdb];
@@ -569,7 +573,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
string targetDatabase,
string templateFileContents)
{
String getNotebookTemplateQuery =
string getNotebookTemplateQuery =
@"
SELECT notebook
from
@@ -589,5 +593,53 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
DataRow templateDataRow = templateDataTable.Rows[0];
return templateDataRow["notebook"] as string;
}
public static async Task UpdateMaterializedNotebookName(
ConnectionInfo connInfo,
int materializedId,
string targetDatabase,
string name)
{
string updateMaterializedNotebookNameQuery =
@"
UPDATE notebooks.nb_materialized
SET
notebook_name = @notebookName
WHERE
materialized_id = @materializedId
";
List<SqlParameter> updateMaterializedNotebookNameParams = new List<SqlParameter>();
updateMaterializedNotebookNameParams.Add(new SqlParameter("notebookName", name));
updateMaterializedNotebookNameParams.Add(new SqlParameter("materializedId", materializedId));
await AgentNotebookHelper.ExecuteSqlQueries(
connInfo,
updateMaterializedNotebookNameQuery,
updateMaterializedNotebookNameParams,
targetDatabase);
}
public static async Task UpdateMaterializedNotebookPin(
ConnectionInfo connInfo,
string materializedId,
string targetDatabase,
bool pin)
{
string updateMaterializedNotebookPinQuery =
@"
UPDATE notebooks.nb_materialized
SET
pin = @notebookPin
WHERE
materialized_id = @materializedId
";
List<SqlParameter> updateMaterializedNotebookPinParams = new List<SqlParameter>();
updateMaterializedNotebookPinParams.Add(new SqlParameter("notebookPin", pin));
updateMaterializedNotebookPinParams.Add(new SqlParameter("materializedId", materializedId));
await AgentNotebookHelper.ExecuteSqlQueries(
connInfo,
updateMaterializedNotebookPinQuery,
updateMaterializedNotebookPinParams,
targetDatabase);
}
}
}