Search in sources :

Example 16 with InternalInfrastructureException

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

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

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

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

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

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)

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