mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-13 19:21:56 +01:00
Migrate policy API calls to generated service (#17782)
Signed-off-by: AllForNothing <sshijun@vmware.com> Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
parent
f2212eef25
commit
e86e9aa529
@ -8,6 +8,7 @@ import { clone } from '../../../../shared/units/utils';
|
||||
import { InlineAlertComponent } from '../../../../shared/components/inline-alert/inline-alert.component';
|
||||
import { SharedTestingModule } from '../../../../shared/shared.module';
|
||||
import { AddImmutableRuleComponent } from './add-rule/add-immutable-rule.component';
|
||||
import { ImmutableService } from '../../../../../../ng-swagger-gen/services/immutable.service';
|
||||
|
||||
describe('ImmutableTagComponent', () => {
|
||||
let component: ImmutableTagComponent;
|
||||
@ -110,16 +111,13 @@ describe('ImmutableTagComponent', () => {
|
||||
},
|
||||
},
|
||||
];
|
||||
const fakedImmutableTagService = {
|
||||
getI18nKey() {
|
||||
return 'test';
|
||||
},
|
||||
getRetentionMetadata() {
|
||||
const mockedImmutableService = {
|
||||
getRentenitionMetadata() {
|
||||
return throwError(() => {
|
||||
return { error: { message: 'error' } };
|
||||
});
|
||||
},
|
||||
getRules(projectId) {
|
||||
ListImmuRules(projectId) {
|
||||
if (projectId) {
|
||||
return of(mockRules);
|
||||
}
|
||||
@ -127,13 +125,13 @@ describe('ImmutableTagComponent', () => {
|
||||
return 'error';
|
||||
});
|
||||
},
|
||||
updateRule() {
|
||||
UpdateImmuRule() {
|
||||
return of(null);
|
||||
},
|
||||
deleteRule() {
|
||||
DeleteImmuRule() {
|
||||
return of(null);
|
||||
},
|
||||
createRule(projectId, cloneRuleNoId) {
|
||||
CreateImmuRule(projectId, cloneRuleNoId) {
|
||||
if (projectId) {
|
||||
return of(mockRules);
|
||||
}
|
||||
@ -145,6 +143,11 @@ describe('ImmutableTagComponent', () => {
|
||||
return of(null);
|
||||
},
|
||||
};
|
||||
const fakedImmutableTagService = {
|
||||
getI18nKey() {
|
||||
return 'test';
|
||||
},
|
||||
};
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [
|
||||
@ -159,6 +162,10 @@ describe('ImmutableTagComponent', () => {
|
||||
provide: ImmutableTagService,
|
||||
useValue: fakedImmutableTagService,
|
||||
},
|
||||
{
|
||||
provide: ImmutableService,
|
||||
useValue: mockedImmutableService,
|
||||
},
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
|
@ -1,11 +1,17 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ImmutableTagService } from './immutable-tag.service';
|
||||
import { ImmutableRetentionRule } from '../tag-retention/retention';
|
||||
import {
|
||||
ImmutableRetentionRule,
|
||||
RuleMetadate,
|
||||
} from '../tag-retention/retention';
|
||||
import { finalize } from 'rxjs/operators';
|
||||
import { ErrorHandler } from '../../../../shared/units/error-handler';
|
||||
import { clone } from '../../../../shared/units/utils';
|
||||
import { AddImmutableRuleComponent } from './add-rule/add-immutable-rule.component';
|
||||
import { ImmutableService } from '../../../../../../ng-swagger-gen/services/immutable.service';
|
||||
import { RetentionService } from '../../../../../../ng-swagger-gen/services/retention.service';
|
||||
import { ProjectService } from '../../../../../../ng-swagger-gen/services/project.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-immutable-tag',
|
||||
@ -25,7 +31,10 @@ export class ImmutableTagComponent implements OnInit {
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private immutableTagService: ImmutableTagService,
|
||||
public errorHandler: ErrorHandler
|
||||
private immutableService: ImmutableService,
|
||||
private retentionService: RetentionService,
|
||||
public errorHandler: ErrorHandler,
|
||||
private projectService: ProjectService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@ -35,27 +44,31 @@ export class ImmutableTagComponent implements OnInit {
|
||||
}
|
||||
|
||||
getMetadata() {
|
||||
this.immutableTagService.getRetentionMetadata().subscribe(
|
||||
response => {
|
||||
this.addRuleComponent.metadata = response;
|
||||
this.retentionService.getRentenitionMetadata().subscribe({
|
||||
next: res => {
|
||||
this.addRuleComponent.metadata = res as RuleMetadate;
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
getRules() {
|
||||
this.immutableTagService.getRules(this.projectId).subscribe(
|
||||
response => {
|
||||
this.rules = response as ImmutableRetentionRule[];
|
||||
this.loadingRule = false;
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
this.loadingRule = false;
|
||||
}
|
||||
);
|
||||
this.immutableService
|
||||
.ListImmuRules({
|
||||
projectNameOrId: this.projectId.toString(),
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.rules = res as ImmutableRetentionRule[];
|
||||
this.loadingRule = false;
|
||||
},
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
this.loadingRule = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
editRuleByIndex(index) {
|
||||
@ -71,31 +84,40 @@ export class ImmutableTagComponent implements OnInit {
|
||||
cloneRule.disabled = isActionDisable;
|
||||
this.ruleIndex = -1;
|
||||
this.loadingRule = true;
|
||||
this.immutableTagService
|
||||
.updateRule(this.projectId, cloneRule)
|
||||
.subscribe(
|
||||
response => {
|
||||
this.immutableService
|
||||
.UpdateImmuRule({
|
||||
immutableRuleId: cloneRule.id,
|
||||
projectNameOrId: this.projectId.toString(),
|
||||
ImmutableRule: cloneRule,
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.getRules();
|
||||
},
|
||||
error => {
|
||||
error: err => {
|
||||
this.loadingRule = false;
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
deleteRule(ruleId) {
|
||||
// // if rules is empty, clear schedule.
|
||||
this.ruleIndex = -1;
|
||||
this.loadingRule = true;
|
||||
this.immutableTagService.deleteRule(this.projectId, ruleId).subscribe(
|
||||
response => {
|
||||
this.getRules();
|
||||
},
|
||||
error => {
|
||||
this.loadingRule = false;
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
this.immutableService
|
||||
.DeleteImmuRule({
|
||||
projectNameOrId: this.projectId.toString(),
|
||||
immutableRuleId: ruleId,
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.getRules();
|
||||
},
|
||||
error: err => {
|
||||
this.loadingRule = false;
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openAddRule() {
|
||||
@ -113,15 +135,19 @@ export class ImmutableTagComponent implements OnInit {
|
||||
}
|
||||
|
||||
refreshAfterCreatRetention() {
|
||||
this.immutableTagService.getProjectInfo(this.projectId).subscribe(
|
||||
response => {
|
||||
this.getRules();
|
||||
},
|
||||
error => {
|
||||
this.loadingRule = false;
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
this.projectService
|
||||
.getProject({
|
||||
projectNameOrId: this.projectId.toString(),
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.getRules();
|
||||
},
|
||||
error: err => {
|
||||
this.loadingRule = false;
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
clickAdd(rule) {
|
||||
@ -129,76 +155,64 @@ export class ImmutableTagComponent implements OnInit {
|
||||
this.addRuleComponent.onGoing = true;
|
||||
if (this.addRuleComponent.isAdd) {
|
||||
if (!rule.id) {
|
||||
this.immutableTagService
|
||||
.createRule(this.projectId, rule)
|
||||
this.immutableService
|
||||
.CreateImmuRule({
|
||||
projectNameOrId: this.projectId.toString(),
|
||||
ImmutableRule: rule,
|
||||
})
|
||||
.pipe(
|
||||
finalize(() => (this.addRuleComponent.onGoing = false))
|
||||
)
|
||||
.subscribe(
|
||||
response => {
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.refreshAfterCreatRetention();
|
||||
this.addRuleComponent.close();
|
||||
},
|
||||
error => {
|
||||
if (error && error.error && error.error.message) {
|
||||
error = this.immutableTagService.getI18nKey(
|
||||
error.error.message
|
||||
error: err => {
|
||||
if (err && err.error && err.error.message) {
|
||||
err = this.immutableTagService.getI18nKey(
|
||||
err.error.message
|
||||
);
|
||||
}
|
||||
this.addRuleComponent.inlineAlert.showInlineError(
|
||||
error
|
||||
err
|
||||
);
|
||||
this.loadingRule = false;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
this.immutableTagService
|
||||
.updateRule(this.projectId, rule)
|
||||
.pipe(
|
||||
finalize(() => (this.addRuleComponent.onGoing = false))
|
||||
)
|
||||
.subscribe(
|
||||
response => {
|
||||
this.getRules();
|
||||
this.addRuleComponent.close();
|
||||
},
|
||||
error => {
|
||||
this.loadingRule = false;
|
||||
if (error && error.error && error.error.message) {
|
||||
error = this.immutableTagService.getI18nKey(
|
||||
error.error.message
|
||||
);
|
||||
}
|
||||
this.addRuleComponent.inlineAlert.showInlineError(
|
||||
error
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
} else {
|
||||
this.updateRule(rule);
|
||||
}
|
||||
} else {
|
||||
this.immutableTagService
|
||||
.updateRule(this.projectId, rule)
|
||||
.pipe(finalize(() => (this.addRuleComponent.onGoing = false)))
|
||||
.subscribe(
|
||||
response => {
|
||||
this.getRules();
|
||||
this.addRuleComponent.close();
|
||||
},
|
||||
error => {
|
||||
if (error && error.error && error.error.message) {
|
||||
error = this.immutableTagService.getI18nKey(
|
||||
error.error.message
|
||||
);
|
||||
}
|
||||
this.addRuleComponent.inlineAlert.showInlineError(
|
||||
error
|
||||
);
|
||||
this.loadingRule = false;
|
||||
}
|
||||
);
|
||||
this.updateRule(rule);
|
||||
}
|
||||
}
|
||||
|
||||
updateRule(rule: any) {
|
||||
this.immutableService
|
||||
.UpdateImmuRule({
|
||||
projectNameOrId: this.projectId.toString(),
|
||||
immutableRuleId: rule.id,
|
||||
ImmutableRule: rule,
|
||||
})
|
||||
.pipe(finalize(() => (this.addRuleComponent.onGoing = false)))
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.getRules();
|
||||
this.addRuleComponent.close();
|
||||
},
|
||||
error: err => {
|
||||
this.loadingRule = false;
|
||||
if (err && err.error && err.error.message) {
|
||||
err = this.immutableTagService.getI18nKey(
|
||||
err.error.message
|
||||
);
|
||||
}
|
||||
this.addRuleComponent.inlineAlert.showInlineError(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
formatPattern(pattern: string): string {
|
||||
let str: string = pattern;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
|
@ -1,15 +1,10 @@
|
||||
import { ImmutableTagService } from './immutable-tag.service';
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
import {
|
||||
HttpClientTestingModule,
|
||||
HttpTestingController,
|
||||
} from '@angular/common/http/testing';
|
||||
|
||||
describe('ImmutableTagService', () => {
|
||||
beforeEach(() =>
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ImmutableTagService],
|
||||
imports: [HttpClientTestingModule],
|
||||
})
|
||||
);
|
||||
|
||||
@ -17,114 +12,7 @@ describe('ImmutableTagService', () => {
|
||||
const service: ImmutableTagService = TestBed.get(ImmutableTagService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
it('should get rules', inject(
|
||||
[HttpTestingController, ImmutableTagService],
|
||||
(
|
||||
httpMock: HttpTestingController,
|
||||
immutableTagService: ImmutableTagService
|
||||
) => {
|
||||
const mockRules = [
|
||||
{
|
||||
id: 1,
|
||||
project_id: 1,
|
||||
disabled: false,
|
||||
priority: 0,
|
||||
action: 'immutable',
|
||||
template: 'immutable_template',
|
||||
tag_selectors: [
|
||||
{
|
||||
kind: 'doublestar',
|
||||
decoration: 'matches',
|
||||
pattern: '**',
|
||||
},
|
||||
],
|
||||
scope_selectors: {
|
||||
repository: [
|
||||
{
|
||||
kind: 'doublestar',
|
||||
decoration: 'repoMatches',
|
||||
pattern: '**',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
project_id: 1,
|
||||
disabled: false,
|
||||
priority: 0,
|
||||
action: 'immutable',
|
||||
template: 'immutable_template',
|
||||
tag_selectors: [
|
||||
{
|
||||
kind: 'doublestar',
|
||||
decoration: 'matches',
|
||||
pattern: '44',
|
||||
},
|
||||
],
|
||||
scope_selectors: {
|
||||
repository: [
|
||||
{
|
||||
kind: 'doublestar',
|
||||
decoration: 'repoMatches',
|
||||
pattern: '**',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
project_id: 1,
|
||||
disabled: false,
|
||||
priority: 0,
|
||||
action: 'immutable',
|
||||
template: 'immutable_template',
|
||||
tag_selectors: [
|
||||
{
|
||||
kind: 'doublestar',
|
||||
decoration: 'matches',
|
||||
pattern: '555',
|
||||
},
|
||||
],
|
||||
scope_selectors: {
|
||||
repository: [
|
||||
{
|
||||
kind: 'doublestar',
|
||||
decoration: 'repoMatches',
|
||||
pattern: '**',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
project_id: 1,
|
||||
disabled: false,
|
||||
priority: 0,
|
||||
action: 'immutable',
|
||||
template: 'immutable_template',
|
||||
tag_selectors: [
|
||||
{
|
||||
kind: 'doublestar',
|
||||
decoration: 'matches',
|
||||
pattern: 'fff**',
|
||||
},
|
||||
],
|
||||
scope_selectors: {
|
||||
repository: [
|
||||
{
|
||||
kind: 'doublestar',
|
||||
decoration: 'repoMatches',
|
||||
pattern: '**ggg',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
immutableTagService.getRules(1).subscribe(res => {
|
||||
expect(res).toEqual(mockRules);
|
||||
});
|
||||
}
|
||||
));
|
||||
it('should get rules', inject([ImmutableTagService], service => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
|
@ -1,16 +1,4 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {
|
||||
ImmutableRetentionRule,
|
||||
RuleMetadate,
|
||||
} from '../tag-retention/retention';
|
||||
import { Observable, throwError as observableThrowError } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { Project } from '../../project';
|
||||
import {
|
||||
CURRENT_BASE_HREF,
|
||||
HTTP_JSON_OPTIONS,
|
||||
} from '../../../../shared/units/utils';
|
||||
|
||||
@Injectable()
|
||||
export class ImmutableTagService {
|
||||
@ -25,59 +13,10 @@ export class ImmutableTagService {
|
||||
nothing: 'NONE',
|
||||
};
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getI18nKey(str: string): string {
|
||||
if (this.I18nMap[str.trim()]) {
|
||||
return 'IMMUTABLE_TAG.' + this.I18nMap[str.trim()];
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
getRetentionMetadata(): Observable<RuleMetadate> {
|
||||
return this.http
|
||||
.get(`${CURRENT_BASE_HREF}/retentions/metadatas`)
|
||||
.pipe(map(response => response as RuleMetadate))
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
getRules(projectId): Observable<ImmutableRetentionRule[]> {
|
||||
return this.http
|
||||
.get(`${CURRENT_BASE_HREF}/projects/${projectId}/immutabletagrules`)
|
||||
.pipe(map(response => response as ImmutableRetentionRule[]))
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
createRule(projectId: number, retention: ImmutableRetentionRule) {
|
||||
return this.http
|
||||
.post(
|
||||
`${CURRENT_BASE_HREF}/projects/${projectId}/immutabletagrules`,
|
||||
retention
|
||||
)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
updateRule(projectId, immutabletagrule: ImmutableRetentionRule) {
|
||||
return this.http
|
||||
.put(
|
||||
`${CURRENT_BASE_HREF}/projects/${projectId}/immutabletagrules/${immutabletagrule.id}`,
|
||||
immutabletagrule
|
||||
)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
deleteRule(projectId, ruleId) {
|
||||
return this.http
|
||||
.delete(
|
||||
`${CURRENT_BASE_HREF}/projects/${projectId}/immutabletagrules/${ruleId}`,
|
||||
HTTP_JSON_OPTIONS
|
||||
)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
getProjectInfo(projectId) {
|
||||
return this.http
|
||||
.get(`${CURRENT_BASE_HREF}/projects/${projectId}`)
|
||||
.pipe(map(response => response as Project))
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
}
|
||||
|
@ -157,3 +157,7 @@ export class RuleMetadate {
|
||||
export const RUNNING: string = 'Running';
|
||||
export const PENDING: string = 'Pending';
|
||||
export const TIMEOUT: number = 5000;
|
||||
|
||||
export enum RetentionAction {
|
||||
STOP = 'stop',
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import { Registry } from '../../../../../../../../ng-swagger-gen/models/registry
|
||||
import { of } from 'rxjs';
|
||||
import { delay } from 'rxjs/operators';
|
||||
import { TIMEOUT } from '../../retention';
|
||||
import { RetentionService } from '../../../../../../../../ng-swagger-gen/services/retention.service';
|
||||
|
||||
describe('TagRetentionTasksComponent', () => {
|
||||
let component: TagRetentionTasksComponent;
|
||||
@ -44,10 +45,13 @@ describe('TagRetentionTasksComponent', () => {
|
||||
total: 1,
|
||||
},
|
||||
];
|
||||
const mockedTagRetentionService = {
|
||||
seeLog() {},
|
||||
};
|
||||
|
||||
const mockTagRetentionService = {
|
||||
const mockRetentionService = {
|
||||
count: 0,
|
||||
getExecutionHistory() {
|
||||
listRetentionTasksResponse() {
|
||||
if (this.count === 0) {
|
||||
this.count += 1;
|
||||
const response: HttpResponse<Array<Registry>> =
|
||||
@ -80,7 +84,11 @@ describe('TagRetentionTasksComponent', () => {
|
||||
providers: [
|
||||
{
|
||||
provide: TagRetentionService,
|
||||
useValue: mockTagRetentionService,
|
||||
useValue: mockedTagRetentionService,
|
||||
},
|
||||
{
|
||||
provide: RetentionService,
|
||||
useValue: mockRetentionService,
|
||||
},
|
||||
],
|
||||
}).compileComponents();
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { Component, Input, OnDestroy } from '@angular/core';
|
||||
import { finalize } from 'rxjs/operators';
|
||||
import { TagRetentionComponent } from '../../tag-retention.component';
|
||||
import { TagRetentionService } from '../../tag-retention.service';
|
||||
import { ErrorHandler } from '../../../../../../shared/units/error-handler';
|
||||
import { PENDING, RUNNING, TIMEOUT } from '../../retention';
|
||||
import { RetentionService } from '../../../../../../../../ng-swagger-gen/services/retention.service';
|
||||
import { TagRetentionService } from '../../tag-retention.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-tag-retention-tasks',
|
||||
@ -23,6 +24,7 @@ export class TagRetentionTasksComponent implements OnDestroy {
|
||||
tasksTimeout;
|
||||
constructor(
|
||||
private tagRetentionService: TagRetentionService,
|
||||
private retentionService: RetentionService,
|
||||
private errorHandler: ErrorHandler
|
||||
) {}
|
||||
ngOnDestroy() {
|
||||
@ -33,32 +35,22 @@ export class TagRetentionTasksComponent implements OnDestroy {
|
||||
}
|
||||
loadLog() {
|
||||
this.loading = true;
|
||||
this.tagRetentionService
|
||||
.getExecutionHistory(
|
||||
this.retentionId,
|
||||
this.executionId,
|
||||
this.page,
|
||||
this.pageSize
|
||||
)
|
||||
this.retentionService
|
||||
.listRetentionTasksResponse({
|
||||
id: this.retentionId,
|
||||
eid: this.executionId,
|
||||
page: this.page,
|
||||
pageSize: this.pageSize,
|
||||
})
|
||||
.pipe(finalize(() => (this.loading = false)))
|
||||
.subscribe(
|
||||
(response: any) => {
|
||||
// Get total count
|
||||
if (response.headers) {
|
||||
let xHeader: string =
|
||||
response.headers.get('x-total-count');
|
||||
if (xHeader) {
|
||||
this.total = parseInt(xHeader, 0);
|
||||
}
|
||||
}
|
||||
this.tasks = response.body as Array<any>;
|
||||
TagRetentionComponent.calculateDuration(this.tasks);
|
||||
this.loopGettingTasks();
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.handleResponse(res);
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
seeLog(executionId, taskId) {
|
||||
this.tagRetentionService.seeLog(this.retentionId, executionId, taskId);
|
||||
@ -72,28 +64,31 @@ export class TagRetentionTasksComponent implements OnDestroy {
|
||||
})
|
||||
) {
|
||||
this.tasksTimeout = setTimeout(() => {
|
||||
this.tagRetentionService
|
||||
.getExecutionHistory(
|
||||
this.retentionId,
|
||||
this.executionId,
|
||||
this.page,
|
||||
this.pageSize
|
||||
)
|
||||
this.retentionService
|
||||
.listRetentionTasksResponse({
|
||||
id: this.retentionId,
|
||||
eid: this.executionId,
|
||||
page: this.page,
|
||||
pageSize: this.pageSize,
|
||||
})
|
||||
.pipe(finalize(() => (this.loading = false)))
|
||||
.subscribe(res => {
|
||||
// Get total count
|
||||
if (res.headers) {
|
||||
let xHeader: string =
|
||||
res.headers.get('x-total-count');
|
||||
if (xHeader) {
|
||||
this.total = parseInt(xHeader, 0);
|
||||
}
|
||||
}
|
||||
this.tasks = res.body as Array<any>;
|
||||
TagRetentionComponent.calculateDuration(this.tasks);
|
||||
this.loopGettingTasks();
|
||||
this.handleResponse(res);
|
||||
});
|
||||
}, TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
handleResponse(res: any) {
|
||||
// Get total count
|
||||
if (res.headers) {
|
||||
let xHeader: string = res.headers.get('x-total-count');
|
||||
if (xHeader) {
|
||||
this.total = parseInt(xHeader, 0);
|
||||
}
|
||||
}
|
||||
this.tasks = res.body as Array<any>;
|
||||
TagRetentionComponent.calculateDuration(this.tasks);
|
||||
this.loopGettingTasks();
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import { delay } from 'rxjs/operators';
|
||||
import { SharedTestingModule } from '../../../../shared/shared.module';
|
||||
import { HttpHeaders, HttpResponse } from '@angular/common/http';
|
||||
import { Registry } from '../../../../../../ng-swagger-gen/models/registry';
|
||||
import { RetentionService } from 'ng-swagger-gen/services/retention.service';
|
||||
|
||||
describe('TagRetentionComponent', () => {
|
||||
const mockedRunningExecutions = [
|
||||
@ -42,18 +43,12 @@ describe('TagRetentionComponent', () => {
|
||||
let component: TagRetentionComponent;
|
||||
let fixture: ComponentFixture<TagRetentionComponent>;
|
||||
const mockTagRetentionService = {
|
||||
seeLog: () => of(null).pipe(delay(0)),
|
||||
};
|
||||
const mockRetentionService = {
|
||||
createRetention: () => of(null).pipe(delay(0)),
|
||||
updateRetention: () => of(null).pipe(delay(0)),
|
||||
runNowTrigger: () => of(null).pipe(delay(0)),
|
||||
whatIfRunTrigger: () => of(null).pipe(delay(0)),
|
||||
AbortRun: () => of(null).pipe(delay(0)),
|
||||
seeLog: () => of(null).pipe(delay(0)),
|
||||
getExecutionHistory: () =>
|
||||
of({
|
||||
body: [],
|
||||
}).pipe(delay(0)),
|
||||
count: 0,
|
||||
getRunNowList() {
|
||||
listRetentionExecutionsResponse() {
|
||||
if (this.count === 0) {
|
||||
this.count += 1;
|
||||
const response: HttpResponse<Array<Registry>> =
|
||||
@ -78,13 +73,7 @@ describe('TagRetentionComponent', () => {
|
||||
return of(response).pipe(delay(0));
|
||||
}
|
||||
},
|
||||
getProjectInfo: () =>
|
||||
of({
|
||||
metadata: {
|
||||
retention_id: 1,
|
||||
},
|
||||
}).pipe(delay(0)),
|
||||
getRetentionMetadata: () => of(new RuleMetadate()).pipe(delay(0)),
|
||||
getRentenitionMetadata: () => of(new RuleMetadate()).pipe(delay(0)),
|
||||
getRetention: () => of(new Retention()).pipe(delay(0)),
|
||||
};
|
||||
const mockActivatedRoute = {
|
||||
@ -115,6 +104,10 @@ describe('TagRetentionComponent', () => {
|
||||
provide: TagRetentionService,
|
||||
useValue: mockTagRetentionService,
|
||||
},
|
||||
{
|
||||
provide: RetentionService,
|
||||
useValue: mockRetentionService,
|
||||
},
|
||||
{ provide: ActivatedRoute, useValue: mockActivatedRoute },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
@ -14,12 +14,17 @@
|
||||
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { AddRuleComponent } from './add-rule/add-rule.component';
|
||||
import {
|
||||
ClrDatagridStateInterface,
|
||||
ClrDatagridStringFilterInterface,
|
||||
} from '@clr/angular';
|
||||
import { ClrDatagridStateInterface } from '@clr/angular';
|
||||
import { TagRetentionService } from './tag-retention.service';
|
||||
import { PENDING, Retention, Rule, RUNNING, TIMEOUT } from './retention';
|
||||
import {
|
||||
PENDING,
|
||||
Retention,
|
||||
RetentionAction,
|
||||
Rule,
|
||||
RuleMetadate,
|
||||
RUNNING,
|
||||
TIMEOUT,
|
||||
} from './retention';
|
||||
import { finalize } from 'rxjs/operators';
|
||||
import { CronScheduleComponent } from '../../../../shared/components/cron-schedule';
|
||||
import { ErrorHandler } from '../../../../shared/units/error-handler';
|
||||
@ -30,6 +35,9 @@ import {
|
||||
PageSizeMapKeys,
|
||||
setPageSizeToLocalStorage,
|
||||
} from '../../../../shared/units/utils';
|
||||
import { RetentionService } from '../../../../../../ng-swagger-gen/services/retention.service';
|
||||
import { RetentionPolicy } from '../../../../../../ng-swagger-gen/models/retention-policy';
|
||||
import { ProjectService } from '../../../../../../ng-swagger-gen/services/project.service';
|
||||
|
||||
const MIN = 60000;
|
||||
const SEC = 1000;
|
||||
@ -53,24 +61,6 @@ const DECORATION = {
|
||||
styleUrls: ['./tag-retention.component.scss'],
|
||||
})
|
||||
export class TagRetentionComponent implements OnInit, OnDestroy {
|
||||
serialFilter: ClrDatagridStringFilterInterface<any> = {
|
||||
accepts(item: any, search: string): boolean {
|
||||
return item.id.toString().indexOf(search) !== -1;
|
||||
},
|
||||
};
|
||||
statusFilter: ClrDatagridStringFilterInterface<any> = {
|
||||
accepts(item: any, search: string): boolean {
|
||||
return (
|
||||
item.status.toLowerCase().indexOf(search.toLowerCase()) !== -1
|
||||
);
|
||||
},
|
||||
};
|
||||
dryRunFilter: ClrDatagridStringFilterInterface<any> = {
|
||||
accepts(item: any, search: string): boolean {
|
||||
let str = item.dry_run ? 'YES' : 'NO';
|
||||
return str.indexOf(search) !== -1;
|
||||
},
|
||||
};
|
||||
projectId: number;
|
||||
isRetentionRunOpened: boolean = false;
|
||||
isAbortedOpened: boolean = false;
|
||||
@ -98,7 +88,9 @@ export class TagRetentionComponent implements OnInit, OnDestroy {
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private tagRetentionService: TagRetentionService,
|
||||
private errorHandler: ErrorHandler
|
||||
private retentionService: RetentionService,
|
||||
private errorHandler: ErrorHandler,
|
||||
private projectService: ProjectService
|
||||
) {}
|
||||
originCron(): OriginCron {
|
||||
let originCron: OriginCron = {
|
||||
@ -149,67 +141,74 @@ export class TagRetentionComponent implements OnInit, OnDestroy {
|
||||
this.updateCron(this.cron);
|
||||
}
|
||||
updateCron(cron: string) {
|
||||
let retention: Retention = clone(this.retention);
|
||||
retention.trigger.settings.cron = cron;
|
||||
let retention: RetentionPolicy = clone(this.retention);
|
||||
retention.trigger.settings['cron'] = cron;
|
||||
if (!this.retentionId) {
|
||||
this.tagRetentionService.createRetention(retention).subscribe(
|
||||
response => {
|
||||
this.cronScheduleComponent.isEditMode = false;
|
||||
this.refreshAfterCreatRetention();
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
this.retentionService
|
||||
.createRetention({
|
||||
policy: retention,
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.cronScheduleComponent.isEditMode = false;
|
||||
this.refreshAfterCreatRetention();
|
||||
},
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.tagRetentionService
|
||||
.updateRetention(this.retentionId, retention)
|
||||
.subscribe(
|
||||
response => {
|
||||
this.retentionService
|
||||
.updateRetention({
|
||||
id: this.retentionId,
|
||||
policy: retention,
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.cronScheduleComponent.isEditMode = false;
|
||||
this.getRetention();
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
getMetadata() {
|
||||
this.tagRetentionService.getRetentionMetadata().subscribe(
|
||||
response => {
|
||||
this.addRuleComponent.metadata = response;
|
||||
this.retentionService.getRentenitionMetadata().subscribe({
|
||||
next: res => {
|
||||
this.addRuleComponent.metadata = res as RuleMetadate;
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
getRetention() {
|
||||
if (this.retentionId) {
|
||||
this.tagRetentionService.getRetention(this.retentionId).subscribe(
|
||||
response => {
|
||||
if (
|
||||
response &&
|
||||
response.rules &&
|
||||
response.rules.length > 0
|
||||
) {
|
||||
response.rules.forEach(item => {
|
||||
if (!item.params) {
|
||||
item.params = {};
|
||||
}
|
||||
this.setRuleUntagged(item);
|
||||
});
|
||||
}
|
||||
this.retention = response;
|
||||
this.loadingRule = false;
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
this.loadingRule = false;
|
||||
}
|
||||
);
|
||||
this.retentionService
|
||||
.getRetention({
|
||||
id: this.retentionId,
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
if (res?.rules?.length) {
|
||||
res.rules.forEach(item => {
|
||||
if (!item.params) {
|
||||
item.params = {};
|
||||
}
|
||||
this.setRuleUntagged(item);
|
||||
});
|
||||
}
|
||||
this.retention = res as Retention;
|
||||
this.loadingRule = false;
|
||||
},
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
this.loadingRule = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,42 +223,48 @@ export class TagRetentionComponent implements OnInit, OnDestroy {
|
||||
this.ruleIndex = -1;
|
||||
}
|
||||
toggleDisable(index, isActionDisable) {
|
||||
let retention: Retention = clone(this.retention);
|
||||
let retention: RetentionPolicy = clone(this.retention);
|
||||
retention.rules[index].disabled = isActionDisable;
|
||||
this.ruleIndex = -1;
|
||||
this.loadingRule = true;
|
||||
this.tagRetentionService
|
||||
.updateRetention(this.retentionId, retention)
|
||||
.subscribe(
|
||||
response => {
|
||||
this.retentionService
|
||||
.updateRetention({
|
||||
id: this.retentionId,
|
||||
policy: retention,
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.getRetention();
|
||||
},
|
||||
error => {
|
||||
error: err => {
|
||||
this.loadingRule = false;
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
deleteRule(index) {
|
||||
let retention: Retention = clone(this.retention);
|
||||
let retention: RetentionPolicy = clone(this.retention);
|
||||
retention.rules.splice(index, 1);
|
||||
// if rules is empty, clear schedule.
|
||||
if (retention.rules && retention.rules.length === 0) {
|
||||
retention.trigger.settings.cron = '';
|
||||
retention.trigger.settings['cron'] = '';
|
||||
}
|
||||
this.ruleIndex = -1;
|
||||
this.loadingRule = true;
|
||||
this.tagRetentionService
|
||||
.updateRetention(this.retentionId, retention)
|
||||
.subscribe(
|
||||
response => {
|
||||
this.retentionService
|
||||
.updateRetention({
|
||||
id: this.retentionId,
|
||||
policy: retention,
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.getRetention();
|
||||
},
|
||||
error => {
|
||||
error: err => {
|
||||
this.loadingRule = false;
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
setRuleUntagged(rule) {
|
||||
if (!rule.tag_selectors[0].extras) {
|
||||
@ -294,25 +299,39 @@ export class TagRetentionComponent implements OnInit, OnDestroy {
|
||||
|
||||
runRetention() {
|
||||
this.isRetentionRunOpened = false;
|
||||
this.tagRetentionService.runNowTrigger(this.retentionId).subscribe(
|
||||
response => {
|
||||
this.refreshList();
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
this.retentionService
|
||||
.triggerRetentionExecution({
|
||||
id: this.retentionId,
|
||||
body: {
|
||||
dry_run: false,
|
||||
},
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.refreshList();
|
||||
},
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
whatIfRun() {
|
||||
this.tagRetentionService.whatIfRunTrigger(this.retentionId).subscribe(
|
||||
response => {
|
||||
this.refreshList();
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
this.retentionService
|
||||
.triggerRetentionExecution({
|
||||
id: this.retentionId,
|
||||
body: {
|
||||
dry_run: true,
|
||||
},
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.refreshList();
|
||||
},
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
loopGettingExecutions() {
|
||||
if (
|
||||
@ -323,12 +342,12 @@ export class TagRetentionComponent implements OnInit, OnDestroy {
|
||||
})
|
||||
) {
|
||||
this.executionTimeout = setTimeout(() => {
|
||||
this.tagRetentionService
|
||||
.getRunNowList(
|
||||
this.retentionId,
|
||||
this.currentPage,
|
||||
this.pageSize
|
||||
)
|
||||
this.retentionService
|
||||
.listRetentionExecutionsResponse({
|
||||
id: this.retentionId,
|
||||
page: this.currentPage,
|
||||
pageSize: this.pageSize,
|
||||
})
|
||||
.pipe(finalize(() => (this.loadingExecutions = false)))
|
||||
.subscribe(res => {
|
||||
// Get total count
|
||||
@ -370,33 +389,33 @@ export class TagRetentionComponent implements OnInit, OnDestroy {
|
||||
);
|
||||
}
|
||||
this.loadingExecutions = true;
|
||||
this.tagRetentionService
|
||||
.getRunNowList(
|
||||
this.retentionId,
|
||||
this.currentPage,
|
||||
this.pageSize
|
||||
)
|
||||
this.retentionService
|
||||
.listRetentionExecutionsResponse({
|
||||
id: this.retentionId,
|
||||
page: this.currentPage,
|
||||
pageSize: this.pageSize,
|
||||
})
|
||||
.pipe(finalize(() => (this.loadingExecutions = false)))
|
||||
.subscribe(
|
||||
(response: any) => {
|
||||
.subscribe({
|
||||
next: res => {
|
||||
// Get total count
|
||||
if (response.headers) {
|
||||
if (res.headers) {
|
||||
let xHeader: string =
|
||||
response.headers.get('x-total-count');
|
||||
res.headers.get('x-total-count');
|
||||
if (xHeader) {
|
||||
this.totalCount = parseInt(xHeader, 0);
|
||||
}
|
||||
}
|
||||
this.executionList = response.body as Array<any>;
|
||||
this.executionList = res.body as Array<any>;
|
||||
TagRetentionComponent.calculateDuration(
|
||||
this.executionList
|
||||
);
|
||||
this.loopGettingExecutions();
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
this.loadingExecutions = false;
|
||||
@ -433,16 +452,22 @@ export class TagRetentionComponent implements OnInit, OnDestroy {
|
||||
|
||||
abortRun() {
|
||||
this.isAbortedOpened = true;
|
||||
this.tagRetentionService
|
||||
.AbortRun(this.retentionId, this.selectedItem.id)
|
||||
.subscribe(
|
||||
res => {
|
||||
this.retentionService
|
||||
.operateRetentionExecution({
|
||||
id: this.retentionId,
|
||||
eid: this.selectedItem.id,
|
||||
body: {
|
||||
action: RetentionAction.STOP,
|
||||
},
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.refreshList();
|
||||
},
|
||||
error => {
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
error: err => {
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
abortRetention() {
|
||||
@ -457,95 +482,88 @@ export class TagRetentionComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
refreshAfterCreatRetention() {
|
||||
this.tagRetentionService.getProjectInfo(this.projectId).subscribe(
|
||||
response => {
|
||||
this.retentionId = response.metadata.retention_id;
|
||||
this.refreshList();
|
||||
this.getRetention();
|
||||
},
|
||||
error => {
|
||||
this.loadingRule = false;
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
this.projectService
|
||||
.getProject({
|
||||
projectNameOrId: this.projectId.toString(),
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.retentionId = +res.metadata.retention_id;
|
||||
this.refreshList();
|
||||
this.getRetention();
|
||||
},
|
||||
error: err => {
|
||||
this.loadingRule = false;
|
||||
this.errorHandler.error(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
clickAdd(rule) {
|
||||
this.loadingRule = true;
|
||||
this.addRuleComponent.onGoing = true;
|
||||
if (this.addRuleComponent.isAdd) {
|
||||
let retention: Retention = clone(this.retention);
|
||||
let retention: RetentionPolicy = clone(this.retention);
|
||||
retention.rules.push(rule);
|
||||
if (!this.retentionId) {
|
||||
this.tagRetentionService.createRetention(retention).subscribe(
|
||||
response => {
|
||||
this.refreshAfterCreatRetention();
|
||||
this.addRuleComponent.close();
|
||||
this.addRuleComponent.onGoing = false;
|
||||
},
|
||||
error => {
|
||||
if (error && error.error && error.error.message) {
|
||||
error = this.tagRetentionService.getI18nKey(
|
||||
error.error.message
|
||||
);
|
||||
}
|
||||
this.addRuleComponent.inlineAlert.showInlineError(
|
||||
error
|
||||
);
|
||||
this.loadingRule = false;
|
||||
this.addRuleComponent.onGoing = false;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
this.tagRetentionService
|
||||
.updateRetention(this.retentionId, retention)
|
||||
.subscribe(
|
||||
response => {
|
||||
this.getRetention();
|
||||
this.retentionService
|
||||
.createRetention({
|
||||
policy: retention,
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.refreshAfterCreatRetention();
|
||||
this.addRuleComponent.close();
|
||||
this.addRuleComponent.onGoing = false;
|
||||
},
|
||||
error => {
|
||||
this.loadingRule = false;
|
||||
this.addRuleComponent.onGoing = false;
|
||||
if (error && error.error && error.error.message) {
|
||||
error = this.tagRetentionService.getI18nKey(
|
||||
error.error.message
|
||||
error: err => {
|
||||
if (err && err.error && err.error.message) {
|
||||
err = this.tagRetentionService.getI18nKey(
|
||||
err.error.message
|
||||
);
|
||||
}
|
||||
this.addRuleComponent.inlineAlert.showInlineError(
|
||||
error
|
||||
err
|
||||
);
|
||||
}
|
||||
);
|
||||
this.loadingRule = false;
|
||||
this.addRuleComponent.onGoing = false;
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.updateRetention(retention);
|
||||
}
|
||||
} else {
|
||||
let retention: Retention = clone(this.retention);
|
||||
let retention: RetentionPolicy = clone(this.retention);
|
||||
retention.rules[this.editIndex] = rule;
|
||||
this.tagRetentionService
|
||||
.updateRetention(this.retentionId, retention)
|
||||
.subscribe(
|
||||
response => {
|
||||
this.getRetention();
|
||||
this.addRuleComponent.close();
|
||||
this.addRuleComponent.onGoing = false;
|
||||
},
|
||||
error => {
|
||||
if (error && error.error && error.error.message) {
|
||||
error = this.tagRetentionService.getI18nKey(
|
||||
error.error.message
|
||||
);
|
||||
}
|
||||
this.addRuleComponent.inlineAlert.showInlineError(
|
||||
error
|
||||
);
|
||||
this.loadingRule = false;
|
||||
this.addRuleComponent.onGoing = false;
|
||||
}
|
||||
);
|
||||
this.updateRetention(retention);
|
||||
}
|
||||
}
|
||||
|
||||
updateRetention(retention: RetentionPolicy) {
|
||||
this.retentionService
|
||||
.updateRetention({
|
||||
id: this.retentionId,
|
||||
policy: retention,
|
||||
})
|
||||
.subscribe({
|
||||
next: res => {
|
||||
this.getRetention();
|
||||
this.addRuleComponent.close();
|
||||
this.addRuleComponent.onGoing = false;
|
||||
},
|
||||
error: err => {
|
||||
this.loadingRule = false;
|
||||
this.addRuleComponent.onGoing = false;
|
||||
if (err && err.error && err.error.message) {
|
||||
err = this.tagRetentionService.getI18nKey(
|
||||
err.error.message
|
||||
);
|
||||
}
|
||||
this.addRuleComponent.inlineAlert.showInlineError(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
seeLog(executionId, taskId) {
|
||||
this.tagRetentionService.seeLog(this.retentionId, executionId, taskId);
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { TagRetentionService } from './tag-retention.service';
|
||||
|
||||
describe('TagRetentionService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
providers: [TagRetentionService],
|
||||
});
|
||||
});
|
||||
|
@ -12,15 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
|
||||
import { Retention, RuleMetadate } from './retention';
|
||||
import { Observable, throwError as observableThrowError } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { Project } from '../../project';
|
||||
import {
|
||||
buildHttpRequestOptionsWithObserveResponse,
|
||||
CURRENT_BASE_HREF,
|
||||
} from '../../../../shared/units/utils';
|
||||
import { CURRENT_BASE_HREF } from '../../../../shared/units/utils';
|
||||
|
||||
@Injectable()
|
||||
export class TagRetentionService {
|
||||
@ -55,8 +47,6 @@ export class TagRetentionService {
|
||||
'Parameters latestPulledN is too large': 'COUNT_LARGE',
|
||||
};
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getI18nKey(str: string): string {
|
||||
if (this.I18nMap[str.trim()]) {
|
||||
return 'TAG_RETENTION.' + this.I18nMap[str.trim()];
|
||||
@ -64,99 +54,6 @@ export class TagRetentionService {
|
||||
return str;
|
||||
}
|
||||
|
||||
getRetentionMetadata(): Observable<RuleMetadate> {
|
||||
return this.http
|
||||
.get(`${CURRENT_BASE_HREF}/retentions/metadatas`)
|
||||
.pipe(map(response => response as RuleMetadate))
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
getRetention(retentionId): Observable<Retention> {
|
||||
return this.http
|
||||
.get(`${CURRENT_BASE_HREF}/retentions/${retentionId}`)
|
||||
.pipe(map(response => response as Retention))
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
createRetention(retention: Retention) {
|
||||
return this.http
|
||||
.post(`${CURRENT_BASE_HREF}/retentions`, retention)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
updateRetention(retentionId, retention: Retention) {
|
||||
return this.http
|
||||
.put(`${CURRENT_BASE_HREF}/retentions/${retentionId}`, retention)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
getProjectInfo(projectId) {
|
||||
return this.http
|
||||
.get(`${CURRENT_BASE_HREF}/projects/${projectId}`)
|
||||
.pipe(map(response => response as Project))
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
runNowTrigger(retentionId) {
|
||||
return this.http
|
||||
.post(`${CURRENT_BASE_HREF}/retentions/${retentionId}/executions`, {
|
||||
dry_run: false,
|
||||
})
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
whatIfRunTrigger(retentionId) {
|
||||
return this.http
|
||||
.post(`${CURRENT_BASE_HREF}/retentions/${retentionId}/executions`, {
|
||||
dry_run: true,
|
||||
})
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
AbortRun(retentionId, executionId) {
|
||||
return this.http
|
||||
.patch(
|
||||
`${CURRENT_BASE_HREF}/retentions/${retentionId}/executions/${executionId}`,
|
||||
{ action: 'stop' }
|
||||
)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
getRunNowList(retentionId, page: number, pageSize: number) {
|
||||
let params = new HttpParams();
|
||||
if (page && pageSize) {
|
||||
params = params
|
||||
.set('page', page + '')
|
||||
.set('page_size', pageSize + '');
|
||||
}
|
||||
return this.http
|
||||
.get<HttpResponse<Array<any>>>(
|
||||
`${CURRENT_BASE_HREF}/retentions/${retentionId}/executions`,
|
||||
buildHttpRequestOptionsWithObserveResponse(params)
|
||||
)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
getExecutionHistory(
|
||||
retentionId,
|
||||
executionId,
|
||||
page: number,
|
||||
pageSize: number
|
||||
) {
|
||||
let params = new HttpParams();
|
||||
if (page && pageSize) {
|
||||
params = params
|
||||
.set('page', page + '')
|
||||
.set('page_size', pageSize + '');
|
||||
}
|
||||
return this.http
|
||||
.get<HttpResponse<Array<any>>>(
|
||||
`${CURRENT_BASE_HREF}/retentions/${retentionId}/executions/${executionId}/tasks`,
|
||||
buildHttpRequestOptionsWithObserveResponse(params)
|
||||
)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
seeLog(retentionId, executionId, taskId) {
|
||||
window.open(
|
||||
`${CURRENT_BASE_HREF}/retentions/${retentionId}/executions/${executionId}/tasks/${taskId}`,
|
||||
|
Loading…
Reference in New Issue
Block a user