use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.
the class MainNavResource method getNavigation.
@GET
@Produces(MediaType.TEXT_HTML)
public Response getNavigation() throws IOException {
UiExtensionService service = get(UiExtensionService.class);
InputStream navTemplate = getClass().getClassLoader().getResourceAsStream(NAV_HTML);
String html = new String(toByteArray(navTemplate));
int p1s = split(html, 0, INJECT_VIEW_ITEMS_START);
int p1e = split(html, 0, INJECT_VIEW_ITEMS_END);
int p2s = split(html, p1e, null);
StreamEnumeration streams = new StreamEnumeration(of(stream(html, 0, p1s), includeNavItems(service), stream(html, p1e, p2s)));
return Response.ok(new SequenceInputStream(streams)).build();
}
use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.
the class UiWebSocket method createHandlersAndOverlays.
// Creates new message handlers.
private synchronized void createHandlersAndOverlays() {
log.debug("Creating handlers and overlays...");
handlers = new HashMap<>();
overlayCache = new TopoOverlayCache();
overlay2Cache = new Topo2OverlayCache();
Map<Class<?>, UiMessageHandler> handlerInstances = new HashMap<>();
UiExtensionService service = directory.get(UiExtensionService.class);
lionBundleMap = generateLionMap(service);
service.getExtensions().forEach(ext -> {
UiMessageHandlerFactory factory = ext.messageHandlerFactory();
if (factory != null) {
factory.newHandlers().forEach(handler -> {
try {
handler.init(this, directory);
injectLionBundles(handler, lionBundleMap);
handler.messageTypes().forEach(type -> handlers.put(type, handler));
handlerInstances.put(handler.getClass(), handler);
} catch (Exception e) {
log.warn("Unable to setup handler {} due to", handler, e);
}
});
}
registerOverlays(ext);
});
handlerCrossConnects(handlerInstances);
overlay2Cache.switchOverlay(null, Traffic2Overlay.OVERLAY_ID);
log.debug("#handlers = {}, #overlays = Topo: {}, Topo2: {}", handlers.size(), overlayCache.size(), overlay2Cache.size());
}
use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.
the class UiWebSocket method sendBootstrapData.
// Sends initial information (username and cluster member information)
// to allow GUI to display logged-in user, and to be able to
// fail-over to an alternate cluster member if necessary.
private void sendBootstrapData() {
ClusterService service = directory.get(ClusterService.class);
ArrayNode instances = arrayNode();
for (ControllerNode node : service.getNodes()) {
IpAddress nodeIp = node.ip();
ObjectNode instance = objectNode().put(ID, node.id().toString()).put(IP, nodeIp != null ? nodeIp.toString() : node.host()).put(GlyphConstants.UI_ATTACHED, node.equals(service.getLocalNode()));
instances.add(instance);
}
ArrayNode glyphInstances = arrayNode();
UiExtensionService uiExtensionService = directory.get(UiExtensionService.class);
for (UiGlyph glyph : uiExtensionService.getGlyphs()) {
ObjectNode glyphInstance = objectNode().put(GlyphConstants.ID, glyph.id()).put(GlyphConstants.VIEWBOX, glyph.viewbox()).put(GlyphConstants.PATH, glyph.path());
glyphInstances.add(glyphInstance);
}
ObjectNode payload = objectNode();
payload.set(CLUSTER_NODES, instances);
payload.set(GLYPHS, glyphInstances);
payload.put(USER, userName);
sendMessage(BOOTSTRAP, payload);
}
use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.
the class UiWebSocket method sendUberLionBundle.
// sends the collated localization bundle data up to the client.
private void sendUberLionBundle() {
UiExtensionService service = directory.get(UiExtensionService.class);
ObjectNode lion = objectNode();
service.getExtensions().forEach(ext -> {
ext.lionBundles().forEach(lb -> {
ObjectNode lionMap = objectNode();
lb.getItems().forEach(item -> lionMap.put(item.key(), item.value()));
lion.set(lb.id(), lionMap);
});
});
ObjectNode payload = objectNode();
payload.set(LION, lion);
payload.put(LOCALE, Locale.getDefault().toString());
sendMessage(UBERLION, payload);
}
use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.
the class MainViewResource method getViewResource.
@Path("{view}/{resource}")
@GET
public Response getViewResource(@PathParam("view") String viewId, @PathParam("resource") String resource) throws IOException {
UiExtensionService service = get(UiExtensionService.class);
UiExtension extension = service.getViewExtension(viewId);
return extension != null ? Response.ok(extension.resource(viewId, resource)).header(CONTENT_TYPE, contentType(resource)).build() : Response.status(Response.Status.NOT_FOUND).build();
}
Aggregations