use of org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE 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.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE in project devspaces-images by redhat-developer.
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.Constants.DOCKERIMAGE_COMPONENT_TYPE 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.Constants.DOCKERIMAGE_COMPONENT_TYPE in project devspaces-images by redhat-developer.
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;
}
Aggregations