blob: f72b1d02908d1b7e29450f9e929ec54ec165cd4a [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,
19 LoadingService,
20 LogService,
21 WebSocketService,
22 LionService,
23 SortDir, TableBaseImpl, TableResponse
24} from 'gui2-fw-lib';
Priyanka H Mfa5b77a2018-07-27 12:43:44 +053025
26/**
27 * Model of the response from WebSocket
28 */
29interface ClusterTableResponse extends TableResponse {
30 clusters: Cluster[];
31}
32
33/**
34 * Model of the cluster returned from the WebSocket
35 */
36interface Cluster {
37 _iconid_state: string;
38 _iconid_started: string;
39 active: string;
40 started: string;
41 nodeId: string;
42 ipAddress: string;
43 tcpPort: string;
44 lastUpdated: string;
45}
46
47/**
48 * ONOS GUI -- Cluster View Component
49 */
50@Component({
51 selector: 'onos-cluster',
52 templateUrl: './cluster.component.html',
53 styleUrls: ['./cluster.component.css', './cluster.theme.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
54})
55
56export class ClusterComponent extends TableBaseImpl implements OnInit, OnDestroy {
57
58 lionFn; // Function
59
60 constructor(
61 protected fs: FnService,
62 protected ls: LoadingService,
63 protected log: LogService,
64 protected lion: LionService,
65 protected wss: WebSocketService,
66 ) {
67 super(fs, ls, log, wss, 'cluster');
68 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}