Simon Hunt

GUI -- Introduce TableRequestHandler and refactor all table-based requests to use this class.

Change-Id: Ia26a78e9c4abead17de5e7f6babd54202c6772d9
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.ui.table;
18 +
19 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 +import org.onosproject.ui.RequestHandler;
21 +
22 +import java.util.Arrays;
23 +
24 +/**
25 + * Message handler specifically for table views.
26 + */
27 +public abstract class TableRequestHandler extends RequestHandler {
28 +
29 + private final String respType;
30 + private final String nodeName;
31 +
32 + /**
33 + * Constructs a table request handler for a specific table view. When
34 + * table requests come in, the handler will generate the appropriate
35 + * table rows, sort them according the the request sort parameters, and
36 + * send back the response to the client.
37 + *
38 + * @param reqType type of the request event
39 + * @param respType type of the response event
40 + * @param nodeName name of JSON node holding row data
41 + */
42 + public TableRequestHandler(String reqType, String respType, String nodeName) {
43 + super(reqType);
44 + this.respType = respType;
45 + this.nodeName = nodeName;
46 + }
47 +
48 + @Override
49 + public void process(long sid, ObjectNode payload) {
50 + RowComparator rc = TableUtils.createRowComparator(payload, defaultColId());
51 + TableRow[] rows = generateTableRows(payload);
52 + Arrays.sort(rows, rc);
53 + ObjectNode rootNode = MAPPER.createObjectNode();
54 + rootNode.set(nodeName, TableUtils.generateArrayNode(rows));
55 + sendMessage(respType, 0, rootNode);
56 + }
57 +
58 + /**
59 + * Returns the default column ID, when one is not supplied in the payload
60 + * defining the column on which to sort. This implementation returns "id".
61 + *
62 + * @return default sort column id
63 + */
64 + protected String defaultColId() {
65 + return "id";
66 + }
67 +
68 + /**
69 + * Subclasses should generate table rows for their specific table instance.
70 + *
71 + * @param payload provided in case custom parameters are present
72 + * @return generated table rows
73 + */
74 + protected abstract TableRow[] generateTableRows(ObjectNode payload);
75 +}
...@@ -25,11 +25,9 @@ import org.onosproject.core.ApplicationId; ...@@ -25,11 +25,9 @@ import org.onosproject.core.ApplicationId;
25 import org.onosproject.ui.RequestHandler; 25 import org.onosproject.ui.RequestHandler;
26 import org.onosproject.ui.UiMessageHandler; 26 import org.onosproject.ui.UiMessageHandler;
27 import org.onosproject.ui.table.AbstractTableRow; 27 import org.onosproject.ui.table.AbstractTableRow;
28 -import org.onosproject.ui.table.RowComparator; 28 +import org.onosproject.ui.table.TableRequestHandler;
29 import org.onosproject.ui.table.TableRow; 29 import org.onosproject.ui.table.TableRow;
30 -import org.onosproject.ui.table.TableUtils;
31 30
32 -import java.util.Arrays;
33 import java.util.Collection; 31 import java.util.Collection;
34 import java.util.List; 32 import java.util.List;
35 import java.util.stream.Collectors; 33 import java.util.stream.Collectors;
...@@ -42,8 +40,21 @@ import static org.onosproject.app.ApplicationState.ACTIVE; ...@@ -42,8 +40,21 @@ import static org.onosproject.app.ApplicationState.ACTIVE;
42 public class ApplicationViewMessageHandler extends UiMessageHandler { 40 public class ApplicationViewMessageHandler extends UiMessageHandler {
43 41
44 private static final String APP_DATA_REQ = "appDataRequest"; 42 private static final String APP_DATA_REQ = "appDataRequest";
43 + private static final String APP_DATA_RESP = "appDataResponse";
44 + private static final String APPS = "apps";
45 +
45 private static final String APP_MGMT_REQ = "appManagementRequest"; 46 private static final String APP_MGMT_REQ = "appManagementRequest";
46 47
48 + private static final String STATE = "state";
49 + private static final String STATE_IID = "_iconid_state";
50 + private static final String ID = "id";
51 + private static final String VERSION = "version";
52 + private static final String ORIGIN = "origin";
53 + private static final String DESC = "desc";
54 +
55 + private static final String ICON_ID_ACTIVE = "active";
56 + private static final String ICON_ID_INACTIVE = "appInactive";
57 +
47 @Override 58 @Override
48 protected Collection<RequestHandler> getHandlers() { 59 protected Collection<RequestHandler> getHandlers() {
49 return ImmutableSet.of( 60 return ImmutableSet.of(
...@@ -52,38 +63,25 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { ...@@ -52,38 +63,25 @@ public class ApplicationViewMessageHandler extends UiMessageHandler {
52 ); 63 );
53 } 64 }
54 65
55 - // ====================================================================== 66 + // handler for application table requests
56 - 67 + private final class AppDataRequest extends TableRequestHandler {
57 - private final class AppDataRequest extends RequestHandler {
58 -
59 private AppDataRequest() { 68 private AppDataRequest() {
60 - super(APP_DATA_REQ); 69 + super(APP_DATA_REQ, APP_DATA_RESP, APPS);
61 } 70 }
62 71
63 @Override 72 @Override
64 - public void process(long sid, ObjectNode payload) { 73 + protected TableRow[] generateTableRows(ObjectNode payload) {
65 - RowComparator rc = TableUtils.createRowComparator(payload);
66 -
67 ApplicationService service = get(ApplicationService.class); 74 ApplicationService service = get(ApplicationService.class);
68 - TableRow[] rows = generateTableRows(service);
69 - Arrays.sort(rows, rc);
70 - ObjectNode rootNode = MAPPER.createObjectNode();
71 - rootNode.set("apps", TableUtils.generateArrayNode(rows));
72 -
73 - sendMessage("appDataResponse", 0, rootNode);
74 - }
75 -
76 - private TableRow[] generateTableRows(ApplicationService service) {
77 List<TableRow> list = service.getApplications().stream() 75 List<TableRow> list = service.getApplications().stream()
78 .map(application -> new ApplicationTableRow(service, application)) 76 .map(application -> new ApplicationTableRow(service, application))
79 .collect(Collectors.toList()); 77 .collect(Collectors.toList());
80 return list.toArray(new TableRow[list.size()]); 78 return list.toArray(new TableRow[list.size()]);
81 } 79 }
80 +
82 } 81 }
83 - // ======================================================================
84 82
83 + // handler for application management control button actions
85 private final class AppMgmtRequest extends RequestHandler { 84 private final class AppMgmtRequest extends RequestHandler {
86 -
87 private AppMgmtRequest() { 85 private AppMgmtRequest() {
88 super(APP_MGMT_REQ); 86 super(APP_MGMT_REQ);
89 } 87 }
...@@ -106,7 +104,6 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { ...@@ -106,7 +104,6 @@ public class ApplicationViewMessageHandler extends UiMessageHandler {
106 } 104 }
107 } 105 }
108 } 106 }
109 - // ======================================================================
110 107
111 /** 108 /**
112 * TableRow implementation for 109 * TableRow implementation for
...@@ -114,21 +111,10 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { ...@@ -114,21 +111,10 @@ public class ApplicationViewMessageHandler extends UiMessageHandler {
114 */ 111 */
115 private static class ApplicationTableRow extends AbstractTableRow { 112 private static class ApplicationTableRow extends AbstractTableRow {
116 113
117 - private static final String STATE = "state";
118 - private static final String STATE_IID = "_iconid_state";
119 - private static final String ID = "id";
120 - private static final String VERSION = "version";
121 - private static final String ORIGIN = "origin";
122 - private static final String DESC = "desc";
123 -
124 private static final String[] COL_IDS = { 114 private static final String[] COL_IDS = {
125 STATE, STATE_IID, ID, VERSION, ORIGIN, DESC 115 STATE, STATE_IID, ID, VERSION, ORIGIN, DESC
126 }; 116 };
127 117
128 - private static final String ICON_ID_ACTIVE = "active";
129 - private static final String ICON_ID_INACTIVE = "appInactive";
130 -
131 -
132 public ApplicationTableRow(ApplicationService service, Application app) { 118 public ApplicationTableRow(ApplicationService service, Application app) {
133 ApplicationState state = service.getState(app.id()); 119 ApplicationState state = service.getState(app.id());
134 String iconId = state == ACTIVE ? ICON_ID_ACTIVE : ICON_ID_INACTIVE; 120 String iconId = state == ACTIVE ? ICON_ID_ACTIVE : ICON_ID_INACTIVE;
......
...@@ -26,11 +26,9 @@ import org.onosproject.cluster.NodeId; ...@@ -26,11 +26,9 @@ import org.onosproject.cluster.NodeId;
26 import org.onosproject.ui.RequestHandler; 26 import org.onosproject.ui.RequestHandler;
27 import org.onosproject.ui.UiMessageHandler; 27 import org.onosproject.ui.UiMessageHandler;
28 import org.onosproject.ui.table.AbstractTableRow; 28 import org.onosproject.ui.table.AbstractTableRow;
29 -import org.onosproject.ui.table.RowComparator; 29 +import org.onosproject.ui.table.TableRequestHandler;
30 import org.onosproject.ui.table.TableRow; 30 import org.onosproject.ui.table.TableRow;
31 -import org.onosproject.ui.table.TableUtils;
32 31
33 -import java.util.Arrays;
34 import java.util.Collection; 32 import java.util.Collection;
35 import java.util.List; 33 import java.util.List;
36 import java.util.stream.Collectors; 34 import java.util.stream.Collectors;
...@@ -42,34 +40,29 @@ import java.util.stream.Collectors; ...@@ -42,34 +40,29 @@ import java.util.stream.Collectors;
42 public class ClusterViewMessageHandler extends UiMessageHandler { 40 public class ClusterViewMessageHandler extends UiMessageHandler {
43 41
44 private static final String CLUSTER_DATA_REQ = "clusterDataRequest"; 42 private static final String CLUSTER_DATA_REQ = "clusterDataRequest";
43 + private static final String CLUSTER_DATA_RESP = "clusterDataResponse";
44 + private static final String CLUSTERS = "clusters";
45 +
46 + private static final String ID = "id";
47 + private static final String IP = "ip";
48 + private static final String TCP_PORT = "tcp";
49 + private static final String STATE_IID = "_iconid_state";
50 + private static final String UPDATED = "updated";
45 51
46 @Override 52 @Override
47 protected Collection<RequestHandler> getHandlers() { 53 protected Collection<RequestHandler> getHandlers() {
48 return ImmutableSet.of(new ClusterDataRequest()); 54 return ImmutableSet.of(new ClusterDataRequest());
49 } 55 }
50 56
51 - // ====================================================================== 57 + // handler for cluster table requests
52 - 58 + private final class ClusterDataRequest extends TableRequestHandler {
53 - private final class ClusterDataRequest extends RequestHandler {
54 -
55 private ClusterDataRequest() { 59 private ClusterDataRequest() {
56 - super(CLUSTER_DATA_REQ); 60 + super(CLUSTER_DATA_REQ, CLUSTER_DATA_RESP, CLUSTERS);
57 } 61 }
58 62
59 @Override 63 @Override
60 - public void process(long sid, ObjectNode payload) { 64 + protected TableRow[] generateTableRows(ObjectNode payload) {
61 - RowComparator rc = TableUtils.createRowComparator(payload);
62 -
63 ClusterService service = get(ClusterService.class); 65 ClusterService service = get(ClusterService.class);
64 - TableRow[] rows = generateTableRows(service);
65 - Arrays.sort(rows, rc);
66 - ObjectNode rootNode = MAPPER.createObjectNode();
67 - rootNode.set("clusters", TableUtils.generateArrayNode(rows));
68 -
69 - sendMessage("clusterDataResponse", 0, rootNode);
70 - }
71 -
72 - private TableRow[] generateTableRows(ClusterService service) {
73 List<TableRow> list = service.getNodes().stream() 66 List<TableRow> list = service.getNodes().stream()
74 .map(node -> new ControllerNodeTableRow(service, node)) 67 .map(node -> new ControllerNodeTableRow(service, node))
75 .collect(Collectors.toList()); 68 .collect(Collectors.toList());
...@@ -77,19 +70,11 @@ public class ClusterViewMessageHandler extends UiMessageHandler { ...@@ -77,19 +70,11 @@ public class ClusterViewMessageHandler extends UiMessageHandler {
77 } 70 }
78 } 71 }
79 72
80 - // ======================================================================
81 -
82 /** 73 /**
83 * TableRow implementation for {@link ControllerNode controller nodes}. 74 * TableRow implementation for {@link ControllerNode controller nodes}.
84 */ 75 */
85 private static class ControllerNodeTableRow extends AbstractTableRow { 76 private static class ControllerNodeTableRow extends AbstractTableRow {
86 77
87 - private static final String ID = "id";
88 - private static final String IP = "ip";
89 - private static final String TCP_PORT = "tcp";
90 - private static final String STATE_IID = "_iconid_state";
91 - private static final String UPDATED = "updated";
92 -
93 private static final String[] COL_IDS = { 78 private static final String[] COL_IDS = {
94 ID, IP, TCP_PORT, STATE_IID, UPDATED 79 ID, IP, TCP_PORT, STATE_IID, UPDATED
95 }; 80 };
......
...@@ -30,12 +30,10 @@ import org.onosproject.net.link.LinkService; ...@@ -30,12 +30,10 @@ import org.onosproject.net.link.LinkService;
30 import org.onosproject.ui.RequestHandler; 30 import org.onosproject.ui.RequestHandler;
31 import org.onosproject.ui.UiMessageHandler; 31 import org.onosproject.ui.UiMessageHandler;
32 import org.onosproject.ui.table.AbstractTableRow; 32 import org.onosproject.ui.table.AbstractTableRow;
33 -import org.onosproject.ui.table.RowComparator; 33 +import org.onosproject.ui.table.TableRequestHandler;
34 import org.onosproject.ui.table.TableRow; 34 import org.onosproject.ui.table.TableRow;
35 -import org.onosproject.ui.table.TableUtils;
36 35
37 import java.util.ArrayList; 36 import java.util.ArrayList;
38 -import java.util.Arrays;
39 import java.util.Collection; 37 import java.util.Collection;
40 import java.util.Collections; 38 import java.util.Collections;
41 import java.util.List; 39 import java.util.List;
...@@ -47,7 +45,12 @@ import java.util.Set; ...@@ -47,7 +45,12 @@ import java.util.Set;
47 public class DeviceViewMessageHandler extends UiMessageHandler { 45 public class DeviceViewMessageHandler extends UiMessageHandler {
48 46
49 private static final String DEV_DATA_REQ = "deviceDataRequest"; 47 private static final String DEV_DATA_REQ = "deviceDataRequest";
50 - private static final String DEV_DETAIL_REQ = "deviceDetailRequest"; 48 + private static final String DEV_DATA_RESP = "deviceDataResponse";
49 + private static final String DEVICES = "devices";
50 +
51 + private static final String DEV_DETAILS_REQ = "deviceDetailsRequest";
52 + private static final String DEV_DETAILS_RESP = "deviceDetailsResponse";
53 + private static final String DETAILS = "details";
51 54
52 private static final String ID = "id"; 55 private static final String ID = "id";
53 private static final String TYPE = "type"; 56 private static final String TYPE = "type";
...@@ -78,30 +81,16 @@ public class DeviceViewMessageHandler extends UiMessageHandler { ...@@ -78,30 +81,16 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
78 ); 81 );
79 } 82 }
80 83
81 - // ====================================================================== 84 + // handler for device table requests
82 - 85 + private final class DataRequestHandler extends TableRequestHandler {
83 - private final class DataRequestHandler extends RequestHandler {
84 -
85 private DataRequestHandler() { 86 private DataRequestHandler() {
86 - super(DEV_DATA_REQ); 87 + super(DEV_DATA_REQ, DEV_DATA_RESP, DEVICES);
87 } 88 }
88 89
89 @Override 90 @Override
90 - public void process(long sid, ObjectNode payload) { 91 + protected TableRow[] generateTableRows(ObjectNode payload) {
91 - RowComparator rc = TableUtils.createRowComparator(payload);
92 -
93 DeviceService service = get(DeviceService.class); 92 DeviceService service = get(DeviceService.class);
94 MastershipService mastershipService = get(MastershipService.class); 93 MastershipService mastershipService = get(MastershipService.class);
95 - TableRow[] rows = generateTableRows(service, mastershipService);
96 - Arrays.sort(rows, rc);
97 - ObjectNode rootNode = MAPPER.createObjectNode();
98 - rootNode.set("devices", TableUtils.generateArrayNode(rows));
99 -
100 - sendMessage("deviceDataResponse", 0, rootNode);
101 - }
102 -
103 - private TableRow[] generateTableRows(DeviceService service,
104 - MastershipService mastershipService) {
105 List<TableRow> list = new ArrayList<>(); 94 List<TableRow> list = new ArrayList<>();
106 for (Device dev : service.getDevices()) { 95 for (Device dev : service.getDevices()) {
107 list.add(new DeviceTableRow(service, mastershipService, dev)); 96 list.add(new DeviceTableRow(service, mastershipService, dev));
...@@ -110,11 +99,10 @@ public class DeviceViewMessageHandler extends UiMessageHandler { ...@@ -110,11 +99,10 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
110 } 99 }
111 } 100 }
112 101
113 - // ====================================================================== 102 + // handler for selected device detail requests
114 -
115 private final class DetailRequestHandler extends RequestHandler { 103 private final class DetailRequestHandler extends RequestHandler {
116 private DetailRequestHandler() { 104 private DetailRequestHandler() {
117 - super(DEV_DETAIL_REQ); 105 + super(DEV_DETAILS_REQ);
118 } 106 }
119 107
120 @Override 108 @Override
...@@ -152,8 +140,8 @@ public class DeviceViewMessageHandler extends UiMessageHandler { ...@@ -152,8 +140,8 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
152 data.set(PORTS, ports); 140 data.set(PORTS, ports);
153 141
154 ObjectNode rootNode = MAPPER.createObjectNode(); 142 ObjectNode rootNode = MAPPER.createObjectNode();
155 - rootNode.set("details", data); 143 + rootNode.set(DETAILS, data);
156 - sendMessage("deviceDetailsResponse", 0, rootNode); 144 + sendMessage(DEV_DETAILS_RESP, 0, rootNode);
157 } 145 }
158 146
159 private ObjectNode portData(Port p, DeviceId id) { 147 private ObjectNode portData(Port p, DeviceId id) {
...@@ -183,7 +171,6 @@ public class DeviceViewMessageHandler extends UiMessageHandler { ...@@ -183,7 +171,6 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
183 171
184 } 172 }
185 173
186 -
187 private static String getTypeIconId(Device d) { 174 private static String getTypeIconId(Device d) {
188 return DEV_ICON_PREFIX + d.type().toString(); 175 return DEV_ICON_PREFIX + d.type().toString();
189 } 176 }
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
17 package org.onosproject.ui.impl; 17 package org.onosproject.ui.impl;
18 18
19 import com.fasterxml.jackson.databind.node.ObjectNode; 19 import com.fasterxml.jackson.databind.node.ObjectNode;
20 +import com.google.common.base.Strings;
20 import com.google.common.collect.ImmutableSet; 21 import com.google.common.collect.ImmutableSet;
21 -import org.apache.commons.lang.WordUtils;
22 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
23 import org.onosproject.net.flow.FlowEntry; 23 import org.onosproject.net.flow.FlowEntry;
24 import org.onosproject.net.flow.FlowRuleService; 24 import org.onosproject.net.flow.FlowRuleService;
...@@ -29,16 +29,16 @@ import org.onosproject.net.flow.instructions.Instruction; ...@@ -29,16 +29,16 @@ import org.onosproject.net.flow.instructions.Instruction;
29 import org.onosproject.ui.RequestHandler; 29 import org.onosproject.ui.RequestHandler;
30 import org.onosproject.ui.UiMessageHandler; 30 import org.onosproject.ui.UiMessageHandler;
31 import org.onosproject.ui.table.AbstractTableRow; 31 import org.onosproject.ui.table.AbstractTableRow;
32 -import org.onosproject.ui.table.RowComparator; 32 +import org.onosproject.ui.table.TableRequestHandler;
33 import org.onosproject.ui.table.TableRow; 33 import org.onosproject.ui.table.TableRow;
34 -import org.onosproject.ui.table.TableUtils;
35 34
36 import java.util.ArrayList; 35 import java.util.ArrayList;
37 -import java.util.Arrays;
38 import java.util.Collection; 36 import java.util.Collection;
39 import java.util.List; 37 import java.util.List;
40 import java.util.Set; 38 import java.util.Set;
41 39
40 +import static org.apache.commons.lang.WordUtils.capitalizeFully;
41 +
42 42
43 /** 43 /**
44 * Message handler for flow view related messages. 44 * Message handler for flow view related messages.
...@@ -46,45 +46,42 @@ import java.util.Set; ...@@ -46,45 +46,42 @@ import java.util.Set;
46 public class FlowViewMessageHandler extends UiMessageHandler { 46 public class FlowViewMessageHandler extends UiMessageHandler {
47 47
48 private static final String FLOW_DATA_REQ = "flowDataRequest"; 48 private static final String FLOW_DATA_REQ = "flowDataRequest";
49 - 49 + private static final String FLOW_DATA_RESP = "flowDataResponse";
50 - private static final String NO_DEV = "none"; 50 + private static final String FLOWS = "flows";
51 +
52 + private static final String ID = "id";
53 + private static final String APP_ID = "appId";
54 + private static final String GROUP_ID = "groupId";
55 + private static final String TABLE_ID = "tableId";
56 + private static final String PRIORITY = "priority";
57 + private static final String SELECTOR = "selector";
58 + private static final String TREATMENT = "treatment";
59 + private static final String TIMEOUT = "timeout";
60 + private static final String PERMANENT = "permanent";
61 + private static final String STATE = "state";
62 +
63 + private static final String COMMA = ", ";
51 64
52 @Override 65 @Override
53 protected Collection<RequestHandler> getHandlers() { 66 protected Collection<RequestHandler> getHandlers() {
54 return ImmutableSet.of(new FlowDataRequest()); 67 return ImmutableSet.of(new FlowDataRequest());
55 } 68 }
56 69
57 - // ====================================================================== 70 + // handler for flow table requests
58 - 71 + private final class FlowDataRequest extends TableRequestHandler {
59 - private final class FlowDataRequest extends RequestHandler {
60 72
61 private FlowDataRequest() { 73 private FlowDataRequest() {
62 - super(FLOW_DATA_REQ); 74 + super(FLOW_DATA_REQ, FLOW_DATA_RESP, FLOWS);
63 } 75 }
64 76
65 @Override 77 @Override
66 - public void process(long sid, ObjectNode payload) { 78 + protected TableRow[] generateTableRows(ObjectNode payload) {
67 - RowComparator rc = TableUtils.createRowComparator(payload); 79 + String uri = string(payload, "devId");
68 - String uri = string(payload, "devId", NO_DEV); 80 + if (Strings.isNullOrEmpty(uri)) {
69 - 81 + return new TableRow[0];
70 - ObjectNode rootNode;
71 - if (uri.equals(NO_DEV)) {
72 - rootNode = MAPPER.createObjectNode();
73 - rootNode.set("flows", MAPPER.createArrayNode());
74 - } else {
75 - DeviceId deviceId = DeviceId.deviceId(uri);
76 - FlowRuleService service = get(FlowRuleService.class);
77 - TableRow[] rows = generateTableRows(service, deviceId);
78 - Arrays.sort(rows, rc);
79 - rootNode = MAPPER.createObjectNode();
80 - rootNode.set("flows", TableUtils.generateArrayNode(rows));
81 } 82 }
82 - 83 + DeviceId deviceId = DeviceId.deviceId(uri);
83 - sendMessage("flowDataResponse", 0, rootNode); 84 + FlowRuleService service = get(FlowRuleService.class);
84 - }
85 -
86 - private TableRow[] generateTableRows(FlowRuleService service,
87 - DeviceId deviceId) {
88 List<TableRow> list = new ArrayList<>(); 85 List<TableRow> list = new ArrayList<>();
89 for (FlowEntry flow : service.getFlowEntries(deviceId)) { 86 for (FlowEntry flow : service.getFlowEntries(deviceId)) {
90 list.add(new FlowTableRow(flow)); 87 list.add(new FlowTableRow(flow));
...@@ -93,42 +90,28 @@ public class FlowViewMessageHandler extends UiMessageHandler { ...@@ -93,42 +90,28 @@ public class FlowViewMessageHandler extends UiMessageHandler {
93 } 90 }
94 } 91 }
95 92
96 - // ======================================================================
97 -
98 /** 93 /**
99 - * TableRow implementation for {@link org.onosproject.net.flow.FlowRule flows}. 94 + * TableRow implementation for
95 + * {@link org.onosproject.net.flow.FlowRule flows}.
100 */ 96 */
101 private static class FlowTableRow extends AbstractTableRow { 97 private static class FlowTableRow extends AbstractTableRow {
102 98
103 - private static final String ID = "id";
104 - private static final String APP_ID = "appId";
105 - private static final String GROUP_ID = "groupId";
106 - private static final String TABLE_ID = "tableId";
107 - private static final String PRIORITY = "priority";
108 - private static final String SELECTOR = "selector";
109 - private static final String TREATMENT = "treatment";
110 - private static final String TIMEOUT = "timeout";
111 - private static final String PERMANENT = "permanent";
112 - private static final String STATE = "state";
113 -
114 - private static final String COMMA = ", ";
115 -
116 private static final String[] COL_IDS = { 99 private static final String[] COL_IDS = {
117 - ID, APP_ID, GROUP_ID, TABLE_ID, PRIORITY, SELECTOR, 100 + ID, APP_ID, GROUP_ID, TABLE_ID, PRIORITY, SELECTOR,
118 TREATMENT, TIMEOUT, PERMANENT, STATE 101 TREATMENT, TIMEOUT, PERMANENT, STATE
119 }; 102 };
120 103
121 public FlowTableRow(FlowEntry f) { 104 public FlowTableRow(FlowEntry f) {
122 - add(ID, Long.toString(f.id().value())); 105 + add(ID, f.id().value());
123 - add(APP_ID, Short.toString(f.appId())); 106 + add(APP_ID, f.appId());
124 - add(GROUP_ID, Integer.toString(f.groupId().id())); 107 + add(GROUP_ID, f.groupId().id());
125 - add(TABLE_ID, Integer.toString(f.tableId())); 108 + add(TABLE_ID, f.tableId());
126 - add(PRIORITY, Integer.toString(f.priority())); 109 + add(PRIORITY, f.priority());
127 add(SELECTOR, getSelectorString(f)); 110 add(SELECTOR, getSelectorString(f));
128 add(TREATMENT, getTreatmentString(f)); 111 add(TREATMENT, getTreatmentString(f));
129 - add(TIMEOUT, Integer.toString(f.timeout())); 112 + add(TIMEOUT, f.timeout());
130 - add(PERMANENT, Boolean.toString(f.isPermanent())); 113 + add(PERMANENT, f.isPermanent());
131 - add(STATE, WordUtils.capitalizeFully(f.state().toString())); 114 + add(STATE, capitalizeFully(f.state().toString()));
132 } 115 }
133 116
134 private String getSelectorString(FlowEntry f) { 117 private String getSelectorString(FlowEntry f) {
...@@ -141,8 +124,7 @@ public class FlowViewMessageHandler extends UiMessageHandler { ...@@ -141,8 +124,7 @@ public class FlowViewMessageHandler extends UiMessageHandler {
141 } else { 124 } else {
142 StringBuilder sb = new StringBuilder("Criteria = "); 125 StringBuilder sb = new StringBuilder("Criteria = ");
143 for (Criterion c : criteria) { 126 for (Criterion c : criteria) {
144 - sb.append(WordUtils.capitalizeFully(c.type().toString())) 127 + sb.append(capitalizeFully(c.type().toString())).append(COMMA);
145 - .append(COMMA);
146 } 128 }
147 result = removeTrailingComma(sb).toString(); 129 result = removeTrailingComma(sb).toString();
148 } 130 }
...@@ -177,8 +159,7 @@ public class FlowViewMessageHandler extends UiMessageHandler { ...@@ -177,8 +159,7 @@ public class FlowViewMessageHandler extends UiMessageHandler {
177 if (!deferred.isEmpty()) { 159 if (!deferred.isEmpty()) {
178 sb.append("Deferred instructions = "); 160 sb.append("Deferred instructions = ");
179 for (Instruction i : deferred) { 161 for (Instruction i : deferred) {
180 - sb.append(WordUtils.capitalizeFully(i.type().toString())) 162 + sb.append(capitalizeFully(i.type().toString())).append(COMMA);
181 - .append(COMMA);
182 } 163 }
183 removeTrailingComma(sb); 164 removeTrailingComma(sb);
184 } 165 }
...@@ -188,8 +169,7 @@ public class FlowViewMessageHandler extends UiMessageHandler { ...@@ -188,8 +169,7 @@ public class FlowViewMessageHandler extends UiMessageHandler {
188 if (!immediate.isEmpty()) { 169 if (!immediate.isEmpty()) {
189 sb.append("Immediate instructions = "); 170 sb.append("Immediate instructions = ");
190 for (Instruction i : immediate) { 171 for (Instruction i : immediate) {
191 - sb.append(WordUtils.capitalizeFully(i.type().toString())) 172 + sb.append(capitalizeFully(i.type().toString())).append(COMMA);
192 - .append(COMMA);
193 } 173 }
194 removeTrailingComma(sb); 174 removeTrailingComma(sb);
195 } 175 }
......
...@@ -24,12 +24,10 @@ import org.onosproject.net.host.HostService; ...@@ -24,12 +24,10 @@ import org.onosproject.net.host.HostService;
24 import org.onosproject.ui.RequestHandler; 24 import org.onosproject.ui.RequestHandler;
25 import org.onosproject.ui.UiMessageHandler; 25 import org.onosproject.ui.UiMessageHandler;
26 import org.onosproject.ui.table.AbstractTableRow; 26 import org.onosproject.ui.table.AbstractTableRow;
27 -import org.onosproject.ui.table.RowComparator; 27 +import org.onosproject.ui.table.TableRequestHandler;
28 import org.onosproject.ui.table.TableRow; 28 import org.onosproject.ui.table.TableRow;
29 -import org.onosproject.ui.table.TableUtils;
30 29
31 import java.util.ArrayList; 30 import java.util.ArrayList;
32 -import java.util.Arrays;
33 import java.util.Collection; 31 import java.util.Collection;
34 import java.util.List; 32 import java.util.List;
35 33
...@@ -41,6 +39,17 @@ import static com.google.common.base.Strings.isNullOrEmpty; ...@@ -41,6 +39,17 @@ import static com.google.common.base.Strings.isNullOrEmpty;
41 public class HostViewMessageHandler extends UiMessageHandler { 39 public class HostViewMessageHandler extends UiMessageHandler {
42 40
43 private static final String HOST_DATA_REQ = "hostDataRequest"; 41 private static final String HOST_DATA_REQ = "hostDataRequest";
42 + private static final String HOST_DATA_RESP = "hostDataResponse";
43 + private static final String HOSTS = "hosts";
44 +
45 + private static final String TYPE_IID = "_iconid_type";
46 + private static final String ID = "id";
47 + private static final String MAC = "mac";
48 + private static final String VLAN = "vlan";
49 + private static final String IPS = "ips";
50 + private static final String LOCATION = "location";
51 +
52 + private static final String HOST_ICON_PREFIX = "hostIcon_";
44 53
45 54
46 @Override 55 @Override
...@@ -48,28 +57,15 @@ public class HostViewMessageHandler extends UiMessageHandler { ...@@ -48,28 +57,15 @@ public class HostViewMessageHandler extends UiMessageHandler {
48 return ImmutableSet.of(new HostDataRequest()); 57 return ImmutableSet.of(new HostDataRequest());
49 } 58 }
50 59
51 - // ====================================================================== 60 + // handler for host table requests
52 - 61 + private final class HostDataRequest extends TableRequestHandler {
53 - private final class HostDataRequest extends RequestHandler {
54 -
55 private HostDataRequest() { 62 private HostDataRequest() {
56 - super(HOST_DATA_REQ); 63 + super(HOST_DATA_REQ, HOST_DATA_RESP, HOSTS);
57 } 64 }
58 65
59 @Override 66 @Override
60 - public void process(long sid, ObjectNode payload) { 67 + protected TableRow[] generateTableRows(ObjectNode payload) {
61 - RowComparator rc = TableUtils.createRowComparator(payload);
62 -
63 HostService service = get(HostService.class); 68 HostService service = get(HostService.class);
64 - TableRow[] rows = generateTableRows(service);
65 - Arrays.sort(rows, rc);
66 - ObjectNode rootNode = MAPPER.createObjectNode();
67 - rootNode.set("hosts", TableUtils.generateArrayNode(rows));
68 -
69 - sendMessage("hostDataResponse", 0, rootNode);
70 - }
71 -
72 - private TableRow[] generateTableRows(HostService service) {
73 List<TableRow> list = new ArrayList<>(); 69 List<TableRow> list = new ArrayList<>();
74 for (Host host : service.getHosts()) { 70 for (Host host : service.getHosts()) {
75 list.add(new HostTableRow(host)); 71 list.add(new HostTableRow(host));
...@@ -78,22 +74,11 @@ public class HostViewMessageHandler extends UiMessageHandler { ...@@ -78,22 +74,11 @@ public class HostViewMessageHandler extends UiMessageHandler {
78 } 74 }
79 } 75 }
80 76
81 - // ======================================================================
82 -
83 /** 77 /**
84 * TableRow implementation for {@link Host hosts}. 78 * TableRow implementation for {@link Host hosts}.
85 */ 79 */
86 private static class HostTableRow extends AbstractTableRow { 80 private static class HostTableRow extends AbstractTableRow {
87 81
88 - private static final String TYPE_IID = "_iconid_type";
89 - private static final String ID = "id";
90 - private static final String MAC = "mac";
91 - private static final String VLAN = "vlan";
92 - private static final String IPS = "ips";
93 - private static final String LOCATION = "location";
94 -
95 - private static final String HOST_ICON_PREFIX = "hostIcon_";
96 -
97 private static final String[] COL_IDS = { 82 private static final String[] COL_IDS = {
98 TYPE_IID, ID, MAC, VLAN, IPS, LOCATION 83 TYPE_IID, ID, MAC, VLAN, IPS, LOCATION
99 }; 84 };
......
...@@ -34,12 +34,10 @@ import org.onosproject.net.intent.SinglePointToMultiPointIntent; ...@@ -34,12 +34,10 @@ import org.onosproject.net.intent.SinglePointToMultiPointIntent;
34 import org.onosproject.ui.RequestHandler; 34 import org.onosproject.ui.RequestHandler;
35 import org.onosproject.ui.UiMessageHandler; 35 import org.onosproject.ui.UiMessageHandler;
36 import org.onosproject.ui.table.AbstractTableRow; 36 import org.onosproject.ui.table.AbstractTableRow;
37 -import org.onosproject.ui.table.RowComparator; 37 +import org.onosproject.ui.table.TableRequestHandler;
38 import org.onosproject.ui.table.TableRow; 38 import org.onosproject.ui.table.TableRow;
39 -import org.onosproject.ui.table.TableUtils;
40 39
41 import java.util.ArrayList; 40 import java.util.ArrayList;
42 -import java.util.Arrays;
43 import java.util.Collection; 41 import java.util.Collection;
44 import java.util.List; 42 import java.util.List;
45 import java.util.Set; 43 import java.util.Set;
...@@ -50,6 +48,8 @@ import java.util.Set; ...@@ -50,6 +48,8 @@ import java.util.Set;
50 public class IntentViewMessageHandler extends UiMessageHandler { 48 public class IntentViewMessageHandler extends UiMessageHandler {
51 49
52 private static final String INTENT_DATA_REQ = "intentDataRequest"; 50 private static final String INTENT_DATA_REQ = "intentDataRequest";
51 + private static final String INTENT_DATA_RESP = "intentDataResponse";
52 + private static final String INTENTS = "intents";
53 53
54 private static final String APP_ID = "appId"; 54 private static final String APP_ID = "appId";
55 private static final String KEY = "key"; 55 private static final String KEY = "key";
...@@ -63,37 +63,27 @@ public class IntentViewMessageHandler extends UiMessageHandler { ...@@ -63,37 +63,27 @@ public class IntentViewMessageHandler extends UiMessageHandler {
63 return ImmutableSet.of(new IntentDataRequest()); 63 return ImmutableSet.of(new IntentDataRequest());
64 } 64 }
65 65
66 - // ====================================================================== 66 + // handler for intent table requests
67 - 67 + private final class IntentDataRequest extends TableRequestHandler {
68 - private final class IntentDataRequest extends RequestHandler {
69 -
70 private IntentDataRequest() { 68 private IntentDataRequest() {
71 - super(INTENT_DATA_REQ); 69 + super(INTENT_DATA_REQ, INTENT_DATA_RESP, INTENTS);
72 } 70 }
73 71
74 @Override 72 @Override
75 - public void process(long sid, ObjectNode payload) { 73 + protected TableRow[] generateTableRows(ObjectNode payload) {
76 - RowComparator rc = TableUtils.createRowComparator(payload, APP_ID);
77 -
78 IntentService service = get(IntentService.class); 74 IntentService service = get(IntentService.class);
79 - TableRow[] rows = generateTableRows(service);
80 - Arrays.sort(rows, rc);
81 - ObjectNode rootNode = MAPPER.createObjectNode();
82 - rootNode.set("intents", TableUtils.generateArrayNode(rows));
83 -
84 - sendMessage("intentDataResponse", 0, rootNode);
85 - }
86 -
87 - private TableRow[] generateTableRows(IntentService service) {
88 List<TableRow> list = new ArrayList<>(); 75 List<TableRow> list = new ArrayList<>();
89 for (Intent intent : service.getIntents()) { 76 for (Intent intent : service.getIntents()) {
90 list.add(new IntentTableRow(intent)); 77 list.add(new IntentTableRow(intent));
91 } 78 }
92 return list.toArray(new TableRow[list.size()]); 79 return list.toArray(new TableRow[list.size()]);
93 } 80 }
94 - }
95 81
96 - // ====================================================================== 82 + @Override
83 + protected String defaultColId() {
84 + return APP_ID;
85 + }
86 + }
97 87
98 /** 88 /**
99 * TableRow implementation for {@link Intent intents}. 89 * TableRow implementation for {@link Intent intents}.
......
...@@ -27,12 +27,10 @@ import org.onosproject.ui.RequestHandler; ...@@ -27,12 +27,10 @@ import org.onosproject.ui.RequestHandler;
27 import org.onosproject.ui.UiMessageHandler; 27 import org.onosproject.ui.UiMessageHandler;
28 import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink; 28 import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink;
29 import org.onosproject.ui.table.AbstractTableRow; 29 import org.onosproject.ui.table.AbstractTableRow;
30 -import org.onosproject.ui.table.RowComparator; 30 +import org.onosproject.ui.table.TableRequestHandler;
31 import org.onosproject.ui.table.TableRow; 31 import org.onosproject.ui.table.TableRow;
32 -import org.onosproject.ui.table.TableUtils;
33 32
34 import java.util.ArrayList; 33 import java.util.ArrayList;
35 -import java.util.Arrays;
36 import java.util.Collection; 34 import java.util.Collection;
37 import java.util.List; 35 import java.util.List;
38 import java.util.Map; 36 import java.util.Map;
...@@ -45,35 +43,30 @@ import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink; ...@@ -45,35 +43,30 @@ import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink;
45 public class LinkViewMessageHandler extends UiMessageHandler { 43 public class LinkViewMessageHandler extends UiMessageHandler {
46 44
47 private static final String LINK_DATA_REQ = "linkDataRequest"; 45 private static final String LINK_DATA_REQ = "linkDataRequest";
46 + private static final String LINK_DATA_RESP = "linkDataResponse";
47 + private static final String LINKS = "links";
48 48
49 + private static final String ONE = "one";
50 + private static final String TWO = "two";
51 + private static final String TYPE = "type";
52 + private static final String STATE = "_iconid_state";
53 + private static final String DIRECTION = "direction";
54 + private static final String DURABLE = "durable";
49 55
50 @Override 56 @Override
51 protected Collection<RequestHandler> getHandlers() { 57 protected Collection<RequestHandler> getHandlers() {
52 return ImmutableSet.of(new LinkDataRequest()); 58 return ImmutableSet.of(new LinkDataRequest());
53 } 59 }
54 60
55 - // ====================================================================== 61 + // handler for link table requests
56 - 62 + private final class LinkDataRequest extends TableRequestHandler {
57 - private final class LinkDataRequest extends RequestHandler {
58 -
59 private LinkDataRequest() { 63 private LinkDataRequest() {
60 - super(LINK_DATA_REQ); 64 + super(LINK_DATA_REQ, LINK_DATA_RESP, LINKS);
61 } 65 }
62 66
63 @Override 67 @Override
64 - public void process(long sid, ObjectNode payload) { 68 + protected TableRow[] generateTableRows(ObjectNode payload) {
65 - RowComparator rc = TableUtils.createRowComparator(payload, "one");
66 -
67 LinkService service = get(LinkService.class); 69 LinkService service = get(LinkService.class);
68 - TableRow[] rows = generateTableRows(service);
69 - Arrays.sort(rows, rc);
70 - ObjectNode rootNode = MAPPER.createObjectNode();
71 - rootNode.set("links", TableUtils.generateArrayNode(rows));
72 -
73 - sendMessage("linkDataResponse", 0, rootNode);
74 - }
75 -
76 - private TableRow[] generateTableRows(LinkService service) {
77 List<TableRow> list = new ArrayList<>(); 70 List<TableRow> list = new ArrayList<>();
78 71
79 // First consolidate all uni-directional links into two-directional ones. 72 // First consolidate all uni-directional links into two-directional ones.
...@@ -84,22 +77,18 @@ public class LinkViewMessageHandler extends UiMessageHandler { ...@@ -84,22 +77,18 @@ public class LinkViewMessageHandler extends UiMessageHandler {
84 biLinks.values().forEach(biLink -> list.add(new LinkTableRow(biLink))); 77 biLinks.values().forEach(biLink -> list.add(new LinkTableRow(biLink)));
85 return list.toArray(new TableRow[list.size()]); 78 return list.toArray(new TableRow[list.size()]);
86 } 79 }
87 - }
88 80
89 - // ====================================================================== 81 + @Override
82 + protected String defaultColId() {
83 + return ONE;
84 + }
85 + }
90 86
91 /** 87 /**
92 * TableRow implementation for {@link org.onosproject.net.Link links}. 88 * TableRow implementation for {@link org.onosproject.net.Link links}.
93 */ 89 */
94 private static class LinkTableRow extends AbstractTableRow { 90 private static class LinkTableRow extends AbstractTableRow {
95 91
96 - private static final String ONE = "one";
97 - private static final String TWO = "two";
98 - private static final String TYPE = "type";
99 - private static final String STATE = "_iconid_state";
100 - private static final String DIRECTION = "direction";
101 - private static final String DURABLE = "durable";
102 -
103 private static final String[] COL_IDS = { 92 private static final String[] COL_IDS = {
104 ONE, TWO, TYPE, STATE, DIRECTION, DURABLE 93 ONE, TWO, TYPE, STATE, DIRECTION, DURABLE
105 }; 94 };
......