GUI -- Added facility to upload and track various sprite JSON definitions. WIP
Change-Id: I5629e07d84b91d2d885737a9011acc4e13538cf2
Showing
7 changed files
with
130 additions
and
4 deletions
tools/test/bin/onos-upload-sprites
0 → 100755
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------- | ||
| 3 | +# Tool to upload GUI sprites definitions using GUI REST API. | ||
| 4 | +# ----------------------------------------------------------------------------- | ||
| 5 | + | ||
| 6 | +node=${1} | ||
| 7 | +sprites=${2} | ||
| 8 | + | ||
| 9 | +export URL=http://$node:8181/onos/ui/rs/topology/sprites | ||
| 10 | +export HDR="-HContent-Type:application/json" | ||
| 11 | + | ||
| 12 | +curl --fail -sS -X POST $HDR $URL --data @$sprites |
| 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 | +package org.onosproject.ui.impl; | ||
| 17 | + | ||
| 18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 19 | + | ||
| 20 | +import java.util.Set; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * Provisional service to keep track of the topology view sprite definitions. | ||
| 24 | + */ | ||
| 25 | +public interface SpriteService { | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * Returns set of registered sprite definition names. | ||
| 29 | + * | ||
| 30 | + * @return set of sprite definition names | ||
| 31 | + */ | ||
| 32 | + Set<String> getNames(); | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * Registers sprite data under the specified name. | ||
| 36 | + * | ||
| 37 | + * @param name sprite definition name | ||
| 38 | + * @param spriteData sprite data | ||
| 39 | + */ | ||
| 40 | + void put(String name, JsonNode spriteData); | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * Returns the sprite definition registered under the given name. | ||
| 44 | + * | ||
| 45 | + * @param name sprite definition name | ||
| 46 | + * @return sprite data | ||
| 47 | + */ | ||
| 48 | + JsonNode get(String name); | ||
| 49 | + | ||
| 50 | +} |
| ... | @@ -15,16 +15,21 @@ | ... | @@ -15,16 +15,21 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.ui.impl; | 16 | package org.onosproject.ui.impl; |
| 17 | 17 | ||
| 18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 18 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import com.fasterxml.jackson.databind.node.ArrayNode; | 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 21 | import org.onlab.rest.BaseResource; | 22 | import org.onlab.rest.BaseResource; |
| 22 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
| 23 | 24 | ||
| 25 | +import javax.ws.rs.Consumes; | ||
| 24 | import javax.ws.rs.GET; | 26 | import javax.ws.rs.GET; |
| 27 | +import javax.ws.rs.POST; | ||
| 25 | import javax.ws.rs.Path; | 28 | import javax.ws.rs.Path; |
| 26 | import javax.ws.rs.Produces; | 29 | import javax.ws.rs.Produces; |
| 27 | import javax.ws.rs.core.Response; | 30 | import javax.ws.rs.core.Response; |
| 31 | +import java.io.IOException; | ||
| 32 | +import java.io.InputStream; | ||
| 28 | import java.util.Map; | 33 | import java.util.Map; |
| 29 | 34 | ||
| 30 | import static org.slf4j.LoggerFactory.getLogger; | 35 | import static org.slf4j.LoggerFactory.getLogger; |
| ... | @@ -39,8 +44,7 @@ public class TopologyResource extends BaseResource { | ... | @@ -39,8 +44,7 @@ public class TopologyResource extends BaseResource { |
| 39 | 44 | ||
| 40 | private final ObjectMapper mapper = new ObjectMapper(); | 45 | private final ObjectMapper mapper = new ObjectMapper(); |
| 41 | 46 | ||
| 42 | - | 47 | + @Path("geoloc") |
| 43 | - @Path("/geoloc") | ||
| 44 | @GET | 48 | @GET |
| 45 | @Produces("application/json") | 49 | @Produces("application/json") |
| 46 | public Response getGeoLocations() { | 50 | public Response getGeoLocations() { |
| ... | @@ -77,4 +81,14 @@ public class TopologyResource extends BaseResource { | ... | @@ -77,4 +81,14 @@ public class TopologyResource extends BaseResource { |
| 77 | } | 81 | } |
| 78 | } | 82 | } |
| 79 | 83 | ||
| 84 | + @Path("sprites") | ||
| 85 | + @POST | ||
| 86 | + @Consumes("application/json") | ||
| 87 | + public Response setSprites(InputStream stream) throws IOException { | ||
| 88 | + JsonNode root = mapper.readTree(stream); | ||
| 89 | + String name = root.path("defn_id").asText("sprites"); | ||
| 90 | + get(SpriteService.class).put(name, root); | ||
| 91 | + return Response.ok().build(); | ||
| 92 | + } | ||
| 93 | + | ||
| 80 | } | 94 | } | ... | ... |
| ... | @@ -145,7 +145,9 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -145,7 +145,9 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
| 145 | "cancelTraffic", | 145 | "cancelTraffic", |
| 146 | "requestSummary", | 146 | "requestSummary", |
| 147 | "cancelSummary", | 147 | "cancelSummary", |
| 148 | - "equalizeMasters" | 148 | + "equalizeMasters", |
| 149 | + "spriteListRequest", | ||
| 150 | + "spriteDataRequest" | ||
| 149 | )); | 151 | )); |
| 150 | } | 152 | } |
| 151 | 153 | ||
| ... | @@ -211,6 +213,11 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -211,6 +213,11 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
| 211 | } else if (type.equals("equalizeMasters")) { | 213 | } else if (type.equals("equalizeMasters")) { |
| 212 | equalizeMasters(event); | 214 | equalizeMasters(event); |
| 213 | 215 | ||
| 216 | + } else if (type.equals("spriteListRequest")) { | ||
| 217 | + sendSpriteList(event); | ||
| 218 | + } else if (type.equals("spriteDataRequest")) { | ||
| 219 | + sendSpriteData(event); | ||
| 220 | + | ||
| 214 | } else if (type.equals("topoStart")) { | 221 | } else if (type.equals("topoStart")) { |
| 215 | sendAllInitialData(); | 222 | sendAllInitialData(); |
| 216 | } else if (type.equals("topoStop")) { | 223 | } else if (type.equals("topoStop")) { |
| ... | @@ -563,6 +570,22 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -563,6 +570,22 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
| 563 | directory.get(MastershipAdminService.class).balanceRoles(); | 570 | directory.get(MastershipAdminService.class).balanceRoles(); |
| 564 | } | 571 | } |
| 565 | 572 | ||
| 573 | + // Sends a list of sprite names. | ||
| 574 | + private void sendSpriteList(ObjectNode event) { | ||
| 575 | + ObjectNode root = mapper.createObjectNode(); | ||
| 576 | + ArrayNode names = mapper.createArrayNode(); | ||
| 577 | + get(SpriteService.class).getNames().forEach(names::add); | ||
| 578 | + root.set("names", names); | ||
| 579 | + sendMessage(envelope("spriteListResponse", number(event, "sid"), root)); | ||
| 580 | + } | ||
| 581 | + | ||
| 582 | + // Sends requested sprite data. | ||
| 583 | + private void sendSpriteData(ObjectNode event) { | ||
| 584 | + ObjectNode root = mapper.createObjectNode(); | ||
| 585 | + root.set("defn", get(SpriteService.class).get(event.path("payload").path("name").asText())); | ||
| 586 | + sendMessage(envelope("spriteDataResponse", number(event, "sid"), root)); | ||
| 587 | + } | ||
| 588 | + | ||
| 566 | 589 | ||
| 567 | // Adds all internal listeners. | 590 | // Adds all internal listeners. |
| 568 | private void addListeners() { | 591 | private void addListeners() { | ... | ... |
| ... | @@ -15,7 +15,9 @@ | ... | @@ -15,7 +15,9 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.ui.impl; | 16 | package org.onosproject.ui.impl; |
| 17 | 17 | ||
| 18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 18 | import com.google.common.collect.ImmutableList; | 19 | import com.google.common.collect.ImmutableList; |
| 20 | +import com.google.common.collect.ImmutableSet; | ||
| 19 | import com.google.common.collect.Lists; | 21 | import com.google.common.collect.Lists; |
| 20 | import com.google.common.collect.Maps; | 22 | import com.google.common.collect.Maps; |
| 21 | import org.apache.felix.scr.annotations.Activate; | 23 | import org.apache.felix.scr.annotations.Activate; |
| ... | @@ -31,6 +33,7 @@ import org.slf4j.LoggerFactory; | ... | @@ -31,6 +33,7 @@ import org.slf4j.LoggerFactory; |
| 31 | 33 | ||
| 32 | import java.util.List; | 34 | import java.util.List; |
| 33 | import java.util.Map; | 35 | import java.util.Map; |
| 36 | +import java.util.Set; | ||
| 34 | 37 | ||
| 35 | import static com.google.common.collect.ImmutableList.of; | 38 | import static com.google.common.collect.ImmutableList.of; |
| 36 | import static java.util.stream.Collectors.toSet; | 39 | import static java.util.stream.Collectors.toSet; |
| ... | @@ -40,7 +43,7 @@ import static java.util.stream.Collectors.toSet; | ... | @@ -40,7 +43,7 @@ import static java.util.stream.Collectors.toSet; |
| 40 | */ | 43 | */ |
| 41 | @Component(immediate = true) | 44 | @Component(immediate = true) |
| 42 | @Service | 45 | @Service |
| 43 | -public class UiExtensionManager implements UiExtensionService { | 46 | +public class UiExtensionManager implements UiExtensionService, SpriteService { |
| 44 | 47 | ||
| 45 | private final Logger log = LoggerFactory.getLogger(getClass()); | 48 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 46 | 49 | ||
| ... | @@ -115,4 +118,25 @@ public class UiExtensionManager implements UiExtensionService { | ... | @@ -115,4 +118,25 @@ public class UiExtensionManager implements UiExtensionService { |
| 115 | public synchronized UiExtension getViewExtension(String viewId) { | 118 | public synchronized UiExtension getViewExtension(String viewId) { |
| 116 | return views.get(viewId); | 119 | return views.get(viewId); |
| 117 | } | 120 | } |
| 121 | + | ||
| 122 | + | ||
| 123 | + // Provisional tracking of sprite definitions | ||
| 124 | + private Map<String, JsonNode> sprites = Maps.newHashMap(); | ||
| 125 | + | ||
| 126 | + @Override | ||
| 127 | + public Set<String> getNames() { | ||
| 128 | + return ImmutableSet.copyOf(sprites.keySet()); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Override | ||
| 132 | + public void put(String name, JsonNode spriteData) { | ||
| 133 | + log.info("Registered sprite definition {}", name); | ||
| 134 | + sprites.put(name, spriteData); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Override | ||
| 138 | + public JsonNode get(String name) { | ||
| 139 | + return sprites.get(name); | ||
| 140 | + } | ||
| 141 | + | ||
| 118 | } | 142 | } | ... | ... |
| ... | @@ -86,6 +86,8 @@ | ... | @@ -86,6 +86,8 @@ |
| 86 | openListener = wss.addOpenListener(wsOpen); | 86 | openListener = wss.addOpenListener(wsOpen); |
| 87 | wss.bindHandlers(handlerMap); | 87 | wss.bindHandlers(handlerMap); |
| 88 | wss.sendEvent('topoStart'); | 88 | wss.sendEvent('topoStart'); |
| 89 | + wss.sendEvent('spriteListRequest'); | ||
| 90 | + wss.sendEvent('spriteDataRequest', {name: 'sample'}); | ||
| 89 | $log.debug('topo comms started'); | 91 | $log.debug('topo comms started'); |
| 90 | } | 92 | } |
| 91 | 93 | ... | ... |
-
Please register or login to post a comment