Search in sources :

Example 11 with RuntimeStartInterruptedException

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

the class KubernetesInternalRuntime method internalStart.

@Override
protected void internalStart(Map<String, String> startOptions) throws InfrastructureException {
    KubernetesRuntimeContext<E> context = getContext();
    String workspaceId = context.getIdentity().getWorkspaceId();
    try {
        startSynchronizer.setStartThread();
        startSynchronizer.start();
        runtimeCleaner.cleanUp(namespace, workspaceId);
        provisionWorkspace(startOptions, context, workspaceId);
        volumesStrategy.prepare(context.getEnvironment(), context.getIdentity(), startSynchronizer.getStartTimeoutMillis(), startOptions);
        startSynchronizer.checkFailure();
        startMachines();
        watchLogsIfDebugEnabled(startOptions);
        previewUrlCommandProvisioner.provision(context.getEnvironment(), namespace);
        runtimeStates.updateCommands(context.getIdentity(), context.getEnvironment().getCommands());
        startSynchronizer.checkFailure();
        final Map<String, CompletableFuture<Void>> machinesFutures = new LinkedHashMap<>();
        // futures that must be cancelled explicitly
        final List<CompletableFuture<?>> toCancelFutures = new CopyOnWriteArrayList<>();
        final EnvironmentContext currentContext = EnvironmentContext.getCurrent();
        CompletableFuture<Void> startFailure = startSynchronizer.getStartFailure();
        Span waitRunningAsyncSpan = tracer.buildSpan(WAIT_MACHINES_START).start();
        try (Scope waitRunningAsyncScope = tracer.scopeManager().activate(waitRunningAsyncSpan)) {
            TracingTags.WORKSPACE_ID.set(waitRunningAsyncSpan, workspaceId);
            for (KubernetesMachineImpl machine : machines.getMachines(context.getIdentity()).values()) {
                String machineName = machine.getName();
                final CompletableFuture<Void> machineBootChain = waitRunningAsync(toCancelFutures, machine).thenComposeAsync(checkFailure(startFailure), executor).thenRun(publishRunningStatus(machineName)).thenCompose(checkFailure(startFailure)).thenCompose(setContext(currentContext, checkServers(toCancelFutures, machine))).exceptionally(publishFailedStatus(startFailure, machineName));
                machinesFutures.put(machineName, machineBootChain);
            }
            waitMachines(machinesFutures, toCancelFutures, startFailure);
        } finally {
            waitRunningAsyncSpan.finish();
        }
        startSynchronizer.complete();
    } catch (InfrastructureException | RuntimeException e) {
        Exception startFailureCause = startSynchronizer.getStartFailureNow();
        if (startFailureCause == null) {
            startFailureCause = e;
        }
        startSynchronizer.completeExceptionally(startFailureCause);
        LOG.warn("Failed to start Kubernetes runtime of workspace {}.", workspaceId, startFailureCause);
        boolean interrupted = Thread.interrupted() || startFailureCause instanceof RuntimeStartInterruptedException;
        // Cancels workspace servers probes if any
        probeScheduler.cancel(workspaceId);
        // stop watching before namespace cleaning up
        namespace.deployments().stopWatch(true);
        try {
            runtimeCleaner.cleanUp(namespace, workspaceId);
        } catch (InfrastructureException cleanUppingEx) {
            LOG.warn("Failed to clean up namespace after workspace '{}' start failing.", context.getIdentity().getWorkspaceId(), cleanUppingEx);
        }
        if (interrupted) {
            throw new RuntimeStartInterruptedException(getContext().getIdentity());
        }
        wrapAndRethrow(startFailureCause);
    } finally {
        namespace.deployments().stopWatch();
    }
}
Also used : Span(io.opentracing.Span) TimeoutException(java.util.concurrent.TimeoutException) StateException(org.eclipse.che.api.workspace.server.spi.StateException) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) ValidationException(org.eclipse.che.api.core.ValidationException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) ExecutionException(java.util.concurrent.ExecutionException) LinkedHashMap(java.util.LinkedHashMap) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) CompletableFuture(java.util.concurrent.CompletableFuture) Scope(io.opentracing.Scope) KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 12 with RuntimeStartInterruptedException

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

the class KubernetesInternalRuntime method waitMachines.

/**
 * Waits for readiness of given machines.
 *
 * @param machinesFutures machines futures to wait
 * @param toCancelFutures futures that must be explicitly closed when any error occurs
 * @param failure failure callback that is used to prevent subsequent steps when any error occurs
 * @throws InfrastructureException when waiting for machines exceeds the timeout
 * @throws InfrastructureException when any problem occurred while waiting
 * @throws RuntimeStartInterruptedException when the thread is interrupted while waiting machines
 */
