Search in sources :

Example 6 with UiExtensionService

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();
}
Also used : SequenceInputStream(java.io.SequenceInputStream) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UiExtensionService(org.onosproject.ui.UiExtensionService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with UiExtensionService

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());
}
Also used : UiMessageHandlerFactory(org.onosproject.ui.UiMessageHandlerFactory) UiMessageHandler(org.onosproject.ui.UiMessageHandler) Topo2OverlayCache(org.onosproject.ui.impl.topo.Topo2OverlayCache) HashMap(java.util.HashMap) UiExtensionService(org.onosproject.ui.UiExtensionService) ServiceNotFoundException(org.onlab.osgi.ServiceNotFoundException) IOException(java.io.IOException)

Example 8 with UiExtensionService

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);
}
Also used : UiGlyph(org.onosproject.ui.UiGlyph) ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UiExtensionService(org.onosproject.ui.UiExtensionService) ControllerNode(org.onosproject.cluster.ControllerNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 9 with UiExtensionService

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);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UiExtensionService(org.onosproject.ui.UiExtensionService)

Example 10 with UiExtensionService

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();
}
Also used : UiExtension(org.onosproject.ui.UiExtension) UiExtensionService(org.onosproject.ui.UiExtensionService) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

UiExtensionService (org.onosproject.ui.UiExtensionService)11 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 SequenceInputStream (java.io.SequenceInputStream)4 Path (javax.ws.rs.Path)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ServiceNotFoundException (org.onlab.osgi.ServiceNotFoundException)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 UiExtension (org.onosproject.ui.UiExtension)2 UiSessionToken (org.onosproject.ui.UiSessionToken)2 UiTokenService (org.onosproject.ui.UiTokenService)2 UiTopoMapFactory (org.onosproject.ui.UiTopoMapFactory)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 IpAddress (org.onlab.packet.IpAddress)1 ClusterService (org.onosproject.cluster.ClusterService)1