Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 842c90a

Browse files
cppwfsBoykoAlex
authored andcommitted
Adds support for restarting and stopping jobs.
resolves #577
1 parent 2828166 commit 842c90a

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

ui/src/app/jobs/jobs.component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,27 @@ export class JobsComponent implements OnInit {
6464
}
6565

6666
restartJob(item: JobExecution) {
67-
console.log('Restart Job');
67+
console.log('Restart Job ' + item.jobExecutionId);
68+
this.jobsService.restartJob(item).subscribe(
69+
data => {
70+
this.toastyService.success('Successfully restarted job "' + item.name + '"');
71+
},
72+
error => {
73+
this.toastyService.error(error);
74+
}
75+
);
6876
}
6977

7078
stopJob(item: JobExecution) {
71-
console.log('Stop Job');
79+
console.log('Stop Job' + item.jobExecutionId);
80+
this.jobsService.stopJob(item).subscribe(
81+
data => {
82+
this.toastyService.success('Successfully stopped job "' + item.name + '"');
83+
},
84+
error => {
85+
this.toastyService.error(error);
86+
}
87+
);
7288
}
7389

7490
viewJobExecutionDetails(item: JobExecution) {

ui/src/app/jobs/jobs.service.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '../tests/mocks/mock-data';
1010
import {Page} from '../shared/model/page';
1111
import {JobExecution} from './model/job-execution.model';
12+
import {RequestOptionsArgs} from '@angular/http';
1213

1314
export class MockResponse {
1415

@@ -30,7 +31,7 @@ export class MockResponse {
3031
describe('JobsService', () => {
3132

3233
beforeEach(() => {
33-
this.mockHttp = jasmine.createSpyObj('mockHttp', ['get']);
34+
this.mockHttp = jasmine.createSpyObj('mockHttp', ['get', 'put']);
3435
this.jsonData = { };
3536
const errorHandler = new ErrorHandler();
3637
this.jobsService = new JobsService(this.mockHttp, errorHandler);
@@ -96,6 +97,30 @@ describe('JobsService', () => {
9697
});
9798
});
9899

100+
describe('restartJobExecution', () => {
101+
it('should execute a PUT command to restart a job', () => {
102+
const jobExecution: JobExecution = new JobExecution();
103+
jobExecution.jobExecutionId = 1;
104+
jobExecution.name = 'foo';
105+
this.mockHttp.put.and.returnValue(Observable.of(this.jsonData));
106+
this.jobsService.restartJob(jobExecution);
107+
const options: RequestOptionsArgs = HttpUtils.getDefaultRequestOptions();
108+
expect(this.mockHttp.put).toHaveBeenCalledWith('/jobs/executions/1?restart=true', options);
109+
});
110+
});
111+
112+
describe('stopJobExecution', () => {
113+
it('should execute a PUT command to stop a job', () => {
114+
const jobExecution: JobExecution = new JobExecution();
115+
jobExecution.jobExecutionId = 1;
116+
jobExecution.name = 'foo';
117+
this.mockHttp.put.and.returnValue(Observable.of(this.jsonData));
118+
this.jobsService.stopJob(jobExecution);
119+
const options: RequestOptionsArgs = HttpUtils.getDefaultRequestOptions();
120+
expect(this.mockHttp.put).toHaveBeenCalledWith('/jobs/executions/1?stop=true', options);
121+
});
122+
});
123+
99124
describe('extractData', () => {
100125
it('should call the jobs service to extract data from json', () => {
101126
const response = new MockResponse();

ui/src/app/jobs/jobs.service.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import { Http, Response } from '@angular/http';
2+
import { Http, Response, RequestOptionsArgs } from '@angular/http';
33

44
import { Observable } from 'rxjs/Observable';
55
import 'rxjs/add/operator/catch';
@@ -347,4 +347,28 @@ export class JobsService {
347347
this.jobExecutions.update(page);
348348
return this.jobExecutions;
349349
}
350+
351+
/**
352+
* Restarts a job if the job failed.
353+
* @param {JobExecution} item JobExecution to restart.
354+
* @returns {Observable<any | any>} with the state of the restart.
355+
*/
356+
restartJob(item: JobExecution) {
357+
const options: RequestOptionsArgs = HttpUtils.getDefaultRequestOptions();
358+
359+
return this.http.put(this.jobExecutionsUrl + '/' + item.jobExecutionId + '?restart=true', options)
360+
.catch(this.errorHandler.handleError);
361+
}
362+
363+
/**
364+
* Stops a running JobExecution.
365+
* @param {JobExecution} item the JobExecution to stop
366+
* @returns {Observable<any | any>} state of the job execution stop event.
367+
*/
368+
stopJob(item: JobExecution) {
369+
const options: RequestOptionsArgs = HttpUtils.getDefaultRequestOptions();
370+
371+
return this.http.put(this.jobExecutionsUrl + '/' + item.jobExecutionId + '?stop=true', options)
372+
.catch(this.errorHandler.handleError);
373+
}
350374
}

0 commit comments

Comments
 (0)