Search in sources :

Example 1 with HttpProbeConfig

use of org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig in project che-server by eclipse-che.

the class TerminalServerLivenessProbeConfigFactory method get.

@Override
public HttpProbeConfig get(String userId, String workspaceId, Server server) throws InternalInfrastructureException {
    URI uri;
    try {
        uri = new URI(server.getUrl());
    } catch (URISyntaxException e) {
        throw new InternalInfrastructureException("Terminal agent server liveness probe url is invalid. Error: " + e.getMessage());
    }
    String protocol;
    if ("wss".equals(uri.getScheme())) {
        protocol = "https";
    } else {
        protocol = "http";
    }
    int port;
    if (uri.getPort() == -1) {
        if ("http".equals(protocol)) {
            port = 80;
        } else {
            port = 443;
        }
    } else {
        port = uri.getPort();
    }
    String path = uri.getPath().replaceFirst("/pty$", "/liveness");
    return new HttpProbeConfig(port, uri.getHost(), protocol, path, null, successThreshold, 3, 120, 10, 10);
}
Also used : URISyntaxException(java.net.URISyntaxException) HttpProbeConfig(org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig) URI(java.net.URI) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Example 2 with HttpProbeConfig

use of org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig in project devspaces-images by redhat-developer.

the class TerminalServerLivenessProbeConfigFactory method get.

@Override
public HttpProbeConfig get(String userId, String workspaceId, Server server) throws InternalInfrastructureException {
    URI uri;
    try {
        uri = new URI(server.getUrl());
    } catch (URISyntaxException e) {
        throw new InternalInfrastructureException("Terminal agent server liveness probe url is invalid. Error: " + e.getMessage());
    }
    String protocol;
    if ("wss".equals(uri.getScheme())) {
        protocol = "https";
    } else {
        protocol = "http";
    }
    int port;
    if (uri.getPort() == -1) {
        if ("http".equals(protocol)) {
            port = 80;
        } else {
            port = 443;
        }
    } else {
        port = uri.getPort();
    }
    String path = uri.getPath().replaceFirst("/pty$", "/liveness");
    return new HttpProbeConfig(port, uri.getHost(), protocol, path, null, successThreshold, 3, 120, 10, 10);
}
Also used : URISyntaxException(java.net.URISyntaxException) HttpProbeConfig(org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig) URI(java.net.URI) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Example 3 with HttpProbeConfig

use of org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig in project devspaces-images by redhat-developer.

the class WsAgentServerLivenessProbeConfigFactory method get.

@Override
public HttpProbeConfig get(String userId, String workspaceId, Server server) throws InternalInfrastructureException {
    try {
        // add check path
        URI uri = UriBuilder.fromUri(server.getUrl()).path("/liveness").build();
        int port;
        if (uri.getPort() == -1) {
            if ("http".equals(uri.getScheme())) {
                port = 80;
            } else {
                port = 443;
            }
        } else {
            port = uri.getPort();
        }
        return new HttpProbeConfig(port, uri.getHost(), uri.getScheme(), uri.getPath(), singletonMap(HttpHeaders.AUTHORIZATION, "Bearer " + machineTokenProvider.getToken(userId, workspaceId)), successThreshold, 3, 120, 10, 10);
    } catch (MachineTokenException e) {
        throw new InternalInfrastructureException("Failed to retrieve workspace token for ws-agent server liveness probe. Error: " + e.getMessage());
    } catch (UriBuilderException e) {
        throw new InternalInfrastructureException("Wsagent server liveness probe url is invalid. Error: " + e.getMessage());
    }
}
Also used : MachineTokenException(org.eclipse.che.api.workspace.server.token.MachineTokenException) HttpProbeConfig(org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig) UriBuilderException(jakarta.ws.rs.core.UriBuilderException) URI(java.net.URI) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Example 4 with HttpProbeConfig

use of org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig in project che-server by eclipse-che.

the class WsAgentServerLivenessProbeConfigFactory method get.

@Override
public HttpProbeConfig get(String userId, String workspaceId, Server server) throws InternalInfrastructureException {
    try {
        // add check path
        URI uri = UriBuilder.fromUri(server.getUrl()).path("/liveness").build();
        int port;
        if (uri.getPort() == -1) {
            if ("http".equals(uri.getScheme())) {
                port = 80;
            } else {
                port = 443;
            }
        } else {
            port = uri.getPort();
        }
        return new HttpProbeConfig(port, uri.getHost(), uri.getScheme(), uri.getPath(), singletonMap(HttpHeaders.AUTHORIZATION, "Bearer " + machineTokenProvider.getToken(userId, workspaceId)), successThreshold, 3, 120, 10, 10);
    } catch (MachineTokenException e) {
        throw new InternalInfrastructureException("Failed to retrieve workspace token for ws-agent server liveness probe. Error: " + e.getMessage());
    } catch (UriBuilderException e) {
        throw new InternalInfrastructureException("Wsagent server liveness probe url is invalid. Error: " + e.getMessage());
    }
}
Also used : MachineTokenException(org.eclipse.che.api.workspace.server.token.MachineTokenException) HttpProbeConfig(org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig) UriBuilderException(jakarta.ws.rs.core.UriBuilderException) URI(java.net.URI) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Aggregations

URI (java.net.URI)4 HttpProbeConfig (org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig)4 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)4 UriBuilderException (jakarta.ws.rs.core.UriBuilderException)2 URISyntaxException (java.net.URISyntaxException)2 MachineTokenException (org.eclipse.che.api.workspace.server.token.MachineTokenException)2