Search in sources :

Example 1 with ContainerProxyRequest

use of eu.openanalytics.shinyproxy.container.ContainerProxyRequest in project shinyproxy by openanalytics.

the class ProxyService method startProxy.

private IContainerProxy startProxy(String userName, String appName) {
    ShinyApp app = appService.getApp(appName);
    if (app == null) {
        throw new ShinyProxyException("Cannot start container: unknown application: " + appName);
    }
    if (findProxy(userName, appName) != null) {
        throw new ShinyProxyException("Cannot start container: user " + userName + " already has an active proxy for " + appName);
    }
    ContainerProxyRequest request = new ContainerProxyRequest();
    request.userId = userName;
    request.app = app;
    IContainerProxy proxy = backend.createProxy(request);
    activeProxies.add(proxy);
    try {
        backend.startProxy(proxy);
    } finally {
        if (proxy.getStatus() != ContainerProxyStatus.Up)
            activeProxies.remove(proxy);
    }
    try {
        URI target = new URI(proxy.getTarget());
        synchronized (mappingListeners) {
            for (MappingListener listener : mappingListeners) {
                listener.mappingAdded(proxy.getName(), target);
            }
        }
    } catch (URISyntaxException ignore) {
    }
    if (logService.isContainerLoggingEnabled()) {
        BiConsumer<File, File> outputAttacher = backend.getOutputAttacher(proxy);
        if (outputAttacher == null) {
            log.warn("Cannot log container output: " + backend.getClass() + " does not support output attaching.");
        } else {
            logService.attachToOutput(proxy, outputAttacher);
        }
    }
    log.info(String.format("Proxy activated [user: %s] [app: %s]", userName, appName));
    eventService.post(EventType.AppStart.toString(), userName, appName);
    return proxy;
}
Also used : ContainerProxyRequest(eu.openanalytics.shinyproxy.container.ContainerProxyRequest) IContainerProxy(eu.openanalytics.shinyproxy.container.IContainerProxy) ShinyProxyException(eu.openanalytics.shinyproxy.ShinyProxyException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) ShinyApp(eu.openanalytics.shinyproxy.services.AppService.ShinyApp)

Aggregations

ShinyProxyException (eu.openanalytics.shinyproxy.ShinyProxyException)1 ContainerProxyRequest (eu.openanalytics.shinyproxy.container.ContainerProxyRequest)1 IContainerProxy (eu.openanalytics.shinyproxy.container.IContainerProxy)1 ShinyApp (eu.openanalytics.shinyproxy.services.AppService.ShinyApp)1 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1