blob: ee74446fb229cda79936bf340d1f25b32afe2836 [file] [log] [blame]
Priyanka H Mfa5b77a2018-07-27 12:43:44 +05301/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import {Component, OnDestroy, OnInit} from '@angular/core';
Sean Condon5ca00262018-09-06 17:55:25 +010017import {
18 FnService,
Sean Condon5ca00262018-09-06 17:55:25 +010019 LogService,
20 WebSocketService,
21 LionService,
22 SortDir, TableBaseImpl, TableResponse
23} from 'gui2-fw-lib';
Priyanka H Mfa5b77a2018-07-27 12:43:44 +053024
25/**
26 * Model of the response from WebSocket
27 */
28interface ClusterTableResponse extends TableResponse {
29 clusters: Cluster[];
30}
31
32/**
33 * Model of the cluster returned from the WebSocket
34 */
35interface Cluster {
36 _iconid_state: string;
37 _iconid_started: string;
38 active: string;
39 started: string;
40 nodeId: string;
41 ipAddress: string;
42 tcpPort: string;
43 lastUpdated: string;
44}
45
46/**
47 * ONOS GUI -- Cluster View Component
48 */
49@Component({
50 selector: 'onos-cluster',
51 templateUrl: './cluster.component.html',
52 styleUrls: ['./cluster.component.css', './cluster.theme.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
53})
54
55export class ClusterComponent extends TableBaseImpl implements OnInit, OnDestroy {
56
57 lionFn; // Function
58
59 constructor(
60 protected fs: FnService,
Priyanka H Mfa5b77a2018-07-27 12:43:44 +053061 protected log: LogService,
62 protected lion: LionService,
63 protected wss: WebSocketService,
64 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010065 super(fs, log, wss, 'cluster');
Priyanka H Mfa5b77a2018-07-27 12:43:44 +053066 this.responseCallback = this.clusterResponseCb;
67
68 this.sortParams = {
69 firstCol: 'id',
70 firstDir: SortDir.desc,
71 secondCol: 'ip',
72 secondDir: SortDir.asc,
73 };
74
75 if (this.lion.ubercache.length === 0) {
76 this.lionFn = this.dummyLion;
77 this.lion.loadCbs.set('cluster', () => this.doLion());
78 } else {
79 this.doLion();
80 }
81 }
82
83 ngOnInit() {
84 this.init();
85 this.log.debug('ClusterComponent initialized');
86 }
87
88 ngOnDestroy() {
89 this.destroy();
90 this.log.debug('ClusterComponent destroyed');
91 }
92
93 clusterResponseCb(data: ClusterTableResponse) {
94 this.log.debug('Cluster response received for ', data.clusters.length, 'cluster');
95 }
96
97 doLion() {
98 this.lionFn = this.lion.bundle('core.view.Cluster');
99
100 }
101}