Simon Hunt
Committed by Gerrit Code Review

GUI -- refactored all the table views (server side) to use the new TableModel me…

…thod of data generation.

Change-Id: Ib8a188ad432ff335db6cff1e49e08dbaf039436b
Showing 28 changed files with 639 additions and 409 deletions
......@@ -26,6 +26,7 @@ import java.util.Map;
/**
* Provides a partial implementation of {@link TableRow}.
*/
@Deprecated
public abstract class AbstractTableRow implements TableRow {
private static final ObjectMapper MAPPER = new ObjectMapper();
......
......@@ -21,6 +21,7 @@ import java.util.Comparator;
/**
* Comparator for {@link TableRow}.
*/
@Deprecated
public class RowComparator implements Comparator<TableRow> {
/** Designates the sort direction. */
public enum Direction {
......
......@@ -46,8 +46,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class TableModel {
private static final CellComparator DEF_CMP = new DefaultCellComparator();
private static final CellFormatter DEF_FMT = new DefaultCellFormatter();
private static final CellComparator DEF_CMP = DefaultCellComparator.INSTANCE;
private static final CellFormatter DEF_FMT = DefaultCellFormatter.INSTANCE;
private final String[] columnIds;
private final Set<String> idSet;
......@@ -99,13 +99,16 @@ public class TableModel {
}
/**
* Returns the {@link TableRow} representation of the rows in this table.
* Returns the array of column IDs for this table model.
* <p>
* Implementation note: we are knowingly passing you a reference to
* our internal array to avoid copying. Don't mess with it. It's your
* table you'll break if you do!
*
* @return formatted table rows
* @return the column identifiers
*/
// TODO: still need to decide if we need this
public TableRow[] getTableRows() {
return new TableRow[0];
public String[] getColumnIds() {
return columnIds;
}
/**
......@@ -113,7 +116,6 @@ public class TableModel {
*
* @return raw table rows
*/
// TODO: still need to decide if we should expose this
public Row[] getRows() {
return rows.toArray(new Row[rows.size()]);
}
......@@ -264,9 +266,22 @@ public class TableModel {
* @param columnId column identifier
* @return formatted cell value
*/
public String getAsString(String columnId) {
String getAsString(String columnId) {
return getFormatter(columnId).format(get(columnId));
}
/**
* Returns the row as an array of formatted strings.
*
* @return the formatted row data
*/
public String[] getAsFormattedStrings() {
List<String> formatted = new ArrayList<>(columnCount());
for (String c : columnIds) {
formatted.add(getAsString(c));
}
return formatted.toArray(new String[formatted.size()]);
}
}
private static final String DESC = "desc";
......
......@@ -17,10 +17,9 @@
package org.onosproject.ui.table;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.ui.JsonUtils;
import org.onosproject.ui.RequestHandler;
import java.util.Arrays;
/**
* Message handler specifically for table views.
*/
......@@ -47,29 +46,66 @@ public abstract class TableRequestHandler extends RequestHandler {
@Override
public void process(long sid, ObjectNode payload) {
RowComparator rc = TableUtils.createRowComparator(payload, defaultColId());
TableRow[] rows = generateTableRows(payload);
Arrays.sort(rows, rc);
TableModel tm = createTableModel();
populateTable(tm, payload);
String sortCol = JsonUtils.string(payload, "sortCol", defaultColumnId());
String sortDir = JsonUtils.string(payload, "sortDir", "asc");
tm.sort(sortCol, TableModel.sortDir(sortDir));
ObjectNode rootNode = MAPPER.createObjectNode();
rootNode.set(nodeName, TableUtils.generateArrayNode(rows));
rootNode.set(nodeName, TableUtils.generateArrayNode(tm));
sendMessage(respType, 0, rootNode);
}
/**
* Returns the default column ID, when one is not supplied in the payload
* defining the column on which to sort. This implementation returns "id".
* Creates the table model (devoid of data) using {@link #getColumnIds()}
* to initialize it, ready to be populated.
* <p>
* This default implementation returns a table model with default
* formatters and comparators for all columns.
*
* @return an empty table model
*/
protected TableModel createTableModel() {
return new TableModel(getColumnIds());
}
/**
* Returns the default column ID to be used when one is not supplied in
* the payload as the column on which to sort.
* <p>
* This default implementation returns "id".
*
* @return default sort column id
* @return default sort column identifier
*/
protected String defaultColId() {
protected String defaultColumnId() {
return "id";
}
/**
* Subclasses should generate table rows for their specific table instance.
* Subclasses should return the array of column IDs with which
* to initialize their table model.
*
* @return the column IDs
*/
protected abstract String[] getColumnIds();
/**
* Subclasses should populate the table model by adding
* {@link TableModel.Row rows}.
* <pre>
* tm.addRow()
* .cell(COL_ONE, ...)
* .cell(COL_TWO, ...)
* ... ;
* </pre>
* The request payload is provided in case there are request filtering
* parameters (other than sort column and sort direction) that are required
* to generate the appropriate data.
*
* @param payload provided in case custom parameters are present
* @return generated table rows
* @param tm the table model
* @param payload request payload
*/
protected abstract TableRow[] generateTableRows(ObjectNode payload);
protected abstract void populateTable(TableModel tm, ObjectNode payload);
}
......
......@@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* Defines a table row abstraction to support sortable tables on the GUI.
*/
@Deprecated
public interface TableRow {
// TODO: Define TableCell interface and return that, rather than String
......
......@@ -16,10 +16,10 @@
package org.onosproject.ui.table;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.ui.JsonUtils;
/**
* Provides static utility methods for dealing with tables.
......@@ -32,46 +32,27 @@ public final class TableUtils {
private TableUtils() { }
/**
* Produces a JSON array node from the specified table rows.
* Generates a JSON array node from a table model.
*
* @param rows table rows
* @return JSON array
* @param tm the table model
* @return the array node representation
*/
public static ArrayNode generateArrayNode(TableRow[] rows) {
public static ArrayNode generateArrayNode(TableModel tm) {
ArrayNode array = MAPPER.createArrayNode();
for (TableRow r : rows) {
array.add(r.toJsonNode());
for (TableModel.Row r : tm.getRows()) {
array.add(toJsonNode(r, tm));
}
return array;
}
/**
* Creates a row comparator for the given request. The ID of the column
* to sort on is the payload's "sortCol" property (defaults to "id").
* The direction for the sort is the payload's "sortDir" property
* (defaults to "asc").
*
* @param payload the event payload
* @return a row comparator
*/
public static RowComparator createRowComparator(ObjectNode payload) {
return createRowComparator(payload, "id");
}
/**
* Creates a row comparator for the given request. The ID of the column to
* sort on is the payload's "sortCol" property (or the specified default).
* The direction for the sort is the payload's "sortDir" property
* (defaults to "asc").
*
* @param payload the event payload
* @param defColId the default column ID
* @return a row comparator
*/
public static RowComparator createRowComparator(ObjectNode payload,
String defColId) {
String sortCol = JsonUtils.string(payload, "sortCol", defColId);
String sortDir = JsonUtils.string(payload, "sortDir", "asc");
return new RowComparator(sortCol, RowComparator.direction(sortDir));
private static JsonNode toJsonNode(TableModel.Row row, TableModel tm) {
ObjectNode result = MAPPER.createObjectNode();
String[] keys = tm.getColumnIds();
String[] cells = row.getAsFormattedStrings();
int n = keys.length;
for (int i = 0; i < n; i++) {
result.put(keys[i], cells[i]);
}
return result;
}
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.onosproject.ui.table.cell;
import org.onosproject.core.ApplicationId;
import org.onosproject.ui.table.CellFormatter;
/**
* Formats an application identifier as "(app-id) : (app-name)".
*/
public class AppIdFormatter extends AbstractCellFormatter {
@Override
protected String nonNullFormat(Object value) {
ApplicationId appId = (ApplicationId) value;
return appId.id() + " : " + appId.name();
}
/**
* An instance of this class.
*/
public static final CellFormatter INSTANCE = new AppIdFormatter();
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.onosproject.ui.table.cell;
import org.onosproject.net.ConnectPoint;
import org.onosproject.ui.table.CellFormatter;
/**
* Formats a connect point as "(element-id)/(port)".
*/
public class ConnectPointFormatter extends AbstractCellFormatter {
@Override
protected String nonNullFormat(Object value) {
ConnectPoint cp = (ConnectPoint) value;
return cp.elementId() + "/" + cp.port();
}
/**
* An instance of this class.
*/
public static final CellFormatter INSTANCE = new ConnectPointFormatter();
}
......@@ -17,6 +17,8 @@
package org.onosproject.ui.table.cell;
import org.onosproject.ui.table.CellComparator;
/**
* A default cell comparator. Implements a lexicographical compare function
* (i.e. string sorting). Uses the objects' toString() method and then
......@@ -24,8 +26,14 @@ package org.onosproject.ui.table.cell;
* are considered "smaller" than any non-null value.
*/
public class DefaultCellComparator extends AbstractCellComparator {
@Override
protected int nonNullCompare(Object o1, Object o2) {
return o1.toString().compareTo(o2.toString());
}
/**
* An instance of this class.
*/
public static final CellComparator INSTANCE = new DefaultCellComparator();
}
......
......@@ -17,12 +17,20 @@
package org.onosproject.ui.table.cell;
import org.onosproject.ui.table.CellFormatter;
/**
* A default cell formatter. Uses the object's toString() method.
*/
public class DefaultCellFormatter extends AbstractCellFormatter {
@Override
public String nonNullFormat(Object value) {
return value.toString();
}
/**
* An instance of this class.
*/
public static final CellFormatter INSTANCE = new DefaultCellFormatter();
}
......
......@@ -17,12 +17,20 @@
package org.onosproject.ui.table.cell;
import org.onosproject.ui.table.CellFormatter;
/**
* Formats integer values as hex strings.
* Formats integer values as hex strings with a "0x" prefix.
*/
public class HexFormatter extends AbstractCellFormatter {
@Override
protected String nonNullFormat(Object value) {
return "0x" + Integer.toHexString((Integer) value);
}
/**
* An instance of this class.
*/
public static final CellFormatter INSTANCE = new HexFormatter();
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.onosproject.ui.table.cell;
import org.onosproject.net.HostLocation;
import org.onosproject.ui.table.CellFormatter;
/**
* Formats a host location as "(device-id)/(port)".
*/
public class HostLocationFormatter extends AbstractCellFormatter {
@Override
protected String nonNullFormat(Object value) {
HostLocation loc = (HostLocation) value;
return loc.deviceId() + "/" + loc.port();
}
/**
* An instance of this class.
*/
public static final CellFormatter INSTANCE = new HostLocationFormatter();
}
......@@ -17,14 +17,22 @@
package org.onosproject.ui.table.cell;
import org.onosproject.ui.table.CellComparator;
/**
* An integer-based cell comparator.
* Note that null values are acceptable and are considered "smaller" than
* any non-null value.
*/
public class IntComparator extends AbstractCellComparator {
@Override
protected int nonNullCompare(Object o1, Object o2) {
return ((int) o1) - ((int) o2);
}
/**
* An instance of this class.
*/
public static final CellComparator INSTANCE = new IntComparator();
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.onosproject.ui.table.cell;
import org.onosproject.ui.table.CellComparator;
/**
* A long-based cell comparator.
* Note that null values are acceptable and are considered "smaller" than
* any non-null value.
*/
public class LongComparator extends AbstractCellComparator {
@Override
protected int nonNullCompare(Object o1, Object o2) {
long diff = ((long) o1) - ((long) o2);
return diff == 0 ? 0 : (diff < 0 ? -1 : 1);
}
/**
* An instance of this class.
*/
public static final CellComparator INSTANCE = new LongComparator();
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.onosproject.ui.table.cell;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.onosproject.ui.table.CellFormatter;
/**
* Formats time values using {@link DateTimeFormatter}.
*/
public class TimeFormatter extends AbstractCellFormatter {
private static final DateTimeFormatter DTF = DateTimeFormat.longTime();
@Override
protected String nonNullFormat(Object value) {
return DTF.print((DateTime) value);
}
/**
* An instance of this class.
*/
public static final CellFormatter INSTANCE = new TimeFormatter();
}
......@@ -45,7 +45,6 @@ public class TableModelTest {
private TableModel tm;
private TableModel.Row[] rows;
private TableModel.Row row;
private TableRow[] tableRows;
private CellFormatter fmt;
@Test(expected = NullPointerException.class)
......@@ -68,9 +67,6 @@ public class TableModelTest {
tm = new TableModel(FOO, BAR);
assertEquals("column count", 2, tm.columnCount());
assertEquals("row count", 0, tm.rowCount());
tableRows = tm.getTableRows();
assertEquals("row count alt", 0, tableRows.length);
}
@Test
......@@ -225,7 +221,7 @@ public class TableModelTest {
initUnsortedTable();
// first, tell the table to use an integer-based comparator
tm.setComparator(BAR, new IntComparator());
tm.setComparator(BAR, IntComparator.INSTANCE);
// sort by number
tm.sort(BAR, SortDir.ASC);
......@@ -256,8 +252,8 @@ public class TableModelTest {
initUnsortedTable();
// set integer-based comparator and hex formatter
tm.setComparator(BAR, new IntComparator());
tm.setFormatter(BAR, new HexFormatter());
tm.setComparator(BAR, IntComparator.INSTANCE);
tm.setFormatter(BAR, HexFormatter.INSTANCE);
// sort by number
tm.sort(BAR, SortDir.ASC);
......
......@@ -39,7 +39,7 @@ public class DefaultCellComparatorTest {
private static final int NUMBER = 42;
private static final TestClass OBJECT = new TestClass();
private CellComparator cmp = new DefaultCellComparator();
private CellComparator cmp = DefaultCellComparator.INSTANCE;
@Test
public void sameString() {
......
......@@ -37,7 +37,7 @@ public class DefaultCellFormatterTest {
}
}
private CellFormatter fmt = new DefaultCellFormatter();
private CellFormatter fmt = DefaultCellFormatter.INSTANCE;
@Test
public void formatNull() {
......
......@@ -18,6 +18,7 @@
package org.onosproject.ui.table.cell;
import org.junit.Test;
import org.onosproject.ui.table.CellFormatter;
import static org.junit.Assert.assertEquals;
......@@ -26,7 +27,7 @@ import static org.junit.Assert.assertEquals;
*/
public class HexFormatterTest {
private HexFormatter fmt = new HexFormatter();
private CellFormatter fmt = HexFormatter.INSTANCE;
@Test
public void nullValue() {
......
......@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue;
*/
public class IntComparatorTest {
private CellComparator cmp = new IntComparator();
private CellComparator cmp = IntComparator.INSTANCE;
@Test
public void twoNulls() {
......
......@@ -24,13 +24,10 @@ import org.onosproject.core.Application;
import org.onosproject.core.ApplicationId;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.table.AbstractTableRow;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.TableRow;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import static org.onosproject.app.ApplicationState.ACTIVE;
......@@ -55,6 +52,10 @@ public class ApplicationViewMessageHandler extends UiMessageHandler {
private static final String ICON_ID_ACTIVE = "active";
private static final String ICON_ID_INACTIVE = "appInactive";
private static final String[] COL_IDS = {
STATE, STATE_IID, ID, VERSION, ORIGIN, DESC
};
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(
......@@ -70,14 +71,31 @@ public class ApplicationViewMessageHandler extends UiMessageHandler {
}
@Override
protected TableRow[] generateTableRows(ObjectNode payload) {
ApplicationService service = get(ApplicationService.class);
List<TableRow> list = service.getApplications().stream()
.map(application -> new ApplicationTableRow(service, application))
.collect(Collectors.toList());
return list.toArray(new TableRow[list.size()]);
protected String[] getColumnIds() {
return COL_IDS;
}
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
ApplicationService as = get(ApplicationService.class);
for (Application app : as.getApplications()) {
populateRow(tm.addRow(), app, as);
}
}
private void populateRow(TableModel.Row row, Application app,
ApplicationService as) {
ApplicationId id = app.id();
ApplicationState state = as.getState(id);
String iconId = state == ACTIVE ? ICON_ID_ACTIVE : ICON_ID_INACTIVE;
row.cell(STATE, state)
.cell(STATE_IID, iconId)
.cell(ID, id.name())
.cell(VERSION, app.version())
.cell(ORIGIN, app.origin())
.cell(DESC, app.description());
}
}
// handler for application management control button actions
......@@ -104,33 +122,4 @@ public class ApplicationViewMessageHandler extends UiMessageHandler {
}
}
}
/**
* TableRow implementation for
* {@link org.onosproject.core.Application applications}.
*/
private static class ApplicationTableRow extends AbstractTableRow {
private static final String[] COL_IDS = {
STATE, STATE_IID, ID, VERSION, ORIGIN, DESC
};
public ApplicationTableRow(ApplicationService service, Application app) {
ApplicationState state = service.getState(app.id());
String iconId = state == ACTIVE ? ICON_ID_ACTIVE : ICON_ID_INACTIVE;
add(STATE, state);
add(STATE_IID, iconId);
add(ID, app.id().name());
add(VERSION, app.version());
add(ORIGIN, app.origin());
add(DESC, app.description());
}
@Override
protected String[] columnIds() {
return COL_IDS;
}
}
}
......
......@@ -19,19 +19,17 @@ package org.onosproject.ui.impl;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.NodeId;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.table.AbstractTableRow;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.TableRow;
import org.onosproject.ui.table.cell.IntComparator;
import org.onosproject.ui.table.cell.TimeFormatter;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
/**
......@@ -49,6 +47,13 @@ public class ClusterViewMessageHandler extends UiMessageHandler {
private static final String STATE_IID = "_iconid_state";
private static final String UPDATED = "updated";
private static final String[] COL_IDS = {
ID, IP, TCP_PORT, STATE_IID, UPDATED
};
private static final String ICON_ID_ONLINE = "active";
private static final String ICON_ID_OFFLINE = "inactive";
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(new ClusterDataRequest());
......@@ -61,45 +66,38 @@ public class ClusterViewMessageHandler extends UiMessageHandler {
}
@Override
protected TableRow[] generateTableRows(ObjectNode payload) {
ClusterService service = get(ClusterService.class);
List<TableRow> list = service.getNodes().stream()
.map(node -> new ControllerNodeTableRow(service, node))
.collect(Collectors.toList());
return list.toArray(new TableRow[list.size()]);
protected String[] getColumnIds() {
return COL_IDS;
}
}
/**
* TableRow implementation for {@link ControllerNode controller nodes}.
*/
private static class ControllerNodeTableRow extends AbstractTableRow {
private static final String[] COL_IDS = {
ID, IP, TCP_PORT, STATE_IID, UPDATED
};
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
tm.setComparator(TCP_PORT, IntComparator.INSTANCE);
tm.setFormatter(UPDATED, TimeFormatter.INSTANCE);
return tm;
}
private static final String ICON_ID_ONLINE = "active";
private static final String ICON_ID_OFFLINE = "inactive";
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
ClusterService cs = get(ClusterService.class);
for (ControllerNode node : cs.getNodes()) {
populateRow(tm.addRow(), node, cs);
}
}
public ControllerNodeTableRow(ClusterService service, ControllerNode n) {
NodeId id = n.id();
DateTime lastUpdated = service.getLastUpdated(id);
org.joda.time.format.DateTimeFormatter format = DateTimeFormat.longTime();
String iconId = (service.getState(id) == ControllerNode.State.ACTIVE) ?
private void populateRow(TableModel.Row row, ControllerNode node,
ClusterService cs) {
NodeId id = node.id();
DateTime lastUpdated = cs.getLastUpdated(id);
String iconId = (cs.getState(id) == ControllerNode.State.ACTIVE) ?
ICON_ID_ONLINE : ICON_ID_OFFLINE;
add(ID, id.toString());
add(IP, n.ip().toString());
add(TCP_PORT, Integer.toString(n.tcpPort()));
add(STATE_IID, iconId);
add(UPDATED, format.print(lastUpdated));
}
@Override
protected String[] columnIds() {
return COL_IDS;
row.cell(ID, id)
.cell(IP, node.ip())
.cell(TCP_PORT, node.tcpPort())
.cell(STATE_IID, iconId)
.cell(UPDATED, lastUpdated);
}
}
}
......
......@@ -29,9 +29,9 @@ import org.onosproject.net.device.DeviceService;
import org.onosproject.net.link.LinkService;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.table.AbstractTableRow;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.TableRow;
import org.onosproject.ui.table.cell.IntComparator;
import java.util.ArrayList;
import java.util.Collection;
......@@ -73,6 +73,15 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
private static final String NAME = "name";
private static final String[] COL_IDS = {
AVAILABLE, AVAILABLE_IID, TYPE_IID, ID,
NUM_PORTS, MASTER_ID, MFR, HW, SW,
PROTOCOL, CHASSIS_ID, SERIAL
};
private static final String ICON_ID_ONLINE = "active";
private static final String ICON_ID_OFFLINE = "inactive";
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(
......@@ -81,6 +90,10 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
);
}
private static String getTypeIconId(Device d) {
return DEV_ICON_PREFIX + d.type().toString();
}
// handler for device table requests
private final class DataRequestHandler extends TableRequestHandler {
private DataRequestHandler() {
......@@ -88,14 +101,42 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
}
@Override
protected TableRow[] generateTableRows(ObjectNode payload) {
DeviceService service = get(DeviceService.class);
MastershipService mastershipService = get(MastershipService.class);
List<TableRow> list = new ArrayList<>();
for (Device dev : service.getDevices()) {
list.add(new DeviceTableRow(service, mastershipService, dev));
protected String[] getColumnIds() {
return COL_IDS;
}
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
tm.setComparator(NUM_PORTS, IntComparator.INSTANCE);
return tm;
}
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
DeviceService ds = get(DeviceService.class);
MastershipService ms = get(MastershipService.class);
for (Device dev : ds.getDevices()) {
populateRow(tm.addRow(), dev, ds, ms);
}
return list.toArray(new TableRow[list.size()]);
}
private void populateRow(TableModel.Row row, Device dev,
DeviceService ds, MastershipService ms) {
DeviceId id = dev.id();
boolean available = ds.isAvailable(id);
String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;
row.cell(ID, id)
.cell(AVAILABLE, available)
.cell(AVAILABLE_IID, iconId)
.cell(TYPE_IID, getTypeIconId(dev))
.cell(MFR, dev.manufacturer())
.cell(HW, dev.hwVersion())
.cell(SW, dev.swVersion())
.cell(PROTOCOL, dev.annotations().value(PROTOCOL))
.cell(NUM_PORTS, ds.getPorts(id).size())
.cell(MASTER_ID, ms.getMasterFor(id));
}
}
......@@ -168,51 +209,5 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
return port;
}
}
private static String getTypeIconId(Device d) {
return DEV_ICON_PREFIX + d.type().toString();
}
/**
* TableRow implementation for {@link Device devices}.
*/
private static class DeviceTableRow extends AbstractTableRow {
private static final String[] COL_IDS = {
AVAILABLE, AVAILABLE_IID, TYPE_IID, ID,
NUM_PORTS, MASTER_ID, MFR, HW, SW,
PROTOCOL, CHASSIS_ID, SERIAL
};
private static final String ICON_ID_ONLINE = "active";
private static final String ICON_ID_OFFLINE = "inactive";
public DeviceTableRow(DeviceService service,
MastershipService ms,
Device d) {
boolean available = service.isAvailable(d.id());
String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;
DeviceId id = d.id();
List<Port> ports = service.getPorts(id);
add(ID, id.toString());
add(AVAILABLE, Boolean.toString(available));
add(AVAILABLE_IID, iconId);
add(TYPE_IID, getTypeIconId(d));
add(MFR, d.manufacturer());
add(HW, d.hwVersion());
add(SW, d.swVersion());
add(PROTOCOL, d.annotations().value(PROTOCOL));
add(NUM_PORTS, Integer.toString(ports.size()));
add(MASTER_ID, ms.getMasterFor(d.id()).toString());
}
@Override
protected String[] columnIds() {
return COL_IDS;
}
}
}
......
......@@ -28,11 +28,11 @@ import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.table.AbstractTableRow;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.TableRow;
import org.onosproject.ui.table.cell.IntComparator;
import org.onosproject.ui.table.cell.LongComparator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
......@@ -64,6 +64,11 @@ public class FlowViewMessageHandler extends UiMessageHandler {
private static final String COMMA = ", ";
private static final String[] COL_IDS = {
ID, APP_ID, GROUP_ID, TABLE_ID, PRIORITY, SELECTOR,
TREATMENT, TIMEOUT, PERMANENT, STATE, PACKETS, BYTES
};
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(new FlowDataRequest());
......@@ -77,45 +82,47 @@ public class FlowViewMessageHandler extends UiMessageHandler {
}
@Override
protected TableRow[] generateTableRows(ObjectNode payload) {
protected String[] getColumnIds() {
return COL_IDS;
}
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
tm.setComparator(GROUP_ID, IntComparator.INSTANCE);
tm.setComparator(TABLE_ID, IntComparator.INSTANCE);
tm.setComparator(PRIORITY, IntComparator.INSTANCE);
tm.setComparator(TIMEOUT, IntComparator.INSTANCE);
tm.setComparator(PACKETS, LongComparator.INSTANCE);
tm.setComparator(BYTES, LongComparator.INSTANCE);
return tm;
}
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
String uri = string(payload, "devId");
if (Strings.isNullOrEmpty(uri)) {
return new TableRow[0];
}
DeviceId deviceId = DeviceId.deviceId(uri);
FlowRuleService service = get(FlowRuleService.class);
List<TableRow> list = new ArrayList<>();
for (FlowEntry flow : service.getFlowEntries(deviceId)) {
list.add(new FlowTableRow(flow));
if (!Strings.isNullOrEmpty(uri)) {
DeviceId deviceId = DeviceId.deviceId(uri);
FlowRuleService frs = get(FlowRuleService.class);
for (FlowEntry flow : frs.getFlowEntries(deviceId)) {
populateRow(tm.addRow(), flow);
}
}
return list.toArray(new TableRow[list.size()]);
}
}
/**
* TableRow implementation for
* {@link org.onosproject.net.flow.FlowRule flows}.
*/
private static class FlowTableRow extends AbstractTableRow {
private static final String[] COL_IDS = {
ID, APP_ID, GROUP_ID, TABLE_ID, PRIORITY, SELECTOR,
TREATMENT, TIMEOUT, PERMANENT, STATE, PACKETS, BYTES
};
public FlowTableRow(FlowEntry f) {
add(ID, f.id().value());
add(APP_ID, f.appId());
add(GROUP_ID, f.groupId().id());
add(TABLE_ID, f.tableId());
add(PRIORITY, f.priority());
add(SELECTOR, getSelectorString(f));
add(TREATMENT, getTreatmentString(f));
add(TIMEOUT, f.timeout());
add(PERMANENT, f.isPermanent());
add(STATE, capitalizeFully(f.state().toString()));
add(PACKETS, f.packets());
add(BYTES, f.packets());
private void populateRow(TableModel.Row row, FlowEntry flow) {
row.cell(ID, flow.id().value())
.cell(APP_ID, flow.appId())
.cell(GROUP_ID, flow.groupId().id())
.cell(TABLE_ID, flow.tableId())
.cell(PRIORITY, flow.priority())
.cell(SELECTOR, getSelectorString(flow))
.cell(TREATMENT, getTreatmentString(flow))
.cell(TIMEOUT, flow.timeout())
.cell(PERMANENT, flow.isPermanent())
.cell(STATE, capitalizeFully(flow.state().toString()))
.cell(PACKETS, flow.packets())
.cell(BYTES, flow.bytes());
}
private String getSelectorString(FlowEntry f) {
......@@ -184,11 +191,5 @@ public class FlowViewMessageHandler extends UiMessageHandler {
sb.delete(pos, sb.length());
return sb;
}
@Override
protected String[] columnIds() {
return COL_IDS;
}
}
}
......
......@@ -19,17 +19,14 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Host;
import org.onosproject.net.HostLocation;
import org.onosproject.net.host.HostService;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.table.AbstractTableRow;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.TableRow;
import org.onosproject.ui.table.cell.HostLocationFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static com.google.common.base.Strings.isNullOrEmpty;
......@@ -51,6 +48,9 @@ public class HostViewMessageHandler extends UiMessageHandler {
private static final String HOST_ICON_PREFIX = "hostIcon_";
private static final String[] COL_IDS = {
TYPE_IID, ID, MAC, VLAN, IPS, LOCATION
};
@Override
protected Collection<RequestHandler> getHandlers() {
......@@ -64,34 +64,32 @@ public class HostViewMessageHandler extends UiMessageHandler {
}
@Override
protected TableRow[] generateTableRows(ObjectNode payload) {
HostService service = get(HostService.class);
List<TableRow> list = new ArrayList<>();
for (Host host : service.getHosts()) {
list.add(new HostTableRow(host));
}
return list.toArray(new TableRow[list.size()]);
protected String[] getColumnIds() {
return COL_IDS;
}
}
/**
* TableRow implementation for {@link Host hosts}.
*/
private static class HostTableRow extends AbstractTableRow {
private static final String[] COL_IDS = {
TYPE_IID, ID, MAC, VLAN, IPS, LOCATION
};
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
tm.setFormatter(LOCATION, HostLocationFormatter.INSTANCE);
return tm;
}
public HostTableRow(Host h) {
HostLocation location = h.location();
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
HostService hs = get(HostService.class);
for (Host host : hs.getHosts()) {
populateRow(tm.addRow(), host);
}
}
add(TYPE_IID, getTypeIconId(h));
add(ID, h.id());
add(MAC, h.mac());
add(VLAN, h.vlan());
add(IPS, h.ipAddresses());
add(LOCATION, concat(location.deviceId(), "/", location.port()));
private void populateRow(TableModel.Row row, Host host) {
row.cell(TYPE_IID, getTypeIconId(host))
.cell(ID, host.id())
.cell(MAC, host.mac())
.cell(VLAN, host.vlan())
.cell(IPS, host.ipAddresses())
.cell(LOCATION, host.location());
}
private String getTypeIconId(Host host) {
......@@ -99,11 +97,5 @@ public class HostViewMessageHandler extends UiMessageHandler {
return HOST_ICON_PREFIX +
(isNullOrEmpty(hostType) ? "endstation" : hostType);
}
@Override
protected String[] columnIds() {
return COL_IDS;
}
}
}
......
......@@ -17,7 +17,6 @@ package org.onosproject.ui.impl;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.instructions.Instruction;
......@@ -33,11 +32,11 @@ import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.table.AbstractTableRow;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.TableRow;
import org.onosproject.ui.table.cell.AppIdFormatter;
import org.onosproject.ui.table.cell.IntComparator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
......@@ -58,6 +57,10 @@ public class IntentViewMessageHandler extends UiMessageHandler {
private static final String RESOURCES = "resources";
private static final String DETAILS = "details";
private static final String[] COL_IDS = {
APP_ID, KEY, TYPE, PRIORITY, RESOURCES, DETAILS
};
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(new IntentDataRequest());
......@@ -70,30 +73,42 @@ public class IntentViewMessageHandler extends UiMessageHandler {
}
@Override
protected TableRow[] generateTableRows(ObjectNode payload) {
IntentService service = get(IntentService.class);
List<TableRow> list = new ArrayList<>();
for (Intent intent : service.getIntents()) {
list.add(new IntentTableRow(intent));
}
return list.toArray(new TableRow[list.size()]);
protected String defaultColumnId() {
return APP_ID;
}
@Override
protected String defaultColId() {
return APP_ID;
protected String[] getColumnIds() {
return COL_IDS;
}
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
tm.setComparator(PRIORITY, IntComparator.INSTANCE);
tm.setFormatter(APP_ID, AppIdFormatter.INSTANCE);
return tm;
}
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
IntentService is = get(IntentService.class);
for (Intent intent : is.getIntents()) {
populateRow(tm.addRow(), intent);
}
}
}
/**
* TableRow implementation for {@link Intent intents}.
*/
private static class IntentTableRow extends AbstractTableRow {
private void populateRow(TableModel.Row row, Intent intent) {
row.cell(APP_ID, intent.appId())
.cell(KEY, intent.key())
.cell(TYPE, intent.getClass().getSimpleName())
.cell(PRIORITY, intent.priority())
.cell(RESOURCES, formatResources(intent))
.cell(DETAILS, formatDetails(intent));
}
private static final String[] COL_IDS = {
APP_ID, KEY, TYPE, PRIORITY, RESOURCES, DETAILS
};
// == TODO: Review -- Move the following code to a helper class?
private StringBuilder details = new StringBuilder();
private void appendMultiPointsDetails(Set<ConnectPoint> points) {
......@@ -217,25 +232,8 @@ public class IntentViewMessageHandler extends UiMessageHandler {
private String formatResources(Intent intent) {
return (intent.resources().isEmpty() ?
"(No resources for this intent)" :
"Resources: " + intent.resources());
}
public IntentTableRow(Intent intent) {
ApplicationId appid = intent.appId();
add(APP_ID, concat(appid.id(), " : ", appid.name()));
add(KEY, intent.key());
add(TYPE, intent.getClass().getSimpleName());
add(PRIORITY, intent.priority());
add(RESOURCES, formatResources(intent));
add(DETAILS, formatDetails(intent));
}
@Override
protected String[] columnIds() {
return COL_IDS;
"(No resources for this intent)" :
"Resources: " + intent.resources());
}
}
}
......
......@@ -19,20 +19,17 @@ package org.onosproject.ui.impl;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
import org.onosproject.net.link.LinkService;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink;
import org.onosproject.ui.table.AbstractTableRow;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.TableRow;
import org.onosproject.ui.table.cell.ConnectPointFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink;
......@@ -53,6 +50,13 @@ public class LinkViewMessageHandler extends UiMessageHandler {
private static final String DIRECTION = "direction";
private static final String DURABLE = "durable";
private static final String[] COL_IDS = {
ONE, TWO, TYPE, STATE, DIRECTION, DURABLE
};
private static final String ICON_ID_ONLINE = "active";
private static final String ICON_ID_OFFLINE = "inactive";
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(new LinkDataRequest());
......@@ -65,48 +69,51 @@ public class LinkViewMessageHandler extends UiMessageHandler {
}
@Override
protected TableRow[] generateTableRows(ObjectNode payload) {
LinkService service = get(LinkService.class);
List<TableRow> list = new ArrayList<>();
protected String[] getColumnIds() {
return COL_IDS;
}
@Override
protected String defaultColumnId() {
return ONE;
}
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
tm.setFormatter(ONE, ConnectPointFormatter.INSTANCE);
tm.setFormatter(TWO, ConnectPointFormatter.INSTANCE);
return tm;
}
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
LinkService ls = get(LinkService.class);
// First consolidate all uni-directional links into two-directional ones.
Map<LinkKey, BiLink> biLinks = Maps.newHashMap();
service.getLinks().forEach(link -> addLink(biLinks, link));
ls.getLinks().forEach(link -> addLink(biLinks, link));
// Now scan over all bi-links and produce table rows from them.
biLinks.values().forEach(biLink -> list.add(new LinkTableRow(biLink)));
return list.toArray(new TableRow[list.size()]);
biLinks.values().forEach(biLink -> populateRow(tm.addRow(), biLink));
}
@Override
protected String defaultColId() {
return ONE;
private void populateRow(TableModel.Row row, BiLink biLink) {
row.cell(ONE, biLink.one.src())
.cell(TWO, biLink.one.dst())
.cell(TYPE, linkType(biLink))
.cell(STATE, linkState(biLink))
.cell(DIRECTION, linkDir(biLink))
.cell(DURABLE, biLink.one.isDurable());
}
}
/**
* TableRow implementation for {@link org.onosproject.net.Link links}.
*/
private static class LinkTableRow extends AbstractTableRow {
private static final String[] COL_IDS = {
ONE, TWO, TYPE, STATE, DIRECTION, DURABLE
};
private static final String ICON_ID_ONLINE = "active";
private static final String ICON_ID_OFFLINE = "inactive";
public LinkTableRow(BiLink link) {
ConnectPoint src = link.one.src();
ConnectPoint dst = link.one.dst();
linkState(link);
add(ONE, concat(src.elementId(), "/", src.port()));
add(TWO, concat(dst.elementId(), "/", dst.port()));
add(TYPE, linkType(link).toLowerCase());
add(STATE, linkState(link));
add(DIRECTION, link.two != null ? "A <--> B" : "A --> B");
add(DURABLE, Boolean.toString(link.one.isDurable()));
private String linkType(BiLink link) {
StringBuilder sb = new StringBuilder();
sb.append(link.one.type());
if (link.two != null && link.two.type() != link.one.type()) {
sb.append(" / ").append(link.two.type());
}
return sb.toString().toLowerCase();
}
private String linkState(BiLink link) {
......@@ -115,16 +122,8 @@ public class LinkViewMessageHandler extends UiMessageHandler {
ICON_ID_ONLINE : ICON_ID_OFFLINE;
}
private String linkType(BiLink link) {
return link.two == null || link.one.type() == link.two.type() ?
link.one.type().toString() :
link.one.type().toString() + " / " + link.two.type().toString();
}
@Override
protected String[] columnIds() {
return COL_IDS;
private String linkDir(BiLink link) {
return link.two != null ? "A <--> B" : "A --> B";
}
}
}
......
......@@ -24,13 +24,11 @@ import org.onosproject.net.device.DeviceService;
import org.onosproject.net.device.PortStatistics;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.table.AbstractTableRow;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.TableRow;
import org.onosproject.ui.table.cell.LongComparator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
......@@ -51,6 +49,11 @@ public class PortViewMessageHandler extends UiMessageHandler {
private static final String PKT_TX_DRP = "pkt_tx_drp";
private static final String DURATION = "duration";
private static final String[] COL_IDS = {
ID, PKT_RX, PKT_TX, BYTES_RX, BYTES_TX,
PKT_RX_DRP, PKT_TX_DRP, DURATION
};
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(new PortDataRequest());
......@@ -64,47 +67,44 @@ public class PortViewMessageHandler extends UiMessageHandler {
}
@Override
protected TableRow[] generateTableRows(ObjectNode payload) {
String uri = string(payload, "devId");
if (Strings.isNullOrEmpty(uri)) {
return new TableRow[0];
}
DeviceId deviceId = DeviceId.deviceId(uri);
DeviceService service = get(DeviceService.class);
List<TableRow> list = new ArrayList<>();
for (PortStatistics stat : service.getPortStatistics(deviceId)) {
list.add(new PortTableRow(stat));
}
return list.toArray(new TableRow[list.size()]);
protected String[] getColumnIds() {
return COL_IDS;
}
}
/**
* TableRow implementation for
* {@link org.onosproject.net.device.PortStatistics port statistics}.
*/
private static class PortTableRow extends AbstractTableRow {
private static final String[] COL_IDS = {
ID, PKT_RX, PKT_TX, BYTES_RX, BYTES_TX,
PKT_RX_DRP, PKT_TX_DRP, DURATION
};
public PortTableRow(PortStatistics stat) {
add(ID, Integer.toString(stat.port()));
add(PKT_RX, Long.toString(stat.packetsReceived()));
add(PKT_TX, Long.toString(stat.packetsSent()));
add(BYTES_RX, Long.toString(stat.bytesReceived()));
add(BYTES_TX, Long.toString(stat.bytesSent()));
add(PKT_RX_DRP, Long.toString(stat.packetsRxDropped()));
add(PKT_TX_DRP, Long.toString(stat.packetsTxDropped()));
add(DURATION, Long.toString(stat.durationSec()));
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
tm.setComparator(PKT_RX, LongComparator.INSTANCE);
tm.setComparator(PKT_TX, LongComparator.INSTANCE);
tm.setComparator(BYTES_RX, LongComparator.INSTANCE);
tm.setComparator(BYTES_TX, LongComparator.INSTANCE);
tm.setComparator(PKT_RX_DRP, LongComparator.INSTANCE);
tm.setComparator(PKT_TX_DRP, LongComparator.INSTANCE);
tm.setComparator(DURATION, LongComparator.INSTANCE);
return tm;
}
@Override
protected String[] columnIds() {
return COL_IDS;
protected void populateTable(TableModel tm, ObjectNode payload) {
String uri = string(payload, "devId");
if (!Strings.isNullOrEmpty(uri)) {
DeviceId deviceId = DeviceId.deviceId(uri);
DeviceService ds = get(DeviceService.class);
for (PortStatistics stat : ds.getPortStatistics(deviceId)) {
populateRow(tm.addRow(), stat);
}
}
}
}
private void populateRow(TableModel.Row row, PortStatistics stat) {
row.cell(ID, stat.port())
.cell(PKT_RX, stat.packetsReceived())
.cell(PKT_TX, stat.packetsSent())
.cell(BYTES_RX, stat.bytesReceived())
.cell(BYTES_TX, stat.bytesSent())
.cell(PKT_RX_DRP, stat.packetsRxDropped())
.cell(PKT_TX_DRP, stat.packetsTxDropped())
.cell(DURATION, stat.durationSec());
}
}
}
......