Committed by
Gerrit Code Review
Add select control box in chart view
Provide the ability to navigate different device's chart view. Change-Id: Iebf87965580295ca31e93bdf799d5d3d334a1102
Showing
3 changed files
with
33 additions
and
3 deletions
... | @@ -15,10 +15,12 @@ | ... | @@ -15,10 +15,12 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.cpman.gui; | 16 | package org.onosproject.cpman.gui; |
17 | 17 | ||
18 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
18 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
19 | import com.google.common.base.Strings; | 20 | import com.google.common.base.Strings; |
20 | import com.google.common.collect.ImmutableSet; | 21 | import com.google.common.collect.ImmutableSet; |
21 | import com.google.common.collect.Maps; | 22 | import com.google.common.collect.Maps; |
23 | +import com.google.common.collect.Sets; | ||
22 | import org.apache.commons.lang.ArrayUtils; | 24 | import org.apache.commons.lang.ArrayUtils; |
23 | import org.apache.commons.lang3.StringUtils; | 25 | import org.apache.commons.lang3.StringUtils; |
24 | import org.joda.time.LocalDateTime; | 26 | import org.joda.time.LocalDateTime; |
... | @@ -27,6 +29,7 @@ import org.onosproject.cpman.ControlLoadSnapshot; | ... | @@ -27,6 +29,7 @@ import org.onosproject.cpman.ControlLoadSnapshot; |
27 | import org.onosproject.cpman.ControlMetricType; | 29 | import org.onosproject.cpman.ControlMetricType; |
28 | import org.onosproject.cpman.ControlPlaneMonitorService; | 30 | import org.onosproject.cpman.ControlPlaneMonitorService; |
29 | import org.onosproject.net.DeviceId; | 31 | import org.onosproject.net.DeviceId; |
32 | +import org.onosproject.net.device.DeviceService; | ||
30 | import org.onosproject.ui.RequestHandler; | 33 | import org.onosproject.ui.RequestHandler; |
31 | import org.onosproject.ui.UiMessageHandler; | 34 | import org.onosproject.ui.UiMessageHandler; |
32 | import org.onosproject.ui.chart.ChartModel; | 35 | import org.onosproject.ui.chart.ChartModel; |
... | @@ -56,8 +59,10 @@ public class CpmanViewMessageHandler extends UiMessageHandler { | ... | @@ -56,8 +59,10 @@ public class CpmanViewMessageHandler extends UiMessageHandler { |
56 | private static final String CPMAN_DATA_RESP = "cpmanDataResponse"; | 59 | private static final String CPMAN_DATA_RESP = "cpmanDataResponse"; |
57 | private static final String CPMANS = "cpmans"; | 60 | private static final String CPMANS = "cpmans"; |
58 | 61 | ||
62 | + private static final String DEVICE_IDS = "deviceIds"; | ||
63 | + | ||
59 | // TODO: we assume that server side always returns 20 data points | 64 | // TODO: we assume that server side always returns 20 data points |
60 | - // to feed 1 hour time slots, later this should make to be configurable | 65 | + // to feed 20 minutes time slots, later this should make to be configurable |
61 | private static final int NUM_OF_DATA_POINTS = 20; | 66 | private static final int NUM_OF_DATA_POINTS = 20; |
62 | 67 | ||
63 | private static final int MILLI_CONV_UNIT = 1000; | 68 | private static final int MILLI_CONV_UNIT = 1000; |
... | @@ -90,6 +95,8 @@ public class CpmanViewMessageHandler extends UiMessageHandler { | ... | @@ -90,6 +95,8 @@ public class CpmanViewMessageHandler extends UiMessageHandler { |
90 | String uri = string(payload, "devId"); | 95 | String uri = string(payload, "devId"); |
91 | ControlPlaneMonitorService cpms = get(ControlPlaneMonitorService.class); | 96 | ControlPlaneMonitorService cpms = get(ControlPlaneMonitorService.class); |
92 | ClusterService cs = get(ClusterService.class); | 97 | ClusterService cs = get(ClusterService.class); |
98 | + DeviceService ds = get(DeviceService.class); | ||
99 | + | ||
93 | if (!Strings.isNullOrEmpty(uri)) { | 100 | if (!Strings.isNullOrEmpty(uri)) { |
94 | DeviceId deviceId = DeviceId.deviceId(uri); | 101 | DeviceId deviceId = DeviceId.deviceId(uri); |
95 | if (cpms.availableResources(CONTROL_MESSAGE).contains(deviceId.toString())) { | 102 | if (cpms.availableResources(CONTROL_MESSAGE).contains(deviceId.toString())) { |
... | @@ -97,6 +104,10 @@ public class CpmanViewMessageHandler extends UiMessageHandler { | ... | @@ -97,6 +104,10 @@ public class CpmanViewMessageHandler extends UiMessageHandler { |
97 | LocalDateTime ldt = new LocalDateTime(timestamp * MILLI_CONV_UNIT); | 104 | LocalDateTime ldt = new LocalDateTime(timestamp * MILLI_CONV_UNIT); |
98 | 105 | ||
99 | populateMetrics(cm, data, ldt, NUM_OF_DATA_POINTS); | 106 | populateMetrics(cm, data, ldt, NUM_OF_DATA_POINTS); |
107 | + | ||
108 | + Set<DeviceId> deviceIds = Sets.newHashSet(); | ||
109 | + ds.getAvailableDevices().forEach(device -> deviceIds.add(device.id())); | ||
110 | + attachDeviceList(cm, deviceIds); | ||
100 | } | 111 | } |
101 | } else { | 112 | } else { |
102 | Set<String> deviceIds = cpms.availableResources(CONTROL_MESSAGE); | 113 | Set<String> deviceIds = cpms.availableResources(CONTROL_MESSAGE); |
... | @@ -189,7 +200,13 @@ public class CpmanViewMessageHandler extends UiMessageHandler { | ... | @@ -189,7 +200,13 @@ public class CpmanViewMessageHandler extends UiMessageHandler { |
189 | 200 | ||
190 | private void populateMetric(ChartModel.DataPoint dataPoint, | 201 | private void populateMetric(ChartModel.DataPoint dataPoint, |
191 | Map<String, Object> data) { | 202 | Map<String, Object> data) { |
192 | - data.forEach((k, v) -> dataPoint.data(k, v)); | 203 | + data.forEach(dataPoint::data); |
204 | + } | ||
205 | + | ||
206 | + private void attachDeviceList(ChartModel cm, Set<DeviceId> deviceIds) { | ||
207 | + ArrayNode array = arrayNode(); | ||
208 | + deviceIds.forEach(id -> array.add(id.toString())); | ||
209 | + cm.addAnnotation(DEVICE_IDS, array); | ||
193 | } | 210 | } |
194 | } | 211 | } |
195 | } | 212 | } | ... | ... |
... | @@ -13,6 +13,12 @@ | ... | @@ -13,6 +13,12 @@ |
13 | <h2> | 13 | <h2> |
14 | Chart for Device {{devId || "(No device selected)"}} | 14 | Chart for Device {{devId || "(No device selected)"}} |
15 | </h2> | 15 | </h2> |
16 | + <div class="ctrl-btns"> | ||
17 | + <select ng-options="deviceId as deviceId for deviceId in deviceIds" | ||
18 | + ng-model="selectedItem" ng-change="onChange(selectedItem)"> | ||
19 | + <option value="">-- select a device --</option> | ||
20 | + </select> | ||
21 | + </div> | ||
16 | <canvas id="line" class="chart chart-line" chart-data="data" | 22 | <canvas id="line" class="chart chart-line" chart-data="data" |
17 | chart-labels="labels" chart-legend="true" | 23 | chart-labels="labels" chart-legend="true" |
18 | chart-series="series" chart-options="options" height="100%"> | 24 | chart-series="series" chart-options="options" height="100%"> | ... | ... |
... | @@ -66,7 +66,6 @@ | ... | @@ -66,7 +66,6 @@ |
66 | $scope.devId = params['devId']; | 66 | $scope.devId = params['devId']; |
67 | hasDeviceId = true; | 67 | hasDeviceId = true; |
68 | } else { | 68 | } else { |
69 | - $scope.type = 'StackedBar'; | ||
70 | hasDeviceId = false; | 69 | hasDeviceId = false; |
71 | } | 70 | } |
72 | 71 | ||
... | @@ -113,6 +112,14 @@ | ... | @@ -113,6 +112,14 @@ |
113 | $log.log(points[0].label); | 112 | $log.log(points[0].label); |
114 | } | 113 | } |
115 | }; | 114 | }; |
115 | + | ||
116 | + if (!fs.isEmptyObject($scope.annots)) { | ||
117 | + $scope.deviceIds = JSON.parse($scope.annots.deviceIds); | ||
118 | + } | ||
119 | + | ||
120 | + $scope.onChange = function (deviceId) { | ||
121 | + ns.navTo('cpman', { devId: deviceId }); | ||
122 | + }; | ||
116 | }); | 123 | }); |
117 | 124 | ||
118 | $scope.series = ['INBOUND', 'OUTBOUND', 'FLOW-MOD', | 125 | $scope.series = ['INBOUND', 'OUTBOUND', 'FLOW-MOD', | ... | ... |
-
Please register or login to post a comment