From 8d9b1e18d399e6cc4fbfc1f26966a19b022673a4 Mon Sep 17 00:00:00 2001 From: AllForNothing Date: Mon, 20 Jul 2020 17:50:43 +0800 Subject: [PATCH] Add dry run to gc page Signed-off-by: AllForNothing --- src/portal/src/i18n/lang/en-us-lang.json | 3 ++- src/portal/src/i18n/lang/es-es-lang.json | 3 ++- src/portal/src/i18n/lang/fr-fr-lang.json | 3 ++- src/portal/src/i18n/lang/pt-br-lang.json | 3 ++- src/portal/src/i18n/lang/tr-tr-lang.json | 3 ++- src/portal/src/i18n/lang/zh-cn-lang.json | 3 ++- src/portal/src/i18n/lang/zh-tw-lang.json | 3 ++- .../gc/gc-history/gc-history.component.html | 2 ++ .../gc-history/gc-history.component.spec.ts | 2 ++ .../gc/gc-history/gc-history.component.ts | 12 ++++++++++++ .../components/config/gc/gc.component.html | 10 ++++++++-- .../components/config/gc/gc.component.scss | 1 - .../components/config/gc/gc.component.spec.ts | 1 + .../lib/components/config/gc/gc.component.ts | 19 ++++++++++++++++++- .../lib/components/config/gc/gc.service.ts | 5 +++-- .../config/gc/gc.viewmodel.factory.ts | 1 + .../src/lib/components/config/gc/gcLog.ts | 2 ++ 17 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/portal/src/i18n/lang/en-us-lang.json b/src/portal/src/i18n/lang/en-us-lang.json index 47c538879..29fe9dff7 100644 --- a/src/portal/src/i18n/lang/en-us-lang.json +++ b/src/portal/src/i18n/lang/en-us-lang.json @@ -1214,7 +1214,8 @@ "MSG_SCHEDULE_RESET": "Garbage Collection schedule has been reset", "PARAMETERS": "Parameters", "DELETE_UNTAGGED": "Allow garbage collection on untagged artifacts", - "EXPLAIN": "GC is a compute intensive operation that may impact registry performance" + "EXPLAIN": "GC is a compute intensive operation that may impact registry performance", + "DRY_RUN_SUCCESS": "Triggered dry run successfully" }, "RETAG": { "MSG_SUCCESS": "Copy artifact successfully", diff --git a/src/portal/src/i18n/lang/es-es-lang.json b/src/portal/src/i18n/lang/es-es-lang.json index 9a7a3cc8f..e91916ac0 100644 --- a/src/portal/src/i18n/lang/es-es-lang.json +++ b/src/portal/src/i18n/lang/es-es-lang.json @@ -1208,7 +1208,8 @@ "MSG_SCHEDULE_RESET": "Garbage Collection schedule has been reset", "PARAMETERS": "Parameters", "DELETE_UNTAGGED": "Allow garbage collection on untagged artifacts", - "EXPLAIN": "GC is a compute intensive operation that may impact registry performance" + "EXPLAIN": "GC is a compute intensive operation that may impact registry performance", + "DRY_RUN_SUCCESS": "Triggered dry run successfully" }, "RETAG": { "MSG_SUCCESS": "Copy artifact successfully", diff --git a/src/portal/src/i18n/lang/fr-fr-lang.json b/src/portal/src/i18n/lang/fr-fr-lang.json index 4e6f705ea..9be671116 100644 --- a/src/portal/src/i18n/lang/fr-fr-lang.json +++ b/src/portal/src/i18n/lang/fr-fr-lang.json @@ -1178,7 +1178,8 @@ "MSG_SCHEDULE_RESET": "Garbage Collection schedule has been reset", "PARAMETERS": "Parameters", "DELETE_UNTAGGED": "Allow garbage collection on untagged artifacts", - "EXPLAIN": "GC is a compute intensive operation that may impact registry performance" + "EXPLAIN": "GC is a compute intensive operation that may impact registry performance", + "DRY_RUN_SUCCESS": "Triggered dry run successfully" }, "RETAG": { "MSG_SUCCESS": "Copy artifact successfully", diff --git a/src/portal/src/i18n/lang/pt-br-lang.json b/src/portal/src/i18n/lang/pt-br-lang.json index fd8252007..85f1dd3fa 100644 --- a/src/portal/src/i18n/lang/pt-br-lang.json +++ b/src/portal/src/i18n/lang/pt-br-lang.json @@ -1206,7 +1206,8 @@ "MSG_SCHEDULE_RESET": "Agendamento de Garbage Collection foi redefinido", "PARAMETERS": "Parameters", "DELETE_UNTAGGED": "Allow garbage collection on untagged artifacts", - "EXPLAIN": "GC is a compute intensive operation that may impact registry performance" + "EXPLAIN": "GC is a compute intensive operation that may impact registry performance", + "DRY_RUN_SUCCESS": "Triggered dry run successfully" }, "RETAG": { "MSG_SUCCESS": "Copy artifact successfully", diff --git a/src/portal/src/i18n/lang/tr-tr-lang.json b/src/portal/src/i18n/lang/tr-tr-lang.json index 62856b140..daf02cc9e 100644 --- a/src/portal/src/i18n/lang/tr-tr-lang.json +++ b/src/portal/src/i18n/lang/tr-tr-lang.json @@ -1210,7 +1210,8 @@ "MSG_SCHEDULE_RESET": "Çöp Toplama programı sıfırlandı", "PARAMETERS": "Parameters", "DELETE_UNTAGGED": "Allow garbage collection on untagged artifacts", - "EXPLAIN": "GC is a compute intensive operation that may impact registry performance" + "EXPLAIN": "GC is a compute intensive operation that may impact registry performance", + "DRY_RUN_SUCCESS": "Triggered dry run successfully" }, "RETAG": { "MSG_SUCCESS": "Copy artifact successfully", diff --git a/src/portal/src/i18n/lang/zh-cn-lang.json b/src/portal/src/i18n/lang/zh-cn-lang.json index 0aa577cee..37720a26f 100644 --- a/src/portal/src/i18n/lang/zh-cn-lang.json +++ b/src/portal/src/i18n/lang/zh-cn-lang.json @@ -1207,7 +1207,8 @@ "MSG_SCHEDULE_RESET": "垃圾回收定时任务已被重置", "PARAMETERS": "参数", "DELETE_UNTAGGED": "允许回收无 tag 的 artifacts", - "EXPLAIN": "垃圾回收是一个计算密集型操作,可能会影响仓库性能" + "EXPLAIN": "垃圾回收是一个计算密集型操作,可能会影响仓库性能", + "DRY_RUN_SUCCESS": "触发模拟运行成功" }, "RETAG": { "MSG_SUCCESS": "Artifact 拷贝成功", diff --git a/src/portal/src/i18n/lang/zh-tw-lang.json b/src/portal/src/i18n/lang/zh-tw-lang.json index 8e42cda2f..adec4b9cd 100644 --- a/src/portal/src/i18n/lang/zh-tw-lang.json +++ b/src/portal/src/i18n/lang/zh-tw-lang.json @@ -1194,7 +1194,8 @@ "MSG_SCHEDULE_RESET": "垃圾回收定時任務已被重置", "PARAMETERS": "參數", "DELETE_UNTAGGED": "Allow garbage collection on untagged artifacts", - "EXPLAIN": "GC is a compute intensive operation that may impact registry performance" + "EXPLAIN": "GC is a compute intensive operation that may impact registry performance", + "DRY_RUN_SUCCESS": "Triggered dry run successfully" }, "RETAG":{ "MSG_SUCCESS": "Artifact 拷貝成功", diff --git a/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.html b/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.html index 45bc82554..0de711948 100644 --- a/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.html +++ b/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.html @@ -5,6 +5,7 @@ {{'GC.JOB_ID' | translate}} {{'GC.TRIGGER_TYPE' | translate}} + {{'TAG_RETENTION.DRY_RUN' | translate}} {{'STATUS' | translate}} {{'CREATION_TIME' | translate}} {{'UPDATE_TIME' | translate}} @@ -12,6 +13,7 @@ {{job.id }} {{(job.type ? 'SCHEDULE.'+ job.type.toUpperCase() : '') | translate }} + {{isDryRun(job?.parameters)}} {{job.status.toUpperCase() | translate}} {{job.createTime | date:'medium'}} {{job.updateTime | date:'medium'}} diff --git a/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.spec.ts b/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.spec.ts index 54bf66ef1..1bd37b42f 100644 --- a/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.spec.ts +++ b/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.spec.ts @@ -18,6 +18,7 @@ describe('GcHistoryComponent', () => { job_kind: 'manual', schedule: null, job_status: 'pending', + job_parameters: '{"dry_run":true}', job_uuid: 'abc', creation_time: null, update_time: null, @@ -29,6 +30,7 @@ describe('GcHistoryComponent', () => { job_kind: 'manual', schedule: null, job_status: 'finished', + job_parameters: '{"dry_run":true}', job_uuid: 'bcd', creation_time: null, update_time: null, diff --git a/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.ts b/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.ts index 0d430ac94..1bf82dcb4 100644 --- a/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.ts +++ b/src/portal/src/lib/components/config/gc/gc-history/gc-history.component.ts @@ -9,6 +9,8 @@ const JOB_STATUS = { PENDING: "pending", RUNNING: "running" }; +const YES: string = 'Yes'; +const NO: string = 'No'; @Component({ selector: 'gc-history', templateUrl: './gc-history.component.html', @@ -59,6 +61,16 @@ export class GcHistoryComponent implements OnInit, OnDestroy { }); } + isDryRun(param: string): string { + if (param) { + const paramObj: any = JSON.parse(param); + if (paramObj && paramObj.dry_run) { + return YES; + } + } + return NO; + } + ngOnDestroy() { if (this.timerDelay) { this.timerDelay.unsubscribe(); diff --git a/src/portal/src/lib/components/config/gc/gc.component.html b/src/portal/src/lib/components/config/gc/gc.component.html index 22382675e..cca32fb40 100644 --- a/src/portal/src/lib/components/config/gc/gc.component.html +++ b/src/portal/src/lib/components/config/gc/gc.component.html @@ -21,7 +21,13 @@
- +
+ +
+
+ +
diff --git a/src/portal/src/lib/components/config/gc/gc.component.scss b/src/portal/src/lib/components/config/gc/gc.component.scss index 955d212aa..74840d900 100644 --- a/src/portal/src/lib/components/config/gc/gc.component.scss +++ b/src/portal/src/lib/components/config/gc/gc.component.scss @@ -6,7 +6,6 @@ .gc-start-btn { width:150px; - margin-left: 0.5rem; margin-top: 35px; } diff --git a/src/portal/src/lib/components/config/gc/gc.component.spec.ts b/src/portal/src/lib/components/config/gc/gc.component.spec.ts index da440eeab..c4dc1f6a2 100644 --- a/src/portal/src/lib/components/config/gc/gc.component.spec.ts +++ b/src/portal/src/lib/components/config/gc/gc.component.spec.ts @@ -25,6 +25,7 @@ describe('GcComponent', () => { id: 22222, schedule: null, job_status: 'string', + job_parameters: '{"dry_run":true}', creation_time: new Date().toDateString(), update_time: new Date().toDateString(), job_name: 'string', diff --git a/src/portal/src/lib/components/config/gc/gc.component.ts b/src/portal/src/lib/components/config/gc/gc.component.ts index f12038817..a71f0e61b 100644 --- a/src/portal/src/lib/components/config/gc/gc.component.ts +++ b/src/portal/src/lib/components/config/gc/gc.component.ts @@ -34,6 +34,7 @@ export class GcComponent implements OnInit { @ViewChild(CronScheduleComponent, {static: false}) CronScheduleComponent: CronScheduleComponent; shouldDeleteUntagged: boolean; + dryRunOnGoing: boolean = false; constructor( private gcRepoService: GcRepoService, private gcViewModelFactory: GcViewModelFactory, @@ -90,7 +91,7 @@ export class GcComponent implements OnInit { this.enableGc(); }, ONE_MINITUE); - this.gcRepoService.manualGc(this.shouldDeleteUntagged).subscribe( + this.gcRepoService.manualGc(this.shouldDeleteUntagged, false).subscribe( response => { this.translate.get("GC.MSG_SUCCESS").subscribe((res: string) => { this.errorHandler.info(res); @@ -102,6 +103,22 @@ export class GcComponent implements OnInit { ); } + dryRun() { + this.dryRunOnGoing = true; + this.gcRepoService.manualGc(this.shouldDeleteUntagged, true) + .pipe(finalize(() => this.dryRunOnGoing = false)) + .subscribe( + response => { + this.translate.get("GC.DRY_RUN_SUCCESS").subscribe((res: string) => { + this.errorHandler.info(res); + }); + }, + error => { + this.errorHandler.error(error); + } + ); + } + private enableGc() { this.disableGC = false; } diff --git a/src/portal/src/lib/components/config/gc/gc.service.ts b/src/portal/src/lib/components/config/gc/gc.service.ts index 956909548..7d3f1c875 100644 --- a/src/portal/src/lib/components/config/gc/gc.service.ts +++ b/src/portal/src/lib/components/config/gc/gc.service.ts @@ -14,13 +14,14 @@ export class GcRepoService { private errorHandler: ErrorHandler) { } - public manualGc(shouldDeleteUntagged: boolean): Observable { + public manualGc(shouldDeleteUntagged: boolean, isDryRun: boolean): Observable { const param = { "schedule": { "type": "Manual" }, parameters: { - delete_untagged: shouldDeleteUntagged + delete_untagged: shouldDeleteUntagged, + dry_run: isDryRun } }; return this.gcApiRepository.postSchedule(param); diff --git a/src/portal/src/lib/components/config/gc/gc.viewmodel.factory.ts b/src/portal/src/lib/components/config/gc/gc.viewmodel.factory.ts index ba109ba75..0266a7bff 100644 --- a/src/portal/src/lib/components/config/gc/gc.viewmodel.factory.ts +++ b/src/portal/src/lib/components/config/gc/gc.viewmodel.factory.ts @@ -13,6 +13,7 @@ export class GcViewModelFactory { id: job.id, type: job.schedule ? job.schedule.type : null, status: job.job_status, + parameters: job.job_parameters, createTime: createTime, updateTime: updateTime, details: null diff --git a/src/portal/src/lib/components/config/gc/gcLog.ts b/src/portal/src/lib/components/config/gc/gcLog.ts index e55dd3751..04f54311d 100644 --- a/src/portal/src/lib/components/config/gc/gcLog.ts +++ b/src/portal/src/lib/components/config/gc/gcLog.ts @@ -4,6 +4,7 @@ export class GcJobData { job_kind: string; schedule: Schedule; job_status: string; + job_parameters: string; job_uuid: string; creation_time: string; update_time: string; @@ -18,6 +19,7 @@ export class GcJobViewModel { id: number; type: string; status: string; + parameters: string; createTime: Date; updateTime: Date; details: string;