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",
97 nodeInfo : "one_f_troubleshooting_existingNodes_id_modal_nodeInfo",
98 cancelButton : "one_f_troubleshooting_existingNodes_id_modal_cancelButton",
102 main: function($dashlet) {
103 one.lib.dashlet.empty($dashlet);
104 $dashlet.append(one.lib.dashlet.header(one.f.dashlet.existingNodes.name));
105 // TODO(l): Add a generic auto expand function to one.lib and replace custom height setting.
106 //$('#left-top').height('100%');
107 one.f.troubleshooting.existingNodes.ajax(one.f.troubleshooting.rootUrl + "/existingNodes" , function(content) {
108 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.existingNodesDataGrid, {
112 flexibleRowsPerPage: true
113 }, "table-striped table-condensed");
114 $dashlet.append($gridHTML);
115 var dataSource = one.f.troubleshooting.existingNodes.data.existingNodesGrid(content);
116 $("#" + one.f.troubleshooting.existingNodes.id.existingNodesDataGrid).datagrid({dataSource: dataSource});
120 flows: function(nodeId) {
122 if(one.f.troubleshooting === undefined){
125 $.getJSON(one.main.constants.address.prefix + "/troubleshoot/flowStats?nodeId=" + nodeId, function(content) {
126 $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();
127 one.f.troubleshooting.rightBottomDashlet.setDashletHeader("Flows");
128 one.lib.dashlet.empty($rightBottomDashlet);
129 $rightBottomDashlet.append(one.lib.dashlet.header("Flow Details"));
130 var button = one.lib.dashlet.button.single("Refresh",
131 one.f.troubleshooting.existingNodes.id.refreshFlowsButton, "btn-primary", "btn-mini");
132 var $button = one.lib.dashlet.button.button(button);
133 $button.click(function() {
134 one.f.troubleshooting.existingNodes.load.flows(nodeId);
136 $rightBottomDashlet.append($button);
137 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.flowsDataGrid, {
141 flexibleRowsPerPage: true
142 }, "table-striped table-condensed");
143 $rightBottomDashlet.append($gridHTML);
144 var dataSource = one.f.troubleshooting.existingNodes.data.flowsGrid(content);
145 $("#" + one.f.troubleshooting.existingNodes.id.flowsDataGrid).datagrid({dataSource: dataSource});
149 ports: function(nodeId) {
151 if(one.f.troubleshooting === undefined){
154 $.getJSON(one.main.constants.address.prefix + "/troubleshoot/portStats?nodeId=" + nodeId, function(content) {
155 $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();
156 one.f.troubleshooting.rightBottomDashlet.setDashletHeader("Ports");
157 one.lib.dashlet.empty($rightBottomDashlet);
158 $rightBottomDashlet.append(one.lib.dashlet.header("Port Details"));
159 var button = one.lib.dashlet.button.single("Refresh",
160 one.f.troubleshooting.existingNodes.id.refreshPortsButton, "btn-primary", "btn-mini");
161 var $button = one.lib.dashlet.button.button(button);
162 $button.click(function() {
163 one.f.troubleshooting.existingNodes.load.ports(nodeId);
165 $rightBottomDashlet.append($button);
166 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.existingNodes.id.portsDataGrid, {
170 flexibleRowsPerPage: true
171 }, "table-striped table-condensed");
172 $rightBottomDashlet.append($gridHTML);
173 var dataSource = one.f.troubleshooting.existingNodes.data.portsGrid(content);
174 $("#" + one.f.troubleshooting.existingNodes.id.portsDataGrid).datagrid({dataSource: dataSource});
179 ajax : function(url, callback) {
180 $.getJSON(url, function(data) {
188 existingNodesGrid: function(data) {
189 var source = new StaticDataSource({
192 property: 'nodeName',
202 property: 'statistics',
208 formatter: function(items) {
209 $.each(items, function(index, item) {
210 item.nodeName = "<a href=\"javascript:one.f.troubleshooting.existingNodes.data.nodeInfo('"
211 + item.nodeId + "');\">" + item.nodeName + "</a>"
212 item["statistics"] = "<a href=\"javascript:one.f.troubleshooting.existingNodes.load.flows('" + item["nodeId"] + "');\">Flows</a>" +
213 " <a href=\"javascript:one.f.troubleshooting.existingNodes.load.ports('" + item["nodeId"] + "');\">Ports</a>";
220 portsGrid: function(data) {
221 $.each(data.nodeData, function(index, item) {
222 item.rxPkts = one.lib.helper.parseInt(item.rxPkts);
223 item.txPkts = one.lib.helper.parseInt(item.txPkts);
224 item.rxBytes = one.lib.helper.parseInt(item.rxBytes);
225 item.txBytes = one.lib.helper.parseInt(item.txBytes);
226 item.rxDrops = one.lib.helper.parseInt(item.rxDrops);
227 item.txDrops = one.lib.helper.parseInt(item.txDrops);
228 item.rxErrors = one.lib.helper.parseInt(item.rxErrors);
229 item.txErrors = one.lib.helper.parseInt(item.txErrors);
230 item.rxFrameErrors = one.lib.helper.parseInt(item.rxFrameErrors);
231 item.rxOverRunErrors = one.lib.helper.parseInt(item.rxOverRunErrors);
232 item.rxCRCErrors = one.lib.helper.parseInt(item.rxCRCErrors);
233 item.collisions = one.lib.helper.parseInt(item.collisions);
235 var source = new StaticDataSource({
238 property: 'nodeConnector',
239 label: 'Node Connector',
273 property: 'rxErrors',
278 property: 'txErrors',
283 property: 'rxFrameErrors',
284 label: 'Rx Frame Errs',
288 property: 'rxOverRunErrors',
289 label: 'Rx OverRun Errs',
293 property: 'rxCRCErrors',
294 label: 'Rx CRC Errs',
298 property: 'collisions',
308 ports: function(data) {
310 $.each(data.nodeData, function(key, value) {
313 entry.push(value["nodeConnector"]);
314 entry.push(value["rxPkts"]);
315 entry.push(value["txPkts"]);
316 entry.push(value["rxBytes"]);
317 entry.push(value["txBytes"]);
318 entry.push(value["rxDrops"]);
319 entry.push(value["txDrops"]);
320 entry.push(value["rxErrors"]);
321 entry.push(value["txErrors"]);
322 entry.push(value["rxFrameErrors"]);
323 entry.push(value["rxOverRunErrors"]);
324 entry.push(value["rxCRCErrors"]);
325 entry.push(value["collisions"]);
331 flowsGrid: function(data) {
332 $.each(data.nodeData, function(index, item) {
333 item.byteCount = one.lib.helper.parseInt(item.byteCount);
334 item.packetCount = one.lib.helper.parseInt(item.packetCount);
335 item.durationSeconds = one.lib.helper.parseInt(item.durationSeconds);
336 item.idleTimeout = one.lib.helper.parseInt(item.idleTimeout);
337 item.priority = one.lib.helper.parseInt(item.priority);
339 var source = new StaticDataSource({
342 property: 'nodeName',
372 property: 'dlVlanPriority',
412 property: 'byteCount',
417 property: 'packetCount',
418 label: 'Packet Count',
422 property: 'durationSeconds',
423 label: 'Duration Seconds',
427 property: 'idleTimeout',
428 label: 'Idle Timeout',
432 property: 'priority',
442 flows: function(data) {
444 $.each(data.nodeData, function(key, value) {
447 entry.push(value["nodeName"]);
448 entry.push(value["inPort"]);
449 entry.push(value["dlSrc"]);
450 entry.push(value["dlDst"]);
451 entry.push(value["dlType"]);
452 entry.push(value["dlVlan"]);
453 entry.push(value["nwSrc"]);
454 entry.push(value["nwDst"]);
455 entry.push(value["nwTOS"]);
456 entry.push(value["nwProto"]);
457 entry.push(value["tpSrc"]);
458 entry.push(value["tpDst"]);
459 entry.push(value["actions"]);
460 entry.push(value["byteCount"]);
461 entry.push(value["packetCount"]);
462 entry.push(value["durationSeconds"]);
463 entry.push(value["idleTimeout"]);
464 entry.push(value["priority"]);
470 nodeInfo : function(nodeId){
471 $.getJSON(one.main.constants.address.prefix + "/troubleshoot/nodeInfo?nodeId=" + nodeId, function(content) {
472 var h3 = 'Node Information'
474 var headers = [ 'Description','Specification'];
476 var attributes = ['table-striped', 'table-bordered', 'table-condensed'];
477 var $table = one.lib.dashlet.table.table(attributes);
478 var $thead = one.lib.dashlet.table.header(headers);
479 $table.append($thead);
483 var cancelButton = one.lib.dashlet.button.single("Cancel",
484 one.f.troubleshooting.existingNodes.id.modal.nodeInfo, "", "");
485 var $cancelButton = one.lib.dashlet.button.button(cancelButton);
486 footer.push($cancelButton);
489 $.each(content, function(key, value) {
499 var $tbody = one.lib.dashlet.table.body(body);
500 $table.append($tbody);
502 var $modal = one.lib.modal.spawn(one.f.troubleshooting.existingNodes.id.modal.nodeInfo, h3, $table , footer);
505 $('#'+one.f.troubleshooting.existingNodes.id.modal.nodeInfo, $modal).click(function() {
506 $modal.modal('hide');
513 one.f.troubleshooting.uptime = {
515 popout: "one_f_troubleshooting_uptime_id_popout",
516 modal: "one_f_troubleshooting_uptime_id_modal",
517 datagrid: "one_f_troubleshooting_uptime_id_datagrid"
520 dashlet: function($dashlet) {
521 one.lib.dashlet.empty($dashlet);
522 $dashlet.append(one.lib.dashlet.header(one.f.dashlet.uptime.name));
523 var url = one.f.troubleshooting.rootUrl + "/uptime";
524 one.f.troubleshooting.uptime.ajax.main(url , {} ,function(content) {
525 var $gridHTML = one.lib.dashlet.datagrid.init(one.f.troubleshooting.uptime.id.datagrid, {
529 flexibleRowsPerPage: true
530 }, "table-striped table-condensed");
531 $dashlet.append($gridHTML);
532 var dataSource = one.f.troubleshooting.uptime.data.uptimeDataGrid(content);
533 $("#" + one.f.troubleshooting.uptime.id.datagrid).datagrid({dataSource: dataSource});
538 main : function(url, requestData, callback) {
539 $.getJSON(url, requestData, function(data) {
546 uptimeDataGrid: function(data) {
547 var source = new StaticDataSource({
550 property: 'nodeName',
560 property: 'connectedSince',
570 uptime: function(data) {
572 $.each(data.nodeData, function(key, value) {
575 entry.push(value["nodeName"]);
576 entry.push(value["nodeId"]);
577 entry.push(value["connectedSince"]);
586 one.f.troubleshooting.statistics = {
587 dashlet : function($dashlet) {
588 var $h4 = one.lib.dashlet.header("Statistics");
589 $dashlet.append($h4);
591 var $none = $(document.createElement('div'));
592 $none.addClass('none');
593 var $p = $(document.createElement('p'));
594 $p.text('Please select a Flow or Ports statistics');
595 $p.addClass('text-center').addClass('text-info');
597 $dashlet.append($none)
603 $('.dash .nav a', '#main').click(function() {
605 var $li = $(this).parent();
606 var $ul = $li.parent();
607 one.lib.nav.unfocus($ul);
608 $li.addClass('active');
609 // clear respective dashlet
610 var $dashlet = $ul.parent().find('.dashlet');
611 one.lib.dashlet.empty($dashlet);
612 // callback based on menu
613 var id = $(this).attr('id');
614 var menu = one.f.dashlet;
616 case menu.existingNodes.id:
617 one.f.troubleshooting.existingNodes.load.main($dashlet);
620 one.f.troubleshooting.uptime.dashlet($dashlet);
622 case menu.flowsOrPorts.id:
623 one.f.troubleshooting.statistics.dashlet($dashlet);
628 // activate first tab on each dashlet
629 $('.dash .nav').each(function(index, value) {
630 $($(value).find('li')[0]).find('a').click();