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>";
216 portsGrid: function(data) {
217 var source = new StaticDataSource({
220 property: 'nodeConnector',
221 label: 'Node Connector',
255 property: 'rxErrors',
260 property: 'txErrors',
265 property: 'rxFrameErrors',
266 label: 'Rx Frame Errs',
270 property: 'rxOverRunErrors',
271 label: 'Rx OverRun Errs',
275 property: 'rxCRCErrors',
276 label: 'Rx CRC Errs',
280 property: 'collisions',
290 ports: function(data) {
292 $.each(data.nodeData, function(key, value) {
295 entry.push(value["nodeConnector"]);
296 entry.push(value["rxPkts"]);
297 entry.push(value["txPkts"]);
298 entry.push(value["rxBytes"]);
299 entry.push(value["txBytes"]);
300 entry.push(value["rxDrops"]);
301 entry.push(value["txDrops"]);
302 entry.push(value["rxErrors"]);
303 entry.push(value["txErrors"]);
304 entry.push(value["rxFrameErrors"]);
305 entry.push(value["rxOverRunErrors"]);
306 entry.push(value["rxCRCErrors"]);
307 entry.push(value["collisions"]);
313 flowsGrid: function(data) {
314 var source = new StaticDataSource({
317 property: 'nodeName',
377 property: 'byteCount',
382 property: 'packetCount',
383 label: 'Packet Count',
387 property: 'durationSeconds',
388 label: 'Duration Seconds',
392 property: 'idleTimeout',
393 label: 'Idle Timeout',
397 property: 'priority',
407 flows: function(data) {
409 $.each(data.nodeData, function(key, value) {
412 entry.push(value["nodeName"]);
413 entry.push(value["inPort"]);
414 entry.push(value["dlSrc"]);
415 entry.push(value["dlDst"]);
416 entry.push(value["dlType"]);
417 entry.push(value["dlVlan"]);
418 entry.push(value["nwSrc"]);
419 entry.push(value["nwDst"]);
420 entry.push(value["nwProto"]);
421 entry.push(value["tpSrc"]);
422 entry.push(value["tpDst"]);
423 entry.push(value["actions"]);
424 entry.push(value["byteCount"]);
425 entry.push(value["packetCount"]);
426 entry.push(value["durationSeconds"]);
427 entry.push(value["idleTimeout"]);
428 entry.push(value["priority"]);
437 one.f.troubleshooting.uptime = {
439 popout: "one_f_troubleshooting_uptime_id_popout",
440 modal: "one_f_troubleshooting_uptime_id_modal",
441 datagrid: "one_f_troubleshooting_uptime_id_datagrid"
444 dashlet: function($dashlet) {
445 one.lib.dashlet.empty($dashlet);
446 $dashlet.append(one.lib.dashlet.header(one.f.dashlet.uptime.name));
447 var url = one.f.troubleshooting.rootUrl + "/uptime";
448 one.f.troubleshooting.uptime.ajax.main(url , {} ,function(content) {
449 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.uptime.id.datagrid, {
453 flexibleRowsPerPage: true
454 }, "table-striped table-condensed");
455 $dashlet.append($gridHTML);
456 var dataSource = one.f.troubleshooting.uptime.data.uptimeDataGrid(content);
457 $("#" + one.f.troubleshooting.uptime.id.datagrid).datagrid({dataSource: dataSource});
462 main : function(url, requestData, callback) {
463 $.getJSON(url, requestData, function(data) {
470 uptimeDataGrid: function(data) {
471 var source = new StaticDataSource({
474 property: 'nodeName',
484 property: 'connectedSince',
494 uptime: function(data) {
496 $.each(data.nodeData, function(key, value) {
499 entry.push(value["nodeName"]);
500 entry.push(value["nodeId"]);
501 entry.push(value["connectedSince"]);
510 one.f.troubleshooting.statistics = {
511 dashlet : function($dashlet) {
512 var $h4 = one.lib.dashlet.header("Statistics");
513 $dashlet.append($h4);
515 var $none = $(document.createElement('div'));
516 $none.addClass('none');
517 var $p = $(document.createElement('p'));
518 $p.text('Please select a Flow or Ports statistics');
519 $p.addClass('text-center').addClass('text-info');
521 $dashlet.append($none)
527 $('.dash .nav a', '#main').click(function() {
529 var $li = $(this).parent();
530 var $ul = $li.parent();
531 one.lib.nav.unfocus($ul);
532 $li.addClass('active');
533 // clear respective dashlet
534 var $dashlet = $ul.parent().find('.dashlet');
535 one.lib.dashlet.empty($dashlet);
536 // callback based on menu
537 var id = $(this).attr('id');
538 var menu = one.f.dashlet;
540 case menu.existingNodes.id:
541 one.f.troubleshooting.existingNodes.load.main($dashlet);
544 one.f.troubleshooting.uptime.dashlet($dashlet);
546 case menu.flowsOrPorts.id:
547 one.f.troubleshooting.statistics.dashlet($dashlet);
552 // activate first tab on each dashlet
553 $('.dash .nav').each(function(index, value) {
554 $($(value).find('li')[0]).find('a').click();