Search in sources :

Example 1 with UiExtensionService

use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.

the class MainIndexResource method getMainIndex.

@GET
@Produces(MediaType.TEXT_HTML)
@Path("/index.html")
public Response getMainIndex() throws IOException {
    ClassLoader classLoader = getClass().getClassLoader();
    UiExtensionService service;
    UiTokenService tokens;
    try {
        service = get(UiExtensionService.class);
        tokens = get(UiTokenService.class);
    } catch (ServiceNotFoundException e) {
        return Response.ok(classLoader.getResourceAsStream(NOT_READY)).build();
    }
    InputStream indexTemplate = classLoader.getResourceAsStream(INDEX);
    String index = new String(toByteArray(indexTemplate));
    int p0s = split(index, 0, INJECT_USER_START) - INJECT_USER_START.length();
    int p0e = split(index, p0s, INJECT_USER_END);
    int p1s = split(index, p0e, INJECT_JS_START) - INJECT_JS_START.length();
    int p1e = split(index, p1s, INJECT_JS_END);
    int p2s = split(index, p1e, INJECT_CSS_START) - INJECT_CSS_START.length();
    int p2e = split(index, p2s, INJECT_CSS_END);
    int p3s = split(index, p2e, null);
    // FIXME: use global opaque auth token to allow secure failover
    // for now, just use the user principal name...
    String userName = ctx.getUserPrincipal().getName();
    // get a session token to use for UI-web-socket authentication
    UiSessionToken token = tokens.issueToken(userName);
    String auth = "var onosUser='" + userName + "',\n" + "    onosAuth='" + token + "';\n";
    StreamEnumeration streams = new StreamEnumeration(of(stream(index, 0, p0s), new ByteArrayInputStream(SCRIPT_START), stream(auth, 0, auth.length()), userPreferences(userName), userConsoleLog(userName), new ByteArrayInputStream(SCRIPT_END), stream(index, p0e, p1s), includeJs(service), stream(index, p1e, p2s), includeCss(service), stream(index, p2e, p3s)));
    return Response.ok(new SequenceInputStream(streams)).build();
}
Also used : SequenceInputStream(java.io.SequenceInputStream) UiTokenService(org.onosproject.ui.UiTokenService) ByteArrayInputStream(java.io.ByteArrayInputStream) ServiceNotFoundException(org.onlab.osgi.ServiceNotFoundException) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UiExtensionService(org.onosproject.ui.UiExtensionService) UiSessionToken(org.onosproject.ui.UiSessionToken) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with UiExtensionService

use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.

the class MainModuleResource method getMainModule.

@GET
@Produces(SCRIPT)
public Response getMainModule() throws IOException {
    UiExtensionService service = get(UiExtensionService.class);
    InputStream jsTemplate = getClass().getClassLoader().getResourceAsStream(MAIN_JS);
    String js = new String(toByteArray(jsTemplate));
    int p1s = split(js, 0, INJECT_VIEW_IDS_START) - INJECT_VIEW_IDS_START.length();
    int p1e = split(js, 0, INJECT_VIEW_IDS_END);
    int p2s = split(js, p1e, null);
    StreamEnumeration streams = new StreamEnumeration(of(stream(js, 0, p1s), includeViewIds(service), stream(js, 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 3 with UiExtensionService

use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.

the class MapSelectorMessageHandler method mapsJson.

private ObjectNode mapsJson() {
    ObjectNode payload = objectNode();
    ArrayNode order = arrayNode();
    ObjectNode maps = objectNode();
    payload.set(ORDER, order);
    payload.set(MAPS, maps);
    UiExtensionService service = get(UiExtensionService.class);
    service.getExtensions().forEach(ext -> {
        UiTopoMapFactory mapFactory = ext.topoMapFactory();
        if (mapFactory != null) {
            List<UiTopoMap> topoMaps = mapFactory.geoMaps();
            topoMaps.forEach(m -> {
                maps.set(m.id(), objectNode().put(MAP_ID, m.id()).put(DESCRIPTION, m.description()).put(FILE_PATH, m.filePath()).put(SCALE, m.scale()));
                order.add(m.id());
            });
        }
    });
    return payload;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UiExtensionService(org.onosproject.ui.UiExtensionService) UiTopoMap(org.onosproject.ui.UiTopoMap) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UiTopoMapFactory(org.onosproject.ui.UiTopoMapFactory)

Example 4 with UiExtensionService

use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.

the class MainIndexResource method getMainIndex.

@GET
@Produces(MediaType.TEXT_HTML)
@Path("/index.html")
public Response getMainIndex() throws IOException {
    ClassLoader classLoader = getClass().getClassLoader();
    UiExtensionService service;
    UiTokenService tokens;
    try {
        service = get(UiExtensionService.class);
        tokens = get(UiTokenService.class);
    } catch (ServiceNotFoundException e) {
        return Response.ok(classLoader.getResourceAsStream(NOT_READY)).build();
    }
    InputStream indexTemplate = classLoader.getResourceAsStream(INDEX);
    String index = new String(toByteArray(indexTemplate));
    int p0s = split(index, 0, INJECT_USER_START) - INJECT_USER_START.length();
    int p0e = split(index, p0s, INJECT_USER_END);
    int p3s = split(index, p0e, null);
    // FIXME: use global opaque auth token to allow secure failover
    // for now, just use the user principal name...
    String userName = ctx.getUserPrincipal().getName();
    // get a session token to use for UI-web-socket authentication
    UiSessionToken token = tokens.issueToken(userName);
    String auth = "var onosUser='" + userName + "',\n" + "    onosAuth='" + token + "';\n";
    StreamEnumeration streams = new StreamEnumeration(of(stream(index, 0, p0s), new ByteArrayInputStream(SCRIPT_START), stream(auth, 0, auth.length()), userPreferences(userName), userConsoleLog(userName), new ByteArrayInputStream(SCRIPT_END), stream(index, p0e, p3s)));
    return Response.ok(new SequenceInputStream(streams)).build();
}
Also used : SequenceInputStream(java.io.SequenceInputStream) UiTokenService(org.onosproject.ui.UiTokenService) ByteArrayInputStream(java.io.ByteArrayInputStream) ServiceNotFoundException(org.onlab.osgi.ServiceNotFoundException) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UiExtensionService(org.onosproject.ui.UiExtensionService) UiSessionToken(org.onosproject.ui.UiSessionToken) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with UiExtensionService

use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.

the class NavResource method getNavigation.

@GET
@Path("uiextensions")
@Produces(MediaType.APPLICATION_JSON)
public Response getNavigation() throws JsonProcessingException {
    UiExtensionService service = get(UiExtensionService.class);
    UiViewSerializer serializer = new UiViewSerializer(UiView.class);
    ObjectMapper mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule("UiViewSerializer");
    module.addSerializer(serializer);
    mapper.registerModule(module);
    StringBuilder sb = new StringBuilder("[");
    boolean first = true;
    for (UiExtension uiExt : service.getExtensions()) {
        for (UiView view : uiExt.views()) {
            if (first) {
                first = false;
            } else {
                sb.append(",");
            }
            sb.append(mapper.writeValueAsString(view));
        }
    }
    sb.append("]");
    return ok(sb.toString()).build();
}
Also used : UiView(org.onosproject.ui.UiView) UiExtension(org.onosproject.ui.UiExtension) UiExtensionService(org.onosproject.ui.UiExtensionService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) 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