use of org.eclipse.che.api.core.model.workspace.devfile.Component in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplier method provisionVolumes.
private void provisionVolumes(ComponentImpl component, Container container, MachineConfigImpl config) throws DevfileException {
for (org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl componentVolume : component.getVolumes()) {
Optional<VolumeMount> sameNameMount = container.getVolumeMounts().stream().filter(vm -> vm.getName().equals(componentVolume.getName())).findFirst();
if (sameNameMount.isPresent() && sameNameMount.get().getMountPath().equals(componentVolume.getContainerPath())) {
continue;
} else if (sameNameMount.isPresent()) {
throw new DevfileException(format("Conflicting volume with same name ('%s') but different path ('%s') found for component '%s' and its container '%s'.", componentVolume.getName(), componentVolume.getContainerPath(), getIdentifiableComponentName(component), container.getName()));
}
if (container.getVolumeMounts().stream().anyMatch(vm -> vm.getMountPath().equals(componentVolume.getContainerPath()))) {
throw new DevfileException(format("Conflicting volume with same path ('%s') but different name ('%s') found for component '%s' and its container '%s'.", componentVolume.getContainerPath(), componentVolume.getName(), getIdentifiableComponentName(component), container.getName()));
}
config.getVolumes().put(componentVolume.getName(), new VolumeImpl().withPath(componentVolume.getContainerPath()));
}
}
use of org.eclipse.che.api.core.model.workspace.devfile.Component in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplier method apply.
@Override
public void apply(RuntimeIdentity runtimeIdentity, InternalEnvironment internalEnvironment, Collection<ChePlugin> chePlugins) throws InfrastructureException {
if (chePlugins.isEmpty()) {
return;
}
KubernetesEnvironment k8sEnv = (KubernetesEnvironment) internalEnvironment;
Map<String, PodData> pods = k8sEnv.getPodsData();
switch(pods.size()) {
case 0:
addToolingPod(k8sEnv);
pods = k8sEnv.getPodsData();
break;
case 1:
break;
default:
throw new InfrastructureException("Che plugins tooling configuration can be applied to a workspace with one pod only");
}
PodData pod = pods.values().iterator().next();
CommandsResolver commandsResolver = new CommandsResolver(k8sEnv);
for (ChePlugin chePlugin : chePlugins) {
Map<String, ComponentImpl> devfilePlugins = k8sEnv.getDevfile().getComponents().stream().filter(c -> c.getType().equals("cheEditor") || c.getType().equals("chePlugin")).collect(Collectors.toMap(ComponentImpl::getId, Function.identity()));
if (!devfilePlugins.containsKey(chePlugin.getId())) {
throw new InfrastructureException(String.format("The downloaded plugin '%s' configuration does not have the " + "corresponding component in devfile. Devfile contains the following cheEditor/chePlugins: %s", chePlugin.getId(), devfilePlugins.keySet()));
}
ComponentImpl pluginRelatedComponent = devfilePlugins.get(chePlugin.getId());
for (CheContainer container : chePlugin.getInitContainers()) {
Container k8sInitContainer = toK8sContainer(container);
envVars.apply(k8sInitContainer, pluginRelatedComponent.getEnv());
chePluginsVolumeApplier.applyVolumes(pod, k8sInitContainer, container.getVolumes(), k8sEnv);
pod.getSpec().getInitContainers().add(k8sInitContainer);
}
Collection<CommandImpl> pluginRelatedCommands = commandsResolver.resolve(chePlugin);
for (CheContainer container : chePlugin.getContainers()) {
addSidecar(pod, container, chePlugin, k8sEnv, pluginRelatedCommands, pluginRelatedComponent, runtimeIdentity);
}
}
chePlugins.forEach(chePlugin -> populateWorkspaceEnvVars(chePlugin, k8sEnv));
}
use of org.eclipse.che.api.core.model.workspace.devfile.Component in project che-server by eclipse-che.
the class DefaultEditorProvisioner method apply.
/**
* Provision default editor if there is no editor. Also provisions default plugins for default
* editor regardless whether it is provisioned or set by user.
*
* @param devfile devfile where editor and plugins should be provisioned
* @param contentProvider content provider for plugin references retrieval
*/
public void apply(DevfileImpl devfile, FileContentProvider contentProvider) throws DevfileException {
if (defaultEditorRef == null) {
// there is no default editor configured
return;
}
if ("true".equals(devfile.getAttributes().get(EDITOR_FREE_DEVFILE_ATTRIBUTE))) {
return;
}
List<ComponentImpl> components = devfile.getComponents();
Optional<ComponentImpl> editorOpt = components.stream().filter(t -> EDITOR_COMPONENT_TYPE.equals(t.getType())).findFirst();
boolean isDefaultEditorUsed;
if (!editorOpt.isPresent()) {
components.add(new ComponentImpl(EDITOR_COMPONENT_TYPE, defaultEditorRef));
isDefaultEditorUsed = true;
} else {
Component editor = editorOpt.get();
String editorPublisherAndName = getPluginPublisherAndName(editor, contentProvider);
isDefaultEditorUsed = defaultEditor.equals(editorPublisherAndName);
}
if (isDefaultEditorUsed) {
provisionDefaultPlugins(components, contentProvider);
}
if ("false".equals(devfile.getAttributes().get(PERSIST_VOLUMES_ATTRIBUTE)) && "true".equals(devfile.getAttributes().get(ASYNC_PERSIST_ATTRIBUTE))) {
provisionAsyncStoragePlugin(components, contentProvider);
}
}
use of org.eclipse.che.api.core.model.workspace.devfile.Component in project che-server by eclipse-che.
the class DevfileIntegrityValidator method validateComponents.
private Set<String> validateComponents(Devfile devfile) throws DevfileFormatException {
Set<String> definedAliases = new HashSet<>();
Component editorComponent = null;
Map<String, Set<String>> idsPerComponentType = new HashMap<>();
for (Component component : devfile.getComponents()) {
if (component.getAlias() != null && !definedAliases.add(component.getAlias())) {
throw new DevfileFormatException(format("Duplicate component alias found:'%s'", component.getAlias()));
}
Optional<Map.Entry<String, Long>> duplicatedEndpoint = component.getEndpoints().stream().map(Endpoint::getName).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().filter(e -> e.getValue() > 1L).findFirst();
if (duplicatedEndpoint.isPresent()) {
throw new DevfileFormatException(format("Duplicated endpoint name '%s' found in '%s' component", duplicatedEndpoint.get().getKey(), getIdentifiableComponentName(component)));
}
Set<String> tempSet = new HashSet<>();
for (Env env : component.getEnv()) {
if (!tempSet.add(env.getName())) {
throw new DevfileFormatException(format("Duplicate environment variable '%s' found in component '%s'", env.getName(), getIdentifiableComponentName(component)));
}
}
if (!idsPerComponentType.computeIfAbsent(component.getType(), __ -> new HashSet<>()).add(getIdentifiableComponentName(component))) {
throw new DevfileFormatException(format("There are multiple components '%s' of type '%s' that cannot be uniquely" + " identified. Please add aliases that would distinguish the components.", getIdentifiableComponentName(component), component.getType()));
}
if (component.getAutomountWorkspaceSecrets() != null && component.getAlias() == null) {
throw new DevfileFormatException(format("The 'automountWorkspaceSecrets' property cannot be used in component which doesn't have alias. " + "Please add alias to component '%s' that would allow to distinguish its containers.", getIdentifiableComponentName(component)));
}
switch(component.getType()) {
case EDITOR_COMPONENT_TYPE:
if (editorComponent != null) {
throw new DevfileFormatException(format("Multiple editor components found: '%s', '%s'", getIdentifiableComponentName(editorComponent), getIdentifiableComponentName(component)));
}
editorComponent = component;
break;
case PLUGIN_COMPONENT_TYPE:
case KUBERNETES_COMPONENT_TYPE:
case OPENSHIFT_COMPONENT_TYPE:
case DOCKERIMAGE_COMPONENT_TYPE:
// do nothing
break;
default:
throw new DevfileFormatException(format("One of the components has unsupported component type: '%s'", component.getType()));
}
}
return definedAliases;
}
use of org.eclipse.che.api.core.model.workspace.devfile.Component in project devspaces-images by redhat-developer.
the class KubernetesComponentToWorkspaceApplier method provisionVolumes.
private void provisionVolumes(ComponentImpl component, Container container, MachineConfigImpl config) throws DevfileException {
for (org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl componentVolume : component.getVolumes()) {
Optional<VolumeMount> sameNameMount = container.getVolumeMounts().stream().filter(vm -> vm.getName().equals(componentVolume.getName())).findFirst();
if (sameNameMount.isPresent() && sameNameMount.get().getMountPath().equals(componentVolume.getContainerPath())) {
continue;
} else if (sameNameMount.isPresent()) {
throw new DevfileException(format("Conflicting volume with same name ('%s') but different path ('%s') found for component '%s' and its container '%s'.", componentVolume.getName(), componentVolume.getContainerPath(), getIdentifiableComponentName(component), container.getName()));
}
if (container.getVolumeMounts().stream().anyMatch(vm -> vm.getMountPath().equals(componentVolume.getContainerPath()))) {
throw new DevfileException(format("Conflicting volume with same path ('%s') but different name ('%s') found for component '%s' and its container '%s'.", componentVolume.getContainerPath(), componentVolume.getName(), getIdentifiableComponentName(component), container.getName()));
}
config.getVolumes().put(componentVolume.getName(), new VolumeImpl().withPath(componentVolume.getContainerPath()));
}
}
Aggregations