private void waitMachines(Map<String, CompletableFuture<Void>> machinesFutures, List<CompletableFuture<?>> toCancelFutures, CompletableFuture<Void> failure) throws InfrastructureException {
    try {
        LOG.debug("Waiting to start machines of workspace '{}'", getContext().getIdentity().getWorkspaceId());
        final CompletableFuture<Void> allDone = CompletableFuture.allOf(machinesFutures.values().toArray(new CompletableFuture[0]));
        CompletableFuture.anyOf(allDone, failure).get(startSynchronizer.getStartTimeoutMillis(), TimeUnit.MILLISECONDS);
        if (failure.isCompletedExceptionally()) {
            cancelAll(toCancelFutures);
            // rethrow the failure cause
            failure.get();
        }
        LOG.debug("Machines of workspace '{}' started", getContext().getIdentity().getWorkspaceId());
    } catch (TimeoutException ex) {
        InfrastructureException ie = new InfrastructureException("Waiting for Kubernetes environment '" + getContext().getIdentity().getEnvName() + "' of the workspace'" + getContext().getIdentity().getWorkspaceId() + "' reached timeout");
        failure.completeExceptionally(ie);
        cancelAll(toCancelFutures);
        throw ie;
    } catch (InterruptedException ex) {
        RuntimeStartInterruptedException runtimeInterruptedEx = new RuntimeStartInterruptedException(getContext().getIdentity());
        failure.completeExceptionally(runtimeInterruptedEx);
        cancelAll(toCancelFutures);
        throw runtimeInterruptedEx;
    } catch (ExecutionException ex) {
        failure.completeExceptionally(ex.getCause());
        cancelAll(toCancelFutures);
        wrapAndRethrow(ex.getCause());
    // note that we do NOT finish the startup traces here, because execution exception is
    // handled by the "exceptional" parts of the completable chain.
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) ExecutionException(java.util.concurrent.ExecutionException) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) TimeoutException(java.util.concurrent.TimeoutException)

Example 13 with RuntimeStartInterruptedException

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

the class StartSynchronizerTest method shouldThrowExceptionOnCheckingFailureIfStartIsCompletedExceptionally.

@Test(expectedExceptions = RuntimeStartInterruptedException.class)
public void shouldThrowExceptionOnCheckingFailureIfStartIsCompletedExceptionally() throws Exception {
    // given
    startSynchronizer.start();
    RuntimeStartInterruptedException expected = new RuntimeStartInterruptedException(runtimeId);
    startSynchronizer.completeExceptionally(expected);
    // when
    startSynchronizer.checkFailure();
}
Also used : RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) Test(org.testng.annotations.Test)

Example 14 with RuntimeStartInterruptedException

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

the class StartSynchronizerTest method shouldAwaitTerminationWhenItIsCompletedExceptionally.

@Test
public void shouldAwaitTerminationWhenItIsCompletedExceptionally() throws Exception {
    // given
    startSynchronizer.completeExceptionally(new RuntimeStartInterruptedException(runtimeId));
    // when
    boolean isInterrupted = startSynchronizer.awaitInterruption(1, TimeUnit.SECONDS);
    // then
    assertTrue(isInterrupted);
}
Also used : RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) Test(org.testng.annotations.Test)

Example 15 with RuntimeStartInterruptedException

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

the class KubernetesInternalRuntime method waitMachines.

/**
 * Waits for readiness of given machines.
 *
 * @param machinesFutures machines futures to wait
 * @param toCancelFutures futures that must be explicitly closed when any error occurs
 * @param failure failure callback that is used to prevent subsequent steps when any error occurs
 * @throws InfrastructureException when waiting for machines exceeds the timeout
 * @throws InfrastructureException when any problem occurred while waiting
 * @throws RuntimeStartInterruptedException when the thread is interrupted while waiting machines
 */
private void waitMachines(Map<String, CompletableFuture<Void>> machinesFutures, List<CompletableFuture<?>> toCancelFutures, CompletableFuture<Void> failure) throws InfrastructureException {
    try {
        LOG.debug("Waiting to start machines of workspace '{}'", getContext().getIdentity().getWorkspaceId());
        final CompletableFuture<Void> allDone = CompletableFuture.allOf(machinesFutures.values().toArray(new CompletableFuture[0]));
        CompletableFuture.anyOf(allDone, failure).get(startSynchronizer.getStartTimeoutMillis(), TimeUnit.MILLISECONDS);
        if (failure.isCompletedExceptionally()) {
            cancelAll(toCancelFutures);
            // rethrow the failure cause
            failure.get();
        }
        LOG.debug("Machines of workspace '{}' started", getContext().getIdentity().getWorkspaceId());
    } catch (TimeoutException ex) {
        InfrastructureException ie = new InfrastructureException("Waiting for Kubernetes environment '" + getContext().getIdentity().getEnvName() + "' of the workspace'" + getContext().getIdentity().getWorkspaceId() + "' reached timeout");
        failure.completeExceptionally(ie);
        cancelAll(toCancelFutures);
        throw ie;
    } catch (InterruptedException ex) {
        RuntimeStartInterruptedException runtimeInterruptedEx = new RuntimeStartInterruptedException(getContext().getIdentity());
        failure.completeExceptionally(runtimeInterruptedEx);
        cancelAll(toCancelFutures);
        throw runtimeInterruptedEx;
    } catch (ExecutionException ex) {
        failure.completeExceptionally(ex.getCause());
        cancelAll(toCancelFutures);
        wrapAndRethrow(ex.getCause());
    // note that we do NOT finish the startup traces here, because execution exception is
    // handled by the "exceptional" parts of the completable chain.
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) ExecutionException(java.util.concurrent.ExecutionException) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

RuntimeStartInterruptedException (org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException)16 Test (org.testng.annotations.Test)10 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)6 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)6 CompletableFuture (java.util.concurrent.CompletableFuture)4 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 Scope (io.opentracing.Scope)2 Span (io.opentracing.Span)2 LinkedHashMap (java.util.LinkedHashMap)2 CompletionException (java.util.concurrent.CompletionException)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ValidationException (org.eclipse.che.api.core.ValidationException)2 StateException (org.eclipse.che.api.workspace.server.spi.StateException)2 EnvironmentContext (org.eclipse.che.commons.env.EnvironmentContext)2 KubernetesMachineImpl (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl)2