use of org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException in project che-server by eclipse-che.
the class StartSynchronizer method interrupt.
/**
* Interrupts workspace start if it is in progress and is not interrupted yet
*
* @return true if workspace start is interrupted, false otherwise
*/
public synchronized boolean interrupt() {
if (!isStarting) {
return false;
}
startFailure.completeExceptionally(new RuntimeStartInterruptedException(runtimeId));
if (startThread != null) {
startThread.interrupt();
// set to not to interrupt twice
startThread = null;
}
return true;
}
use of org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException in project devspaces-images by redhat-developer.
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();
}
}
use of org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException in project devspaces-images by redhat-developer.
the class StartSynchronizerTest method testFailureStartCompletion.
@Test
public void testFailureStartCompletion() throws Exception {
// given
startSynchronizer.setStartThread();
RuntimeStartInterruptedException expected = new RuntimeStartInterruptedException(runtimeId);
// when
startSynchronizer.completeExceptionally(expected);
// then
assertTrue(startSynchronizer.isCompleted());
assertTrue(startSynchronizer.getStartFailure().isCompletedExceptionally());
try {
startSynchronizer.getStartFailure().getNow(null);
fail("Start failure is empty");
} catch (CompletionException actual) {
assertEquals(actual.getCause(), expected);
}
}
use of org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException in project devspaces-images by redhat-developer.
the class StartSynchronizerTest method shouldRethrowOriginalExceptionIfStartCompletedExceptionallyOnCompletion.
@Test(expectedExceptions = RuntimeStartInterruptedException.class)
public void shouldRethrowOriginalExceptionIfStartCompletedExceptionallyOnCompletion() throws Exception {
// given
startSynchronizer.completeExceptionally(new RuntimeStartInterruptedException(runtimeId));
// when
startSynchronizer.complete();
}
use of org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException in project devspaces-images by redhat-developer.
the class StartSynchronizerTest method shouldReturnStartFailureWhenItIsCompletedExceptionally.
@Test
public void shouldReturnStartFailureWhenItIsCompletedExceptionally() {
// given
InfrastructureException toThrow = new RuntimeStartInterruptedException(runtimeId);
startSynchronizer.completeExceptionally(toThrow);
// when
InfrastructureException startFailure = startSynchronizer.getStartFailureNow();
// then
assertTrue(startFailure instanceof RuntimeStartInterruptedException);
assertEquals(startFailure, toThrow);
}
Aggregations