Remove unused DefaultNetconfOperation marker
[controller.git] / opendaylight / web / troubleshoot / src / main / resources / js / page.js
1 /* 
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved. 
3  * 
4  * This program and the accompanying materials are made available under the 
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution, 
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  */
9
10 //PAGE troubleshoot
11 one.f = {};
12
13 // specify dashlets and layouts
14 one.f.dashlet = {
15     existingNodes : {
16         id : 'existingNodes',
17         name : 'Existing Nodes'
18     },
19     uptime: {
20         id: 'uptime',
21         name: 'Uptime'
22     },
23     flowsOrPorts: {
24         id: "flowsOrPorts",
25         name: "Statistics"
26     }
27 };
28
29 one.f.menu = {
30     left : {
31         top : [
32             one.f.dashlet.existingNodes
33         ],
34         bottom : [
35             one.f.dashlet.uptime
36         ]
37     },
38     right : {
39         top : [],
40         bottom : [
41             one.f.dashlet.flowsOrPorts
42         ]
43     }
44 };
45
46 /** INIT **/
47 // populate nav tabs
48 $(one.f.menu.left.top).each(function(index, value) {
49     var $nav = $(".nav", "#left-top");
50     one.main.page.dashlet($nav, value);
51 });
52
53 $(one.f.menu.left.bottom).each(function(index, value) {
54     var $nav = $(".nav", "#left-bottom");
55     one.main.page.dashlet($nav, value);
56 });
57
58 $(one.f.menu.right.bottom).each(function(index, value) {
59     var $nav = $(".nav", "#right-bottom");
60     one.main.page.dashlet($nav, value);
61 });
62
63 /**Troubleshoot modules*/
64 one.f.troubleshooting = {
65     rootUrl: "/controller/web/troubleshoot",
66     rightBottomDashlet: { 
67         get: function() {
68             var $rightBottomDashlet = $("#right-bottom").find(".dashlet");
69             return $rightBottomDashlet;
70         },
71         setDashletHeader: function(label) {
72             $("#right-bottom li a")[0].innerHTML = label; 
73         }
74     },
75     createTable: function(columnNames, body) {
76         var tableAttributes = ["table-striped", "table-bordered", "table-condensed"];
77         var $table = one.lib.dashlet.table.table(tableAttributes);
78         var tableHeaders = columnNames;
79         var $thead = one.lib.dashlet.table.header(tableHeaders);
80         var $tbody = one.lib.dashlet.table.body(body, tableHeaders);
81         $table.append($thead)
82             .append($tbody);
83         return $table;
84     }
85 };
86
87 one.f.troubleshooting.existingNodes = {
88         id: {
89             popout: "one_f_troubleshooting_existingNodes_id_popout",
90             modal: "one_f_troubleshooting_existingNodes_id_modal",
91             existingNodesDataGrid: "one_f_troubleshooting_existingNodes_id_datagrid",
92             portsDataGrid: "one_f_troubleshooting_existingNodes_id_portsDataGrid",
93             flowsDataGrid: "one_f_troubleshooting_existingNodes_id_flowsDataGrid",
94             refreshFlowsButton:"one_f_troubleshooting_existingNodes_id_refreshFlowsButton",
95             refreshPortsButton:"one_f_troubleshooting_existingNodes_id_refreshPortsButton"
96
97         },
98         load: {
99             main: function($dashlet) {
100                 one.lib.dashlet.empty($dashlet);
101                 $dashlet.append(one.lib.dashlet.header(one.f.dashlet.existingNodes.name));
102                 // TODO(l): Add a generic auto expand function to one.lib and replace custom height setting.
103                 //$('#left-top').height('100%');
104                 one.f.troubleshooting.existingNodes.ajax(one.f.troubleshooting.rootUrl + "/existingNodes" , function(content) {
105                     var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.existingNodesDataGrid, {
106                         searchable: true,
107                         filterable: false,
108                         pagination: true,
109                         flexibleRowsPerPage: true
110                         }, "table-striped table-condensed");
111                     $dashlet.append($gridHTML);
112                     var dataSource = one.f.troubleshooting.existingNodes.data.existingNodesGrid(content);
113                     $("#" + one.f.troubleshooting.existingNodes.id.existingNodesDataGrid).datagrid({dataSource: dataSource});
114
115                 });
116             },
117             flows: function(nodeId) {
118                 try {
119                     if(one.f.troubleshooting === undefined){
120                         return;
121                     }
122                     $.getJSON(one.main.constants.address.prefix + "/troubleshoot/flowStats?nodeId=" + nodeId, function(content) {
123                         $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();
124                         one.f.troubleshooting.rightBottomDashlet.setDashletHeader("Flows");
125                         one.lib.dashlet.empty($rightBottomDashlet);
126                         $rightBottomDashlet.append(one.lib.dashlet.header("Flow Details"));
127                         var button = one.lib.dashlet.button.single("Refresh",
128                                 one.f.troubleshooting.existingNodes.id.refreshFlowsButton, "btn-primary", "btn-mini");
129                         var $button = one.lib.dashlet.button.button(button);
130                         $button.click(function() {
131                             one.f.troubleshooting.existingNodes.load.flows(nodeId);
132                         });
133                         $rightBottomDashlet.append($button);
134                         var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.flowsDataGrid, {
135                             searchable: true,
136                             filterable: false,
137                             pagination: true,
138                             flexibleRowsPerPage: true
139                             }, "table-striped table-condensed");
140                         $rightBottomDashlet.append($gridHTML);
141                         var dataSource = one.f.troubleshooting.existingNodes.data.flowsGrid(content);
142                         $("#" + one.f.troubleshooting.existingNodes.id.flowsDataGrid).datagrid({dataSource: dataSource});
143                     });
144                 } catch(e) {}
145             },
146             ports: function(nodeId) {
147                 try {
148                     if(one.f.troubleshooting === undefined){
149                         return;
150                     }
151                     $.getJSON(one.main.constants.address.prefix + "/troubleshoot/portStats?nodeId=" + nodeId, function(content) {
152                         $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();
153                         one.f.troubleshooting.rightBottomDashlet.setDashletHeader("Ports");
154                         one.lib.dashlet.empty($rightBottomDashlet);
155                         $rightBottomDashlet.append(one.lib.dashlet.header("Port Details"));
156                         var button = one.lib.dashlet.button.single("Refresh",
157                                 one.f.troubleshooting.existingNodes.id.refreshPortsButton, "btn-primary", "btn-mini");
158                         var $button = one.lib.dashlet.button.button(button);
159                         $button.click(function() {
160                             one.f.troubleshooting.existingNodes.load.ports(nodeId);
161                         });
162                         $rightBottomDashlet.append($button);
163                         var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.portsDataGrid, {
164                             searchable: true,
165                             filterable: false,
166                             pagination: true,
167                             flexibleRowsPerPage: true
168                             }, "table-striped table-condensed");
169                         $rightBottomDashlet.append($gridHTML);
170                         var dataSource = one.f.troubleshooting.existingNodes.data.portsGrid(content);
171                         $("#" + one.f.troubleshooting.existingNodes.id.portsDataGrid).datagrid({dataSource: dataSource});
172                     });
173                 } catch(e) {}
174             } 
175         },
176         ajax : function(url, callback) {
177             $.getJSON(url, function(data) {
178                 callback(data);
179             });
180         },
181         registry: {},
182         modal : {
183         },
184         data : {
185             existingNodesGrid: function(data) {
186                 var source = new StaticDataSource({
187                     columns: [
188                         {
189                             property: 'nodeName',
190                             label: 'Name',
191                             sortable: true
192                         },
193                         {
194                             property: 'nodeId',
195                             label: 'Node ID',
196                             sortable: true
197                         },
198                         {
199                             property: 'statistics',
200                             label: 'Statistics',
201                             sortable: true
202                         }
203                     ],
204                     data: data.nodeData,
205                     formatter: function(items) {
206                         $.each(items, function(index, item) {
207                             item["statistics"] = "<a href=\"javascript:one.f.troubleshooting.existingNodes.load.flows('" + item["nodeId"] + "');\">Flows</a>" + 
208                             " <a href=\"javascript:one.f.troubleshooting.existingNodes.load.ports('" + item["nodeId"] + "');\">Ports</a>";
209                         });
210                     },
211                     delay: 0
212                 });
213                 return source;
214             },
215             portsGrid: function(data) {
216                 $.each(data.nodeData, function(index, item) {
217                     item.rxPkts = one.lib.helper.parseInt(item.rxPkts);
218                     item.txPkts = one.lib.helper.parseInt(item.txPkts);
219                     item.rxBytes = one.lib.helper.parseInt(item.rxBytes);
220                     item.txBytes = one.lib.helper.parseInt(item.txBytes);
221                     item.rxDrops = one.lib.helper.parseInt(item.rxDrops);
222                     item.txDrops = one.lib.helper.parseInt(item.txDrops);
223                     item.rxErrors = one.lib.helper.parseInt(item.rxErrors);
224                     item.txErrors = one.lib.helper.parseInt(item.txErrors);
225                     item.rxFrameErrors = one.lib.helper.parseInt(item.rxFrameErrors);
226                     item.rxOverRunErrors = one.lib.helper.parseInt(item.rxOverRunErrors);
227                     item.rxCRCErrors = one.lib.helper.parseInt(item.rxCRCErrors);
228                     item.collisions = one.lib.helper.parseInt(item.collisions);
229                 });
230                 var source = new StaticDataSource({
231                     columns: [
232                         {
233                             property: 'nodeConnector',
234                             label: 'Node Connector',
235                             sortable: true
236                         },
237                         {
238                             property: 'rxPkts',
239                             label: 'Rx Pkts',
240                             sortable: true
241                         },
242                         {
243                             property: 'txPkts',
244                             label: 'Tx Pkts',
245                             sortable: true
246                         },
247                         {
248                             property: 'rxBytes',
249                             label: 'Rx Bytes',
250                             sortable: true
251                         },
252                         {
253                             property: 'txBytes',
254                             label: 'Tx Bytes',
255                             sortable: true
256                         },
257                         {
258                             property: 'rxDrops',
259                             label: 'Rx Drops',
260                             sortable: true
261                         },
262                         {
263                             property: 'txDrops',
264                             label: 'Tx Drops',
265                             sortable: true
266                         },
267                         {
268                             property: 'rxErrors',
269                             label: 'Rx Errs',
270                             sortable: true
271                         },
272                         {
273                             property: 'txErrors',
274                             label: 'Tx Errs',
275                             sortable: true
276                         },
277                         {
278                             property: 'rxFrameErrors',
279                             label: 'Rx Frame Errs',
280                             sortable: true
281                         },
282                         {
283                             property: 'rxOverRunErrors',
284                             label: 'Rx OverRun Errs',
285                             sortable: true
286                         },
287                         {
288                             property: 'rxCRCErrors',
289                             label: 'Rx CRC Errs',
290                             sortable: true
291                         },
292                         {
293                             property: 'collisions',
294                             label: 'Collisions',
295                             sortable: true
296                         }
297                     ],
298                     data: data.nodeData,
299                     delay: 0
300                 });
301                 return source;
302             },
303             ports: function(data) {
304                 var result = [];
305                 $.each(data.nodeData, function(key, value) {
306                     var tr = {};
307                     var entry = [];
308                     entry.push(value["nodeConnector"]);
309                     entry.push(value["rxPkts"]);
310                     entry.push(value["txPkts"]);
311                     entry.push(value["rxBytes"]);
312                     entry.push(value["txBytes"]);
313                     entry.push(value["rxDrops"]);
314                     entry.push(value["txDrops"]);
315                     entry.push(value["rxErrors"]);
316                     entry.push(value["txErrors"]);
317                     entry.push(value["rxFrameErrors"]);
318                     entry.push(value["rxOverRunErrors"]);
319                     entry.push(value["rxCRCErrors"]);
320                     entry.push(value["collisions"]);
321                     tr.entry = entry;
322                     result.push(tr);
323                 });
324                 return result;
325             },
326             flowsGrid: function(data) {
327                 $.each(data.nodeData, function(index, item) {
328                     item.byteCount = one.lib.helper.parseInt(item.byteCount);
329                     item.packetCount = one.lib.helper.parseInt(item.packetCount);
330                     item.durationSeconds = one.lib.helper.parseInt(item.durationSeconds);
331                     item.idleTimeout = one.lib.helper.parseInt(item.idleTimeout);
332                     item.priority = one.lib.helper.parseInt(item.priority);
333                 });
334                 var source = new StaticDataSource({
335                     columns: [
336                         {
337                             property: 'nodeName',
338                             label: 'Node',
339                             sortable: true
340                         },
341                         {
342                             property: 'inPort',
343                             label: 'In Port',
344                             sortable: true
345                         },
346                         {
347                             property: 'dlSrc',
348                             label: 'DL Src',
349                             sortable: true
350                         },
351                         {
352                             property: 'dlDst',
353                             label: 'DL Dst',
354                             sortable: true
355                         },
356                         {
357                             property: 'dlType',
358                             label: 'DL Type',
359                             sortable: true
360                         },
361                         {
362                             property: 'dlVlan',
363                             label: 'DL Vlan',
364                             sortable: true
365                         },
366                         {
367                             property: 'dlVlanPriority',
368                             label: 'Vlan PCP',
369                             sortable: true
370                         },
371                         {
372                             property: 'nwSrc',
373                             label: 'NW Src',
374                             sortable: true
375                         },
376                         {
377                             property: 'nwDst',
378                             label: 'NW Dst',
379                             sortable: true
380                         },
381                         {
382                             property: 'nwTOS',
383                             label: 'ToS Bits',
384                             sortable: true
385                         },
386                         {
387                             property: 'nwProto',
388                             label: 'NW Proto',
389                             sortable: true
390                         },
391                         {
392                             property: 'tpSrc',
393                             label: 'TP Src',
394                             sortable: true
395                         },
396                         {
397                             property: 'tpDst',
398                             label: 'TP Dst',
399                             sortable: true
400                         },
401                         {
402                             property: 'actions',
403                             label: 'Actions',
404                             sortable: true
405                         },
406                         {
407                             property: 'byteCount',
408                             label: 'Byte Count',
409                             sortable: true
410                         },
411                         {
412                             property: 'packetCount',
413                             label: 'Packet Count',
414                             sortable: true
415                         },
416                         {
417                             property: 'durationSeconds',
418                             label: 'Duration Seconds',
419                             sortable: true
420                         },
421                         {
422                             property: 'idleTimeout',
423                             label: 'Idle Timeout',
424                             sortable: true
425                         },
426                         {
427                             property: 'priority',
428                             label: 'Priority',
429                             sortable: true
430                         }
431                     ],
432                     data: data.nodeData,
433                     delay: 0
434                 });
435                 return source;
436             },
437             flows: function(data) {
438                 var result = [];
439                 $.each(data.nodeData, function(key, value) {
440                     var tr = {};
441                     var entry = [];
442                     entry.push(value["nodeName"]);
443                     entry.push(value["inPort"]);
444                     entry.push(value["dlSrc"]);
445                     entry.push(value["dlDst"]);
446                     entry.push(value["dlType"]);
447                     entry.push(value["dlVlan"]);
448                     entry.push(value["nwSrc"]);
449                     entry.push(value["nwDst"]);
450                     entry.push(value["nwTOS"]);
451                     entry.push(value["nwProto"]);
452                     entry.push(value["tpSrc"]);
453                     entry.push(value["tpDst"]);
454                     entry.push(value["actions"]);
455                     entry.push(value["byteCount"]);
456                     entry.push(value["packetCount"]);
457                     entry.push(value["durationSeconds"]);
458                     entry.push(value["idleTimeout"]);
459                     entry.push(value["priority"]);
460                     tr.entry = entry;
461                     result.push(tr);
462                 });
463                 return result;
464             }
465         }
466 };
467
468 one.f.troubleshooting.uptime = {
469     id: {
470         popout: "one_f_troubleshooting_uptime_id_popout",
471         modal: "one_f_troubleshooting_uptime_id_modal",
472         datagrid: "one_f_troubleshooting_uptime_id_datagrid"
473     },
474
475     dashlet: function($dashlet) {
476             one.lib.dashlet.empty($dashlet);
477             $dashlet.append(one.lib.dashlet.header(one.f.dashlet.uptime.name));
478             var url = one.f.troubleshooting.rootUrl + "/uptime";
479             one.f.troubleshooting.uptime.ajax.main(url , {} ,function(content) {
480                 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.uptime.id.datagrid, {
481                     searchable: true,
482                     filterable: false,
483                     pagination: true,
484                     flexibleRowsPerPage: true
485                     }, "table-striped table-condensed");
486                 $dashlet.append($gridHTML);
487                 var dataSource = one.f.troubleshooting.uptime.data.uptimeDataGrid(content);
488                 $("#" + one.f.troubleshooting.uptime.id.datagrid).datagrid({dataSource: dataSource});
489             });
490     },
491     
492     ajax : {
493         main : function(url, requestData, callback) {
494             $.getJSON(url, requestData, function(data) {
495                 callback(data);
496             });
497         }
498     },
499     
500     data: {
501         uptimeDataGrid: function(data) {
502             var source = new StaticDataSource({
503                 columns: [
504                     {
505                         property: 'nodeName',
506                         label: 'Node',
507                         sortable: true
508                     },
509                     {
510                         property: 'nodeId',
511                         label: 'Node ID',
512                         sortable: true
513                     },
514                     {
515                         property: 'connectedSince',
516                         label: 'Statistics',
517                         sortable: true
518                     }
519                 ],
520                 data: data.nodeData,
521                 delay: 0
522             });
523             return source;
524         },
525         uptime: function(data) {
526             var result = [];
527             $.each(data.nodeData, function(key, value) {
528                 var tr = {};
529                 var entry = [];
530                 entry.push(value["nodeName"]);
531                 entry.push(value["nodeId"]);
532                 entry.push(value["connectedSince"]);
533                 tr.entry = entry;
534                 result.push(tr);
535             });
536             return result;
537         }
538     },
539 };
540
541 one.f.troubleshooting.statistics = {
542     dashlet : function($dashlet) {
543         var $h4 = one.lib.dashlet.header("Statistics");
544         $dashlet.append($h4);
545         // empty
546         var $none = $(document.createElement('div'));
547         $none.addClass('none');
548         var $p = $(document.createElement('p'));
549         $p.text('Please select a Flow or Ports statistics');
550         $p.addClass('text-center').addClass('text-info');
551         
552         $dashlet.append($none)
553             .append($p);
554     }
555 };
556
557 // bind dashlet nav
558 $('.dash .nav a', '#main').click(function() {
559     // de/activation
560     var $li = $(this).parent();
561     var $ul = $li.parent();
562     one.lib.nav.unfocus($ul);
563     $li.addClass('active');
564     // clear respective dashlet
565     var $dashlet = $ul.parent().find('.dashlet');
566     one.lib.dashlet.empty($dashlet);
567     // callback based on menu
568     var id = $(this).attr('id');
569     var menu = one.f.dashlet;
570     switch (id) {
571         case menu.existingNodes.id:
572             one.f.troubleshooting.existingNodes.load.main($dashlet);
573             break;
574         case menu.uptime.id:
575             one.f.troubleshooting.uptime.dashlet($dashlet);
576             break;
577         case menu.flowsOrPorts.id:
578             one.f.troubleshooting.statistics.dashlet($dashlet);
579             break;
580     };
581 });
582
583 // activate first tab on each dashlet
584 $('.dash .nav').each(function(index, value) {
585     $($(value).find('li')[0]).find('a').click();
586 });