Committed by
Gerrit Code Review
Sketching out driver matrix data structures.
Change-Id: I8739e0a49de250bc015b994638bfc6df42393000
Showing
4 changed files
with
167 additions
and
225 deletions
apps/drivermatrix/src/main/java/org/onosproject/drivermatrix/DriverMatrixMessageHandler.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014,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 | -package org.onosproject.drivermatrix; | ||
| 17 | - | ||
| 18 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 19 | -import com.google.common.collect.ImmutableSet; | ||
| 20 | -import org.onosproject.ui.RequestHandler; | ||
| 21 | -import org.onosproject.ui.UiMessageHandler; | ||
| 22 | -import org.onosproject.ui.table.TableModel; | ||
| 23 | -import org.onosproject.ui.table.TableRequestHandler; | ||
| 24 | -import org.slf4j.Logger; | ||
| 25 | -import org.slf4j.LoggerFactory; | ||
| 26 | - | ||
| 27 | -import java.util.ArrayList; | ||
| 28 | -import java.util.Collection; | ||
| 29 | -import java.util.List; | ||
| 30 | - | ||
| 31 | -/** | ||
| 32 | - * Skeletal ONOS UI Table-View message handler. | ||
| 33 | - */ | ||
| 34 | -public class DriverMatrixMessageHandler extends UiMessageHandler { | ||
| 35 | - | ||
| 36 | - private static final String SAMPLE_TABLE_DATA_REQ = "driverMatrixDataRequest"; | ||
| 37 | - private static final String SAMPLE_TABLE_DATA_RESP = "driverMatrixDataResponse"; | ||
| 38 | - private static final String SAMPLE_TABLES = "driverMatrixs"; | ||
| 39 | - | ||
| 40 | - private static final String SAMPLE_TABLE_DETAIL_REQ = "driverMatrixDetailsRequest"; | ||
| 41 | - private static final String SAMPLE_TABLE_DETAIL_RESP = "driverMatrixDetailsResponse"; | ||
| 42 | - private static final String DETAILS = "details"; | ||
| 43 | - | ||
| 44 | - private static final String ID = "id"; | ||
| 45 | - private static final String LABEL = "label"; | ||
| 46 | - private static final String CODE = "code"; | ||
| 47 | - private static final String COMMENT = "comment"; | ||
| 48 | - private static final String RESULT = "result"; | ||
| 49 | - | ||
| 50 | - private static final String[] COLUMN_IDS = {ID, LABEL, CODE}; | ||
| 51 | - | ||
| 52 | - private final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - @Override | ||
| 56 | - protected Collection<RequestHandler> createRequestHandlers() { | ||
| 57 | - return ImmutableSet.of( | ||
| 58 | - new SampleTableDataRequestHandler(), | ||
| 59 | - new SampleTableDetailRequestHandler() | ||
| 60 | - ); | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - // handler for sample table requests | ||
| 64 | - private final class SampleTableDataRequestHandler extends TableRequestHandler { | ||
| 65 | - | ||
| 66 | - private static final String NO_ROWS_MESSAGE = "No data found"; | ||
| 67 | - | ||
| 68 | - private SampleTableDataRequestHandler() { | ||
| 69 | - super(SAMPLE_TABLE_DATA_REQ, SAMPLE_TABLE_DATA_RESP, SAMPLE_TABLES); | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - // if necessary, override defaultColumnId() -- if it isn't "id" | ||
| 73 | - | ||
| 74 | - @Override | ||
| 75 | - protected String[] getColumnIds() { | ||
| 76 | - return COLUMN_IDS; | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - @Override | ||
| 80 | - protected String noRowsMessage(ObjectNode payload) { | ||
| 81 | - return NO_ROWS_MESSAGE; | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - // if required, override createTableModel() to set column formatters / comparators | ||
| 85 | - | ||
| 86 | - @Override | ||
| 87 | - protected void populateTable(TableModel tm, ObjectNode payload) { | ||
| 88 | - // === NOTE: the table model supplied here will have been created | ||
| 89 | - // via a call to createTableModel(). To assign non-default | ||
| 90 | - // cell formatters or comparators to the table model, override | ||
| 91 | - // createTableModel() and set them there. | ||
| 92 | - | ||
| 93 | - // === retrieve table row items from some service... | ||
| 94 | - // SomeService ss = get(SomeService.class); | ||
| 95 | - // List<Item> items = ss.getItems() | ||
| 96 | - | ||
| 97 | - // fake data for demonstration purposes... | ||
| 98 | - List<Item> items = getItems(); | ||
| 99 | - for (Item item : items) { | ||
| 100 | - populateRow(tm.addRow(), item); | ||
| 101 | - } | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - private void populateRow(TableModel.Row row, Item item) { | ||
| 105 | - row.cell(ID, item.id()) | ||
| 106 | - .cell(LABEL, item.label()) | ||
| 107 | - .cell(CODE, item.code()); | ||
| 108 | - } | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - | ||
| 112 | - // handler for sample item details requests | ||
| 113 | - private final class SampleTableDetailRequestHandler extends RequestHandler { | ||
| 114 | - | ||
| 115 | - private SampleTableDetailRequestHandler() { | ||
| 116 | - super(SAMPLE_TABLE_DETAIL_REQ); | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - @Override | ||
| 120 | - public void process(long sid, ObjectNode payload) { | ||
| 121 | - String id = string(payload, ID, "(none)"); | ||
| 122 | - | ||
| 123 | - // SomeService ss = get(SomeService.class); | ||
| 124 | - // Item item = ss.getItemDetails(id) | ||
| 125 | - | ||
| 126 | - // fake data for demonstration purposes... | ||
| 127 | - Item item = getItem(id); | ||
| 128 | - | ||
| 129 | - ObjectNode rootNode = objectNode(); | ||
| 130 | - ObjectNode data = objectNode(); | ||
| 131 | - rootNode.set(DETAILS, data); | ||
| 132 | - | ||
| 133 | - if (item == null) { | ||
| 134 | - rootNode.put(RESULT, "Item with id '" + id + "' not found"); | ||
| 135 | - log.warn("attempted to get item detail for id '{}'", id); | ||
| 136 | - | ||
| 137 | - } else { | ||
| 138 | - rootNode.put(RESULT, "Found item with id '" + id + "'"); | ||
| 139 | - | ||
| 140 | - data.put(ID, item.id()); | ||
| 141 | - data.put(LABEL, item.label()); | ||
| 142 | - data.put(CODE, item.code()); | ||
| 143 | - data.put(COMMENT, "Some arbitrary comment"); | ||
| 144 | - } | ||
| 145 | - | ||
| 146 | - sendMessage(SAMPLE_TABLE_DETAIL_RESP, 0, rootNode); | ||
| 147 | - } | ||
| 148 | - } | ||
| 149 | - | ||
| 150 | - | ||
| 151 | - // =================================================================== | ||
| 152 | - // NOTE: The code below this line is to create fake data for this | ||
| 153 | - // sample code. Normally you would use existing services to | ||
| 154 | - // provide real data. | ||
| 155 | - | ||
| 156 | - // Lookup a single item. | ||
| 157 | - private static Item getItem(String id) { | ||
| 158 | - // We realize this code is really inefficient, but | ||
| 159 | - // it suffices for our purposes of demonstration... | ||
| 160 | - for (Item item : getItems()) { | ||
| 161 | - if (item.id().equals(id)) { | ||
| 162 | - return item; | ||
| 163 | - } | ||
| 164 | - } | ||
| 165 | - return null; | ||
| 166 | - } | ||
| 167 | - | ||
| 168 | - // Produce a list of items. | ||
| 169 | - private static List<Item> getItems() { | ||
| 170 | - List<Item> items = new ArrayList<>(); | ||
| 171 | - items.add(new Item("item-1", "foo", 42)); | ||
| 172 | - items.add(new Item("item-2", "bar", 99)); | ||
| 173 | - items.add(new Item("item-3", "baz", 65)); | ||
| 174 | - return items; | ||
| 175 | - } | ||
| 176 | - | ||
| 177 | - // Simple model class to provide sample data | ||
| 178 | - private static class Item { | ||
| 179 | - private final String id; | ||
| 180 | - private final String label; | ||
| 181 | - private final int code; | ||
| 182 | - | ||
| 183 | - Item(String id, String label, int code) { | ||
| 184 | - this.id = id; | ||
| 185 | - this.label = label; | ||
| 186 | - this.code = code; | ||
| 187 | - } | ||
| 188 | - | ||
| 189 | - String id() { | ||
| 190 | - return id; | ||
| 191 | - } | ||
| 192 | - | ||
| 193 | - String label() { | ||
| 194 | - return label; | ||
| 195 | - } | ||
| 196 | - | ||
| 197 | - int code() { | ||
| 198 | - return code; | ||
| 199 | - } | ||
| 200 | - } | ||
| 201 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -31,10 +31,10 @@ import org.slf4j.LoggerFactory; | ... | @@ -31,10 +31,10 @@ import org.slf4j.LoggerFactory; |
| 31 | import java.util.List; | 31 | import java.util.List; |
| 32 | 32 | ||
| 33 | /** | 33 | /** |
| 34 | - * Skeletal ONOS UI Table-View application component. | 34 | + * Registers driver matrix view. |
| 35 | */ | 35 | */ |
| 36 | @Component(immediate = true) | 36 | @Component(immediate = true) |
| 37 | -public class DriverMatrixComponent { | 37 | +public class DriverViewComponent { |
| 38 | 38 | ||
| 39 | private static final String VIEW_ID = "driverMatrix"; | 39 | private static final String VIEW_ID = "driverMatrix"; |
| 40 | private static final String VIEW_TEXT = "Driver Matrix"; | 40 | private static final String VIEW_TEXT = "Driver Matrix"; |
| ... | @@ -46,13 +46,13 @@ public class DriverMatrixComponent { | ... | @@ -46,13 +46,13 @@ public class DriverMatrixComponent { |
| 46 | 46 | ||
| 47 | // List of application views | 47 | // List of application views |
| 48 | private final List<UiView> uiViews = ImmutableList.of( | 48 | private final List<UiView> uiViews = ImmutableList.of( |
| 49 | - new UiView(UiView.Category.OTHER, VIEW_ID, VIEW_TEXT) | 49 | + new UiView(UiView.Category.PLATFORM, VIEW_ID, VIEW_TEXT) |
| 50 | ); | 50 | ); |
| 51 | 51 | ||
| 52 | // Factory for UI message handlers | 52 | // Factory for UI message handlers |
| 53 | private final UiMessageHandlerFactory messageHandlerFactory = | 53 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 54 | () -> ImmutableList.of( | 54 | () -> ImmutableList.of( |
| 55 | - new DriverMatrixMessageHandler() | 55 | + new DriverViewMessageHandler() |
| 56 | ); | 56 | ); |
| 57 | 57 | ||
| 58 | // Application UI extension | 58 | // Application UI extension | ... | ... |
apps/drivermatrix/src/main/java/org/onosproject/drivermatrix/DriverViewMessageHandler.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2016 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.drivermatrix; | ||
| 18 | + | ||
| 19 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
| 20 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 21 | +import com.google.common.collect.ImmutableSet; | ||
| 22 | +import org.onosproject.net.driver.Behaviour; | ||
| 23 | +import org.onosproject.net.driver.Driver; | ||
| 24 | +import org.onosproject.net.driver.DriverService; | ||
| 25 | +import org.onosproject.ui.RequestHandler; | ||
| 26 | +import org.onosproject.ui.UiMessageHandler; | ||
| 27 | +import org.slf4j.Logger; | ||
| 28 | +import org.slf4j.LoggerFactory; | ||
| 29 | + | ||
| 30 | +import java.util.ArrayList; | ||
| 31 | +import java.util.Collection; | ||
| 32 | +import java.util.Comparator; | ||
| 33 | +import java.util.HashMap; | ||
| 34 | +import java.util.HashSet; | ||
| 35 | +import java.util.List; | ||
| 36 | +import java.util.Map; | ||
| 37 | +import java.util.Set; | ||
| 38 | + | ||
| 39 | +/** | ||
| 40 | + * Message handler for device view related messages. | ||
| 41 | + */ | ||
| 42 | +public class DriverViewMessageHandler extends UiMessageHandler { | ||
| 43 | + | ||
| 44 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 45 | + | ||
| 46 | + private static final String DRIVER_DATA_REQUEST = "driverDataRequest"; | ||
| 47 | + private static final String DRIVER_DATA_RESPONSE = "driverDataResponse"; | ||
| 48 | + | ||
| 49 | + private static final String DRIVERS = "drivers"; | ||
| 50 | + private static final String BEHAVIOURS = "behaviours"; | ||
| 51 | + | ||
| 52 | + private static final Comparator<? super Class<? extends Behaviour>> BEHAVIOUR_BY_NAME = | ||
| 53 | + (o1, o2) -> o1.getSimpleName().compareTo(o2.getSimpleName()); | ||
| 54 | + private static final Comparator<? super Driver> DRIVER_BY_NAME = | ||
| 55 | + (o1, o2) -> o1.name().compareTo(o2.name()); | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + @Override | ||
| 59 | + protected Collection<RequestHandler> createRequestHandlers() { | ||
| 60 | + return ImmutableSet.of( | ||
| 61 | + new DataRequestHandler() | ||
| 62 | +// new DetailRequestHandler() | ||
| 63 | + ); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + // handler for device table requests | ||
| 67 | + private final class DataRequestHandler extends RequestHandler { | ||
| 68 | + | ||
| 69 | + private DataRequestHandler() { | ||
| 70 | + super(DRIVER_DATA_REQUEST); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @Override | ||
| 74 | + public void process(long sid, ObjectNode payload) { | ||
| 75 | + // Search for drivers producing two artifacts: | ||
| 76 | + // 1) list of abstract behaviours as column listing | ||
| 77 | + // 2) sparse matrix of drivers-to-concrete behaviours | ||
| 78 | + | ||
| 79 | + DriverService driverService = get(DriverService.class); | ||
| 80 | + | ||
| 81 | + // Collect all behaviours for all drivers | ||
| 82 | + Map<Driver, Set<Class<? extends Behaviour>>> driverBehaviours = new HashMap<>(); | ||
| 83 | + driverService.getDrivers().forEach(d -> driverBehaviours.put(d, d.behaviours())); | ||
| 84 | + | ||
| 85 | + // Order all drivers | ||
| 86 | + List<Driver> drivers = orderDrivers(driverBehaviours.keySet()); | ||
| 87 | + | ||
| 88 | + // Produce a union of all behaviours (and order them) | ||
| 89 | + List<Class<? extends Behaviour>> behaviours = orderBehaviours(driverBehaviours.values()); | ||
| 90 | + | ||
| 91 | + // Produce a JSON structure and send it | ||
| 92 | + sendMessage(DRIVER_DATA_RESPONSE, 0, driversJson(driverBehaviours, drivers, behaviours)); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + private List<Driver> orderDrivers(Set<Driver> drivers) { | ||
| 96 | + // For now order by alphanumeric name of the driver | ||
| 97 | + List<Driver> ordered = new ArrayList<>(drivers); | ||
| 98 | + ordered.sort(DRIVER_BY_NAME); | ||
| 99 | + return ordered; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + private List<Class<? extends Behaviour>> | ||
| 103 | + orderBehaviours(Collection<Set<Class<? extends Behaviour>>> behaviours) { | ||
| 104 | + // For now order by alphanumeric name of the abstract behaviour simple name | ||
| 105 | + Set<Class<? extends Behaviour>> allBehaviours = new HashSet<>(); | ||
| 106 | + behaviours.forEach(allBehaviours::addAll); | ||
| 107 | + List<Class<? extends Behaviour>> ordered = new ArrayList<>(allBehaviours); | ||
| 108 | + ordered.sort(BEHAVIOUR_BY_NAME); | ||
| 109 | + return ordered; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + private ObjectNode driversJson(Map<Driver, Set<Class<? extends Behaviour>>> driverBehaviours, | ||
| 113 | + List<Driver> drivers, | ||
| 114 | + List<Class<? extends Behaviour>> behaviours) { | ||
| 115 | + ObjectNode root = objectNode(); | ||
| 116 | + addBehaviours(root, behaviours); | ||
| 117 | + addDrivers(root, drivers); | ||
| 118 | + addRelationships(root, drivers, behaviours, driverBehaviours); | ||
| 119 | + return root; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + private void addBehaviours(ObjectNode root, List<Class<? extends Behaviour>> behaviours) { | ||
| 123 | + ArrayNode array = arrayNode(); | ||
| 124 | + root.set(BEHAVIOURS, array); | ||
| 125 | + behaviours.forEach(b -> array.add(b.getSimpleName())); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + private void addDrivers(ObjectNode root, List<Driver> drivers) { | ||
| 129 | + ArrayNode array = arrayNode(); | ||
| 130 | + root.set(DRIVERS, array); | ||
| 131 | + drivers.forEach(d -> array.add(d.name())); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + private void addRelationships(ObjectNode root, | ||
| 135 | + List<Driver> drivers, List<Class<? extends Behaviour>> behaviours, | ||
| 136 | + Map<Driver, Set<Class<? extends Behaviour>>> driverBehaviours) { | ||
| 137 | + } | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | +} |
| ... | @@ -6,8 +6,8 @@ | ... | @@ -6,8 +6,8 @@ |
| 6 | var $log, $scope, fs, wss; | 6 | var $log, $scope, fs, wss; |
| 7 | 7 | ||
| 8 | // constants | 8 | // constants |
| 9 | - var detailsReq = 'driverMatrixDetailsRequest', | 9 | + var detailsReq = 'driverDataRequest', |
| 10 | - detailsResp = 'driverMatrixDetailsResponse', | 10 | + detailsResp = 'driverDataResponse', |
| 11 | pName = 'ov-driver-matrix-item-details-panel', | 11 | pName = 'ov-driver-matrix-item-details-panel', |
| 12 | 12 | ||
| 13 | propOrder = ['id', 'label', 'code'], | 13 | propOrder = ['id', 'label', 'code'], |
| ... | @@ -40,8 +40,9 @@ | ... | @@ -40,8 +40,9 @@ |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | function respDetailsCb(data) { | 42 | function respDetailsCb(data) { |
| 43 | - $scope.panelDetails = data.details; | 43 | + $log.debug(data); |
| 44 | - $scope.$apply(); | 44 | + //$scope.panelDetails = data.details; |
| 45 | + //$scope.$apply(); | ||
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | angular.module('ovDriverMatrix', []) | 48 | angular.module('ovDriverMatrix', []) |
| ... | @@ -62,22 +63,24 @@ | ... | @@ -62,22 +63,24 @@ |
| 62 | handlers[detailsResp] = respDetailsCb; | 63 | handlers[detailsResp] = respDetailsCb; |
| 63 | wss.bindHandlers(handlers); | 64 | wss.bindHandlers(handlers); |
| 64 | 65 | ||
| 65 | - // custom selection callback | 66 | + wss.sendEvent(detailsReq); |
| 66 | - function selCb($event, row) { | 67 | + |
| 67 | - if ($scope.selId) { | 68 | + //// custom selection callback |
| 68 | - wss.sendEvent(detailsReq, { id: row.id }); | 69 | + //function selCb($event, row) { |
| 69 | - } else { | 70 | + // if ($scope.selId) { |
| 70 | - $scope.hidePanel(); | 71 | + // wss.sendEvent(detailsReq, { id: row.id }); |
| 71 | - } | 72 | + // } else { |
| 72 | - $log.debug('Got a click on:', row); | 73 | + // $scope.hidePanel(); |
| 73 | - } | 74 | + // } |
| 74 | - | 75 | + // $log.debug('Got a click on:', row); |
| 75 | - // TableBuilderService creating a table for us | 76 | + //} |
| 76 | - tbs.buildTable({ | 77 | + |
| 77 | - scope: $scope, | 78 | + //// TableBuilderService creating a table for us |
| 78 | - tag: 'driverMatrix', | 79 | + //tbs.buildTable({ |
| 79 | - selCb: selCb | 80 | + // scope: $scope, |
| 80 | - }); | 81 | + // tag: 'driverMatrix', |
| 82 | + // selCb: selCb | ||
| 83 | + //}); | ||
| 81 | 84 | ||
| 82 | // cleanup | 85 | // cleanup |
| 83 | $scope.$on('$destroy', function () { | 86 | $scope.$on('$destroy', function () { | ... | ... |
-
Please register or login to post a comment