Priyanka H M | fa5b77a | 2018-07-27 12:43:44 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | import {Component, OnDestroy, OnInit} from '@angular/core'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 17 | import { |
| 18 | FnService, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 19 | LogService, |
| 20 | WebSocketService, |
| 21 | LionService, |
| 22 | SortDir, TableBaseImpl, TableResponse |
Sean Condon | 3dd062f | 2020-04-14 09:25:00 +0100 | [diff] [blame] | 23 | } from 'org_onosproject_onos/web/gui2-fw-lib/public_api'; |
Priyanka H M | fa5b77a | 2018-07-27 12:43:44 +0530 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Model of the response from WebSocket |
| 27 | */ |
| 28 | interface ClusterTableResponse extends TableResponse { |
| 29 | clusters: Cluster[]; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Model of the cluster returned from the WebSocket |
| 34 | */ |
| 35 | interface 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 Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 52 | 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 M | fa5b77a | 2018-07-27 12:43:44 +0530 | [diff] [blame] | 55 | }) |
| 56 | |
| 57 | export class ClusterComponent extends TableBaseImpl implements OnInit, OnDestroy { |
| 58 | |
| 59 | lionFn; // Function |
| 60 | |
| 61 | constructor( |
| 62 | protected fs: FnService, |
Priyanka H M | fa5b77a | 2018-07-27 12:43:44 +0530 | [diff] [blame] | 63 | protected log: LogService, |
| 64 | protected lion: LionService, |
| 65 | protected wss: WebSocketService, |
| 66 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 67 | super(fs, log, wss, 'cluster'); |
Priyanka H M | fa5b77a | 2018-07-27 12:43:44 +0530 | [diff] [blame] | 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 | } |