Jian Li
Committed by Gerrit Code Review

[ONOS-3722] Augment TableModel to support annotations

Change-Id: Ie90fa6b26887ddd5afb03eb116304c16f10396ff
Showing 31 changed files with 79 additions and 36 deletions
......@@ -74,7 +74,7 @@ public class DhcpViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -77,7 +77,7 @@ public class DriverMatrixMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -92,7 +92,7 @@ public class AlarmTableMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -55,7 +55,7 @@ public abstract class TableRequestHandler extends RequestHandler {
String sortDir = JsonUtils.string(payload, "sortDir", "asc");
tm.sort(sortCol, TableModel.sortDir(sortDir));
addTableConfigAnnotations(tm);
addTableConfigAnnotations(tm, payload);
ObjectNode rootNode = MAPPER.createObjectNode();
rootNode.set(nodeName, TableUtils.generateRowArrayNode(tm));
......@@ -77,12 +77,13 @@ public abstract class TableRequestHandler extends RequestHandler {
}
/**
* Adds all annotations to table model.
* Adds table configuration specific annotations to table model.
*
* @param tm a table model
* @param payload the event payload from the client
*/
protected void addTableConfigAnnotations(TableModel tm) {
tm.addAnnotation(NO_ROWS_MSG_KEY, noRowsMessage());
protected void addTableConfigAnnotations(TableModel tm, ObjectNode payload) {
tm.addAnnotation(NO_ROWS_MSG_KEY, noRowsMessage(payload));
}
/**
......@@ -110,9 +111,10 @@ public abstract class TableRequestHandler extends RequestHandler {
* are no rows to display. For example, a host table might return
* "No hosts found".
*
* @param payload request payload
* @return the message
*/
protected abstract String noRowsMessage();
protected abstract String noRowsMessage(ObjectNode payload);
/**
* Subclasses should populate the table model by adding
......
......@@ -78,7 +78,7 @@ public class ApplicationViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -72,7 +72,7 @@ public class ClusterViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -139,7 +139,7 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -87,7 +87,7 @@ public class FlowViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -19,7 +19,9 @@ package org.onosproject.ui.impl;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.group.Group;
import org.onosproject.net.group.GroupBucket;
import org.onosproject.net.group.GroupService;
......@@ -45,6 +47,9 @@ public class GroupViewMessageHandler extends UiMessageHandler {
private static final String GROUP_DATA_RESP = "groupDataResponse";
private static final String GROUPS = "groups";
private static final String PROTOCOL = "protocol";
private static final String OF_10 = "OF_10";
private static final String ID = "id";
private static final String APP_ID = "app_id";
private static final String STATE = "state";
......@@ -62,10 +67,16 @@ public class GroupViewMessageHandler extends UiMessageHandler {
return ImmutableSet.of(new GroupDataRequest());
}
private static String deviceProtocol(Device device) {
String protocol = device.annotations().value(PROTOCOL);
return protocol != null ? protocol : "";
}
// handler for group table requests
private final class GroupDataRequest extends TableRequestHandler {
private static final String NO_ROWS_MESSAGE = "No groups found";
private static final String NOT_SUPPORT_MESSAGE = "Groups not supported";
private GroupDataRequest() {
super(GROUP_DATA_REQ, GROUP_DATA_RESP, GROUPS);
......@@ -77,8 +88,17 @@ public class GroupViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
// TODO: if devices with OF 1.0, should return not support message
protected String noRowsMessage(ObjectNode payload) {
String uri = string(payload, "devId");
if (!Strings.isNullOrEmpty(uri)) {
DeviceService ds = get(DeviceService.class);
Device dev = ds.getDevice(DeviceId.deviceId(uri));
// TODO: replace with a less brittle solution...
if (deviceProtocol(dev).equals(OF_10)) {
return NOT_SUPPORT_MESSAGE;
}
}
return NO_ROWS_MESSAGE;
}
......
......@@ -74,7 +74,7 @@ public class HostViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -88,7 +88,7 @@ public class IntentViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -77,7 +77,7 @@ public class LinkViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -19,7 +19,9 @@ package org.onosproject.ui.impl;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.meter.Band;
import org.onosproject.net.meter.Meter;
import org.onosproject.net.meter.MeterService;
......@@ -42,6 +44,9 @@ public class MeterViewMessageHandler extends UiMessageHandler {
private static final String METER_DATA_RESP = "meterDataResponse";
private static final String METERS = "meters";
private static final String PROTOCOL = "protocol";
private static final String OF_10 = "OF_10";
private static final String ID = "id";
private static final String APP_ID = "app_id";
private static final String STATE = "state";
......@@ -58,10 +63,16 @@ public class MeterViewMessageHandler extends UiMessageHandler {
return ImmutableSet.of(new MeterDataRequest());
}
private static String deviceProtocol(Device device) {
String protocol = device.annotations().value(PROTOCOL);
return protocol != null ? protocol : "";
}
// handler for meter table requests
private final class MeterDataRequest extends TableRequestHandler {
private static final String NO_ROWS_MESSAGE = "No meters found";
private static final String NOT_SUPPORT_MESSAGE = "Meters not supported";
private MeterDataRequest() {
super(METER_DATA_REQ, METER_DATA_RESP, METERS);
......@@ -73,8 +84,17 @@ public class MeterViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
// TODO: if the device with OF 1.0, return not support message
protected String noRowsMessage(ObjectNode payload) {
String uri = string(payload, "devId");
if (!Strings.isNullOrEmpty(uri)) {
DeviceService ds = get(DeviceService.class);
Device dev = ds.getDevice(DeviceId.deviceId(uri));
// TODO: replace with a less brittle solution...
if (deviceProtocol(dev).equals(OF_10)) {
return NOT_SUPPORT_MESSAGE;
}
}
return NO_ROWS_MESSAGE;
}
......
......@@ -74,7 +74,7 @@ public class PortViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -76,7 +76,7 @@ public class ProcessorViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -65,7 +65,7 @@ public class SettingsViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -67,7 +67,7 @@ public class TunnelViewMessageHandler extends UiMessageHandler {
}
@Override
protected String noRowsMessage() {
protected String noRowsMessage(ObjectNode payload) {
return NO_ROWS_MESSAGE;
}
......
......@@ -64,6 +64,7 @@
cancelTardy();
ls.stop();
o.scope.tableData = data[root];
o.scope.annots = data.annots;
onResp && onResp();
// checks if data changed for row flashing
......
......@@ -53,7 +53,7 @@
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="5">
No Applications found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -43,7 +43,7 @@
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="5">
No Cluster Nodes found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -56,7 +56,7 @@
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="9">
No Devices found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -60,7 +60,7 @@
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="10">
No Flows found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -56,7 +56,7 @@
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="6">
No Groups found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -28,7 +28,7 @@
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="6">
No Hosts found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -32,7 +32,7 @@
<table onos-flash-changes id-prop="key">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="5">
No Intents found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -44,7 +44,7 @@
<table onos-flash-changes id-prop="one">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="6">
No Links found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -55,7 +55,7 @@
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="5">
No Meters found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -58,7 +58,7 @@
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="8">
No Ports found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -40,7 +40,7 @@
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="5">
No Processors found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -28,7 +28,7 @@
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="6">
No Settings found
{{annots.no_rows_msg}}
</td>
</tr>
......
......@@ -46,7 +46,7 @@
<table onos-flash-changes id-prop="one">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="6">
No tunnels found
{{annots.no_rows_msg}}
</td>
</tr>
......