Search in sources :

Example 1 with InternalInfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.

the class KubernetesPersistentVolumeClaims method waitBound.

/**
 * Waits until persistent volume claim state is bound. If used k8s Storage Class has
 * 'volumeBindingMode: WaitForFirstConsumer', we don't wait to avoid deadlock.
 *
 * @param name name of persistent volume claim that should be watched
 * @param timeoutMillis waiting timeout in milliseconds
 * @return persistent volume claim that is bound or in waiting for consumer state
 * @throws InfrastructureException when specified timeout is reached
 * @throws InfrastructureException when {@link Thread} is interrupted while waiting
 * @throws InfrastructureException when any other exception occurs
 */
public PersistentVolumeClaim waitBound(String name, long timeoutMillis) throws InfrastructureException {
    try {
        Resource<PersistentVolumeClaim> pvcResource = clientFactory.create(workspaceId).persistentVolumeClaims().inNamespace(namespace).withName(name);
        PersistentVolumeClaim actualPvc = pvcResource.get();
        if (actualPvc.getStatus().getPhase().equals(PVC_BOUND_PHASE)) {
            return actualPvc;
        }
        CompletableFuture<PersistentVolumeClaim> future = new CompletableFuture<>();
        // any of these watchers can finish the operation resolving the future
        try (Watch boundWatcher = pvcIsBoundWatcher(future, pvcResource);
            Watch waitingWatcher = pvcIsWaitingForConsumerWatcher(future, actualPvc)) {
            return future.get(timeoutMillis, TimeUnit.MILLISECONDS);
        } catch (ExecutionException e) {
            // should take a look.
            throw new InternalInfrastructureException(e.getCause().getMessage(), e);
        } catch (TimeoutException e) {
            // issues that admin should take a look.
            throw new InternalInfrastructureException("Waiting for persistent volume claim '" + name + "' reached timeout");
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new InfrastructureException("Waiting for persistent volume claim '" + name + "' was interrupted");
        }
    } catch (KubernetesClientException e) {
        throw new KubernetesInfrastructureException(e);
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Watch(io.fabric8.kubernetes.client.Watch) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) ExecutionException(java.util.concurrent.ExecutionException) KubernetesInfrastructureException(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) KubernetesInfrastructureException(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) TimeoutException(java.util.concurrent.TimeoutException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 2 with InternalInfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException 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 3 with InternalInfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.

the class ServersChecker method getChecker.

private ServerChecker getChecker(String serverRef, Server server) throws InfrastructureException {
    // TODO replace with correct behaviour
    // workaround needed because we don't have server readiness check in the model
    // Create server readiness endpoint URL
    URL url;
    String token;
    try {
        String serverUrl = server.getUrl();
        if ("terminal".equals(serverRef)) {
            serverUrl = serverUrl.replaceFirst("^ws", "http").replaceFirst("/pty$", "/");
        }
        if ("wsagent/http".equals(serverRef) && !serverUrl.endsWith("/")) {
            // add trailing slash if it is not present
            serverUrl = serverUrl + '/';
        }
        token = machineTokenProvider.getToken(runtimeIdentity.getOwnerId(), runtimeIdentity.getWorkspaceId());
        url = UriBuilder.fromUri(serverUrl).build().toURL();
    } catch (MalformedURLException e) {
        throw new InternalInfrastructureException("Server " + serverRef + " URL is invalid. Error: " + e.getMessage(), e);
    }
    return doCreateChecker(url, serverRef, token);
}
Also used : MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Example 4 with InternalInfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project devspaces-images by redhat-developer.

the class PreviewUrlExposer method expose.

public void expose(T env) throws InternalInfrastructureException {
    List<CommandImpl> previewUrlCommands = env.getCommands().stream().filter(c -> c.getPreviewUrl() != null).collect(Collectors.toList());
    List<ServicePort> portsToProvision = new ArrayList<>();
    for (CommandImpl command : previewUrlCommands) {
        int port = command.getPreviewUrl().getPort();
        Optional<Service> foundService = Services.findServiceWithPort(env.getServices().values(), port);
        if (foundService.isPresent()) {
            if (!hasMatchingEndpoint(env, foundService.get(), port)) {
                ServicePort servicePort = Services.findPort(foundService.get(), port).orElseThrow(() -> new InternalInfrastructureException(String.format("Port '%d' in service '%s' not found. This is not expected, please report a bug!", port, foundService.get().getMetadata().getName())));
                String serviceName = foundService.get().getMetadata().getName();
                externalServerExposer.expose(env, null, serviceName, serviceName, servicePort, Collections.emptyMap());
            }
        } else {
            portsToProvision.add(createServicePort(port));
        }
    }
    if (!portsToProvision.isEmpty()) {
        String serverName = generate(SERVER_PREFIX, SERVER_UNIQUE_PART_SIZE) + "-previewUrl";
        Service service = new ServerServiceBuilder().withName(serverName).withPorts(portsToProvision).build();
        env.getServices().put(serverName, service);
        portsToProvision.forEach(port -> externalServerExposer.expose(env, null, service.getMetadata().getName(), service.getMetadata().getName(), port, Collections.emptyMap()));
    }
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ExternalServerExposerProvider(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServerExposerProvider) NameGenerator.generate(org.eclipse.che.commons.lang.NameGenerator.generate) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ExternalServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServerExposer) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) SERVER_UNIQUE_PART_SIZE(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_UNIQUE_PART_SIZE) Inject(javax.inject.Inject) SERVER_PREFIX(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_PREFIX) List(java.util.List) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Services(org.eclipse.che.workspace.infrastructure.kubernetes.util.Services) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Service(io.fabric8.kubernetes.api.model.Service) Collections(java.util.Collections) Ingresses(org.eclipse.che.workspace.infrastructure.kubernetes.util.Ingresses) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Example 5 with InternalInfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project devspaces-images by redhat-developer.

the class JwtProxyConfigBuilder method build.

public String build() throws InternalInfrastructureException {
    List<VerifierProxyConfig> proxyConfigs = new ArrayList<>();
    Config config = new Config().withJWTProxy(new JWTProxy().withSignerProxy(new SignerProxyConfig().withEnabled(false)).withVerifiedProxyConfigs(proxyConfigs));
    for (VerifierProxy verifierProxy : verifierProxies) {
        VerifierConfig verifierConfig = new VerifierConfig().withAudience(workspaceId).withUpstream(verifierProxy.upstream).withMaxSkew("1m").withMaxTtl(ttl).withKeyServer(new RegistrableComponentConfig().withType("preshared").withOptions(ImmutableMap.of("issuer", issuer, "key_id", workspaceId, "public_key_path", JWT_PROXY_CONFIG_FOLDER + '/' + JWT_PROXY_PUBLIC_KEY_FILE))).withCookiesEnabled(verifierProxy.cookiesAuthEnabled).withCookiePath(ensureStartsWithSlash(verifierProxy.cookiePath)).withClaimsVerifier(Collections.singleton(new RegistrableComponentConfig().withType("static").withOptions(ImmutableMap.of("iss", issuer)))).withNonceStorage(new RegistrableComponentConfig().withType("void"));
        if (!verifierProxy.excludes.isEmpty()) {
            verifierConfig.setExcludes(verifierProxy.excludes);
        }
        if (verifierProxy.cookiesAuthEnabled && authPageUrl != null) {
            verifierConfig.setAuthUrl(authPageUrl.toString());
        }
        if (verifierProxy.publicBasePath != null) {
            verifierConfig.setPublicBasePath(verifierProxy.publicBasePath);
        }
        VerifierProxyConfig proxyConfig = new VerifierProxyConfig().withListenAddr(":" + verifierProxy.listenPort).withVerifierConfig(verifierConfig);
        proxyConfigs.add(proxyConfig);
    }
    try {
        return YAML_PARSER.writeValueAsString(config);
    } catch (JsonProcessingException e) {
        throw new InternalInfrastructureException("Error during creation of JWTProxy config YAML: " + e.getMessage(), e);
    }
}
Also used : SignerProxyConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.SignerProxyConfig) VerifierConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.VerifierConfig) Config(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.Config) RegistrableComponentConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.RegistrableComponentConfig) SignerProxyConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.SignerProxyConfig) VerifierProxyConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.VerifierProxyConfig) RegistrableComponentConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.RegistrableComponentConfig) ArrayList(java.util.ArrayList) VerifierProxyConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.VerifierProxyConfig) VerifierConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.VerifierConfig) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JWTProxy(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.JWTProxy) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Aggregations

InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)18 ArrayList (java.util.ArrayList)6 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 MalformedURLException (java.net.MalformedURLException)4 URI (java.net.URI)4 URL (java.net.URL)4 List (java.util.List)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 HttpProbeConfig (org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Assisted (com.google.inject.assistedinject.Assisted)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)2 Service (io.fabric8.kubernetes.api.model.Service)2 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)2