Skip to content

Commit

Permalink
Merge pull request #508 from BennieMeng/feature/deplayment-replica
Browse files Browse the repository at this point in the history
Feature/deplayment replica
  • Loading branch information
BennieMeng authored Nov 8, 2019
2 parents dd00538 + 8791f20 commit a3c729e
Show file tree
Hide file tree
Showing 26 changed files with 313 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
{{'TITLE.NAME' | translate}}
</ng-container>
</clr-dg-column>
<clr-dg-column class="col-cluster-name">
<ng-container *clrDgHideableColumn="{hidden: false}">
displayname
</ng-container>
</clr-dg-column>
<clr-dg-column class="col-host">
<ng-container *clrDgHideableColumn="{hidden: false}">
Master
Expand Down Expand Up @@ -51,6 +56,7 @@
</clr-dg-action-overflow>
<clr-dg-cell class="col-id">{{cluster.id}}</clr-dg-cell>
<clr-dg-cell class="col-cluster-name copy">{{cluster.name}}</clr-dg-cell>
<clr-dg-cell class="col-cluster-name copy">{{cluster.displayname}}</clr-dg-cell>
<clr-dg-cell class="col-host">{{cluster.master}}</clr-dg-cell>
<clr-dg-cell>{{getClusterStatus(cluster.status)}}</clr-dg-cell>
<clr-dg-cell class="col-metadata">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ <h2 class="header-title">已删除集群列表</h2>
{{'TITLE.NAME' | translate}}
</ng-container>
</clr-dg-column>
<clr-dg-column class="col-cluster-name">
<ng-container *clrDgHideableColumn="{hidden: false}">
displayname
</ng-container>
</clr-dg-column>
<clr-dg-column class="col-host">
<ng-container *clrDgHideableColumn="{hidden: false}">
Master
Expand Down Expand Up @@ -41,6 +46,7 @@ <h2 class="header-title">已删除集群列表</h2>
</clr-dg-action-overflow>
<clr-dg-cell class="col-id">{{cluster.id}}</clr-dg-cell>
<clr-dg-cell class="col-app-name copy">{{cluster.name}}</clr-dg-cell>
<clr-dg-cell class="col-cluster-name copy">{{cluster.displayname}}</clr-dg-cell>
<clr-dg-cell class="col-host">{{cluster.master}}</clr-dg-cell>
<clr-dg-cell>{{cluster.description}}</clr-dg-cell>
<clr-dg-cell>{{cluster.user}}</clr-dg-cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<clr-dg-row *ngFor="let ns of namespaces" [clrDgItem]="ns">
<clr-dg-action-overflow>
<button class="action-item" (click)="editNamespace(ns)">{{'BUTTON.EDIT' | translate}}</button>
<button class="action-item" (click)="migrateNamespace(ns)">空间迁移</button>
<button class="action-item" (click)="deleteNamespace(ns)">{{'BUTTON.DELETE' | translate}}</button>
</clr-dg-action-overflow>
<clr-dg-cell class="col-id">{{ns.id}}</clr-dg-cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ListNamespaceComponent {
@Output() paginate = new EventEmitter<ClrDatagridStateInterface>();
@Output() delete = new EventEmitter<Namespace>();
@Output() edit = new EventEmitter<Namespace>();
@Output() migrate = new EventEmitter<Namespace>();

constructor(private router: Router,
private aceEditorService: AceEditorService) {
Expand All @@ -46,6 +47,10 @@ export class ListNamespaceComponent {
this.edit.emit(ns);
}

migrateNamespace(ns: Namespace) {
this.migrate.emit(ns);
}

goToLink(ns: Namespace, gate: string) {
let linkUrl = '';
switch (gate) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<wayne-modal [isValid]="isValid">
<span header>命名空间迁移</span>
<content>
<form #namespaceForm="ngForm" clrForm clrLayout="horizontal">
<clr-input-container>
<label>当前空间: </label>
<input type="text" clrInput id="ns_name" [(ngModel)]="currentNamespace.name" name="ns_name" size="36" readonly>
</clr-input-container>
<clr-select-container>
<label>目标空间: </label>
<select clrSelect name="target" [(ngModel)]="target">
<option *ngFor="let namespace of namespaces" [value]="namespace.id">{{namespace.name}}</option>
</select>
</clr-select-container>
</form>
</content>
</wayne-modal>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { MigrateNamespaceComponent } from './migrate-namespace.component';

describe('MigrateNamespaceComponent', () => {
let component: MigrateNamespaceComponent;
let fixture: ComponentFixture<MigrateNamespaceComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MigrateNamespaceComponent ]
})
.compileComponents();
}));

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { Namespace } from 'app/shared/model/v1/namespace';
import { NgForm } from '@angular/forms';
import { ModalComponent } from 'app/shared/modal/modal.component';
import { ModalService } from 'app/shared/modal/modal.service';
import { Subscription } from 'rxjs';
import { NamespaceService } from 'app/shared/client/v1/namespace.service';
import { MessageHandlerService } from 'app/shared/message-handler/message-handler.service';
@Component({
selector: 'migrate-namespace',
templateUrl: './migrate-namespace.component.html',
styleUrls: ['./migrate-namespace.component.scss']
})
export class MigrateNamespaceComponent implements OnInit, OnDestroy {
namespaceForm: NgForm;
@ViewChild('namespaceForm', { static: false })
currentForm: NgForm;
@ViewChild(ModalComponent, { static: false })
modalComponent: ModalComponent;

currentNamespace: Namespace = new Namespace;
target: number;
namespaces: Namespace[] = [];
subscription: Subscription;
constructor(
private modalService: ModalService,
private namespaceService: NamespaceService,
private message: MessageHandlerService
) {
this.subscription = this.modalService.modalObservable$.subscribe(res => {
switch (res.method) {
case 'cancel':
this.cancelEvent();
break;
case 'confirm':
this.confirmEvent();
break;
}
});
}

ngOnInit() {
}

ngOnDestroy() {
this.subscription.unsubscribe();
}

cancelEvent() {
this.namespaces = [];
this.modalComponent.opened = false;
}

confirmEvent() {
this.namespaceService.migrateNamespace(this.currentNamespace.id, Number(this.target))
.subscribe(
res => {
this.message.showSuccess(`${this.currentNamespace.name}迁移成功`);
this.modalComponent.opened = false;
},
error => this.message.error(error)
);
}

open(ns: Namespace, namespaceList: Namespace[]) {
this.target = undefined;
this.currentNamespace = ns;
this.modalComponent.opened = true;
this.namespaces = namespaceList.filter(namespace => {
return namespace.id !== ns.id;
}) || [];
}

public get isValid() {
return !!this.target;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ <h2 class="header-title">命名空间列表</h2>
</button>
<!-- <button class="btn btn-link" (click)="initDefault()"><clr-icon shape="add"></clr-icon>初始化默认命名空间</button> -->
<create-edit-namespace (create)="createNamespace($event)"></create-edit-namespace>
<migrate-namespace></migrate-namespace>
</div>
</div>
<list-namespace [namespaces]="changedNamespaces" (delete)="deleteNamespace($event)" (edit)="editNamespace($event)"
(paginate)="retrieve($event)" [page]="pageState.page"></list-namespace>
(migrate)="migrateNamespace($event)" (paginate)="retrieve($event)" [page]="pageState.page"></list-namespace>
</div>
</div>
14 changes: 14 additions & 0 deletions src/frontend/src/app/admin/namespace/namespace.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NamespaceService } from '../../shared/client/v1/namespace.service';
import { PageState } from '../../shared/page/page-state';
import { ClusterService } from '../../shared/client/v1/cluster.service';
import { Cluster } from '../../shared/model/v1/cluster';
import { MigrateNamespaceComponent } from './migrate-namespace/migrate-namespace.component';

@Component({
selector: 'wayne-namespace',
Expand All @@ -23,6 +24,8 @@ export class NamespaceComponent implements OnInit, OnDestroy {
listNamespace: ListNamespaceComponent;
@ViewChild(CreateEditNamespaceComponent, { static: false })
createEditNamespace: CreateEditNamespaceComponent;
@ViewChild(MigrateNamespaceComponent, {static: false})
migrateNamespaceComponent: MigrateNamespaceComponent;

pageState: PageState = new PageState();
changedNamespaces: Namespace[];
Expand Down Expand Up @@ -133,4 +136,15 @@ export class NamespaceComponent implements OnInit, OnDestroy {
editNamespace(ns: Namespace): void {
this.createEditNamespace.newOrEditNamespace(this.clusters, ns.id);
}

migrateNamespace(ns: Namespace): void {
const pageState = new PageState({
pageNo: 1,
pageSize: 10000
});
this.namespaceService.listNamespace(pageState, 'false')
.subscribe(res => {
this.migrateNamespaceComponent.open(ns, res.data.list);
});
}
}
4 changes: 3 additions & 1 deletion src/frontend/src/app/admin/namespace/namespace.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ListNamespaceComponent } from './list-namespace/list-namespace.componen
import { TrashNamespaceComponent } from './trash-namespace/trash-namespace.component';
import { SharedModule } from '../../shared/shared.module';
import { NamespaceService } from '../../shared/client/v1/namespace.service';
import { MigrateNamespaceComponent } from './migrate-namespace/migrate-namespace.component';

@NgModule({
imports: [
Expand All @@ -21,7 +22,8 @@ import { NamespaceService } from '../../shared/client/v1/namespace.service';
NamespaceComponent,
TrashNamespaceComponent,
ListNamespaceComponent,
CreateEditNamespaceComponent
CreateEditNamespaceComponent,
MigrateNamespaceComponent
]
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
(click)="offlineDeployment(deploymentTpl)"
*ngIf="deploymentTpl.status && (authService.currentAppPermission.kubeDeployment.delete || authService.currentUser.admin)">
{{'BUTTON.DROP' | translate}}</button>
<button class="wayne-button text"
(click)="modifyReplicas(deploymentTpl)"
*ngIf="deploymentTpl.status && (authService.currentAppPermission.kubeDeployment.create || authService.currentUser.admin)">
{{'DEPLOYMENT.MODIFY_REPLICA' | translate}}</button>
</clr-dg-cell>
</clr-dg-row>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ export class ListDeploymentComponent implements OnInit, OnDestroy {
});
}

modifyReplicas(tpl: DeploymentTpl) {
this.deploymentService.getById(tpl.deploymentId, this.appId).subscribe(
status => {
const deployment = status.data;
this.publishDeploymentTpl.newPublishTpl(deployment, tpl, ResourcesActionType.MODIFY_REPLICA);
},
error => {
this.messageHandlerService.handleError(error);
});
}

published(success: boolean) {
if (success) {
this.refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ <h3 class="modal-title">{{title}}</h3>
<input class="clr-checkbox" [(ngModel)]="clusterMetas[cluster].checked" type="checkbox" id="{{i}}-check" name="{{i}}-check">
<label for="{{i}}-check">{{cluster}}</label>
</label>
<ng-container *ngIf="actionType==0 || actionType==2">
<input class="clr-input" placeholder="部署份数" [(ngModel)]="clusterMetas[cluster].value" id="{{cluster}}-replica" [readonly]="actionType!=0"
<ng-container *ngIf="actionType==0 || actionType==2 || actionType == 5">
<input class="clr-input" placeholder="部署份数" [(ngModel)]="clusterMetas[cluster].value" id="{{cluster}}-replica" [readonly]="actionType == 2"
name="{{cluster}}-replica" type="number" style="margin-left: 20px;">
<span class="clr-subtext" *ngIf="!replicaValidation(cluster)">部署份数超过系统最大限制{{replicaLimit}}</span>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, EventEmitter, Output, ViewChild } from '@angular/core';
import { forkJoin } from 'rxjs';
import { forkJoin, ObservableInput } from 'rxjs';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
import { NgForm } from '@angular/forms';
Expand Down Expand Up @@ -114,6 +114,9 @@ export class PublishDeploymentTplComponent {
case ResourcesActionType.OFFLINE:
this.title = '下线部署[' + this.deployment.name + ']';
break;
case ResourcesActionType.MODIFY_REPLICA:
this.title = `修改状态副本集[${this.deployment.name}]`;
break;
}
}

Expand Down Expand Up @@ -162,6 +165,9 @@ export class PublishDeploymentTplComponent {
case ResourcesActionType.OFFLINE:
this.offline();
break;
case ResourcesActionType.MODIFY_REPLICA:
this.modifyReplica();
break;
}

this.isSubmitOnGoing = false;
Expand All @@ -188,6 +194,24 @@ export class PublishDeploymentTplComponent {
});
}

modifyReplica() {
const observables: ObservableInput<any>[] = [];
Object.getOwnPropertyNames(this.clusterMetas).forEach(cluster => {
if (this.clusterMetas[cluster].checked) {
observables.push(
this.deploymentClient.modifyReplica(this.appId, cluster, this.deployment.name, this.cacheService.kubeNamespace, {
num: Number(this.clusterMetas[cluster].value)
})
);
}
});
forkJoin(observables)
.subscribe(
res => this.messageHandlerService.showSuccess('修改成功'),
error => this.messageHandlerService.handleError(error)
);
}

deletePublishStatus(id: number) {
this.publishStatusService.deleteById(id).subscribe(
response => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PageState } from '../../../page/page-state';
import { BaseClient } from './base-client';
import { KubeDeployment, ObjectMeta } from '../../../model/v1/kubernetes/deployment';
import { throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';

@Injectable()
export class DeploymentClient {
Expand Down Expand Up @@ -39,4 +40,12 @@ export class DeploymentClient {
.delete(`/api/v1/kubernetes/apps/${appId}/deployments/${name}/namespaces/${namespace}/clusters/${cluster}`)
.catch(error => throwError(error));
}

modifyReplica(appId: number, cluster: string, name: string, namespace: string, data: any) {
return this.http
.post(`/api/v1/kubernetes/apps/${appId}/deployments/${name}/namespaces/${namespace}/clusters/${cluster}/updatescale`, data)
.pipe(
catchError(error => throwError(error))
);
}
}
9 changes: 9 additions & 0 deletions src/frontend/src/app/shared/client/v1/namespace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,13 @@ export class NamespaceService {
.get(`/api/v1/namespaces/${namespaceId}/history`, {params: params})
.catch(error => throwError(error));
}

migrateNamespace(sourceId: number, targetId: number) {
return this.http
.post(`/api/v1/namespaces/migration`, {
sourceId,
targetId
})
.catch(error => throwError(error));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
right: -200px;
top: -12px;
z-index: 520;
filter: drop-shadow(1px 2px 4px #ccc);

&:before {
content: '';
Expand All @@ -20,7 +21,6 @@
width: 16px;
height: 16px;
background: #fff;
box-shadow: 0 2px 8px 1px #dee6f3;
z-index: 1;
}

Expand Down
Loading

0 comments on commit a3c729e

Please sign in to comment.