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