mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-27 17:23:21 -05:00
Agent/edit steps (#2846)
* steps can be now edited * edit jobs now works with steps, alerts, schedules etc * fixed bug when new step in new dialog would fail
This commit is contained in:
@@ -22,7 +22,7 @@ export interface IJobManagementService {
|
||||
fireOnDidChange(): void;
|
||||
|
||||
getJobs(connectionUri: string): Thenable<sqlops.AgentJobsResult>;
|
||||
getJobHistory(connectionUri: string, jobID: string): Thenable<sqlops.AgentJobHistoryResult>;
|
||||
getJobHistory(connectionUri: string, jobID: string, jobName: string): Thenable<sqlops.AgentJobHistoryResult>;
|
||||
deleteJob(connectionUri: string, job: sqlops.AgentJobInfo): Thenable<sqlops.ResultStatus>;
|
||||
|
||||
deleteJobStep(connectionUri: string, step: sqlops.AgentJobStepInfo): Thenable<sqlops.ResultStatus>;
|
||||
|
||||
@@ -43,9 +43,9 @@ export class JobManagementService implements IJobManagementService {
|
||||
});
|
||||
}
|
||||
|
||||
public getJobHistory(connectionUri: string, jobID: string): Thenable<sqlops.AgentJobHistoryResult> {
|
||||
public getJobHistory(connectionUri: string, jobID: string, jobName: string): Thenable<sqlops.AgentJobHistoryResult> {
|
||||
return this._runAction(connectionUri, (runner) => {
|
||||
return runner.getJobHistory(connectionUri, jobID);
|
||||
return runner.getJobHistory(connectionUri, jobID, jobName);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -142,6 +142,9 @@ export class JobCacheObject {
|
||||
_serviceBrand: any;
|
||||
private _jobs: sqlops.AgentJobInfo[] = [];
|
||||
private _jobHistories: { [jobID: string]: sqlops.AgentJobHistoryInfo[]; } = {};
|
||||
private _jobSteps: { [jobID: string]: sqlops.AgentJobStepInfo[]; } = {};
|
||||
private _jobAlerts: { [jobID: string]: sqlops.AgentAlertInfo[]; } = {};
|
||||
private _jobSchedules: { [jobID: string]: sqlops.AgentJobScheduleInfo[]; } = {};
|
||||
private _runCharts: { [jobID: string]: string[]; } = {};
|
||||
private _prevJobID: string;
|
||||
private _serverName: string;
|
||||
@@ -176,6 +179,18 @@ export class JobCacheObject {
|
||||
return this._runCharts[jobID];
|
||||
}
|
||||
|
||||
public getJobSteps(jobID: string): sqlops.AgentJobStepInfo[] {
|
||||
return this._jobSteps[jobID];
|
||||
}
|
||||
|
||||
public getJobAlerts(jobID: string): sqlops.AgentAlertInfo[] {
|
||||
return this._jobAlerts[jobID];
|
||||
}
|
||||
|
||||
public getJobSchedules(jobID: string): sqlops.AgentJobScheduleInfo[] {
|
||||
return this._jobSchedules[jobID];
|
||||
}
|
||||
|
||||
/* Setters */
|
||||
public set jobs(value: sqlops.AgentJobInfo[]) {
|
||||
this._jobs = value;
|
||||
@@ -204,4 +219,16 @@ export class JobCacheObject {
|
||||
public set dataView(value: Slick.Data.DataView<any>) {
|
||||
this._dataView = value;
|
||||
}
|
||||
|
||||
public setJobSteps(jobID: string, value: sqlops.AgentJobStepInfo[]) {
|
||||
this._jobSteps[jobID] = value;
|
||||
}
|
||||
|
||||
public setJobAlerts(jobID: string, value: sqlops.AgentAlertInfo[]) {
|
||||
this._jobAlerts[jobID] = value;
|
||||
}
|
||||
|
||||
public setJobSchedules(jobID: string, value: sqlops.AgentJobScheduleInfo[]) {
|
||||
this._jobSchedules[jobID] = value;
|
||||
}
|
||||
}
|
||||
@@ -150,16 +150,17 @@ export class JobHistoryComponent extends JobManagementView implements OnInit {
|
||||
private loadHistory() {
|
||||
const self = this;
|
||||
let ownerUri: string = this._commonService.connectionManagementService.connectionInfo.ownerUri;
|
||||
this._jobManagementService.getJobHistory(ownerUri, this._agentViewComponent.jobId).then((result) => {
|
||||
if (result && result.jobs) {
|
||||
if (result.jobs.length > 0) {
|
||||
let jobName = this._agentViewComponent.agentJobInfo.name;
|
||||
this._jobManagementService.getJobHistory(ownerUri, this._agentViewComponent.jobId, jobName).then((result) => {
|
||||
if (result && result.histories) {
|
||||
if (result.histories.length > 0) {
|
||||
self._showPreviousRuns = true;
|
||||
self.buildHistoryTree(self, result.jobs);
|
||||
self.buildHistoryTree(self, result.histories);
|
||||
if (self._agentViewComponent.showHistory) {
|
||||
self._cd.detectChanges();
|
||||
}
|
||||
} else {
|
||||
self._jobCacheObject.setJobHistory(self._agentViewComponent.jobId, result.jobs);
|
||||
self._jobCacheObject.setJobHistory(self._agentViewComponent.jobId, result.histories);
|
||||
self._showPreviousRuns = false;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -53,6 +53,7 @@ export abstract class JobManagementView extends TabChild implements AfterContent
|
||||
if (!this.isInitialized) {
|
||||
this._showProgressWheel = true;
|
||||
this.onFirstVisible();
|
||||
this.layout();
|
||||
this.isInitialized = true;
|
||||
}
|
||||
} else if (this.isVisible === true && this._parentComponent.refresh === true) {
|
||||
|
||||
@@ -36,8 +36,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
|
||||
import { IDashboardService } from 'sql/services/dashboard/common/dashboardService';
|
||||
import { escape } from 'sql/base/common/strings';
|
||||
import { IWorkbenchThemeService, IColorTheme } from 'vs/workbench/services/themes/common/workbenchThemeService';
|
||||
import { tableBackground, cellBackground, tableHoverBackground, jobsHeadingBackground, cellBorderColor } from 'sql/common/theme/colors';
|
||||
import { JobStepsViewRow } from 'sql/parts/jobManagement/views/jobStepsViewTree';
|
||||
import { tableBackground, cellBackground, cellBorderColor } from 'sql/common/theme/colors';
|
||||
|
||||
export const JOBSVIEW_SELECTOR: string = 'jobsview-component';
|
||||
export const ROW_HEIGHT: number = 45;
|
||||
@@ -87,7 +86,10 @@ export class JobsViewComponent extends JobManagementView implements OnInit {
|
||||
private sortingStylingMap: { [columnName: string]: any; } = {};
|
||||
|
||||
public jobs: sqlops.AgentJobInfo[];
|
||||
public jobHistories: { [jobId: string]: sqlops.AgentJobHistoryInfo[]; } = Object.create(null);
|
||||
private jobHistories: { [jobId: string]: sqlops.AgentJobHistoryInfo[]; } = Object.create(null);
|
||||
private jobSteps: { [jobId: string]: sqlops.AgentJobStepInfo[]; } = Object.create(null);
|
||||
private jobAlerts: { [jobId: string]: sqlops.AgentAlertInfo[]; } = Object.create(null);
|
||||
private jobSchedules: { [jobId: string]: sqlops.AgentJobScheduleInfo[]; } = Object.create(null);
|
||||
public contextAction = NewJobAction;
|
||||
|
||||
@ViewChild('jobsgrid') _gridEl: ElementRef;
|
||||
@@ -579,10 +581,14 @@ export class JobsViewComponent extends JobManagementView implements OnInit {
|
||||
private async curateJobHistory(jobs: sqlops.AgentJobInfo[], ownerUri: string) {
|
||||
const self = this;
|
||||
jobs.forEach(async (job) => {
|
||||
await this._jobManagementService.getJobHistory(ownerUri, job.jobId).then((result) => {
|
||||
if (result && result.jobs) {
|
||||
self.jobHistories[job.jobId] = result.jobs;
|
||||
self._jobCacheObject.setJobHistory(job.jobId, result.jobs);
|
||||
await this._jobManagementService.getJobHistory(ownerUri, job.jobId, job.name).then((result) => {
|
||||
if (result) {
|
||||
self.jobSteps[job.jobId] = result.steps ? result.steps : [];
|
||||
self.jobAlerts[job.jobId] = result.alerts ? result.alerts : [];
|
||||
self.jobSchedules[job.jobId] = result.schedules ? result.schedules : [];
|
||||
self.jobHistories[job.jobId] = result.histories ? result.histories : [];
|
||||
self._jobCacheObject.setJobSteps(job.jobId, self.jobSteps[job.jobId]);
|
||||
self._jobCacheObject.setJobHistory(job.jobId, self.jobHistories[job.jobId]);
|
||||
let jobHistories = self._jobCacheObject.getJobHistory(job.jobId);
|
||||
let previousRuns: sqlops.AgentJobHistoryInfo[];
|
||||
if (jobHistories.length >= 5) {
|
||||
@@ -592,7 +598,7 @@ export class JobsViewComponent extends JobManagementView implements OnInit {
|
||||
}
|
||||
self.createJobChart(job.jobId, previousRuns);
|
||||
if (self._agentViewComponent.expanded.has(job.jobId)) {
|
||||
let lastJobHistory = jobHistories[result.jobs.length - 1];
|
||||
let lastJobHistory = jobHistories[jobHistories.length - 1];
|
||||
let item = self.dataView.getItemById(job.jobId + '.error');
|
||||
let noStepsMessage = nls.localize('jobsView.noSteps', 'No Steps available for this job.');
|
||||
let errorMessage = lastJobHistory ? lastJobHistory.message : noStepsMessage;
|
||||
@@ -909,29 +915,22 @@ export class JobsViewComponent extends JobManagementView implements OnInit {
|
||||
jobId = data.getItem(rowIndex - 1).jobId;
|
||||
}
|
||||
}
|
||||
|
||||
let job: sqlops.AgentJobInfo[] = this.jobs.filter(job => {
|
||||
return job.jobId === jobId;
|
||||
});
|
||||
let jobHistories = this.jobHistories[jobId];
|
||||
let steps: sqlops.AgentJobStep[] = undefined;
|
||||
let schedules: sqlops.AgentJobScheduleInfo[] = undefined;
|
||||
let alerts: sqlops.AgentAlertInfo[] = undefined;
|
||||
|
||||
// add steps
|
||||
if (this.jobSteps && this.jobSteps[jobId]) {
|
||||
let steps = this.jobSteps[jobId];
|
||||
job[0].JobSteps = steps;
|
||||
}
|
||||
let jobHistories = this.jobHistories[job[0].jobId];
|
||||
let schedules: sqlops.AgentJobScheduleInfo[] = this.jobSchedules[job[0].jobId];
|
||||
let alerts: sqlops.AgentAlertInfo[] = this.jobAlerts[job[0].jobId];
|
||||
if (jobHistories && jobHistories[jobHistories.length-1]) {
|
||||
// add steps
|
||||
steps = jobHistories[jobHistories.length-1].steps;
|
||||
if (steps && steps.length > 0) {
|
||||
if (!job[0].JobSteps) {
|
||||
job[0].JobSteps = [];
|
||||
}
|
||||
if (job[0].JobSteps.length !== steps.length) {
|
||||
job[0].JobSteps = [];
|
||||
steps.forEach(step => {
|
||||
job[0].JobSteps.push(step.stepDetails);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// add schedules
|
||||
schedules = jobHistories[jobHistories.length-1].schedules;
|
||||
if (schedules && schedules.length > 0) {
|
||||
if (!job[0].JobSchedules) {
|
||||
job[0].JobSchedules = [];
|
||||
@@ -944,7 +943,6 @@ export class JobsViewComponent extends JobManagementView implements OnInit {
|
||||
}
|
||||
}
|
||||
// add alerts
|
||||
alerts = jobHistories[jobHistories.length-1].alerts;
|
||||
if (!job[0].Alerts) {
|
||||
job[0].Alerts = [];
|
||||
}
|
||||
|
||||
19
src/sql/sqlops.d.ts
vendored
19
src/sql/sqlops.d.ts
vendored
@@ -1266,6 +1266,16 @@ declare module 'sqlops' {
|
||||
Last = 16
|
||||
}
|
||||
|
||||
export enum JobExecutionStatus {
|
||||
Executing = 1,
|
||||
WaitingForWorkerThread = 2,
|
||||
BetweenRetries = 3,
|
||||
Idle = 4,
|
||||
Suspended = 5,
|
||||
WaitingForStepToFinish = 6,
|
||||
PerformingCompletionAction = 7
|
||||
}
|
||||
|
||||
export interface AgentJobInfo {
|
||||
name: string;
|
||||
owner: string;
|
||||
@@ -1371,8 +1381,6 @@ declare module 'sqlops' {
|
||||
retriesAttempted: string;
|
||||
server: string;
|
||||
steps: AgentJobStep[];
|
||||
schedules: AgentJobScheduleInfo[];
|
||||
alerts: AgentAlertInfo[];
|
||||
}
|
||||
|
||||
export interface AgentProxyInfo {
|
||||
@@ -1441,7 +1449,10 @@ declare module 'sqlops' {
|
||||
}
|
||||
|
||||
export interface AgentJobHistoryResult extends ResultStatus {
|
||||
jobs: AgentJobHistoryInfo[];
|
||||
histories: AgentJobHistoryInfo[];
|
||||
steps: AgentJobStepInfo[];
|
||||
schedules: AgentJobScheduleInfo[];
|
||||
alerts: AgentAlertInfo[];
|
||||
}
|
||||
|
||||
export interface CreateAgentJobResult extends ResultStatus {
|
||||
@@ -1529,7 +1540,7 @@ declare module 'sqlops' {
|
||||
export interface AgentServicesProvider extends DataProvider {
|
||||
// Job management methods
|
||||
getJobs(ownerUri: string): Thenable<AgentJobsResult>;
|
||||
getJobHistory(ownerUri: string, jobId: string): Thenable<AgentJobHistoryResult>;
|
||||
getJobHistory(ownerUri: string, jobId: string, jobName: string): Thenable<AgentJobHistoryResult>;
|
||||
jobAction(ownerUri: string, jobName: string, action: string): Thenable<ResultStatus>;
|
||||
createJob(ownerUri: string, jobInfo: AgentJobInfo): Thenable<CreateAgentJobResult>;
|
||||
updateJob(ownerUri: string, originalJobName: string, jobInfo: AgentJobInfo): Thenable<UpdateAgentJobResult>;
|
||||
|
||||
@@ -95,6 +95,16 @@ export enum JobCompletionActionCondition {
|
||||
Always = 3
|
||||
}
|
||||
|
||||
export enum JobExecutionStatus {
|
||||
Executing = 1,
|
||||
WaitingForWorkerThread = 2,
|
||||
BetweenRetries = 3,
|
||||
Idle = 4,
|
||||
Suspended = 5,
|
||||
WaitingForStepToFinish = 6,
|
||||
PerformingCompletionAction = 7
|
||||
}
|
||||
|
||||
export enum AlertType {
|
||||
sqlServerEvent = 1,
|
||||
sqlServerPerformanceCondition = 2,
|
||||
|
||||
@@ -578,8 +578,8 @@ export class ExtHostDataProtocol extends ExtHostDataProtocolShape {
|
||||
/**
|
||||
* Get a Agent Job's history
|
||||
*/
|
||||
public $getJobHistory(handle: number, ownerUri: string, jobID: string): Thenable<sqlops.AgentJobHistoryResult> {
|
||||
return this._resolveProvider<sqlops.AgentServicesProvider>(handle).getJobHistory(ownerUri, jobID);
|
||||
public $getJobHistory(handle: number, ownerUri: string, jobID: string, jobName: string): Thenable<sqlops.AgentJobHistoryResult> {
|
||||
return this._resolveProvider<sqlops.AgentServicesProvider>(handle).getJobHistory(ownerUri, jobID, jobName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -350,8 +350,8 @@ export class MainThreadDataProtocol implements MainThreadDataProtocolShape {
|
||||
getJobs(connectionUri: string): Thenable<sqlops.AgentJobsResult> {
|
||||
return self._proxy.$getJobs(handle, connectionUri);
|
||||
},
|
||||
getJobHistory(connectionUri: string, jobID: string): Thenable<sqlops.AgentJobHistoryResult> {
|
||||
return self._proxy.$getJobHistory(handle, connectionUri, jobID);
|
||||
getJobHistory(connectionUri: string, jobID: string, jobName: string): Thenable<sqlops.AgentJobHistoryResult> {
|
||||
return self._proxy.$getJobHistory(handle, connectionUri, jobID, jobName);
|
||||
},
|
||||
jobAction(connectionUri: string, jobName: string, action: string): Thenable<sqlops.ResultStatus> {
|
||||
return self._proxy.$jobAction(handle, connectionUri, jobName, action);
|
||||
|
||||
@@ -422,6 +422,7 @@ export function createApiFactory(
|
||||
WeekDays: sqlExtHostTypes.WeekDays,
|
||||
NotifyMethods: sqlExtHostTypes.NotifyMethods,
|
||||
JobCompletionActionCondition: sqlExtHostTypes.JobCompletionActionCondition,
|
||||
JobExecutionStatus: sqlExtHostTypes.JobExecutionStatus,
|
||||
AlertType: sqlExtHostTypes.AlertType,
|
||||
FrequencyTypes: sqlExtHostTypes.FrequencyTypes,
|
||||
FrequencySubDayTypes: sqlExtHostTypes.FrequencySubDayTypes,
|
||||
|
||||
@@ -358,7 +358,7 @@ export abstract class ExtHostDataProtocolShape {
|
||||
/**
|
||||
* Get a Agent Job's history
|
||||
*/
|
||||
$getJobHistory(handle: number, ownerUri: string, jobID: string): Thenable<sqlops.AgentJobHistoryResult> { throw ni(); }
|
||||
$getJobHistory(handle: number, ownerUri: string, jobID: string, jobName: string): Thenable<sqlops.AgentJobHistoryResult> { throw ni(); }
|
||||
|
||||
/**
|
||||
* Run an action on a Job
|
||||
|
||||
Reference in New Issue
Block a user