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

Commit 7be1a02

Browse files
oodamienilayaperumalg
authored andcommitted
Stop task execution
Resolves #1223
1 parent e2ab734 commit 7be1a02

10 files changed

+490
-22
lines changed

ui/src/app/tasks/task-execution/task-execution.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
<span class="fa fa-play"></span>
2020
Relaunch task
2121
</button>
22+
<button name="task-launch" type="button" id="task-stop"
23+
(click)="stop(taskExecution)" class="btn btn-primary btn-fa" title="Stop the task execution"
24+
[dataflowAppRoles]="['ROLE_CREATE']" [disabled]="!isRunning(taskExecution)">
25+
<span class="fa fa-stop"></span>
26+
Stop execution
27+
</button>
2228
</app-page-head-actions>
2329
</app-page-head>
2430

ui/src/app/tasks/task-execution/task-execution.component.spec.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ import { DATAFLOW_LIST } from 'src/app/shared/components/list/list.component';
1717
import { DATAFLOW_PAGE } from '../../shared/components/page/page.component';
1818
import { PagerComponent } from '../../shared/components/pager/pager.component';
1919
import { NgxPaginationModule } from 'ngx-pagination';
20-
import { BsDropdownModule, TooltipModule } from 'ngx-bootstrap';
20+
import { BsDropdownModule, BsModalRef, BsModalService, TooltipModule } from 'ngx-bootstrap';
2121
import { DateTime } from 'luxon';
2222
import { RolesDirective } from '../../auth/directives/roles.directive';
2323
import { SharedAboutService } from '../../shared/services/shared-about.service';
2424
import { AuthService } from '../../auth/auth.service';
2525
import { MockAuthService } from '../../tests/mocks/auth';
2626
import { MocksSharedAboutService } from '../../tests/mocks/shared-about';
27+
import { LoggerService } from '../../shared/services/logger.service';
28+
import { MockModalService } from '../../tests/mocks/modal';
2729

