diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 15:04:52 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | 118626c8752bee7b05c4e0b668852e1aba2416f1 (patch) | |
tree | 6407bdcde3496c6a2480313f0958653aa15bab87 /client/src/app/+admin/system | |
parent | e592df48c73aa9262b04d23b3319de49b6caf95d (diff) | |
download | PeerTube-118626c8752bee7b05c4e0b668852e1aba2416f1.tar.gz PeerTube-118626c8752bee7b05c4e0b668852e1aba2416f1.tar.zst PeerTube-118626c8752bee7b05c4e0b668852e1aba2416f1.zip |
Implement runner in client side
Diffstat (limited to 'client/src/app/+admin/system')
14 files changed, 650 insertions, 1 deletions
diff --git a/client/src/app/+admin/system/index.ts b/client/src/app/+admin/system/index.ts index b398832cc..6d84dafa8 100644 --- a/client/src/app/+admin/system/index.ts +++ b/client/src/app/+admin/system/index.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | export * from './debug' | 1 | export * from './debug' |
2 | export * from './jobs' | 2 | export * from './jobs' |
3 | export * from './logs' | 3 | export * from './logs' |
4 | export * from './runners' | ||
4 | export * from './system.routes' | 5 | export * from './system.routes' |
diff --git a/client/src/app/+admin/system/runners/index.ts b/client/src/app/+admin/system/runners/index.ts new file mode 100644 index 000000000..dbbf32fb5 --- /dev/null +++ b/client/src/app/+admin/system/runners/index.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export * from './runner.service' | ||
2 | export * from './runner-job-list' | ||
3 | export * from './runner-list' | ||
4 | export * from './runner-registration-token-list' | ||
5 | export * from './runners.routes' | ||
diff --git a/client/src/app/+admin/system/runners/runner-job-list/index.ts b/client/src/app/+admin/system/runners/runner-job-list/index.ts new file mode 100644 index 000000000..bdcf93234 --- /dev/null +++ b/client/src/app/+admin/system/runners/runner-job-list/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './runner-job-list.component' | |||
diff --git a/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.html b/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.html new file mode 100644 index 000000000..7858b4bca --- /dev/null +++ b/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.html | |||
@@ -0,0 +1,101 @@ | |||
1 | <h1 class="d-flex justify-content-between"> | ||
2 | <span class="text-nowrap me-2"> | ||
3 | <my-global-icon iconName="globe" aria-hidden="true"></my-global-icon> | ||
4 | <span i18n>Runner jobs</span> | ||
5 | </span> | ||
6 | |||
7 | <a routerLink="/admin/system/runners/runners-list" class="peertube-button-link peertube-button-icon grey-button"> | ||
8 | <my-global-icon iconName="codesandbox" aria-hidden="true"></my-global-icon> | ||
9 | <ng-container i18n>Remote runners</ng-container> | ||
10 | </a> | ||
11 | </h1> | ||
12 | |||
13 | <p-table | ||
14 | [value]="runnerJobs" [paginator]="totalRecords > 0" [totalRecords]="totalRecords" [rows]="rowsPerPage" [first]="pagination.start" | ||
15 | [rowsPerPageOptions]="rowsPerPageOptions" [sortField]="sort.field" [sortOrder]="sort.order" | ||
16 | [lazy]="true" (onLazyLoad)="loadLazy($event)" [lazyLoadOnInit]="false" | ||
17 | [showCurrentPageReport]="true" i18n-currentPageReportTemplate | ||
18 | currentPageReportTemplate="Showing {{'{first}'}} to {{'{last}'}} of {{'{totalRecords}'}} runner jobs" | ||
19 | [expandedRowKeys]="expandedRows" dataKey="uuid" | ||
20 | > | ||
21 | <ng-template pTemplate="header"> | ||
22 | <tr> | ||
23 | <th style="width: 40px"></th> | ||
24 | <th style="width: 120px;"></th> | ||
25 | <th i18n>UUID</th> | ||
26 | <th i18n>Type</th> | ||
27 | <th i18n pSortableColumn="state">State <p-sortIcon field="state"></p-sortIcon></th> | ||
28 | <th style="width: 100px" i18n pSortableColumn="priority">Priority <p-sortIcon field="priority"></p-sortIcon></th> | ||
29 | <th style="width: 100px" i18n pSortableColumn="progress">Progress <p-sortIcon field="progress"></p-sortIcon></th> | ||
30 | <th i18n>Runner</th> | ||
31 | <th style="width: 150px;" i18n pSortableColumn="createdAt">Created <p-sortIcon field="createdAt"></p-sortIcon></th> | ||
32 | </tr> | ||
33 | </ng-template> | ||
34 | |||
35 | <ng-template pTemplate="caption"> | ||
36 | <div class="caption"> | ||
37 | <div class="ms-auto d-flex"> | ||
38 | <my-advanced-input-filter class="me-2" (search)="onSearch($event)"></my-advanced-input-filter> | ||
39 | |||
40 | <my-button i18n-label label="Refresh" icon="refresh" (click)="reloadData()"></my-button> | ||
41 | </div> | ||
42 | </div> | ||
43 | </ng-template> | ||
44 | |||
45 | <ng-template pTemplate="body" let-expanded="expanded" let-runnerJob> | ||
46 | <tr> | ||
47 | <td class="expand-cell" [pRowToggler]="runnerJob"> | ||
48 | <my-table-expander-icon [expanded]="expanded"></my-table-expander-icon> | ||
49 | </td> | ||
50 | |||
51 | <td class="action-cell"> | ||
52 | <my-action-dropdown | ||
53 | placement="bottom-right top-right left auto" container="body" | ||
54 | i18n-label label="Actions" [actions]="actions" [entry]="runnerJob" | ||
55 | ></my-action-dropdown> | ||
56 | </td> | ||
57 | |||
58 | <td>{{ runnerJob.uuid }}</td> | ||
59 | <td>{{ runnerJob.type }}</td> | ||
60 | <td>{{ runnerJob.state.label }}</td> | ||
61 | <td>{{ runnerJob.priority }}</td> | ||
62 | <td>{{ runnerJob.progress }}</td> | ||
63 | <td>{{ runnerJob.runner?.name }}</td> | ||
64 | <td>{{ runnerJob.createdAt | date: 'short' }}</td> | ||
65 | </tr> | ||
66 | </ng-template> | ||
67 | |||
68 | <ng-template pTemplate="rowexpansion" let-runnerJob> | ||
69 | <tr> | ||
70 | <td colspan="9"> | ||
71 | <div class="mt-2 fs-7 font-monospace"> | ||
72 | Parent job: {{ runnerJob.parent?.uuid || '-' }} <br /> | ||
73 | Processed on {{ (runnerJob.startedAt || '-') }} <br /> | ||
74 | Finished on {{ (runnerJob.finishedAt || '-') }} <br /> | ||
75 | </div> | ||
76 | |||
77 | <div class="mt-2"> | ||
78 | <strong i18n>Payload:</strong> | ||
79 | <pre>{{ runnerJob.payload }}</pre> | ||
80 | </div> | ||
81 | |||
82 | <div class="mt-2"> | ||
83 | <strong i18n>Private payload:</strong> | ||
84 | <pre>{{ runnerJob.privatePayload }}</pre> | ||
85 | </div> | ||
86 | |||
87 | <pre *ngIf="runnerJob.error" class=".text-danger" >{{ runnerJob.error }}</pre> | ||
88 | </td> | ||
89 | </tr> | ||
90 | </ng-template> | ||
91 | |||
92 | <ng-template pTemplate="emptymessage"> | ||
93 | <tr> | ||
94 | <td colspan="9"> | ||
95 | <div class="no-results"> | ||
96 | <ng-container i18n>No runner jobs found.</ng-container> | ||
97 | </div> | ||
98 | </td> | ||
99 | </tr> | ||
100 | </ng-template> | ||
101 | </p-table> | ||
diff --git a/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts b/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts new file mode 100644 index 000000000..ea889f0f7 --- /dev/null +++ b/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts | |||
@@ -0,0 +1,76 @@ | |||
1 | import { SortMeta } from 'primeng/api' | ||
2 | import { Component, OnInit } from '@angular/core' | ||
3 | import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | ||
4 | import { DropdownAction } from '@app/shared/shared-main' | ||
5 | import { RunnerJob } from '@shared/models' | ||
6 | import { RunnerJobFormatted, RunnerService } from '../runner.service' | ||
7 | |||
8 | @Component({ | ||
9 | selector: 'my-runner-job-list', | ||
10 | templateUrl: './runner-job-list.component.html' | ||
11 | }) | ||
12 | export class RunnerJobListComponent extends RestTable <RunnerJob> implements OnInit { | ||
13 | runnerJobs: RunnerJobFormatted[] = [] | ||
14 | totalRecords = 0 | ||
15 | |||
16 | sort: SortMeta = { field: 'createdAt', order: -1 } | ||
17 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | ||
18 | |||
19 | actions: DropdownAction<RunnerJob>[][] = [] | ||
20 | |||
21 | constructor ( | ||
22 | private runnerService: RunnerService, | ||
23 | private notifier: Notifier, | ||
24 | private confirmService: ConfirmService | ||
25 | ) { | ||
26 | super() | ||
27 | } | ||
28 | |||
29 | ngOnInit () { | ||
30 | this.actions = [ | ||
31 | [ | ||
32 | { | ||
33 | label: $localize`Cancel this job`, | ||
34 | handler: job => this.cancelJob(job) | ||
35 | } | ||
36 | ] | ||
37 | ] | ||
38 | |||
39 | this.initialize() | ||
40 | } | ||
41 | |||
42 | getIdentifier () { | ||
43 | return 'RunnerJobListComponent' | ||
44 | } | ||
45 | |||
46 | async cancelJob (job: RunnerJob) { | ||
47 | const res = await this.confirmService.confirm( | ||
48 | $localize`Do you really want to cancel this job? Children won't be processed.`, | ||
49 | $localize`Cancel job` | ||
50 | ) | ||
51 | |||
52 | if (res === false) return | ||
53 | |||
54 | this.runnerService.cancelJob(job) | ||
55 | .subscribe({ | ||
56 | next: () => { | ||
57 | this.reloadData() | ||
58 | this.notifier.success($localize`Job cancelled.`) | ||
59 | }, | ||
60 | |||
61 | error: err => this.notifier.error(err.message) | ||
62 | }) | ||
63 | } | ||
64 | |||
65 | protected reloadDataInternal () { | ||
66 | this.runnerService.listRunnerJobs({ pagination: this.pagination, sort: this.sort, search: this.search }) | ||
67 | .subscribe({ | ||
68 | next: resultList => { | ||
69 | this.runnerJobs = resultList.data | ||
70 | this.totalRecords = resultList.total | ||
71 | }, | ||
72 | |||
73 | error: err => this.notifier.error(err.message) | ||
74 | }) | ||
75 | } | ||
76 | } | ||
diff --git a/client/src/app/+admin/system/runners/runner-list/index.ts b/client/src/app/+admin/system/runners/runner-list/index.ts new file mode 100644 index 000000000..5c12bb6d6 --- /dev/null +++ b/client/src/app/+admin/system/runners/runner-list/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './runner-list.component' | |||
diff --git a/client/src/app/+admin/system/runners/runner-list/runner-list.component.html b/client/src/app/+admin/system/runners/runner-list/runner-list.component.html new file mode 100644 index 000000000..606eb9afd --- /dev/null +++ b/client/src/app/+admin/system/runners/runner-list/runner-list.component.html | |||
@@ -0,0 +1,61 @@ | |||
1 | <h1 class="d-flex justify-content-between"> | ||
2 | <span class="text-nowrap me-2"> | ||
3 | <my-global-icon iconName="codesandbox" aria-hidden="true"></my-global-icon> | ||
4 | <ng-container i18n>Remote runners</ng-container> | ||
5 | </span> | ||
6 | |||
7 | <a routerLink="/admin/system/runners/registration-tokens-list" class="peertube-button-link peertube-button-icon grey-button"> | ||
8 | <my-global-icon iconName="cog" aria-hidden="true"></my-global-icon> | ||
9 | <ng-container i18n>Runner registration tokens</ng-container> | ||
10 | </a> | ||
11 | </h1> | ||
12 | |||
13 | <p-table | ||
14 | [value]="runners" [paginator]="totalRecords > 0" [totalRecords]="totalRecords" [rows]="rowsPerPage" [first]="pagination.start" | ||
15 | [rowsPerPageOptions]="rowsPerPageOptions" [sortField]="sort.field" [sortOrder]="sort.order" | ||
16 | [lazy]="true" (onLazyLoad)="loadLazy($event)" | ||
17 | [showCurrentPageReport]="true" i18n-currentPageReportTemplate | ||
18 | currentPageReportTemplate="Showing {{'{first}'}} to {{'{last}'}} of {{'{totalRecords}'}} remote runners" | ||
19 | > | ||
20 | <ng-template pTemplate="header"> | ||
21 | <tr> | ||
22 | <th style="width: 120px;"></th> | ||
23 | <th i18n>Name</th> | ||
24 | <th i18n>Description</th> | ||
25 | <th i18n>IP</th> | ||
26 | <th i18n>Last contact</th> | ||
27 | <th style="width: 150px;" i18n pSortableColumn="createdAt">Created <p-sortIcon field="createdAt"></p-sortIcon></th> | ||
28 | </tr> | ||
29 | </ng-template> | ||
30 | |||
31 | <ng-template pTemplate="body" let-runner> | ||
32 | <tr> | ||
33 | <td class="action-cell"> | ||
34 | <my-action-dropdown | ||
35 | placement="bottom-right top-right left auto" container="body" | ||
36 | i18n-label label="Actions" [actions]="actions" [entry]="runner" | ||
37 | ></my-action-dropdown> | ||
38 | </td> | ||
39 | |||
40 | <td>{{ runner.name }}</td> | ||
41 | |||
42 | <td>{{ runner.description }}</td> | ||
43 | |||
44 | <td>{{ runner.ip }}</td> | ||
45 | |||
46 | <td>{{ runner.lastContact | date: 'short' }}</td> | ||
47 | |||
48 | <td>{{ runner.createdAt | date: 'short' }}</td> | ||
49 | </tr> | ||
50 | </ng-template> | ||
51 | |||
52 | <ng-template pTemplate="emptymessage"> | ||
53 | <tr> | ||
54 | <td colspan="6"> | ||
55 | <div class="no-results"> | ||
56 | <ng-container i18n>No remote runners found.</ng-container> | ||
57 | </div> | ||
58 | </td> | ||
59 | </tr> | ||
60 | </ng-template> | ||
61 | </p-table> | ||
diff --git a/client/src/app/+admin/system/runners/runner-list/runner-list.component.ts b/client/src/app/+admin/system/runners/runner-list/runner-list.component.ts new file mode 100644 index 000000000..7566f967e --- /dev/null +++ b/client/src/app/+admin/system/runners/runner-list/runner-list.component.ts | |||
@@ -0,0 +1,76 @@ | |||
1 | import { SortMeta } from 'primeng/api' | ||
2 | import { Component, OnInit } from '@angular/core' | ||
3 | import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | ||
4 | import { DropdownAction } from '@app/shared/shared-main' | ||
5 | import { Runner } from '@shared/models' | ||
6 | import { RunnerService } from '../runner.service' | ||
7 | |||
8 | @Component({ | ||
9 | selector: 'my-runner-list', | ||
10 | templateUrl: './runner-list.component.html' | ||
11 | }) | ||
12 | export class RunnerListComponent extends RestTable <Runner> implements OnInit { | ||
13 | runners: Runner[] = [] | ||
14 | totalRecords = 0 | ||
15 | |||
16 | sort: SortMeta = { field: 'createdAt', order: -1 } | ||
17 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | ||
18 | |||
19 | actions: DropdownAction<Runner>[][] = [] | ||
20 | |||
21 | constructor ( | ||
22 | private runnerService: RunnerService, | ||
23 | private notifier: Notifier, | ||
24 | private confirmService: ConfirmService | ||
25 | ) { | ||
26 | super() | ||
27 | } | ||
28 | |||
29 | ngOnInit () { | ||
30 | this.actions = [ | ||
31 | [ | ||
32 | { | ||
33 | label: $localize`Remove`, | ||
34 | handler: runer => this.deleteRunner(runer) | ||
35 | } | ||
36 | ] | ||
37 | ] | ||
38 | |||
39 | this.initialize() | ||
40 | } | ||
41 | |||
42 | getIdentifier () { | ||
43 | return 'RunnerListComponent' | ||
44 | } | ||
45 | |||
46 | async deleteRunner (runner: Runner) { | ||
47 | const res = await this.confirmService.confirm( | ||
48 | $localize`Do you really want to delete this runner? It won't be able to process jobs anymore.`, | ||
49 | $localize`Remove ${runner.name}` | ||
50 | ) | ||
51 | |||
52 | if (res === false) return | ||
53 | |||
54 | this.runnerService.deleteRunner(runner) | ||
55 | .subscribe({ | ||
56 | next: () => { | ||
57 | this.reloadData() | ||
58 | this.notifier.success($localize`Runner removed.`) | ||
59 | }, | ||
60 | |||
61 | error: err => this.notifier.error(err.message) | ||
62 | }) | ||
63 | } | ||
64 | |||
65 | protected reloadDataInternal () { | ||
66 | this.runnerService.listRunners({ pagination: this.pagination, sort: this.sort }) | ||
67 | .subscribe({ | ||
68 | next: resultList => { | ||
69 | this.runners = resultList.data | ||
70 | this.totalRecords = resultList.total | ||
71 | }, | ||
72 | |||
73 | error: err => this.notifier.error(err.message) | ||
74 | }) | ||
75 | } | ||
76 | } | ||
diff --git a/client/src/app/+admin/system/runners/runner-registration-token-list/index.ts b/client/src/app/+admin/system/runners/runner-registration-token-list/index.ts new file mode 100644 index 000000000..8e77978b3 --- /dev/null +++ b/client/src/app/+admin/system/runners/runner-registration-token-list/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './runner-registration-token-list.component' | |||
diff --git a/client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.html b/client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.html new file mode 100644 index 000000000..2fd23e2fc --- /dev/null +++ b/client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.html | |||
@@ -0,0 +1,65 @@ | |||
1 | <h1 class="d-flex justify-content-between"> | ||
2 | <span class="text-nowrap me-2"> | ||
3 | <my-global-icon iconName="cog" aria-hidden="true"></my-global-icon> | ||
4 | <ng-container i18n>Runner registration tokens</ng-container> | ||
5 | </span> | ||
6 | |||
7 | <div> | ||
8 | <a routerLink="/admin/system/runners/runners-list" class="peertube-button-link peertube-button-icon grey-button"> | ||
9 | <my-global-icon iconName="codesandbox" aria-hidden="true"></my-global-icon> | ||
10 | <ng-container i18n>Remote runners</ng-container> | ||
11 | </a> | ||
12 | </div> | ||
13 | </h1> | ||
14 | |||
15 | <p-table | ||
16 | [value]="registrationTokens" [paginator]="totalRecords > 0" [totalRecords]="totalRecords" [rows]="rowsPerPage" [first]="pagination.start" | ||
17 | [rowsPerPageOptions]="rowsPerPageOptions" [sortField]="sort.field" [sortOrder]="sort.order" | ||
18 | [lazy]="true" (onLazyLoad)="loadLazy($event)" | ||
19 | [showCurrentPageReport]="true" i18n-currentPageReportTemplate | ||
20 | currentPageReportTemplate="Showing {{'{first}'}} to {{'{last}'}} of {{'{totalRecords}'}} registration tokens" | ||
21 | > | ||
22 | <ng-template pTemplate="header"> | ||
23 | <tr> | ||
24 | <th style="width: 120px;"></th> | ||
25 | <th i18n>Token</th> | ||
26 | <th style="width: 150px;" i18n pSortableColumn="createdAt">Created <p-sortIcon field="createdAt"></p-sortIcon></th> | ||
27 | <th style="width: 160px;" i18n>Associated runners</th> | ||
28 | </tr> | ||
29 | </ng-template> | ||
30 | |||
31 | <ng-template pTemplate="caption"> | ||
32 | <div class="caption"> | ||
33 | <div class="left-buttons"> | ||
34 | <my-button className="orange-button" i18n-label label="Generate token" icon="add" (click)="generateToken()"></my-button> | ||
35 | </div> | ||
36 | </div> | ||
37 | </ng-template> | ||
38 | |||
39 | <ng-template pTemplate="body" let-registrationToken> | ||
40 | <tr> | ||
41 | <td class="action-cell"> | ||
42 | <my-action-dropdown | ||
43 | placement="bottom-right top-right left auto" container="body" | ||
44 | i18n-label label="Actions" [actions]="actions" [entry]="registrationToken" | ||
45 | ></my-action-dropdown> | ||
46 | </td> | ||
47 | |||
48 | <td>{{ registrationToken.registrationToken }}</td> | ||
49 | |||
50 | <td>{{ registrationToken.createdAt | date: 'short' }}</td> | ||
51 | |||
52 | <td>{{ registrationToken.registeredRunnersCount }}</td> | ||
53 | </tr> | ||
54 | </ng-template> | ||
55 | |||
56 | <ng-template pTemplate="emptymessage"> | ||
57 | <tr> | ||
58 | <td colspan="4"> | ||
59 | <div class="no-results"> | ||
60 | <ng-container i18n>No registration token found for remote runners.</ng-container> | ||
61 | </div> | ||
62 | </td> | ||
63 | </tr> | ||
64 | </ng-template> | ||
65 | </p-table> | ||
diff --git a/client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.ts b/client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.ts new file mode 100644 index 000000000..f03aab189 --- /dev/null +++ b/client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.ts | |||
@@ -0,0 +1,88 @@ | |||
1 | import { SortMeta } from 'primeng/api' | ||
2 | import { Component, OnInit } from '@angular/core' | ||
3 | import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | ||
4 | import { DropdownAction } from '@app/shared/shared-main' | ||
5 | import { RunnerRegistrationToken } from '@shared/models' | ||
6 | import { RunnerService } from '../runner.service' | ||
7 | |||
8 | @Component({ | ||
9 | selector: 'my-runner-registration-token-list', | ||
10 | templateUrl: './runner-registration-token-list.component.html' | ||
11 | }) | ||
12 | export class RunnerRegistrationTokenListComponent extends RestTable <RunnerRegistrationToken> implements OnInit { | ||
13 | registrationTokens: RunnerRegistrationToken[] = [] | ||
14 | totalRecords = 0 | ||
15 | |||
16 | sort: SortMeta = { field: 'createdAt', order: -1 } | ||
17 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | ||
18 | |||
19 | actions: DropdownAction<RunnerRegistrationToken>[][] = [] | ||
20 | |||
21 | constructor ( | ||
22 | private runnerService: RunnerService, | ||
23 | private notifier: Notifier, | ||
24 | private confirmService: ConfirmService | ||
25 | ) { | ||
26 | super() | ||
27 | } | ||
28 | |||
29 | ngOnInit () { | ||
30 | this.actions = [ | ||
31 | [ | ||
32 | { | ||
33 | label: $localize`Remove this token`, | ||
34 | handler: token => this.removeToken(token) | ||
35 | } | ||
36 | ] | ||
37 | ] | ||
38 | |||
39 | this.initialize() | ||
40 | } | ||
41 | |||
42 | getIdentifier () { | ||
43 | return 'RunnerRegistrationTokenListComponent' | ||
44 | } | ||
45 | |||
46 | generateToken () { | ||
47 | this.runnerService.generateToken() | ||
48 | .subscribe({ | ||
49 | next: () => { | ||
50 | this.reloadData() | ||
51 | this.notifier.success($localize`Registration token generated.`) | ||
52 | }, | ||
53 | |||
54 | error: err => this.notifier.error(err.message) | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | async removeToken (token: RunnerRegistrationToken) { | ||
59 | const res = await this.confirmService.confirm( | ||
60 | $localize`Do you really want to remove this registration token? All associated runners will also be removed.`, | ||
61 | $localize`Remove registration token` | ||
62 | ) | ||
63 | |||
64 | if (res === false) return | ||
65 | |||
66 | this.runnerService.removeToken(token) | ||
67 | .subscribe({ | ||
68 | next: () => { | ||
69 | this.reloadData() | ||
70 | this.notifier.success($localize`Registration token removed.`) | ||
71 | }, | ||
72 | |||
73 | error: err => this.notifier.error(err.message) | ||
74 | }) | ||
75 | } | ||
76 | |||
77 | protected reloadDataInternal () { | ||
78 | this.runnerService.listRegistrationTokens({ pagination: this.pagination, sort: this.sort }) | ||
79 | .subscribe({ | ||
80 | next: resultList => { | ||
81 | this.registrationTokens = resultList.data | ||
82 | this.totalRecords = resultList.total | ||
83 | }, | ||
84 | |||
85 | error: err => this.notifier.error(err.message) | ||
86 | }) | ||
87 | } | ||
88 | } | ||
diff --git a/client/src/app/+admin/system/runners/runner.service.ts b/client/src/app/+admin/system/runners/runner.service.ts new file mode 100644 index 000000000..05083318c --- /dev/null +++ b/client/src/app/+admin/system/runners/runner.service.ts | |||
@@ -0,0 +1,117 @@ | |||
1 | |||
2 | import { SortMeta } from 'primeng/api' | ||
3 | import { catchError, forkJoin, map } from 'rxjs' | ||
4 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
5 | import { Injectable } from '@angular/core' | ||
6 | import { RestExtractor, RestPagination, RestService, ServerService } from '@app/core' | ||
7 | import { peertubeTranslate } from '@shared/core-utils' | ||
8 | import { ResultList } from '@shared/models/common' | ||
9 | import { Runner, RunnerJob, RunnerJobAdmin, RunnerRegistrationToken } from '@shared/models/runners' | ||
10 | import { environment } from '../../../../environments/environment' | ||
11 | |||
12 | export type RunnerJobFormatted = RunnerJob & { | ||
13 | payload: string | ||
14 | privatePayload: string | ||
15 | } | ||
16 | |||
17 | @Injectable() | ||
18 | export class RunnerService { | ||
19 | private static BASE_RUNNER_URL = environment.apiUrl + '/api/v1/runners' | ||
20 | |||
21 | constructor ( | ||
22 | private authHttp: HttpClient, | ||
23 | private server: ServerService, | ||
24 | private restService: RestService, | ||
25 | private restExtractor: RestExtractor | ||
26 | ) {} | ||
27 | |||
28 | listRegistrationTokens (options: { | ||
29 | pagination: RestPagination | ||
30 | sort: SortMeta | ||
31 | }) { | ||
32 | const { pagination, sort } = options | ||
33 | |||
34 | let params = new HttpParams() | ||
35 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
36 | |||
37 | return this.authHttp.get<ResultList<RunnerRegistrationToken>>(RunnerService.BASE_RUNNER_URL + '/registration-tokens', { params }) | ||
38 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
39 | } | ||
40 | |||
41 | generateToken () { | ||
42 | return this.authHttp.post(RunnerService.BASE_RUNNER_URL + '/registration-tokens/generate', {}) | ||
43 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
44 | } | ||
45 | |||
46 | removeToken (token: RunnerRegistrationToken) { | ||
47 | return this.authHttp.delete(RunnerService.BASE_RUNNER_URL + '/registration-tokens/' + token.id) | ||
48 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
49 | } | ||
50 | |||
51 | // --------------------------------------------------------------------------- | ||
52 | |||
53 | listRunnerJobs (options: { | ||
54 | pagination: RestPagination | ||
55 | sort: SortMeta | ||
56 | search?: string | ||
57 | }) { | ||
58 | const { pagination, sort, search } = options | ||
59 | |||
60 | let params = new HttpParams() | ||
61 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
62 | |||
63 | if (search) params = params.append('search', search) | ||
64 | |||
65 | return forkJoin([ | ||
66 | this.authHttp.get<ResultList<RunnerJobAdmin>>(RunnerService.BASE_RUNNER_URL + '/jobs', { params }), | ||
67 | this.server.getServerLocale() | ||
68 | ]).pipe( | ||
69 | map(([ res, translations ]) => { | ||
70 | const newData = res.data.map(job => { | ||
71 | return { | ||
72 | ...job, | ||
73 | |||
74 | state: { | ||
75 | id: job.state.id, | ||
76 | label: peertubeTranslate(job.state.label, translations) | ||
77 | }, | ||
78 | payload: JSON.stringify(job.payload, null, 2), | ||
79 | privatePayload: JSON.stringify(job.privatePayload, null, 2) | ||
80 | } as RunnerJobFormatted | ||
81 | }) | ||
82 | |||
83 | return { | ||
84 | total: res.total, | ||
85 | data: newData | ||
86 | } | ||
87 | }), | ||
88 | map(res => this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'startedAt', 'finishedAt' ], 'precise')), | ||
89 | catchError(res => this.restExtractor.handleError(res)) | ||
90 | ) | ||
91 | } | ||
92 | |||
93 | cancelJob (job: RunnerJob) { | ||
94 | return this.authHttp.post(RunnerService.BASE_RUNNER_URL + '/jobs/' + job.uuid + '/cancel', {}) | ||
95 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
96 | } | ||
97 | |||
98 | // --------------------------------------------------------------------------- | ||
99 | |||
100 | listRunners (options: { | ||
101 | pagination: RestPagination | ||
102 | sort: SortMeta | ||
103 | }) { | ||
104 | const { pagination, sort } = options | ||
105 | |||
106 | let params = new HttpParams() | ||
107 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
108 | |||
109 | return this.authHttp.get<ResultList<Runner>>(RunnerService.BASE_RUNNER_URL + '/', { params }) | ||
110 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
111 | } | ||
112 | |||
113 | deleteRunner (runner: Runner) { | ||
114 | return this.authHttp.delete(RunnerService.BASE_RUNNER_URL + '/' + runner.id) | ||
115 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
116 | } | ||
117 | } | ||
diff --git a/client/src/app/+admin/system/runners/runners.routes.ts b/client/src/app/+admin/system/runners/runners.routes.ts new file mode 100644 index 000000000..fabe687d6 --- /dev/null +++ b/client/src/app/+admin/system/runners/runners.routes.ts | |||
@@ -0,0 +1,53 @@ | |||
1 | import { Routes } from '@angular/router' | ||
2 | import { UserRightGuard } from '@app/core' | ||
3 | import { UserRight } from '@shared/models' | ||
4 | import { RunnerJobListComponent } from './runner-job-list' | ||
5 | import { RunnerListComponent } from './runner-list' | ||
6 | import { RunnerRegistrationTokenListComponent } from './runner-registration-token-list' | ||
7 | |||
8 | export const RunnersRoutes: Routes = [ | ||
9 | { | ||
10 | path: 'runners', | ||
11 | canActivate: [ UserRightGuard ], | ||
12 | data: { | ||
13 | userRight: UserRight.MANAGE_RUNNERS | ||
14 | }, | ||
15 | children: [ | ||
16 | { | ||
17 | path: '', | ||
18 | redirectTo: 'jobs-list', | ||
19 | pathMatch: 'full' | ||
20 | }, | ||
21 | |||
22 | { | ||
23 | path: 'jobs-list', | ||
24 | component: RunnerJobListComponent, | ||
25 | data: { | ||
26 | meta: { | ||
27 | title: $localize`List runner jobs` | ||
28 | } | ||
29 | } | ||
30 | }, | ||
31 | |||
32 | { | ||
33 | path: 'runners-list', | ||
34 | component: RunnerListComponent, | ||
35 | data: { | ||
36 | meta: { | ||
37 | title: $localize`List remote runners` | ||
38 | } | ||
39 | } | ||
40 | }, | ||
41 | |||
42 | { | ||
43 | path: 'registration-tokens-list', | ||
44 | component: RunnerRegistrationTokenListComponent, | ||
45 | data: { | ||
46 | meta: { | ||
47 | title: $localize`List registration runner tokens` | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | ] | ||
52 | } | ||
53 | ] | ||
diff --git a/client/src/app/+admin/system/system.routes.ts b/client/src/app/+admin/system/system.routes.ts index d180aa3b9..87e4b25b3 100644 --- a/client/src/app/+admin/system/system.routes.ts +++ b/client/src/app/+admin/system/system.routes.ts | |||
@@ -4,6 +4,7 @@ import { UserRight } from '@shared/models' | |||
4 | import { DebugComponent } from './debug' | 4 | import { DebugComponent } from './debug' |
5 | import { JobsComponent } from './jobs/jobs.component' | 5 | import { JobsComponent } from './jobs/jobs.component' |
6 | import { LogsComponent } from './logs' | 6 | import { LogsComponent } from './logs' |
7 | import { RunnersRoutes } from './runners' | ||
7 | 8 | ||
8 | export const SystemRoutes: Routes = [ | 9 | export const SystemRoutes: Routes = [ |
9 | { | 10 | { |
@@ -46,7 +47,9 @@ export const SystemRoutes: Routes = [ | |||
46 | title: $localize`Debug` | 47 | title: $localize`Debug` |
47 | } | 48 | } |
48 | } | 49 | } |
49 | } | 50 | }, |
51 | |||
52 | ...RunnersRoutes | ||
50 | ] | 53 | ] |
51 | } | 54 | } |
52 | ] | 55 | ] |