Search in sources :

Example 11 with InternalInfrastructureException

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

the class PassThroughProxyProvisioner method constructSignatureKeyPair.

/**
 * Constructs a key pair to satisfy JWT proxy which needs a key pair in its configuration. In case
 * of pass-through proxy, this key pair is unused so we just generate a random one.
 *
 * @return a random key pair
 * @throws InternalInfrastructureException if RSA is not available as a key pair generator. This
 *     should not happen.
 */
private static KeyPair constructSignatureKeyPair() throws InternalInfrastructureException {
    try {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
        kpg.initialize(512);
        return kpg.generateKeyPair();
    } catch (NoSuchAlgorithmException e) {
        throw new InternalInfrastructureException("Could not generate a fake key pair to support JWT proxy in single-user mode.");
    }
}
Also used : KeyPairGenerator(java.security.KeyPairGenerator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Example 12 with InternalInfrastructureException

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

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 13 with InternalInfrastructureException

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

Example 14 with InternalInfrastructureException

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

the class ServersChecker method startAsync.

/**
 * Asynchronously starts checking readiness of servers of a machine. Method {@link #await()} waits
 * the result of this asynchronous check.
 *
 * @param serverReadinessHandler consumer which will be called with server reference as the
 *     argument when server become available
 * @throws InternalInfrastructureException if check of a server failed due to an unexpected error
 * @throws InfrastructureException if check of a server failed due to an error
 */
public CompletableFuture<?> startAsync(Consumer<String> serverReadinessHandler) throws InfrastructureException {
    timer = new Timer("ServersChecker", true);
    List<ServerChecker> serverCheckers = getServerCheckers();
    // should be completed with an exception if a server considered unavailable
    CompletableFuture<Void> firstNonAvailable = new CompletableFuture<>();
    CompletableFuture[] checkTasks = serverCheckers.stream().map(ServerChecker::getReportCompFuture).map(compFut -> compFut.thenAccept(serverReadinessHandler).exceptionally(e -> {
        // cleanup checkers tasks
        timer.cancel();
        firstNonAvailable.completeExceptionally(e);
        return null;
    })).toArray(CompletableFuture[]::new);
    resultTimeoutSeconds = checkTasks.length * 180;
    // should complete when all servers checks reported availability
    CompletableFuture<Void> allAvailable = CompletableFuture.allOf(checkTasks);
    // should complete when all servers are available or any server is unavailable
    result = CompletableFuture.anyOf(allAvailable, firstNonAvailable);
    for (ServerChecker serverChecker : serverCheckers) {
        serverChecker.start();
    }
    return result;
}
Also used : Arrays(java.util.Arrays) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) Set(java.util.Set) TimeoutException(java.util.concurrent.TimeoutException) Timer(java.util.Timer) CompletableFuture(java.util.concurrent.CompletableFuture) MachineTokenProvider(org.eclipse.che.api.workspace.server.token.MachineTokenProvider) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Inject(javax.inject.Inject) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) UriBuilder(jakarta.ws.rs.core.UriBuilder) Map(java.util.Map) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Named(javax.inject.Named) Server(org.eclipse.che.api.core.model.workspace.runtime.Server) CompletableFuture(java.util.concurrent.CompletableFuture) Timer(java.util.Timer)

Example 15 with InternalInfrastructureException

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

the class StartSynchronizerTest method shouldWrapExceptionIntoInternalExcWhenItIsCompletedWithNonInfraException.

@Test
public void shouldWrapExceptionIntoInternalExcWhenItIsCompletedWithNonInfraException() {
    // given
    RuntimeException toThrow = new RuntimeException("test exception");
    startSynchronizer.completeExceptionally(toThrow);
    // when
    InfrastructureException startFailure = startSynchronizer.getStartFailureNow();
    // then
    assertTrue(startFailure instanceof InternalInfrastructureException);
    assertEquals(startFailure.getCause(), toThrow);
}
Also used : InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Test(org.testng.annotations.Test)

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