use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldThrowExceptionWhenRecipeComponentIsPresentAndContentProviderDoesNotSupportFetching.
@Test(expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = "Fetching content of file `reference.yaml` specified in `reference` field of component `foo` is not " + "supported. Please provide its content in `referenceContent` field. Cause: fetch is not supported")
public void shouldThrowExceptionWhenRecipeComponentIsPresentAndContentProviderDoesNotSupportFetching() throws Exception {
// given
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
// when
applier.apply(workspaceConfig, component, e -> {
throw new DevfileException("fetch is not supported");
});
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class DevfileConverterTest method shouldThrowServerExceptionIfAnyDevfileExceptionOccursOnConvertingDevfileToWorkspaceConfig.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "error")
public void shouldThrowServerExceptionIfAnyDevfileExceptionOccursOnConvertingDevfileToWorkspaceConfig() throws Exception {
devfileConverter = spy(devfileConverter);
doThrow(new DevfileException("error")).when(devfileConverter).devFileToWorkspaceConfig(any(), any());
devfileConverter.convert(new DevfileImpl());
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class DockerimageComponentToWorkspaceApplier method apply.
/**
* Applies changes on workspace config according to the specified dockerimage component.
*
* <p>Dockerimage component is provisioned as Deployment in Kubernetes recipe.<br>
* Generated deployment contains container with environment variables, memory limit, docker image,
* arguments and commands specified in component.<br>
* Also, environment is provisioned with machine config with volumes and servers specified, then
* Kubernetes infra will created needed PVC, Services, Ingresses, Routes according to specified
* configuration.
*
* @param workspaceConfig workspace config on which changes should be applied
* @param dockerimageComponent dockerimage component that should be applied
* @param contentProvider optional content provider that may be used for external component
* resource fetching
* @throws DevfileException if specified workspace config already has default environment where
* dockerimage component should be stored
* @throws IllegalArgumentException if specified workspace config or plugin component is null
* @throws IllegalArgumentException if specified component has type different from dockerimage
*/
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl dockerimageComponent, FileContentProvider contentProvider) throws DevfileException {
checkArgument(workspaceConfig != null, "Workspace config must not be null");
checkArgument(dockerimageComponent != null, "Component must not be null");
checkArgument(DOCKERIMAGE_COMPONENT_TYPE.equals(dockerimageComponent.getType()), format("Plugin must have `%s` type", DOCKERIMAGE_COMPONENT_TYPE));
String componentAlias = dockerimageComponent.getAlias();
String machineName = componentAlias == null ? toMachineName(dockerimageComponent.getImage()) : componentAlias;
MachineConfigImpl machineConfig = createMachineConfig(dockerimageComponent, componentAlias);
List<HasMetadata> componentObjects = createComponentObjects(dockerimageComponent, machineName);
k8sEnvProvisioner.provision(workspaceConfig, KubernetesEnvironment.TYPE, componentObjects, ImmutableMap.of(machineName, machineConfig));
workspaceConfig.getCommands().stream().filter(c -> componentAlias != null && componentAlias.equals(c.getAttributes().get(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE))).forEach(c -> c.getAttributes().put(MACHINE_NAME_ATTRIBUTE, machineName));
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplier method retrieveContent.
private String retrieveContent(Component recipeComponent, FileContentProvider fileContentProvider) throws DevfileException {
checkArgument(fileContentProvider != null, "Content provider must not be null");
if (!isNullOrEmpty(recipeComponent.getReferenceContent())) {
return recipeComponent.getReferenceContent();
}
String recipeFileContent;
try {
recipeFileContent = fileContentProvider.fetchContent(recipeComponent.getReference());
} catch (DevfileException e) {
throw new DevfileException(format("Fetching content of file `%s` specified in `reference` field of component `%s` is not supported. " + "Please provide its content in `referenceContent` field. Cause: %s", recipeComponent.getReference(), getIdentifiableComponentName(recipeComponent), e.getMessage()), e);
} catch (IOException e) {
throw new DevfileException(format("Error during recipe content retrieval for component '%s' with type '%s': %s", getIdentifiableComponentName(recipeComponent), recipeComponent.getType(), e.getMessage()), e);
}
if (isNullOrEmpty(recipeFileContent)) {
throw new DevfileException(format("The reference file '%s' defined in component '%s' is empty.", recipeComponent.getReference(), getIdentifiableComponentName(recipeComponent)));
}
return recipeFileContent;
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class KubernetesEnvironmentProvisioner method provision.
/**
* Provisions default K8s/OS environment with specified objects (K8s/OS objects, machines) into
* {@link WorkspaceConfigImpl}.
*
* <p>If there is already a default environment with kubernetes/openshift recipe then content will
* be updated with result or merging existing objects and specified ones.
*
* @param workspaceConfig workspace where recipe should be provisioned
* @param environmentType type of environment that should be provisioned. Should be one of the
* Kubernetes-based environments.
* @param componentObjects objects that should be provisioned into the workspace config
* @param machines machines that should be provisioned into the workspace config
* @throws DevfileRecipeFormatException if exception occurred during existing environment parsing
* @throws DevfileRecipeFormatException if exception occurred during kubernetes object
* serialization
* @throws DevfileException if any other exception occurred
*/
public void provision(WorkspaceConfigImpl workspaceConfig, String environmentType, List<HasMetadata> componentObjects, Map<String, MachineConfigImpl> machines) throws DevfileException, DevfileRecipeFormatException {
String defaultEnv = workspaceConfig.getDefaultEnv();
EnvironmentImpl environment = workspaceConfig.getEnvironments().get(defaultEnv);
if (environment == null) {
checkItemsHasUniqueKindToName(componentObjects);
RecipeImpl recipe = new RecipeImpl(environmentType, YAML_CONTENT_TYPE, asYaml(componentObjects), null);
String envName = "default";
EnvironmentImpl env = new EnvironmentImpl(recipe, emptyMap());
env.getMachines().putAll(machines);
workspaceConfig.getEnvironments().put(envName, env);
workspaceConfig.setDefaultEnv(envName);
} else {
RecipeImpl envRecipe = environment.getRecipe();
for (Entry<String, MachineConfigImpl> machineEntry : machines.entrySet()) {
if (environment.getMachines().put(machineEntry.getKey(), machineEntry.getValue()) != null) {
throw new DevfileException(format("Environment already contains machine '%s'", machineEntry.getKey()));
}
}
environment.getMachines().putAll(machines);
// check if it is needed to update recipe type since
// kubernetes component is compatible with openshift but not vice versa
Set<String> allowedEnvTypeBases = allowedEnvironmentTypeUpgrades.get(environmentType);
if (allowedEnvTypeBases != null) {
envRecipe.setType(environmentType);
}
// workspace already has k8s/OS recipe
// it is needed to merge existing recipe objects with component's ones
List<HasMetadata> envObjects = unmarshalObjects(envRecipe);
mergeProjectsPVC(envObjects, componentObjects);
envObjects.addAll(componentObjects);
checkItemsHasUniqueKindToName(envObjects);
envRecipe.setContent(asYaml(envObjects));
}
}
Aggregations