component.ts 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.

15
import {HttpParams} from '@angular/common/http';
16
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input} from '@angular/core';
17
import {Metric, Node, NodeList} from '@api/backendapi';
18
import {Observable} from 'rxjs';
19 20 21 22 23
import {ResourceListWithStatuses} from '../../../resources/list';
import {NotificationsService} from '../../../services/global/notifications';
import {EndpointManager, Resource} from '../../../services/resource/endpoint';
import {ResourceService} from '../../../services/resource/resource';
import {MenuComponent} from '../../list/column/menu/component';
24
import {ListGroupIdentifier, ListIdentifier} from '../groupids';
25 26 27 28

@Component({
  selector: 'kd-node-list',
  templateUrl: './template.html',
29
  changeDetection: ChangeDetectionStrategy.OnPush,
30
})
31
export class NodeListComponent extends ResourceListWithStatuses<NodeList, Node> {
32
  @Input() endpoint = EndpointManager.resource(Resource.node).list();
33 34
  @Input() showMetrics = false;
  cumulativeMetrics: Metric[];
35 36

  constructor(
S
Shu Muto 已提交
37 38
    private readonly node_: ResourceService<NodeList>,
    notifications: NotificationsService,
39
    cdr: ChangeDetectorRef
S
Shu Muto 已提交
40
  ) {
41
    super('node', notifications, cdr);
42 43
    this.id = ListIdentifier.node;
    this.groupId = ListGroupIdentifier.cluster;
44

45 46 47
    // Register action columns.
    this.registerActionColumn<MenuComponent>('menu', MenuComponent);

48
    // Register status icon handlers
49
    this.registerBinding(this.icon.checkCircle, 'kd-success', this.isInSuccessState);
50 51 52 53 54 55 56 57 58
    this.registerBinding(this.icon.help, 'kd-muted', this.isInUnknownState);
    this.registerBinding(this.icon.error, 'kd-error', this.isInErrorState);
  }

  getResourceObservable(params?: HttpParams): Observable<NodeList> {
    return this.node_.get(this.endpoint, undefined, params);
  }

  map(nodeList: NodeList): Node[] {
59
    this.cumulativeMetrics = nodeList.cumulativeMetrics;
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    return nodeList.nodes;
  }

  isInErrorState(resource: Node): boolean {
    return resource.ready === 'False';
  }

  isInUnknownState(resource: Node): boolean {
    return resource.ready === 'Unknown';
  }

  isInSuccessState(resource: Node): boolean {
    return resource.ready === 'True';
  }

  getDisplayColumns(): string[] {
M
Marcin Maciaszczyk 已提交
76
    return ['statusicon', 'name', 'labels', 'ready', 'cpureq', 'cpulim', 'memreq', 'memlim', 'created'];
77 78
  }
}