2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
13 // specify dashlets and layouts
17 name : 'Existing Nodes'
32 one.f.dashlet.existingNodes
41 one.f.dashlet.flowsOrPorts
48 $(one.f.menu.left.top).each(function(index, value) {
49 var $nav = $(".nav", "#left-top");
50 one.main.page.dashlet($nav, value);
53 $(one.f.menu.left.bottom).each(function(index, value) {
54 var $nav = $(".nav", "#left-bottom");
55 one.main.page.dashlet($nav, value);
58 $(one.f.menu.right.bottom).each(function(index, value) {
59 var $nav = $(".nav", "#right-bottom");
60 one.main.page.dashlet($nav, value);
63 /**Troubleshoot modules*/
64 one.f.troubleshooting = {
65 rootUrl: "/controller/web/troubleshoot",
68 var $rightBottomDashlet = $("#right-bottom").find(".dashlet");
69 return $rightBottomDashlet;
71 setDashletHeader: function(label) {
72 $("#right-bottom li a")[0].innerHTML = label;
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);
87 one.f.troubleshooting.existingNodes = {
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"
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, {
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});
117 flows: function(nodeId) {
119 if(one.f.troubleshooting === undefined){
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);
133 $rightBottomDashlet.append($button);
134 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.flowsDataGrid, {
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});
146 ports: function(nodeId) {
148 if(one.f.troubleshooting === undefined){
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);
162 $rightBottomDashlet.append($button);
163 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.portsDataGrid, {
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});
176 ajax : function(url, callback) {
177 $.getJSON(url, function(data) {
185 existingNodesGrid: function(data) {
186 var source = new StaticDataSource({
189 property: 'nodeName',
199 property: 'statistics',
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>";
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);
230 var source = new StaticDataSource({
233 property: 'nodeConnector',
234 label: 'Node Connector',
268 property: 'rxErrors',
273 property: 'txErrors',
278 property: 'rxFrameErrors',
279 label: 'Rx Frame Errs',
283 property: 'rxOverRunErrors',
284 label: 'Rx OverRun Errs',
288 property: 'rxCRCErrors',
289 label: 'Rx CRC Errs',
293 property: 'collisions',
303 ports: function(data) {
305 $.each(data.nodeData, function(key, value) {
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"]);
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);
334 var source = new StaticDataSource({
337 property: 'nodeName',
402 property: 'byteCount',
407 property: 'packetCount',
408 label: 'Packet Count',
412 property: 'durationSeconds',
413 label: 'Duration Seconds',
417 property: 'idleTimeout',
418 label: 'Idle Timeout',
422 property: 'priority',
432 flows: function(data) {
434 $.each(data.nodeData, function(key, value) {
437 entry.push(value["nodeName"]);
438 entry.push(value["inPort"]);
439 entry.push(value["dlSrc"]);
440 entry.push(value["dlDst"]);
441 entry.push(value["dlType"]);
442 entry.push(value["dlVlan"]);
443 entry.push(value["nwSrc"]);
444 entry.push(value["nwDst"]);
445 entry.push(value["nwTOS"]);
446 entry.push(value["nwProto"]);
447 entry.push(value["tpSrc"]);
448 entry.push(value["tpDst"]);
449 entry.push(value["actions"]);
450 entry.push(value["byteCount"]);
451 entry.push(value["packetCount"]);
452 entry.push(value["durationSeconds"]);
453 entry.push(value["idleTimeout"]);
454 entry.push(value["priority"]);
463 one.f.troubleshooting.uptime = {
465 popout: "one_f_troubleshooting_uptime_id_popout",
466 modal: "one_f_troubleshooting_uptime_id_modal",
467 datagrid: "one_f_troubleshooting_uptime_id_datagrid"
470 dashlet: function($dashlet) {
471 one.lib.dashlet.empty($dashlet);
472 $dashlet.append(one.lib.dashlet.header(one.f.dashlet.uptime.name));
473 var url = one.f.troubleshooting.rootUrl + "/uptime";
474 one.f.troubleshooting.uptime.ajax.main(url , {} ,function(content) {
475 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.uptime.id.datagrid, {
479 flexibleRowsPerPage: true
480 }, "table-striped table-condensed");
481 $dashlet.append($gridHTML);
482 var dataSource = one.f.troubleshooting.uptime.data.uptimeDataGrid(content);
483 $("#" + one.f.troubleshooting.uptime.id.datagrid).datagrid({dataSource: dataSource});
488 main : function(url, requestData, callback) {
489 $.getJSON(url, requestData, function(data) {
496 uptimeDataGrid: function(data) {
497 var source = new StaticDataSource({
500 property: 'nodeName',
510 property: 'connectedSince',
520 uptime: function(data) {
522 $.each(data.nodeData, function(key, value) {
525 entry.push(value["nodeName"]);
526 entry.push(value["nodeId"]);
527 entry.push(value["connectedSince"]);
536 one.f.troubleshooting.statistics = {
537 dashlet : function($dashlet) {
538 var $h4 = one.lib.dashlet.header("Statistics");
539 $dashlet.append($h4);
541 var $none = $(document.createElement('div'));
542 $none.addClass('none');
543 var $p = $(document.createElement('p'));
544 $p.text('Please select a Flow or Ports statistics');
545 $p.addClass('text-center').addClass('text-info');
547 $dashlet.append($none)
553 $('.dash .nav a', '#main').click(function() {
555 var $li = $(this).parent();
556 var $ul = $li.parent();
557 one.lib.nav.unfocus($ul);
558 $li.addClass('active');
559 // clear respective dashlet
560 var $dashlet = $ul.parent().find('.dashlet');
561 one.lib.dashlet.empty($dashlet);
562 // callback based on menu
563 var id = $(this).attr('id');
564 var menu = one.f.dashlet;
566 case menu.existingNodes.id:
567 one.f.troubleshooting.existingNodes.load.main($dashlet);
570 one.f.troubleshooting.uptime.dashlet($dashlet);
572 case menu.flowsOrPorts.id:
573 one.f.troubleshooting.statistics.dashlet($dashlet);
578 // activate first tab on each dashlet
579 $('.dash .nav').each(function(index, value) {
580 $($(value).find('li')[0]).find('a').click();