Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 19 | 'use strict'; |
| 20 | |
| 21 | angular.module('xos.hpc', [ |
| 22 | 'ngResource', |
| 23 | 'ngCookies', |
| 24 | 'ui.router', |
| 25 | 'xos.helpers' |
| 26 | ]) |
| 27 | .config(($stateProvider) => { |
| 28 | $stateProvider |
| 29 | .state('hpc-list', { |
| 30 | url: '/', |
| 31 | template: '<hpcs-list></hpcs-list>' |
| 32 | }); |
| 33 | }) |
| 34 | .config(function($httpProvider){ |
| 35 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 36 | }) |
| 37 | .service('Hpc', function($q, $http){ |
| 38 | this.query = (params) => { |
| 39 | const d = $q.defer(); |
| 40 | |
| 41 | $http.get('/xoslib/hpcview', {params: params}) |
| 42 | .then((res) => { |
| 43 | d.resolve(res.data); |
| 44 | }) |
| 45 | .catch(d.reject); |
| 46 | |
| 47 | return {$promise: d.promise}; |
| 48 | }; |
| 49 | }) |
| 50 | .directive('hpcsList', function(){ |
| 51 | return { |
| 52 | restrict: 'E', |
| 53 | scope: {}, |
| 54 | bindToController: true, |
| 55 | controllerAs: 'vm', |
| 56 | templateUrl: 'templates/hpc-list.tpl.html', |
| 57 | controller: function(Hpc){ |
| 58 | |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 59 | const secondsToHms = d => { |
| 60 | d = Number(d); |
| 61 | var h = Math.floor(d / 3600); |
| 62 | var m = Math.floor(d % 3600 / 60); |
| 63 | var s = Math.floor(d % 3600 % 60); |
| 64 | return ((h > 0 ? h + 'h ' + (m < 10 ? '0' :'') :'') + m + 'm ' + (s < 10 ? '0' :'') + s + 's'); |
| 65 | }; |
| 66 | |
| 67 | const toDuration = (property) => { |
| 68 | return (item) => { |
| 69 | if(!angular.isNumber(item[property])){ |
| 70 | return item[property] |
| 71 | } |
| 72 | return secondsToHms(item[property]); |
| 73 | } |
| 74 | }; |
| 75 | |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 76 | this.routerConfig = { |
| 77 | filter: 'field', |
| 78 | order: true, |
| 79 | columns: [ |
| 80 | { |
| 81 | label: 'Name', |
| 82 | prop: 'name' |
| 83 | }, |
| 84 | { |
| 85 | label: 'Ip Address', |
| 86 | prop: 'ip' |
| 87 | }, |
| 88 | { |
| 89 | label: 'Record Checker', |
| 90 | prop: 'watcher.DNS.msg' |
| 91 | }, |
| 92 | { |
| 93 | label: 'Name Servers', |
| 94 | prop: 'nameservers', |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 95 | type: 'array' |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 96 | }, |
| 97 | { |
| 98 | label: 'Dns Demux Config Age', |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 99 | prop: 'dnsdemux_config_age', |
| 100 | type: 'custom', |
| 101 | formatter: toDuration('dnsdemux_config_age') |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 102 | }, |
| 103 | { |
| 104 | label: 'Dns Redir Config Age', |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 105 | prop: 'dnsredir_config_age', |
| 106 | type: 'custom', |
| 107 | formatter: toDuration('dnsredir_config_age') |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 108 | } |
| 109 | ] |
| 110 | }; |
| 111 | |
| 112 | this.cacheConfig = { |
| 113 | filter: 'field', |
| 114 | order: true, |
| 115 | columns: [ |
| 116 | { |
| 117 | label: 'Name', |
| 118 | prop: 'name' |
| 119 | }, |
| 120 | { |
| 121 | label: 'Prober', |
| 122 | prop: 'watcher.HPC-hb.msg' |
| 123 | }, |
| 124 | { |
| 125 | label: 'Fetcher', |
| 126 | prop: 'watcher.HPC-fetch.msg' |
| 127 | }, |
| 128 | { |
| 129 | label: 'Config Age', |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 130 | prop: 'config_age', |
| 131 | type: 'custom', |
| 132 | formatter: toDuration('config_age') |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 133 | } |
| 134 | ] |
| 135 | }; |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 136 | |
| 137 | |
| 138 | this.fetch = () => { |
| 139 | Hpc.query().$promise |
| 140 | .then((hpcs) => { |
| 141 | this.routers = hpcs[0].dnsdemux; |
| 142 | this.caches = hpcs[0].hpc; |
| 143 | }) |
| 144 | .catch((e) => { |
| 145 | throw new Error(e); |
| 146 | }); |
| 147 | }; |
| 148 | |
| 149 | this.fetch(); |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 150 | } |
| 151 | }; |
| 152 | }); |