use of org.eclipse.che.api.core.ValidationException in project che-server by eclipse-che.
the class OpenShiftEnvironmentFactoryTest method exceptionOnRecipeLoadError.
@Test(expectedExceptions = ValidationException.class)
public void exceptionOnRecipeLoadError() throws Exception {
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenThrow(new ValidationException("Could not parse recipe"));
osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
}
use of org.eclipse.che.api.core.ValidationException in project devspaces-images by redhat-developer.
the class K8sInfraNamespaceWsAttributeValidatorTest method testWhenNamespaceFactoryThrowsErrorOnCheckingIfNamespaceIsAllowed.
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "The specified namespace name is not valid")
public void testWhenNamespaceFactoryThrowsErrorOnCheckingIfNamespaceIsAllowed() throws ValidationException {
doThrow(new ValidationException("The specified namespace name is not valid")).when(namespaceFactory).checkIfNamespaceIsAllowed(anyString());
validator.validate(ImmutableMap.of(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "any"));
}
use of org.eclipse.che.api.core.ValidationException in project devspaces-images by redhat-developer.
the class WorkspaceManager method createWorkspace.
/**
* Creates a workspace out of a devfile.
*
* <p>The devfile should have been validated using the {@link
* DevfileIntegrityValidator#validateDevfile(Devfile)}. This method does rest of the validation
* and actually creates the workspace.
*
* @param devfile the devfile describing the workspace
* @param namespace workspace name is unique in this namespace
* @param attributes workspace instance attributes
* @param contentProvider the content provider to use for resolving content references in the
* devfile
* @return new workspace instance
* @throws NullPointerException when either {@code config} or {@code namespace} is null
* @throws NotFoundException when account with given id was not found
* @throws ConflictException when any conflict occurs (e.g Workspace with such name already exists
* for {@code owner})
* @throws ServerException when any other error occurs
* @throws ValidationException when incoming configuration or attributes are not valid
*/
@Traced
public WorkspaceImpl createWorkspace(Devfile devfile, String namespace, Map<String, String> attributes, FileContentProvider contentProvider) throws ServerException, NotFoundException, ConflictException, ValidationException {
requireNonNull(devfile, "Required non-null devfile");
requireNonNull(namespace, "Required non-null namespace");
validator.validateAttributes(attributes);
devfile = generateNameIfNeeded(devfile);
try {
devfileIntegrityValidator.validateContentReferences(devfile, contentProvider);
} catch (DevfileFormatException e) {
throw new ValidationException(e.getMessage(), e);
}
WorkspaceImpl workspace = doCreateWorkspace(devfile, accountManager.getByName(namespace), attributes, false);
TracingTags.WORKSPACE_ID.set(workspace.getId());
return workspace;
}
use of org.eclipse.che.api.core.ValidationException in project devspaces-images by redhat-developer.
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.core.ValidationException in project devspaces-images by redhat-developer.
the class KubernetesEnvironmentFactoryTest method exceptionOnRecipeLoadError.
@Test(expectedExceptions = ValidationException.class)
public void exceptionOnRecipeLoadError() throws Exception {
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenThrow(new ValidationException("Could not parse recipe"));
k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
}
Aggregations