use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class InconsistentRuntimesDetectorTest method shouldThrowExceptionIfExceptionOccursDuringRuntimeFetchingOnCheckingConsistency.
@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Failed to get internal runtime for workspace `workspace1` to check consistency. Cause: error")
public void shouldThrowExceptionIfExceptionOccursDuringRuntimeFetchingOnCheckingConsistency() throws Exception {
// given
doThrow(new InfrastructureException("error")).when(workspaceRuntimes).getInternalRuntime("workspace1");
// when
inconsistentRuntimesDetector.checkOne("workspace1");
// then
verifyNoMoreInteractions(eventPublisher);
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class InconsistentRuntimesDetectorTest method shouldThrowExceptionIfExceptionOccursOnCheckingConsistency.
@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Error occurred during runtime 'workspace1:owner1' consistency checking. Cause: error")
public void shouldThrowExceptionIfExceptionOccursOnCheckingConsistency() throws Exception {
// given
doReturn(k8sRuntime).when(workspaceRuntimes).getInternalRuntime("workspace1");
doThrow(new InfrastructureException("error")).when(k8sRuntime).isConsistent();
// when
inconsistentRuntimesDetector.checkOne("workspace1");
// then
verifyNoMoreInteractions(eventPublisher);
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class PrepareStorage method execute.
@Override
public List<ChePlugin> execute() throws InfrastructureException {
Span tracingSpan = tracer.buildSpan(PREPARE_STORAGE_PHASE).start();
TracingTags.WORKSPACE_ID.set(tracingSpan, identity.getWorkspaceId());
try {
volumesStrategy.prepare(brokerEnvironment, identity, startSynchronizer.getStartTimeoutMillis(), startOptions);
} catch (InfrastructureException e) {
TracingTags.setErrorStatus(tracingSpan, e);
throw e;
} finally {
tracingSpan.finish();
}
return nextPhase.execute();
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class WorkspaceRuntimes method recoverOne.
@VisibleForTesting
InternalRuntime<?> recoverOne(RuntimeInfrastructure infra, RuntimeIdentity identity) throws ServerException, ConflictException {
if (isStartRefused.get()) {
throw new ConflictException(format("Recovery of the workspace '%s' is rejected by the system, " + "no more workspaces are allowed to start", identity.getWorkspaceId()));
}
WorkspaceImpl workspace;
try {
workspace = workspaceDao.get(identity.getWorkspaceId());
} catch (NotFoundException x) {
throw new ServerException(format("Workspace configuration is missing for the runtime '%s:%s'. Runtime won't be recovered", identity.getWorkspaceId(), identity.getEnvName()));
}
Environment environment = null;
WorkspaceConfigImpl workspaceConfig = workspace.getConfig();
if (workspaceConfig == null) {
workspaceConfig = devfileConverter.convert(workspace.getDevfile());
}
if (identity.getEnvName() != null) {
environment = workspaceConfig.getEnvironments().get(identity.getEnvName());
if (environment == null) {
throw new ServerException(format("Environment configuration is missing for the runtime '%s:%s'. Runtime won't be recovered", identity.getWorkspaceId(), identity.getEnvName()));
}
}
InternalRuntime runtime;
try {
InternalEnvironment internalEnv = createInternalEnvironment(environment, workspaceConfig.getAttributes(), workspaceConfig.getCommands(), workspaceConfig.getDevfile());
runtime = infra.prepare(identity, internalEnv).getRuntime();
WorkspaceStatus runtimeStatus = runtime.getStatus();
try (Unlocker ignored = lockService.writeLock(workspace.getId())) {
statuses.replace(identity.getWorkspaceId(), runtimeStatus);
runtimes.putIfAbsent(identity.getWorkspaceId(), runtime);
}
LOG.info("Successfully recovered workspace runtime '{}'. Its status is '{}'", identity.getWorkspaceId(), runtimeStatus);
return runtime;
} catch (NotFoundException x) {
LOG.warn("Not able to create internal environment for '{}'. Reason: '{}'", identity.getWorkspaceId(), x.getMessage());
try (Unlocker ignored = lockService.writeLock(identity.getWorkspaceId())) {
runtimes.remove(identity.getWorkspaceId());
statuses.remove(identity.getWorkspaceId());
}
publishWorkspaceStatusEvent(identity.getWorkspaceId(), STOPPED, STOPPING, "Workspace is stopped. Reason: " + x.getMessage(), false);
throw new ServerException(format("Couldn't recover runtime '%s:%s'. Error: %s", identity.getWorkspaceId(), identity.getEnvName(), x.getMessage()));
} catch (InfrastructureException | ValidationException x) {
throw new ServerException(format("Couldn't recover runtime '%s:%s'. Error: %s", identity.getWorkspaceId(), identity.getEnvName(), x.getMessage()));
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class WorkspaceRuntimes method getInternalRuntime.
/**
* Returns {@link InternalRuntime} implementation for workspace with the specified id.
*
* <p>If memory-storage does not contain internal runtime, then runtime will be recovered if it is
* active. Otherwise, an exception will be thrown.
*
* @param workspaceId identifier of workspace to fetch runtime
* @return {@link InternalRuntime} implementation for workspace with the specified id.
* @throws InfrastructureException if any infrastructure exception occurs
* @throws ServerException if there is no active runtime for the specified workspace
* @throws ServerException if any other exception occurs
*/
public InternalRuntime<?> getInternalRuntime(String workspaceId) throws InfrastructureException, ServerException {
try (Unlocker ignored = lockService.writeLock(workspaceId)) {
InternalRuntime<?> runtime = runtimes.get(workspaceId);
if (runtime == null) {
try {
final Optional<RuntimeIdentity> runtimeIdentity = infrastructure.getIdentities().stream().filter(id -> id.getWorkspaceId().equals(workspaceId)).findAny();
if (runtimeIdentity.isPresent()) {
LOG.info("Runtime for workspace '{}' is requested but there is no cached one. Recovering it.", workspaceId);
runtime = recoverOne(infrastructure, runtimeIdentity.get());
} else {
// runtime is not considered by Infrastructure as active
throw new ServerException("No active runtime is found");
}
} catch (ServerException e) {
statuses.remove(workspaceId);
throw e;
} catch (UnsupportedOperationException | ConflictException e) {
statuses.remove(workspaceId);
throw new ServerException(e.getMessage(), e);
}
}
return runtime;
}
}
Aggregations