28-
describe('TaskExecutionsDetailsComponent', () => {
30+
describe('TaskExecutionComponent', () => {
2931
let component: TaskExecutionComponent;
3032
let fixture: ComponentFixture<TaskExecutionComponent>;
3133
let activeRoute: MockActivatedRoute;
@@ -35,6 +37,8 @@ describe('TaskExecutionsDetailsComponent', () => {
3537

3638
const authService = new MockAuthService();
3739
const aboutService = new MocksSharedAboutService();
40+
const bsModalRef = new BsModalRef();
41+
const modalServie = new MockModalService();
3842

3943
const commonTestParams = { id: '1' };
4044
const commonTestExecutionDetails = {
@@ -48,20 +52,7 @@ describe('TaskExecutionsDetailsComponent', () => {
4852
arguments: ['--spring.cloud.task.executionid=1'],
4953
jobExecutionIds: [],
5054
errorMessage: null,
51-
externalExecutionId: 'footask-d465ffe7-6874-42f7-ab04-191e9e6c6376'
52-
}
53-
};
54-
const commonTestExecutionDetailsWithJobIds = {
55-
1: {
56-
executionId: 1,
57-
exitCode: 0,
58-
taskName: 'footask',
59-
startTime: DateTime.fromISO('2017-08-10T05:46:19.079Z'),
60-
endTime: DateTime.fromISO('2017-08-10T05:46:19.098Z'),
61-
exitMessage: null,
62-
arguments: ['--spring.cloud.task.executionid=1'],
63-
jobExecutionIds: [1, 2, 3],
64-
errorMessage: null,
55+
taskExecutionStatus: 'COMPLETE',
6556
externalExecutionId: 'footask-d465ffe7-6874-42f7-ab04-191e9e6c6376'
6657
}
6758
};
@@ -93,7 +84,10 @@ describe('TaskExecutionsDetailsComponent', () => {
9384
{ provide: TasksService, useValue: tasksService },
9485
{ provide: RoutingStateService, useValue: routingStateService },
9586
{ provide: ActivatedRoute, useValue: activeRoute },
96-
{ provide: NotificationService, useValue: notificationService }
87+
{ provide: NotificationService, useValue: notificationService },
88+
{ provide: BsModalRef, useValue: bsModalRef },
89+
{ provide: BsModalService, useValue: modalServie },
90+
LoggerService
9791
]
9892
})
9993
.compileComponents();

ui/src/app/tasks/task-execution/task-execution.component.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { Observable, EMPTY, of } from 'rxjs';
77
import { RoutingStateService } from '../../shared/services/routing-state.service';
88
import { NotificationService } from '../../shared/services/notification.service';
99
import { AppError, HttpAppError } from '../../shared/model/error.model';
10+
import { TaskExecutionsStopComponent } from '../task-executions-stop/task-executions-stop.component';
11+
import { LoggerService } from '../../shared/services/logger.service';
12+
import { BsModalRef, BsModalService } from 'ngx-bootstrap';
1013

1114
/**
1215
* Component that display a Task Execution.
@@ -26,19 +29,28 @@ export class TaskExecutionComponent implements OnInit {
2629
*/
2730
taskExecution$: Observable<any>;
2831

32+
/**
33+
* Modal reference
34+
*/
35+
modal: BsModalRef;
36+
2937
/**
3038
* Constructor
3139
*
3240
* @param {TasksService} tasksService
3341
* @param {RoutingStateService} routingStateService
3442
* @param {NotificationService} notificationService
43+
* @param {LoggerService} loggerService
44+
* @param {BsModalService} modalService
3545
* @param {Router} router
3646
* @param {ActivatedRoute} route
3747
* @param {TasksService} tasksService
3848
*/
3949
constructor(private tasksService: TasksService,
4050
private routingStateService: RoutingStateService,
4151
private notificationService: NotificationService,
52+
private loggerService: LoggerService,
53+
private modalService: BsModalService,
4254
private router: Router,
4355
private route: ActivatedRoute) {
4456
}
@@ -47,6 +59,13 @@ export class TaskExecutionComponent implements OnInit {
4759
* Initialize component
4860
*/
4961
ngOnInit() {
62+
this.refresh();
63+
}
64+
65+
/**
66+
* Refresh Method
67+
*/
68+
refresh() {
5069
this.taskExecution$ = this.route.params
5170
.pipe(
5271
mergeMap(
@@ -114,5 +133,32 @@ export class TaskExecutionComponent implements OnInit {
114133
this.router.navigate([`tasks/definitions/${taskDefinitionName}`]);
115134
}
116135

136+
/**
137+
* Task Execution running
138+
* @param {TaskExecution} execution
139+
*/
140+
isRunning(execution: TaskExecution): boolean {
141+
if (execution && (execution.taskExecutionStatus === 'COMPLETE' || execution.taskExecutionStatus === 'ERROR')) {
142+
return false;
143+
}
144+
return true;
145+
}
146+
147+
/**
148+
* Stop a task execution
149+
* @param {TaskExecution} execution
150+
*/
151+
stop(execution: TaskExecution) {
152+
if (!this.isRunning(execution)) {
153+
this.notificationService.error('The task execution can not be stopped, the execution is already terminated.');
154+
return;
155+
}
156+
this.loggerService.log(`Stop ${execution} task execution`, execution);
157+
this.modal = this.modalService.show(TaskExecutionsStopComponent, { class: 'modal-md' });
158+
this.modal.content.open({ taskExecutions: [execution] }).subscribe(() => {
159+
this.refresh();
160+
});
161+
}
162+
117163

118164
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<div *ngIf="taskExecutions">
2+
<div class="modal-header">
3+
<h4 class="modal-title pull-left">Confirm Stop Task Execution</h4>
4+
<button type="button" class="close pull-right" aria-label="Close" (click)="cancel()">
5+
<span aria-hidden="true">&times;</span>
6+
</button>
7+
</div>
8+
<div class="modal-body" *ngIf="taskExecutions.length == 1">
9+
<p>This action will stop the task execution <strong>{{ taskExecutions[0].executionId }}</strong> (task
10+
<strong>{{ taskExecutions[0].taskName }}</strong>). Are you sure?</p>
11+
</div>
12+
<div class="modal-body" *ngIf="taskExecutions.length > 1">
13+
<p>
14+
This action will stop <strong>{{ taskExecutions.length }} task executions</strong>.
15+
Are you sure?
16+
</p>
17+
<br/>
18+
<table id="table-tasks" class="table table-striped">
19+
<thead>
20+
<tr>
21+
<th>Task Execution ID</th>
22+
<th>Task</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
<tr *ngFor="let item of taskExecutions">
27+
<td>{{ item.executionId }}</td>
28+
<td>{{ item.taskName }}</td>
29+
</tr>
30+
</tbody>
31+
</table>
32+
</div>
33+
<div class="modal-footer" style="text-align:center">
34+
<button id="btn-cancel" type="button" class="btn btn-default" (click)="cancel()">No</button>
35+
<button id="btn-stop" type="button" class="btn btn-primary" (click)="stop()">
36+
Stop Task Execution(s)
37+
</button>
38+
</div>
39+
</div>

0 commit comments

Comments
 (0)