blob: a4d43b1bfed3ba45c1e1828e6205dddbcf7d162d [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
Sean Condon98b6ddb2019-12-24 08:07:40 +000023} from '../../../../../../../../gui2-fw-lib/public_api';
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',
Sean Condon98b6ddb2019-12-24 08:07:40 +000052 styleUrls: ['./cluster.component.css', './cluster.theme.css',
53 '../../../../../../../../gui2-fw-lib/lib/widget/table.css',
54 '../../../../../../../../gui2-fw-lib/lib/widget/table.theme.css']
Priyanka H Mfa5b77a2018-07-27 12:43:44 +053055})
56
57export class ClusterComponent extends TableBaseImpl implements OnInit, OnDestroy {
58
59 lionFn; // Function
60
61 constructor(
62 protected fs: FnService,
Priyanka H Mfa5b77a2018-07-27 12:43:44 +053063 protected log: LogService,
64 protected lion: LionService,
65 protected wss: WebSocketService,
66 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010067 super(fs, log, wss, 'cluster');
Priyanka H Mfa5b77a2018-07-27 12:43:44 +053068 this.responseCallback = this.clusterResponseCb;
69
70 this.sortParams = {
71 firstCol: 'id',
72 firstDir: SortDir.desc,
73 secondCol: 'ip',
74 secondDir: SortDir.asc,
75 };
76
77 if (this.lion.ubercache.length === 0) {
78 this.lionFn = this.dummyLion;
79 this.lion.loadCbs.set('cluster', () => this.doLion());
80 } else {
81 this.doLion();
82 }
83 }
84
85 ngOnInit() {
86 this.init();
87 this.log.debug('ClusterComponent initialized');
88 }
89
90 ngOnDestroy() {
91 this.destroy();
92 this.log.debug('ClusterComponent destroyed');
93 }
94
95 clusterResponseCb(data: ClusterTableResponse) {
96 this.log.debug('Cluster response received for ', data.clusters.length, 'cluster');
97 }
98
99 doLion() {
100 this.lionFn = this.lion.bundle('core.view.Cluster');
101
102 }
103}