Search in sources :

Example 1 with Directory

use of org.restlet.resource.Directory in project pinot by linkedin.

the class ControllerRestApplication method configureRouter.

protected void configureRouter(Router router) {
    // Remove server-side HTTP timeout (see http://stackoverflow.com/questions/12943447/restlet-server-socket-timeout)
    getContext().getParameters().add("maxIoIdleTimeMs", ONE_HOUR_IN_MILLIS);
    getContext().getParameters().add("ioMaxIdleTimeMs", ONE_HOUR_IN_MILLIS);
    router.setDefaultMatchingMode(Template.MODE_EQUALS);
    /**
     * Start Routers 2.0
     */
    attachRoutesForClass(router, PinotTenantRestletResource.class);
    attachRoutesForClass(router, PinotSchemaRestletResource.class);
    attachRoutesForClass(router, PinotTableRestletResource.class);
    // GET
    attachRoutesForClass(router, PinotTableInstances.class);
    attachRoutesForClass(router, PinotTableSchema.class);
    attachRoutesForClass(router, PinotSegmentRestletResource.class);
    attachRoutesForClass(router, TableSize.class);
    // PUT
    attachRoutesForClass(router, PinotTableSegmentConfigs.class);
    attachRoutesForClass(router, PinotTableIndexingConfigs.class);
    attachRoutesForClass(router, PinotTableTenantConfigs.class);
    attachRoutesForClass(router, PinotTableMetadataConfigs.class);
    // Uploading Downloading segments
    attachRoutesForClass(router, PinotSegmentUploadRestletResource.class);
    attachRoutesForClass(router, PinotVersionRestletResource.class);
    // SegmentCompletionProtocol implementation on the controller
    attachRoutesForClass(router, LLCSegmentCommit.class);
    attachRoutesForClass(router, LLCSegmentConsumed.class);
    attachRoutesForClass(router, LLCSegmentStoppedConsuming.class);
    // GET... add it here because it can block visibility of
    // some of the existing paths (like indexingConfigs) added above
    attachRoutesForClass(router, TableViews.class);
    router.attach("/api", SwaggerResource.class);
    /**
     *  End Routes 2.0
     */
    attachRoutesForClass(router, PinotInstanceRestletResource.class);
    router.attach("/pinot-controller/admin", PinotControllerHealthCheck.class);
    router.attach("/pql", PqlQueryResource.class);
    try {
        final Directory webdir = new Directory(getContext(), CONSOLE_WEBAPP_ROOT_PATH);
        webdir.setDeeplyAccessible(true);
        webdir.setIndexName("index.html");
        router.attach("/query", webdir);
    } catch (Exception e) {
        LOGGER.warn("Failed to initialize route for /query", e);
    }
    try {
        final Directory swaggerIndexDir = new Directory(getContext(), getClass().getClassLoader().getResource("swagger-ui").toString());
        swaggerIndexDir.setIndexName("index.html");
        swaggerIndexDir.setDeeplyAccessible(true);
        router.attach("/swagger-ui", swaggerIndexDir);
    } catch (Exception e) {
        LOGGER.warn("Failed to initialize route for /swagger-ui", e);
    }
    try {
        final Directory swaggerUiDir = new Directory(getContext(), getClass().getClassLoader().getResource("META-INF/resources/webjars/swagger-ui/2.2.2").toString());
        swaggerUiDir.setDeeplyAccessible(true);
        router.attach("/swaggerui-dist", swaggerUiDir);
    } catch (Exception e) {
        LOGGER.warn("Failed to initialize route for /swaggerui-dist", e);
    }
    try {
        final Redirector redirector = new Redirector(getContext(), "/swagger-ui/index.html?url=/api", Redirector.MODE_CLIENT_TEMPORARY);
        router.attach("/help", redirector);
    } catch (Exception e) {
        LOGGER.warn("Failed to initialize route for /help", e);
    }
    try {
        final Directory landing = new Directory(getContext(), getClass().getClassLoader().getResource("landing").toString());
        landing.setDeeplyAccessible(false);
        landing.setIndexName("index.html");
        router.attach("/", landing);
    } catch (Exception e) {
        LOGGER.warn("Failed to initialize route for /", e);
    }
}
Also used : Directory(org.restlet.resource.Directory) Redirector(org.restlet.routing.Redirector)

Example 2 with Directory

use of org.restlet.resource.Directory in project pinot by linkedin.

the class StarTreeJsonNode method startServer.

private void startServer(final File segmentDirectory, final String json) throws Exception {
    Component component = new Component();
    int port = 8090;
    component.getServers().add(Protocol.HTTP, port);
    component.getClients().add(Protocol.FILE);
    Application application = new Application() {

        @Override
        public Restlet createInboundRoot() {
            Router router = new Router(getContext());
            StarTreeViewRestResource.json = json;
            router.attach("/data", StarTreeViewRestResource.class);
            Directory directory = new Directory(getContext(), getClass().getClassLoader().getResource("star-tree.html").toString());
            router.attach(directory);
            return router;
        }
    };
    VirtualHost defaultHost = component.getDefaultHost();
    defaultHost.attach(application);
    component.start();
    LOGGER.info("Go to http://{}:{}/  to view the star tree", VirtualHost.getLocalHostName(), port);
}
Also used : Router(org.restlet.routing.Router) VirtualHost(org.restlet.routing.VirtualHost) Component(org.restlet.Component) Application(org.restlet.Application) Directory(org.restlet.resource.Directory)

Aggregations

Directory (org.restlet.resource.Directory)2 Application (org.restlet.Application)1 Component (org.restlet.Component)1 Redirector (org.restlet.routing.Redirector)1 Router (org.restlet.routing.Router)1 VirtualHost (org.restlet.routing.VirtualHost)1