Skip to content

Commit

Permalink
move gc to lib and add in registry config
Browse files Browse the repository at this point in the history
Signed-off-by: Meina Zhou <[email protected]>
  • Loading branch information
zhoumeina committed Feb 14, 2019
1 parent faaa531 commit 0d239cb
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,47 +1,62 @@

import { Injectable } from '@angular/core';
import { Injectable, Inject } from '@angular/core';
import { Http } from '@angular/http';
import { throwError as observableThrowError, Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { SERVICE_CONFIG, IServiceConfig } from "../../service.config";

export abstract class GcApiRepository {
abstract postSchedule(param): Observable<any>;

@Injectable()
export class GcApiRepository {
abstract putSchedule(param): Observable<any>;

abstract getSchedule(): Observable<any>;

abstract getLog(id): Observable<any>;

abstract getStatus(id): Observable<any>;

abstract getJobs(): Observable<any>;
}

@Injectable()
export class GcApiDefaultRepository extends GcApiRepository {
constructor(
private http: Http,
@Inject(SERVICE_CONFIG) private config: IServiceConfig
) {
super();
}

public postSchedule(param): Observable<any> {
return this.http.post("/api/system/gc/schedule", param)
return this.http.post(`${this.config.gcEndpoint}/schedule`, param)
.pipe(catchError(error => observableThrowError(error)));
}

public putSchedule(param): Observable<any> {
return this.http.put("/api/system/gc/schedule", param)
return this.http.put(`${this.config.gcEndpoint}/schedule`, param)
.pipe(catchError(error => observableThrowError(error)));
}

public getSchedule(): Observable<any> {
return this.http.get("/api/system/gc/schedule")
return this.http.get(`${this.config.gcEndpoint}/schedule`)
.pipe(catchError(error => observableThrowError(error)))
.pipe(map(response => response.json()));
}

public getLog(id): Observable<any> {
return this.http.get("/api/system/gc/" + id + "/log")
return this.http.get(`${this.config.gcEndpoint}/${id}/log`)
.pipe(catchError(error => observableThrowError(error)));
}

public getStatus(id): Observable<any> {
return this.http.get("/api/system/gc/" + id)
return this.http.get(`${this.config.gcEndpoint}/id`)
.pipe(catchError(error => observableThrowError(error)))
.pipe(map(response => response.json()));
}

public getJobs(): Observable<any> {
return this.http.get("/api/system/gc")
return this.http.get(`${this.config.gcEndpoint}`)
.pipe(catchError(error => observableThrowError(error)))
.pipe(map(response => response.json()));
}
Expand Down
44 changes: 44 additions & 0 deletions src/portal/lib/src/config/gc/gc.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GcComponent } from './gc.component';
import { SERVICE_CONFIG, IServiceConfig } from '../../service.config';
import { GcApiRepository, GcApiDefaultRepository} from './gc.api.repository';
import { GcRepoService } from './gc.service';
import { SharedModule } from "../../shared/shared.module";
import { ErrorHandler } from '../../error-handler/error-handler';
import { GcViewModelFactory } from './gc.viewmodel.factory';
import { GcUtility } from './gc.utility';

describe('GcComponent', () => {
let component: GcComponent;
let fixture: ComponentFixture<GcComponent>;
let config: IServiceConfig = {
systemInfoEndpoint: "/api/system/gc"
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
SharedModule
],
declarations: [ GcComponent ],
providers: [
{ provide: GcApiRepository, useClass: GcApiDefaultRepository },
{ provide: SERVICE_CONFIG, useValue: config },
GcRepoService,
ErrorHandler,
GcViewModelFactory,
GcUtility
]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(GcComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GcViewModelFactory } from "./gc.viewmodel.factory";
import { GcRepoService } from "./gc.service";
import { WEEKDAYS, SCHEDULE_TYPE, ONE_MINITUE, THREE_SECONDS} from './gc.const';
import { GcUtility } from './gc.utility';
import { ErrorHandler } from '@harbor/ui';
import { ErrorHandler } from '../../error-handler/index';

@Component({
selector: 'gc-config',
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Http } from '@angular/http';
import { Observable, Subscription, Subject, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { GcApiRepository } from './gc.api.repository';
import { ErrorHandler } from '@harbor/ui';
import { ErrorHandler } from '../../error-handler/index';
import { GcJobData } from './gcLog';


@Injectable()
export class GcRepoService {

Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions src/portal/lib/src/config/gc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from "./gc.component";
export * from "./gc.const";
export * from "./gc.api.repository";
export * from "./gc.service";
export * from "./gc.utility";
export * from "./gc.viewmodel.factory";
export * from "./gcLog";
4 changes: 4 additions & 0 deletions src/portal/lib/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { ReplicationConfigComponent } from './replication/replication-config.com
import { SystemSettingsComponent } from './system/system-settings.component';
import { VulnerabilityConfigComponent } from './vulnerability/vulnerability-config.component';
import { RegistryConfigComponent } from './registry-config.component';
import { GcComponent } from './gc/gc.component';


export * from './config';
export * from './replication/replication-config.component';
export * from './system/system-settings.component';
export * from './vulnerability/vulnerability-config.component';
export * from './registry-config.component';
export * from './gc/index';

export const CONFIGURATION_DIRECTIVES: Type<any>[] = [
ReplicationConfigComponent,
GcComponent,
SystemSettingsComponent,
VulnerabilityConfigComponent,
RegistryConfigComponent
Expand Down
6 changes: 6 additions & 0 deletions src/portal/lib/src/config/registry-config.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@
<vulnerability-config *ngIf="withClair" #vulnerabilityConfig [(vulnerabilityConfig)]="config" [showSubTitle]="true"></vulnerability-config>
</clr-tab-content>
</clr-tab>
<clr-tab>
<button id="config-gc" clrTabLink>{{'CONFIG.GC' | translate}}</button>
<clr-tab-content id="gc" *clrIfActive>
<gc-config #gcConfig></gc-config>
</clr-tab-content>
</clr-tab>
</clr-tabs>
<confirmation-dialog #cfgConfirmationDialog (confirmAction)="confirmCancel($event)"></confirmation-dialog>
4 changes: 3 additions & 1 deletion src/portal/lib/src/config/registry-config.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SystemSettingsComponent } from './system/system-settings.component';
import { VulnerabilityConfigComponent } from './vulnerability/vulnerability-config.component';
import { RegistryConfigComponent } from './registry-config.component';
import { ConfirmationDialogComponent } from '../confirmation-dialog/confirmation-dialog.component';
import { GcComponent } from './gc/gc.component';

import {
ConfigurationService,
Expand Down Expand Up @@ -62,7 +63,8 @@ describe('RegistryConfigComponent (inline template)', () => {
SystemSettingsComponent,
VulnerabilityConfigComponent,
RegistryConfigComponent,
ConfirmationDialogComponent
ConfirmationDialogComponent,
GcComponent
],
providers: [
ErrorHandler,
Expand Down
3 changes: 2 additions & 1 deletion src/portal/lib/src/config/registry-config.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
clone
} from '../utils';
import { ErrorHandler } from '../error-handler/index';
import { SystemSettingsComponent, VulnerabilityConfigComponent} from './index';
import { SystemSettingsComponent, VulnerabilityConfigComponent, GcComponent} from './index';
import { Configuration } from './config';

@Component({
Expand All @@ -30,6 +30,7 @@ export class RegistryConfigComponent implements OnInit {

@ViewChild("systemSettings") systemSettings: SystemSettingsComponent;
@ViewChild("vulnerabilityConfig") vulnerabilityCfg: VulnerabilityConfigComponent;
@ViewChild("gc") gc: GcComponent;
@ViewChild("cfgConfirmationDialog") confirmationDlg: ConfirmationDialogComponent;

constructor(
Expand Down
23 changes: 20 additions & 3 deletions src/portal/lib/src/harbor-library.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ import {
UserPermissionService,
UserPermissionDefaultService
} from './service/index';
import { GcRepoService } from './config/gc/gc.service';
import { GcUtility } from './config/gc/gc.utility';
import {GcViewModelFactory} from './config/gc/gc.viewmodel.factory';
import {GcApiRepository, GcApiDefaultRepository} from './config/gc/gc.api.repository';
import {
ErrorHandler,
DefaultErrorHandler
Expand Down Expand Up @@ -98,7 +102,8 @@ export const DefaultServiceConfig: IServiceConfig = {
scanJobEndpoint: "/api/jobs/scan",
labelEndpoint: "/api/labels",
helmChartEndpoint: "/api/chartrepo",
downloadChartEndpoint: "/chartrepo"
downloadChartEndpoint: "/chartrepo",
gcEndpoint: "/api/system/gc"
};

/**
Expand Down Expand Up @@ -154,6 +159,10 @@ export interface HarborModuleConfig {
helmChartService?: Provider;
// Service implementation for userPermission
userPermissionService?: Provider;

// Service implementation for gc
gcApiRepository?: Provider;

}

/**
Expand Down Expand Up @@ -254,6 +263,7 @@ export class HarborLibraryModule {
config.labelService || { provide: LabelService, useClass: LabelDefaultService },
config.helmChartService || { provide: HelmChartService, useClass: HelmChartDefaultService },
config.userPermissionService || { provide: UserPermissionService, useClass: UserPermissionDefaultService },
config.gcApiRepository || {provide: GcApiRepository, useClass: GcApiDefaultRepository},
// Do initializing
TranslateServiceInitializer,
{
Expand All @@ -263,7 +273,10 @@ export class HarborLibraryModule {
multi: true
},
ChannelService,
OperationService
OperationService,
GcRepoService,
GcViewModelFactory,
GcUtility
]
};
}
Expand All @@ -288,8 +301,12 @@ export class HarborLibraryModule {
config.labelService || { provide: LabelService, useClass: LabelDefaultService },
config.helmChartService || { provide: HelmChartService, useClass: HelmChartDefaultService },
config.userPermissionService || { provide: UserPermissionService, useClass: UserPermissionDefaultService },
config.gcApiRepository || {provide: GcApiRepository, useClass: GcApiDefaultRepository},
ChannelService,
OperationService
OperationService,
GcRepoService,
GcViewModelFactory,
GcUtility
]
};
}
Expand Down
1 change: 1 addition & 0 deletions src/portal/lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './repository-gridview/index';
export * from './operation/index';
export * from './_animations/index';
export * from './helm-chart/index';

2 changes: 2 additions & 0 deletions src/portal/lib/src/service.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,6 @@ export interface IServiceConfig {
* * {string}
*/
downloadChartEndpoint?: string;

gcEndpoint?: string;
}
4 changes: 1 addition & 3 deletions src/portal/src/app/config/config.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { Subscription } from "rxjs";
import {
Configuration, StringValueItem, SystemSettingsComponent, VulnerabilityConfigComponent,
isEmpty, clone, getChanges
} from '@harbor/ui';
isEmpty, clone, getChanges, GcComponent, GcRepoService } from '@harbor/ui';

import { ConfirmationTargets, ConfirmationState } from '../shared/shared.const';
import { SessionService } from '../shared/session.service';
Expand All @@ -26,7 +25,6 @@ import { MessageHandlerService } from '../shared/message-handler/message-handler
import { AppConfigService } from '../app-config.service';
import { ConfigurationAuthComponent } from './auth/config-auth.component';
import { ConfigurationEmailComponent } from './email/config-email.component';
import { GcComponent } from './gc/gc.component';
import { ConfigurationService } from './config.service';


Expand Down
14 changes: 3 additions & 11 deletions src/portal/src/app/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { NgModule } from "@angular/core";
import { CoreModule } from "../core/core.module";
import { SharedModule } from "../shared/shared.module";
Expand All @@ -20,28 +21,19 @@ import { ConfigurationService } from "./config.service";
import { ConfirmMessageHandler } from "./config.msg.utils";
import { ConfigurationAuthComponent } from "./auth/config-auth.component";
import { ConfigurationEmailComponent } from "./email/config-email.component";
import { GcComponent } from "./gc/gc.component";
import { GcRepoService } from "./gc/gc.service";
import { GcApiRepository } from "./gc/gc.api.repository";
import { RobotApiRepository } from "../project/robot-account/robot.api.repository";
import { GcViewModelFactory } from "./gc/gc.viewmodel.factory";
import { GcUtility } from "./gc/gc.utility";


@NgModule({
imports: [CoreModule, SharedModule],
declarations: [
ConfigurationComponent,
ConfigurationAuthComponent,
ConfigurationEmailComponent,
GcComponent
ConfigurationEmailComponent
],
exports: [ConfigurationComponent],
providers: [
ConfigurationService,
GcRepoService,
GcApiRepository,
GcViewModelFactory,
GcUtility,
ConfirmMessageHandler,
RobotApiRepository
]
Expand Down
25 changes: 0 additions & 25 deletions src/portal/src/app/config/gc/gc.component.spec.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/portal/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const uiLibConfig: IServiceConfig = {
scanJobEndpoint: "/api/jobs/scan",
labelEndpoint: "/api/labels",
helmChartEndpoint: "/api/chartrepo",
downloadChartEndpoint: "/chartrepo"
downloadChartEndpoint: "/chartrepo",
gcEndpoint: "/api/system/gc"
};

@NgModule({
Expand Down

0 comments on commit 0d239cb

Please sign in to comment.