diff --git a/core/che-core-api-model/src/main/java/org/eclipse/che/api/core/model/workspace/devfile/Component.java b/core/che-core-api-model/src/main/java/org/eclipse/che/api/core/model/workspace/devfile/Component.java index d29966ed38..e71b60982b 100644 --- a/core/che-core-api-model/src/main/java/org/eclipse/che/api/core/model/workspace/devfile/Component.java +++ b/core/che-core-api-model/src/main/java/org/eclipse/che/api/core/model/workspace/devfile/Component.java @@ -16,8 +16,8 @@ import java.util.Map; public interface Component { - /** Returns the name of the component. Is mandator and must be unique per components set. */ - String getName(); + /** Returns the alias of the component. Is optional and must be unique per components set. */ + String getAlias(); /** * Returns type of the component, e.g. whether it is an plugin or editor or other type. It is diff --git a/dashboard/pom.xml b/dashboard/pom.xml index 2487e3e236..f3391928d4 100644 --- a/dashboard/pom.xml +++ b/dashboard/pom.xml @@ -204,11 +204,11 @@ - - - - - + + + + + diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Components.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Components.java new file mode 100644 index 0000000000..f5cfc61ce8 --- /dev/null +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Components.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.api.devfile.server; + +import static org.eclipse.che.api.devfile.server.Constants.DOCKERIMAGE_COMPONENT_TYPE; +import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; +import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; +import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; + +import org.eclipse.che.api.core.model.workspace.devfile.Component; + +/** Utility methods for working with components */ +public class Components { + + private Components() {} + + /** + * Get a name that can be used to identify the component in the devfile. Either the component + * alias is used or, if not defined, the identifying attribute corresponding to the component + * type. + * + * @return + */ + public static String getIdentifiableComponentName(Component component) { + if (component.getAlias() != null) { + return component.getAlias(); + } + + switch (component.getType()) { + case EDITOR_COMPONENT_TYPE: + case PLUGIN_COMPONENT_TYPE: + return component.getId(); + case DOCKERIMAGE_COMPONENT_TYPE: + return component.getImage(); + case KUBERNETES_COMPONENT_TYPE: + case OPENSHIFT_COMPONENT_TYPE: + return component.getReference(); + default: + return null; + } + } +} diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Constants.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Constants.java index 20714cb445..f9ea1d197d 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Constants.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Constants.java @@ -46,10 +46,10 @@ public class Constants { "pluginComponentsAliases"; /** Workspace config attribute which contains cheEditor component name. */ - public static final String EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE = "editorComponentName"; + public static final String EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE = "editorComponentAlias"; /** Workspace command attributes that indicates with which component it is associated. */ - public static final String COMPONENT_NAME_COMMAND_ATTRIBUTE = "componentName"; + public static final String COMPONENT_ALIAS_COMMAND_ATTRIBUTE = "componentAlias"; /** * {@link Endpoint} attribute name which can identify endpoint as public or internal. Attribute diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/CommandConverter.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/CommandConverter.java index f97b4b9987..f77560cfca 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/CommandConverter.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/CommandConverter.java @@ -42,7 +42,7 @@ public class CommandConverter { org.eclipse.che.api.workspace.server.model.impl.CommandImpl command) throws WorkspaceExportException { String componentName = - command.getAttributes().remove(Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE); + command.getAttributes().remove(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE); if (componentName == null) { throw new WorkspaceExportException( format( @@ -96,7 +96,7 @@ public class CommandConverter { command .getAttributes() - .put(Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE, commandAction.getComponent()); + .put(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE, commandAction.getComponent()); command.getAttributes().putAll(devCommand.getAttributes()); diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisioner.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisioner.java index 70b38b3e5c..26852bec87 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisioner.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisioner.java @@ -20,18 +20,14 @@ import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE import com.google.common.base.Strings; import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; import javax.inject.Inject; import javax.inject.Named; import org.eclipse.che.api.core.model.workspace.devfile.Component; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; -import org.eclipse.che.commons.lang.NameGenerator; import org.eclipse.che.commons.lang.Pair; /** @@ -71,19 +67,13 @@ public class DefaultEditorProvisioner { } List components = devfile.getComponents(); - Set componentsNames = - components.stream().map(Component::getName).collect(Collectors.toCollection(HashSet::new)); Optional editorOpt = components.stream().filter(t -> EDITOR_COMPONENT_TYPE.equals(t.getType())).findFirst(); boolean isDefaultEditorUsed; if (!editorOpt.isPresent()) { - components.add( - new ComponentImpl( - EDITOR_COMPONENT_TYPE, - findAvailableName(componentsNames, defaultEditorRef), - defaultEditorRef)); + components.add(new ComponentImpl(EDITOR_COMPONENT_TYPE, defaultEditorRef)); isDefaultEditorUsed = true; } else { Component editor = editorOpt.get(); @@ -91,12 +81,11 @@ public class DefaultEditorProvisioner { } if (isDefaultEditorUsed) { - provisionDefaultPlugins(components, componentsNames); + provisionDefaultPlugins(components); } } - private void provisionDefaultPlugins( - List components, Set componentsNames) { + private void provisionDefaultPlugins(List components) { Map missingPluginsIdToRef = new HashMap<>(defaultPluginsIdToRef); components @@ -106,27 +95,7 @@ public class DefaultEditorProvisioner { missingPluginsIdToRef .values() - .forEach( - pluginRef -> - components.add( - new ComponentImpl( - PLUGIN_COMPONENT_TYPE, - findAvailableName(componentsNames, pluginRef), - pluginRef))); - } - - /** - * Returns available name for component with the specified id. - * - *

Id without version is used as base name and generated part is added if it is already busy. - */ - private String findAvailableName(Set busyNames, String componentRef) { - String id = getId(componentRef); - String name = id; - while (!busyNames.add(name)) { - name = NameGenerator.generate(id, 5); - } - return name; + .forEach(pluginRef -> components.add(new ComponentImpl(PLUGIN_COMPONENT_TYPE, pluginRef))); } private String getId(String reference) { diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DevfileConverter.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DevfileConverter.java index cacc8d84e2..74a189a17c 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DevfileConverter.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DevfileConverter.java @@ -14,6 +14,7 @@ package org.eclipse.che.api.devfile.server.convert; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; import static java.util.stream.Collectors.toCollection; +import static org.eclipse.che.api.devfile.server.Components.getIdentifiableComponentName; import static org.eclipse.che.api.devfile.server.Constants.CURRENT_SPEC_VERSION; import com.google.common.base.Strings; @@ -142,7 +143,7 @@ public class DevfileConverter { throw new DevfileException( String.format( "Devfile contains component `%s` with type `%s` that can not be converted to workspace", - component.getName(), component.getType())); + getIdentifiableComponentName(component), component.getType())); } applier.apply(config, component, contentProvider); } diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisioner.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisioner.java index f3bc7eb89c..17273bf7c5 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisioner.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisioner.java @@ -96,7 +96,7 @@ public class DockerimageComponentProvisioner implements ComponentProvisioner { RecipeImpl recipe = environment.getRecipe(); ComponentImpl dockerimageComponent = new ComponentImpl(); - dockerimageComponent.setName(environmentName); + dockerimageComponent.setAlias(environmentName); dockerimageComponent.setImage(recipe.getContent()); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplier.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplier.java index 5e9c2a174f..4f1a8ace2f 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplier.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplier.java @@ -109,7 +109,9 @@ public class DockerimageComponentToWorkspaceApplier implements ComponentToWorksp DOCKERIMAGE_COMPONENT_TYPE.equals(dockerimageComponent.getType()), format("Plugin must have `%s` type", DOCKERIMAGE_COMPONENT_TYPE)); - String machineName = dockerimageComponent.getName(); + String componentAlias = dockerimageComponent.getAlias(); + String machineName = + componentAlias == null ? toObjectName(dockerimageComponent.getImage()) : componentAlias; MachineConfigImpl machineConfig = new MachineConfigImpl(); dockerimageComponent @@ -162,9 +164,9 @@ public class DockerimageComponentToWorkspaceApplier implements ComponentToWorksp .stream() .filter( c -> - dockerimageComponent - .getName() - .equals(c.getAttributes().get(Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE))) + c.getAttributes() + .get(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE) + .equals(componentAlias)) .forEach(c -> c.getAttributes().put(MACHINE_NAME_ATTRIBUTE, machineName)); } @@ -246,4 +248,8 @@ public class DockerimageComponentToWorkspaceApplier implements ComponentToWorksp .endSpec() .build(); } + + public static String toObjectName(String imageName) { + return imageName.replaceAll("/", "-").replaceAll(":", "-"); + } } diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisioner.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisioner.java index a6a2e51152..3ae6c0556f 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisioner.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisioner.java @@ -44,13 +44,13 @@ public class EditorComponentProvisioner implements ComponentProvisioner { return; } - ComponentImpl editorComponent = - new ComponentImpl( - EDITOR_COMPONENT_TYPE, - workspaceConfig - .getAttributes() - .getOrDefault(EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE, editorAttribute), - editorAttribute); + ComponentImpl editorComponent = new ComponentImpl(EDITOR_COMPONENT_TYPE, editorAttribute); + + editorComponent.setAlias( + workspaceConfig + .getAttributes() + .getOrDefault(EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE, editorAttribute)); + devfile.getComponents().add(editorComponent); } } diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplier.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplier.java index e75dc15924..61e3220d34 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplier.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplier.java @@ -14,7 +14,7 @@ package org.eclipse.che.api.devfile.server.convert.component.editor; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; import static org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE; @@ -52,14 +52,16 @@ public class EditorComponentToWorkspaceApplier implements ComponentToWorkspaceAp EDITOR_COMPONENT_TYPE.equals(editorComponent.getType()), format("Plugin must have `%s` type", EDITOR_COMPONENT_TYPE)); - String editorComponentName = editorComponent.getName(); + String editorComponentAlias = editorComponent.getAlias(); String editorId = editorComponent.getId(); workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, editorId); - workspaceConfig - .getAttributes() - .put(EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE, editorComponentName); + if (editorComponentAlias != null) { + workspaceConfig + .getAttributes() + .put(EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE, editorComponentAlias); + } String editorIdVersion = resolveIdAndVersion(editorComponent.getId()); workspaceConfig @@ -67,7 +69,9 @@ public class EditorComponentToWorkspaceApplier implements ComponentToWorkspaceAp .stream() .filter( c -> - c.getAttributes().get(COMPONENT_NAME_COMMAND_ATTRIBUTE).equals(editorComponentName)) + c.getAttributes() + .get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE) + .equals(editorComponentAlias)) .forEach(c -> c.getAttributes().put(PLUGIN_ATTRIBUTE, editorIdVersion)); } diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplier.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplier.java index 6ed0065004..7056d1a415 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplier.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplier.java @@ -17,6 +17,7 @@ import static java.lang.String.format; import static java.util.Collections.emptyMap; import static java.util.stream.Collectors.toList; import static org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE; +import static org.eclipse.che.api.devfile.server.Components.getIdentifiableComponentName; import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; @@ -122,20 +123,24 @@ public class KubernetesComponentToWorkspaceApplier implements ComponentToWorkspa 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(), recipeComponent.getName(), e.getMessage()), + 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", - recipeComponent.getName(), recipeComponent.getType(), e.getMessage()), + 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(), recipeComponent.getName())); + recipeComponent.getReference(), getIdentifiableComponentName(recipeComponent))); } return recipeFileContent; } @@ -154,9 +159,9 @@ public class KubernetesComponentToWorkspaceApplier implements ComponentToWorkspa .stream() .filter( c -> - component - .getName() - .equals(c.getAttributes().get(Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE))) + c.getAttributes() + .get(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE) + .equals(component.getAlias())) .collect(toList()); if (componentCommands.isEmpty()) { return; @@ -201,7 +206,9 @@ public class KubernetesComponentToWorkspaceApplier implements ComponentToWorkspa throw new DevfileRecipeFormatException( format( "Error occurred during parsing list from file %s for component '%s': %s", - k8sComponent.getReference(), k8sComponent.getName(), e.getMessage()), + k8sComponent.getReference(), + getIdentifiableComponentName(k8sComponent), + e.getMessage()), e); } } diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplier.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplier.java index 80f50a81c8..924cea3cee 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplier.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplier.java @@ -15,7 +15,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.isNullOrEmpty; import static java.lang.String.format; import static org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE; @@ -65,22 +65,24 @@ public class PluginComponentToWorkspaceApplier implements ComponentToWorkspaceAp String pluginsAliases = workspaceConfig.getAttributes().get(PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE); - workspaceConfig - .getAttributes() - .put( - PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE, - append(pluginsAliases, pluginComponent.getId() + "=" + pluginComponent.getName())); + if (pluginComponent.getAlias() != null) { + workspaceConfig + .getAttributes() + .put( + PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE, + append(pluginsAliases, pluginComponent.getId() + "=" + pluginComponent.getAlias())); + } String pluginIdVersion = resolveIdAndVersion(pluginComponent.getId()); for (CommandImpl command : workspaceConfig.getCommands()) { - String commandComponent = command.getAttributes().get(COMPONENT_NAME_COMMAND_ATTRIBUTE); + String commandComponent = command.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE); if (commandComponent == null) { // command does not have component information continue; } - if (!commandComponent.equals(pluginComponent.getName())) { + if (!commandComponent.equals(pluginComponent.getAlias())) { continue; } diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisioner.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisioner.java index 8dabe1e3b4..e6fc506df7 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisioner.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisioner.java @@ -54,19 +54,17 @@ public class PluginProvisioner implements ComponentProvisioner { return; } - Map pluginIdToComponentName = extractPluginIdToComponentName(workspaceConfig); + Map pluginIdToComponentAlias = extractPluginIdToComponentAlias(workspaceConfig); for (String pluginId : pluginsAttribute.split(",")) { - ComponentImpl pluginComponent = - new ComponentImpl( - PLUGIN_COMPONENT_TYPE, - pluginIdToComponentName.getOrDefault(pluginId, pluginId), - pluginId); + ComponentImpl pluginComponent = new ComponentImpl(PLUGIN_COMPONENT_TYPE, pluginId); + + pluginComponent.setAlias(pluginIdToComponentAlias.get(pluginId)); devfile.getComponents().add(pluginComponent); } } - private Map extractPluginIdToComponentName(WorkspaceConfigImpl wsConfig) { + private Map extractPluginIdToComponentAlias(WorkspaceConfigImpl wsConfig) { String aliasesAttribute = wsConfig.getAttributes().get(PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE); if (isNullOrEmpty(aliasesAttribute)) { diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidator.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidator.java index be3e28f77c..df0707a565 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidator.java +++ b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidator.java @@ -12,6 +12,7 @@ package org.eclipse.che.api.devfile.server.validator; import static java.lang.String.format; +import static org.eclipse.che.api.devfile.server.Components.getIdentifiableComponentName; import static org.eclipse.che.api.devfile.server.Constants.DOCKERIMAGE_COMPONENT_TYPE; import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; @@ -23,6 +24,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.utils.Serialization; import java.io.IOException; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -85,8 +87,8 @@ public class DevfileIntegrityValidator { */ public void validateDevfile(Devfile devfile) throws DevfileFormatException { validateProjects(devfile); - Set componentNames = validateComponents(devfile); - validateCommands(devfile, componentNames); + Set knownAliases = validateComponents(devfile); + validateCommands(devfile, knownAliases); } /** @@ -111,20 +113,36 @@ public class DevfileIntegrityValidator { } private Set validateComponents(Devfile devfile) throws DevfileFormatException { - Set existingNames = new HashSet<>(); + Set definedAliases = new HashSet<>(); Component editorComponent = null; + + Map> idsPerComponentType = new HashMap<>(); + for (Component component : devfile.getComponents()) { - if (!existingNames.add(component.getName())) { + if (component.getAlias() != null && !definedAliases.add(component.getAlias())) { throw new DevfileFormatException( - format("Duplicate component name found:'%s'", component.getName())); + format("Duplicate component alias found:'%s'", component.getAlias())); } + + 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())); + } + switch (component.getType()) { case EDITOR_COMPONENT_TYPE: if (editorComponent != null) { throw new DevfileFormatException( format( "Multiple editor components found: '%s', '%s'", - editorComponent.getName(), component.getName())); + getIdentifiableComponentName(editorComponent), + getIdentifiableComponentName(component))); } editorComponent = component; break; @@ -140,13 +158,13 @@ public class DevfileIntegrityValidator { throw new DevfileFormatException( format( "Unsupported component '%s' type provided:'%s'", - component.getName(), component.getType())); + getIdentifiableComponentName(component), component.getType())); } } - return existingNames; + return definedAliases; } - private void validateCommands(Devfile devfile, Set componentNames) + private void validateCommands(Devfile devfile, Set knownAliases) throws DevfileFormatException { Set existingNames = new HashSet<>(); for (Command command : devfile.getCommands()) { @@ -169,10 +187,10 @@ public class DevfileIntegrityValidator { } Action action = command.getActions().get(0); - if (!componentNames.contains(action.getComponent())) { + if (!knownAliases.contains(action.getComponent())) { throw new DevfileFormatException( format( - "Command '%s' has action that refers to non-existing components '%s'", + "Command '%s' has action that refers to a component with unknown alias '%s'", command.getName(), action.getComponent())); } } @@ -229,7 +247,7 @@ public class DevfileIntegrityValidator { throw new DevfileException( format( "The selector of the component %s filters out all objects from the list.", - component.getName())); + component.getAlias())); } return content; @@ -252,7 +270,7 @@ public class DevfileIntegrityValidator { throw new DevfileFormatException( format( "Component %s contains an entry point that doesn't match any container:\n%s", - component.getName(), toYAML(ep))); + component.getAlias(), toYAML(ep))); } } } diff --git a/wsmaster/che-core-api-devfile/src/main/resources/schema/devfile.json b/wsmaster/che-core-api-devfile/src/main/resources/schema/devfile.json index fa8ca682e3..cae6c6494a 100644 --- a/wsmaster/che-core-api-devfile/src/main/resources/schema/devfile.json +++ b/wsmaster/che-core-api-devfile/src/main/resources/schema/devfile.json @@ -128,7 +128,6 @@ "items": { "type": "object", "required": [ - "name", "type" ], "dependencies": { @@ -146,7 +145,7 @@ "chePlugin" ] }, - "name": {}, + "alias": {}, "id": {} }, "required": [ @@ -162,7 +161,7 @@ "openshift" ] }, - "name": {}, + "alias": {}, "reference": {}, "referenceContent": {}, "selector": {}, @@ -180,7 +179,7 @@ "dockerimage" ] }, - "name": {}, + "alias": {}, "image": {}, "memoryLimit": {}, "mountSources": {}, @@ -198,8 +197,8 @@ } ], "properties": { - "name": { - "description": "Describes the name of the component. Should be unique per components set.", + "alias": { + "description": "The name using which other places of this devfile (like commands) can refer to this component.", "type": "string", "examples": [ "mvn-stack" diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/CommandConverterTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/CommandConverterTest.java index 22b373d41b..661a79321e 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/CommandConverterTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/CommandConverterTest.java @@ -12,7 +12,7 @@ package org.eclipse.che.api.devfile.server.convert; import static org.eclipse.che.api.core.model.workspace.config.Command.WORKING_DIRECTORY_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.EXEC_ACTION_TYPE; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -42,7 +42,7 @@ public class CommandConverterTest { org.eclipse.che.api.workspace.server.model.impl.CommandImpl workspaceCommand = new org.eclipse.che.api.workspace.server.model.impl.CommandImpl( "build", "mvn clean install", "custom"); - workspaceCommand.getAttributes().put(COMPONENT_NAME_COMMAND_ATTRIBUTE, "dockerimageComponent"); + workspaceCommand.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "dockerimageComponent"); workspaceCommand.getAttributes().put(WORKING_DIRECTORY_ATTRIBUTE, "/tmp"); workspaceCommand.getAttributes().put("anotherAttribute", "value"); @@ -100,7 +100,7 @@ public class CommandConverterTest { assertEquals(workspaceCommand.getAttributes().get("attr"), "value"); assertEquals(workspaceCommand.getAttributes().get(WORKING_DIRECTORY_ATTRIBUTE), "/tmp"); assertEquals( - workspaceCommand.getAttributes().get(COMPONENT_NAME_COMMAND_ATTRIBUTE), + workspaceCommand.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE), "dockerimageComponent"); assertEquals(workspaceCommand.getCommandLine(), "mvn clean install"); } diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisionerTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisionerTest.java index a79eb2821a..ddfb7c9c5a 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisionerTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisionerTest.java @@ -15,7 +15,6 @@ import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE import static org.eclipse.che.api.devfile.server.Constants.EDITOR_FREE_DEVFILE_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; @@ -73,17 +72,11 @@ public class DefaultEditorProvisionerTest { // then List components = devfile.getComponents(); assertEquals(components.size(), 3); + assertTrue(components.contains(new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_REF))); assertTrue( - components.contains( - new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_ID, DEFAULT_EDITOR_REF))); + components.contains(new ComponentImpl(PLUGIN_COMPONENT_TYPE, DEFAULT_COMMAND_PLUGIN_REF))); assertTrue( - components.contains( - new ComponentImpl( - PLUGIN_COMPONENT_TYPE, DEFAULT_COMMAND_PLUGIN_ID, DEFAULT_COMMAND_PLUGIN_REF))); - assertTrue( - components.contains( - new ComponentImpl( - PLUGIN_COMPONENT_TYPE, DEFAULT_TERMINAL_PLUGIN_ID, DEFAULT_TERMINAL_PLUGIN_REF))); + components.contains(new ComponentImpl(PLUGIN_COMPONENT_TYPE, DEFAULT_TERMINAL_PLUGIN_REF))); } @Test @@ -95,7 +88,7 @@ public class DefaultEditorProvisionerTest { DevfileImpl devfile = new DevfileImpl(); ComponentImpl defaultEditorWithDifferentVersion = - new ComponentImpl(EDITOR_COMPONENT_TYPE, "my-editor", DEFAULT_EDITOR_ID + ":latest"); + new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_ID + ":latest"); devfile.getComponents().add(defaultEditorWithDifferentVersion); // when @@ -108,9 +101,7 @@ public class DefaultEditorProvisionerTest { assertTrue(components.contains(defaultEditorWithDifferentVersion)); assertTrue( - components.contains( - new ComponentImpl( - PLUGIN_COMPONENT_TYPE, DEFAULT_TERMINAL_PLUGIN_ID, DEFAULT_TERMINAL_PLUGIN_REF))); + components.contains(new ComponentImpl(PLUGIN_COMPONENT_TYPE, DEFAULT_TERMINAL_PLUGIN_REF))); } @Test @@ -124,9 +115,7 @@ public class DefaultEditorProvisionerTest { DevfileImpl devfile = new DevfileImpl(); ComponentImpl defaultEditorWithDifferentVersion = new ComponentImpl( - EDITOR_COMPONENT_TYPE, - "my-editor", - "https://my-custom-registry/" + DEFAULT_EDITOR_ID + ":latest"); + EDITOR_COMPONENT_TYPE, "https://my-custom-registry/" + DEFAULT_EDITOR_ID + ":latest"); devfile.getComponents().add(defaultEditorWithDifferentVersion); // when @@ -139,9 +128,7 @@ public class DefaultEditorProvisionerTest { assertTrue(components.contains(defaultEditorWithDifferentVersion)); assertTrue( - components.contains( - new ComponentImpl( - PLUGIN_COMPONENT_TYPE, DEFAULT_TERMINAL_PLUGIN_ID, DEFAULT_TERMINAL_PLUGIN_REF))); + components.contains(new ComponentImpl(PLUGIN_COMPONENT_TYPE, DEFAULT_TERMINAL_PLUGIN_REF))); } @Test @@ -153,8 +140,7 @@ public class DefaultEditorProvisionerTest { DevfileImpl devfile = new DevfileImpl(); ComponentImpl editorWithNameSimilarToDefault = - new ComponentImpl( - EDITOR_COMPONENT_TYPE, "my-editor", DEFAULT_EDITOR_ID + "-dev:dev-version"); + new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_ID + "-dev:dev-version"); devfile.getComponents().add(editorWithNameSimilarToDefault); // when @@ -195,8 +181,7 @@ public class DefaultEditorProvisionerTest { DevfileImpl devfile = new DevfileImpl(); ComponentImpl pluginWithNameSimilarToDefault = - new ComponentImpl( - PLUGIN_COMPONENT_TYPE, "my-plugin", DEFAULT_TERMINAL_PLUGIN_ID + "-dummy:latest"); + new ComponentImpl(PLUGIN_COMPONENT_TYPE, DEFAULT_TERMINAL_PLUGIN_ID + "-dummy:latest"); devfile.getComponents().add(pluginWithNameSimilarToDefault); // when @@ -205,13 +190,9 @@ public class DefaultEditorProvisionerTest { // then List components = devfile.getComponents(); assertEquals(components.size(), 3); + assertTrue(components.contains(new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_REF))); assertTrue( - components.contains( - new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_ID, DEFAULT_EDITOR_REF))); - assertTrue( - components.contains( - new ComponentImpl( - PLUGIN_COMPONENT_TYPE, DEFAULT_TERMINAL_PLUGIN_ID, DEFAULT_TERMINAL_PLUGIN_REF))); + components.contains(new ComponentImpl(PLUGIN_COMPONENT_TYPE, DEFAULT_TERMINAL_PLUGIN_REF))); assertTrue(components.contains(pluginWithNameSimilarToDefault)); } @@ -221,7 +202,7 @@ public class DefaultEditorProvisionerTest { defaultEditorProvisioner = new DefaultEditorProvisioner(DEFAULT_EDITOR_REF, new String[] {}); DevfileImpl devfile = new DevfileImpl(); ComponentImpl nonDefaultEditor = - new ComponentImpl(EDITOR_COMPONENT_TYPE, "editor", "any:v" + DEFAULT_EDITOR_VERSION); + new ComponentImpl(EDITOR_COMPONENT_TYPE, "any:v" + DEFAULT_EDITOR_VERSION); devfile.getComponents().add(nonDefaultEditor); // when @@ -239,8 +220,7 @@ public class DefaultEditorProvisionerTest { defaultEditorProvisioner = new DefaultEditorProvisioner(DEFAULT_EDITOR_REF, new String[] {}); DevfileImpl devfile = new DevfileImpl(); ComponentImpl myTheiaEditor = - new ComponentImpl( - EDITOR_COMPONENT_TYPE, "my-custom-theia", DEFAULT_EDITOR_REF + ":my-custom"); + new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_REF + ":my-custom"); devfile.getComponents().add(myTheiaEditor); // when @@ -253,15 +233,14 @@ public class DefaultEditorProvisionerTest { } @Test - public void shouldNonProvisionDefaultPluginIfDevfileAlreadyContainsSuchButWithDifferentVersion() { + public void shouldNotProvisionDefaultPluginIfDevfileAlreadyContainsSuchButWithDifferentVersion() { // given defaultEditorProvisioner = new DefaultEditorProvisioner( DEFAULT_EDITOR_REF, new String[] {DEFAULT_TERMINAL_PLUGIN_REF}); DevfileImpl devfile = new DevfileImpl(); ComponentImpl myTerminal = - new ComponentImpl( - PLUGIN_COMPONENT_TYPE, "my-terminal", DEFAULT_TERMINAL_PLUGIN_ID + ":my-custom"); + new ComponentImpl(PLUGIN_COMPONENT_TYPE, DEFAULT_TERMINAL_PLUGIN_ID + ":my-custom"); devfile.getComponents().add(myTerminal); // when @@ -270,9 +249,7 @@ public class DefaultEditorProvisionerTest { // then List components = devfile.getComponents(); assertEquals(components.size(), 2); - assertTrue( - components.contains( - new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_ID, DEFAULT_EDITOR_REF))); + assertTrue(components.contains(new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_REF))); assertTrue(components.contains(myTerminal)); } @@ -282,8 +259,7 @@ public class DefaultEditorProvisionerTest { defaultEditorProvisioner = new DefaultEditorProvisioner(DEFAULT_EDITOR_REF, new String[] {"my-plugin:v2.0"}); DevfileImpl devfile = new DevfileImpl(); - ComponentImpl myPlugin = - new ComponentImpl(PLUGIN_COMPONENT_TYPE, "my-plugin", "my-custom-plugin:v0.0.3"); + ComponentImpl myPlugin = new ComponentImpl(PLUGIN_COMPONENT_TYPE, "my-custom-plugin:v0.0.3"); devfile.getComponents().add(myPlugin); // when @@ -292,14 +268,11 @@ public class DefaultEditorProvisionerTest { // then List components = devfile.getComponents(); assertEquals(components.size(), 3); - assertTrue( - components.contains( - new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_ID, DEFAULT_EDITOR_REF))); + assertTrue(components.contains(new ComponentImpl(EDITOR_COMPONENT_TYPE, DEFAULT_EDITOR_REF))); assertTrue(components.contains(myPlugin)); ComponentImpl defaultPlugin = findByRef(components, "my-plugin:v2.0"); assertNotNull(defaultPlugin); - assertNotEquals("my-plugin", defaultPlugin.getName()); - assertTrue(defaultPlugin.getName().startsWith("my-plugin")); + assertNull(defaultPlugin.getAlias()); } private ComponentImpl findById(List components, String id) { diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisionerTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisionerTest.java index ec366245a8..367f86a5b9 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisionerTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisionerTest.java @@ -112,7 +112,7 @@ public class DockerimageComponentProvisionerTest { // then assertEquals(devfile.getComponents().size(), 1); ComponentImpl dockerimageComponent = devfile.getComponents().get(0); - assertEquals(dockerimageComponent.getName(), "dockerEnv"); + assertEquals(dockerimageComponent.getAlias(), "dockerEnv"); assertEquals(dockerimageComponent.getImage(), "eclipse/ubuntu_jdk8:latest"); } @@ -147,7 +147,7 @@ public class DockerimageComponentProvisionerTest { // then assertEquals(devfile.getComponents().size(), 1); ComponentImpl dockerimageComponent = devfile.getComponents().get(0); - assertEquals(dockerimageComponent.getName(), "dockerEnv"); + assertEquals(dockerimageComponent.getAlias(), "dockerEnv"); assertEquals(dockerimageComponent.getId(), "eclipse/ubuntu_jdk8:latest"); } diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplierTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplierTest.java index 7297ff268e..8894881c34 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplierTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplierTest.java @@ -87,7 +87,7 @@ public class DockerimageComponentToWorkspaceApplierTest { // given ComponentImpl dockerimageComponent = new ComponentImpl(); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); - dockerimageComponent.setName("jdk"); + dockerimageComponent.setAlias("jdk"); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); @@ -124,11 +124,54 @@ public class DockerimageComponentToWorkspaceApplierTest { assertEquals(container.getImage(), "eclipse/ubuntu_jdk8:latest"); } + @Test + public void shouldProvisionK8sEnvironmentWithMachineConfigFromSpecifiedDockerimageWithoutAlias() + throws Exception { + ComponentImpl dockerimageComponent = new ComponentImpl(); + dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); + dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); + dockerimageComponent.setMemoryLimit("1G"); + + // when + dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null); + + // then + verify(k8sEnvProvisioner) + .provision( + eq(workspaceConfig), + eq(KubernetesEnvironment.TYPE), + objectsCaptor.capture(), + machinesCaptor.capture()); + MachineConfigImpl machineConfig = machinesCaptor.getValue().get("eclipse-ubuntu_jdk8-latest"); + assertNotNull(machineConfig); + + List objects = objectsCaptor.getValue(); + assertEquals(objects.size(), 1); + assertTrue(objects.get(0) instanceof Deployment); + Deployment deployment = (Deployment) objects.get(0); + PodTemplateSpec podTemplate = deployment.getSpec().getTemplate(); + ObjectMeta podMeta = podTemplate.getMetadata(); + assertEquals(podMeta.getName(), "eclipse-ubuntu_jdk8-latest"); + + Map deploymentSelector = deployment.getSpec().getSelector().getMatchLabels(); + assertFalse(deploymentSelector.isEmpty()); + assertTrue(podMeta.getLabels().entrySet().containsAll(deploymentSelector.entrySet())); + + Map annotations = podMeta.getAnnotations(); + assertEquals( + annotations.get(String.format(MACHINE_NAME_ANNOTATION_FMT, "eclipse-ubuntu_jdk8-latest")), + "eclipse-ubuntu_jdk8-latest"); + + Container container = podTemplate.getSpec().getContainers().get(0); + assertEquals(container.getName(), "eclipse-ubuntu_jdk8-latest"); + assertEquals(container.getImage(), "eclipse/ubuntu_jdk8:latest"); + } + @Test public void shouldProvisionSpecifiedEnvVars() throws Exception { // given ComponentImpl dockerimageComponent = new ComponentImpl(); - dockerimageComponent.setName("jdk"); + dockerimageComponent.setAlias("jdk"); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); @@ -162,7 +205,7 @@ public class DockerimageComponentToWorkspaceApplierTest { public void shouldProvisionContainerWithMemoryLimitSpecified() throws Exception { // given ComponentImpl dockerimageComponent = new ComponentImpl(); - dockerimageComponent.setName("jdk"); + dockerimageComponent.setAlias("jdk"); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); @@ -205,7 +248,7 @@ public class DockerimageComponentToWorkspaceApplierTest { "secure", "false")); ComponentImpl dockerimageComponent = new ComponentImpl(); - dockerimageComponent.setName("jdk"); + dockerimageComponent.setAlias("jdk"); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); @@ -253,7 +296,7 @@ public class DockerimageComponentToWorkspaceApplierTest { DISCOVERABLE_ENDPOINT_ATTRIBUTE, "true")); ComponentImpl dockerimageComponent = new ComponentImpl(); - dockerimageComponent.setName("jdk"); + dockerimageComponent.setAlias("jdk"); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); @@ -294,7 +337,7 @@ public class DockerimageComponentToWorkspaceApplierTest { // given EndpointImpl endpoint = new EndpointImpl("jdk-ls", 4923, emptyMap()); ComponentImpl dockerimageComponent = new ComponentImpl(); - dockerimageComponent.setName("jdk"); + dockerimageComponent.setAlias("jdk"); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); @@ -321,7 +364,7 @@ public class DockerimageComponentToWorkspaceApplierTest { public void shouldProvisionMachineConfigWithConfiguredVolumes() throws Exception { // given ComponentImpl dockerimageComponent = new ComponentImpl(); - dockerimageComponent.setName("jdk"); + dockerimageComponent.setAlias("jdk"); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); @@ -349,7 +392,7 @@ public class DockerimageComponentToWorkspaceApplierTest { public void shouldProvisionMachineConfigWithMountSources() throws Exception { // given ComponentImpl dockerimageComponent = new ComponentImpl(); - dockerimageComponent.setName("jdk"); + dockerimageComponent.setAlias("jdk"); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); @@ -377,7 +420,7 @@ public class DockerimageComponentToWorkspaceApplierTest { public void shouldProvisionMachineConfigWithoutSourcesByDefault() throws Exception { // given ComponentImpl dockerimageComponent = new ComponentImpl(); - dockerimageComponent.setName("jdk"); + dockerimageComponent.setAlias("jdk"); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); @@ -404,7 +447,7 @@ public class DockerimageComponentToWorkspaceApplierTest { List args = Arrays.asList("-r", "f"); ComponentImpl dockerimageComponent = new ComponentImpl(); - dockerimageComponent.setName("jdk"); + dockerimageComponent.setAlias("jdk"); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisionerTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisionerTest.java index 5d1f5581d5..b34d1b9e05 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisionerTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisionerTest.java @@ -48,7 +48,7 @@ public class EditorComponentProvisionerTest { // then assertEquals(devfile.getComponents().size(), 1); ComponentImpl editorComponent = devfile.getComponents().get(0); - assertEquals(editorComponent.getName(), "editor"); + assertEquals(editorComponent.getAlias(), "editor"); assertEquals(editorComponent.getType(), EDITOR_COMPONENT_TYPE); assertEquals(editorComponent.getId(), "org.eclipse.che.super-editor:0.0.1"); } @@ -69,6 +69,6 @@ public class EditorComponentProvisionerTest { // then assertEquals(devfile.getComponents().size(), 1); ComponentImpl editorComponent = devfile.getComponents().get(0); - assertEquals(editorComponent.getName(), "org.eclipse.che.super-editor:0.0.1"); + assertEquals(editorComponent.getAlias(), "org.eclipse.che.super-editor:0.0.1"); } } diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplierTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplierTest.java index a748c311a3..bd8c2b659a 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplierTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplierTest.java @@ -12,7 +12,7 @@ package org.eclipse.che.api.devfile.server.convert.component.editor; import static org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE; @@ -41,7 +41,7 @@ public class EditorComponentToWorkspaceApplierTest { WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); ComponentImpl editorComponent = new ComponentImpl(); editorComponent.setType(EDITOR_COMPONENT_TYPE); - editorComponent.setName("editor"); + editorComponent.setAlias("editor"); editorComponent.setId("org.eclipse.che.super-editor:0.0.1"); // when @@ -60,13 +60,13 @@ public class EditorComponentToWorkspaceApplierTest { throws Exception { // given ComponentImpl superPluginComponent = new ComponentImpl(); - superPluginComponent.setName("editor"); + superPluginComponent.setAlias("editor"); superPluginComponent.setId("org.eclipse.che.super-editor:0.0.1"); superPluginComponent.setType(EDITOR_COMPONENT_TYPE); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); CommandImpl command = new CommandImpl(); - command.getAttributes().put(COMPONENT_NAME_COMMAND_ATTRIBUTE, "editor"); + command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "editor"); workspaceConfig.getCommands().add(command); // when @@ -83,14 +83,14 @@ public class EditorComponentToWorkspaceApplierTest { throws Exception { // given ComponentImpl superPluginComponent = new ComponentImpl(); - superPluginComponent.setName("editor"); + superPluginComponent.setAlias("editor"); superPluginComponent.setId( "https://custom-plugin.registry/plugins/org.eclipse.che.super-editor:0.0.1"); superPluginComponent.setType(EDITOR_COMPONENT_TYPE); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); CommandImpl command = new CommandImpl(); - command.getAttributes().put(COMPONENT_NAME_COMMAND_ATTRIBUTE, "editor"); + command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "editor"); workspaceConfig.getCommands().add(command); // when diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplierTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplierTest.java index f4005d1439..2a8afc52b0 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplierTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplierTest.java @@ -17,7 +17,7 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; import static org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; import static org.mockito.ArgumentMatchers.any; @@ -90,7 +90,7 @@ public class KubernetesComponentToWorkspaceApplierTest { ComponentImpl component = new ComponentImpl(); component.setType(KUBERNETES_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); - component.setName(COMPONENT_NAME); + component.setAlias(COMPONENT_NAME); // when applier.apply( @@ -115,7 +115,7 @@ public class KubernetesComponentToWorkspaceApplierTest { ComponentImpl component = new ComponentImpl(); component.setType(KUBERNETES_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); - component.setName(COMPONENT_NAME); + component.setAlias(COMPONENT_NAME); // when applier.apply(workspaceConfig, component, s -> "some_non_yaml_content"); @@ -130,7 +130,7 @@ public class KubernetesComponentToWorkspaceApplierTest { ComponentImpl component = new ComponentImpl(); component.setType(KUBERNETES_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); - component.setName(COMPONENT_NAME); + component.setAlias(COMPONENT_NAME); // when applier.apply( @@ -150,7 +150,7 @@ public class KubernetesComponentToWorkspaceApplierTest { ComponentImpl component = new ComponentImpl(); component.setType(KUBERNETES_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); - component.setName(COMPONENT_NAME); + component.setAlias(COMPONENT_NAME); // when applier.apply(workspaceConfig, component, s -> yamlRecipeContent); @@ -172,7 +172,7 @@ public class KubernetesComponentToWorkspaceApplierTest { component.setType(KUBERNETES_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); component.setReferenceContent(yamlRecipeContent); - component.setName(COMPONENT_NAME); + component.setAlias(COMPONENT_NAME); applier.apply(workspaceConfig, component, new URLFileContentProvider(null, null)); @@ -193,7 +193,7 @@ public class KubernetesComponentToWorkspaceApplierTest { ComponentImpl component = new ComponentImpl(); component.setType(OPENSHIFT_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); - component.setName(COMPONENT_NAME); + component.setAlias(COMPONENT_NAME); // when applier.apply(workspaceConfig, component, s -> yamlRecipeContent); @@ -216,7 +216,7 @@ public class KubernetesComponentToWorkspaceApplierTest { ComponentImpl component = new ComponentImpl(); component.setType(OPENSHIFT_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); - component.setName(COMPONENT_NAME); + component.setAlias(COMPONENT_NAME); component.setSelector(selector); doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString()); @@ -248,10 +248,10 @@ public class KubernetesComponentToWorkspaceApplierTest { ComponentImpl component = new ComponentImpl(); component.setType(OPENSHIFT_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); - component.setName(COMPONENT_NAME); + component.setAlias(COMPONENT_NAME); component.setSelector(selector); CommandImpl command = new CommandImpl(); - command.getAttributes().put(COMPONENT_NAME_COMMAND_ATTRIBUTE, COMPONENT_NAME); + command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, COMPONENT_NAME); workspaceConfig.getCommands().add(command); // when @@ -273,10 +273,10 @@ public class KubernetesComponentToWorkspaceApplierTest { ComponentImpl component = new ComponentImpl(); component.setType(OPENSHIFT_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); - component.setName(COMPONENT_NAME); + component.setAlias(COMPONENT_NAME); CommandImpl command = new CommandImpl(); - command.getAttributes().put(COMPONENT_NAME_COMMAND_ATTRIBUTE, COMPONENT_NAME); + command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, COMPONENT_NAME); workspaceConfig.getCommands().add(command); // when @@ -297,7 +297,7 @@ public class KubernetesComponentToWorkspaceApplierTest { ComponentImpl component = new ComponentImpl(); component.setType(KUBERNETES_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); - component.setName(COMPONENT_NAME); + component.setAlias(COMPONENT_NAME); EntrypointImpl entrypoint = new EntrypointImpl(); entrypoint.setParentName("petclinic"); diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplierTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplierTest.java index 37c44a9e82..28069614b8 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplierTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplierTest.java @@ -12,7 +12,7 @@ package org.eclipse.che.api.devfile.server.convert.component.plugin; import static org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE; import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE; @@ -40,12 +40,12 @@ public class PluginComponentToWorkspaceApplierTest { throws Exception { // given ComponentImpl superPluginComponent = new ComponentImpl(); - superPluginComponent.setName("super-plugin"); + superPluginComponent.setAlias("super-plugin"); superPluginComponent.setId("org.eclipse.che.super-plugin:0.0.1"); superPluginComponent.setType(PLUGIN_COMPONENT_TYPE); ComponentImpl customPluginComponent = new ComponentImpl(); - customPluginComponent.setName("custom"); + customPluginComponent.setAlias("custom"); customPluginComponent.setId("custom-plugin:v1"); customPluginComponent.setType(PLUGIN_COMPONENT_TYPE); @@ -73,13 +73,13 @@ public class PluginComponentToWorkspaceApplierTest { throws Exception { // given ComponentImpl superPluginComponent = new ComponentImpl(); - superPluginComponent.setName("super-plugin"); + superPluginComponent.setAlias("super-plugin"); superPluginComponent.setId("org.eclipse.che.super-plugin:0.0.1"); superPluginComponent.setType(PLUGIN_COMPONENT_TYPE); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); CommandImpl command = new CommandImpl(); - command.getAttributes().put(COMPONENT_NAME_COMMAND_ATTRIBUTE, "super-plugin"); + command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "super-plugin"); workspaceConfig.getCommands().add(command); // when @@ -96,14 +96,14 @@ public class PluginComponentToWorkspaceApplierTest { throws Exception { // given ComponentImpl superPluginComponent = new ComponentImpl(); - superPluginComponent.setName("super-plugin"); + superPluginComponent.setAlias("super-plugin"); superPluginComponent.setId( "https://custom-plugin.registry/plugins/org.eclipse.che.super-plugin:0.0.1"); superPluginComponent.setType(PLUGIN_COMPONENT_TYPE); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); CommandImpl command = new CommandImpl(); - command.getAttributes().put(COMPONENT_NAME_COMMAND_ATTRIBUTE, "super-plugin"); + command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "super-plugin"); workspaceConfig.getCommands().add(command); // when diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisionerTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisionerTest.java index a45548f403..85fb2e16e3 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisionerTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisionerTest.java @@ -15,6 +15,7 @@ import static org.eclipse.che.api.devfile.server.Constants.PLUGINS_COMPONENTS_AL import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; @@ -54,19 +55,18 @@ public class PluginProvisionerTest { // then assertEquals(devfile.getComponents().size(), 2); ComponentImpl superPluginComponent = devfile.getComponents().get(0); - assertEquals(superPluginComponent.getName(), "super-plugin"); + assertEquals(superPluginComponent.getAlias(), "super-plugin"); assertEquals(superPluginComponent.getId(), "org.eclipse.che.super-plugin:0.0.1"); assertEquals(superPluginComponent.getType(), PLUGIN_COMPONENT_TYPE); ComponentImpl customPluginComponent = devfile.getComponents().get(1); - assertEquals(customPluginComponent.getName(), "custom"); + assertEquals(customPluginComponent.getAlias(), "custom"); assertEquals(customPluginComponent.getId(), "custom-plugin:v1"); assertEquals(customPluginComponent.getType(), PLUGIN_COMPONENT_TYPE); } @Test - public void shouldUsePluginIdAsComponentNameIfAliasIsMissingDuringProvisioningChePluginComponent() - throws Exception { + public void shouldSetAliasOnComponentIfAliasIsMissingInWorkspaceConfig() throws Exception { // given WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); workspaceConfig @@ -80,7 +80,7 @@ public class PluginProvisionerTest { // then assertEquals(devfile.getComponents().size(), 1); ComponentImpl superPluginComponent = devfile.getComponents().get(0); - assertEquals(superPluginComponent.getName(), "org.eclipse.che.super-plugin:0.0.1"); + assertNull(superPluginComponent.getAlias()); assertEquals(superPluginComponent.getId(), "org.eclipse.che.super-plugin:0.0.1"); assertEquals(superPluginComponent.getType(), PLUGIN_COMPONENT_TYPE); } diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidatorTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidatorTest.java index 72160ecec3..766ec77368 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidatorTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidatorTest.java @@ -11,6 +11,7 @@ */ package org.eclipse.che.api.devfile.server.validator; +import static org.eclipse.che.api.devfile.server.Constants.DOCKERIMAGE_COMPONENT_TYPE; import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; @@ -66,11 +67,11 @@ public class DevfileIntegrityValidatorTest { @Test( expectedExceptions = DevfileFormatException.class, - expectedExceptionsMessageRegExp = "Duplicate component name found:'mvn-stack'") + expectedExceptionsMessageRegExp = "Duplicate component alias found:'mvn-stack'") public void shouldThrowExceptionOnDuplicateComponentName() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); ComponentImpl component = new ComponentImpl(); - component.setName(initialDevfile.getComponents().get(0).getName()); + component.setAlias(initialDevfile.getComponents().get(0).getAlias()); broken.getComponents().add(component); // when integrityValidator.validateDevfile(broken); @@ -78,11 +79,12 @@ public class DevfileIntegrityValidatorTest { @Test( expectedExceptions = DevfileFormatException.class, - expectedExceptionsMessageRegExp = "Multiple editor components found: 'theia-ide', 'editor-2'") + expectedExceptionsMessageRegExp = + "Multiple editor components found: 'org.eclipse.chetheia:0.0.3', 'editor-2'") public void shouldThrowExceptionOnMultipleEditors() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); ComponentImpl component = new ComponentImpl(); - component.setName("editor-2"); + component.setAlias("editor-2"); component.setType(EDITOR_COMPONENT_TYPE); broken.getComponents().add(component); // when @@ -128,7 +130,7 @@ public class DevfileIntegrityValidatorTest { @Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = - "Command 'build' has action that refers to non-existing components 'no_such_component'") + "Command 'build' has action that refers to a component with unknown alias 'no_such_component'") public void shouldThrowExceptionOnUnexistingCommandActionComponent() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); broken.getCommands().get(0).getActions().clear(); @@ -239,4 +241,31 @@ public class DevfileIntegrityValidatorTest { // then // no exception is thrown } + + @Test( + expectedExceptions = DevfileFormatException.class, + expectedExceptionsMessageRegExp = + "There are multiple components 'dockerimage:latest' of type 'dockerimage' that cannot be" + + " uniquely identified. Please add aliases that would distinguish the components.") + public void shouldRequireAliasWhenDockerImageComponentsHaveSameImage() throws Exception { + // given + DevfileImpl devfile = new DevfileImpl(initialDevfile); + + ComponentImpl docker1 = new ComponentImpl(); + docker1.setType(DOCKERIMAGE_COMPONENT_TYPE); + docker1.setImage("dockerimage:latest"); + + ComponentImpl docker2 = new ComponentImpl(); + docker2.setType(DOCKERIMAGE_COMPONENT_TYPE); + docker2.setImage("dockerimage:latest"); + + devfile.getComponents().add(docker1); + devfile.getComponents().add(docker2); + + // when + integrityValidator.validateDevfile(devfile); + + // then + // exception is thrown + } } diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileSchemaValidatorTest.java b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileSchemaValidatorTest.java index 65a7e6d7ab..94aafecb9d 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileSchemaValidatorTest.java +++ b/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileSchemaValidatorTest.java @@ -15,7 +15,6 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; import java.io.IOException; -import java.util.regex.Pattern; import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; import org.eclipse.che.api.devfile.server.schema.DevfileSchemaProvider; import org.testng.annotations.BeforeClass; @@ -27,16 +26,13 @@ public class DevfileSchemaValidatorTest { private DevfileSchemaValidator schemaValidator; - private static final Pattern TEST = - Pattern.compile("https?://[a-zA-Z0-9_\\-\\./]+[a-zA-Z0-9_\\-\\.]{1,}:[a-zA-Z0-9_\\-\\.]{1,}"); - @BeforeClass public void setUp() { schemaValidator = new DevfileSchemaValidator(new DevfileSchemaProvider()); } @Test(dataProvider = "validDevfiles") - public void shouldNotThrowExceptionOnValidationValidDevfile(String resourceFilePath) + public void shouldNotThrowExceptionOnValidationOfValidDevfile(String resourceFilePath) throws Exception { schemaValidator.validateBySchema(getResource(resourceFilePath)); } @@ -63,7 +59,7 @@ public class DevfileSchemaValidatorTest { } @Test(dataProvider = "invalidDevfiles") - public void shouldThrowExceptionOnValidationNonValidDevfile( + public void shouldThrowExceptionOnValidationOfNonValidDevfile( String resourceFilePath, String expectedMessageRegexp) throws Exception { try { schemaValidator.validateBySchema(getResource(resourceFilePath)); @@ -94,10 +90,6 @@ public class DevfileSchemaValidatorTest { "Devfile schema validation failed. Error: /devfile object instance has properties which are not allowed by the schema: [\"unknown\"]" }, // component model testing - { - "component/devfile_missing_component_name.yaml", - "Devfile schema validation failed. Error: /devfile/components/0 object has missing required properties ([\"name\"])" - }, { "component/devfile_missing_component_type.yaml", "Devfile schema validation failed. Error: /devfile/components/0 object has missing required properties ([\"type\"])" diff --git a/wsmaster/che-core-api-devfile/src/test/resources/devfile.yaml b/wsmaster/che-core-api-devfile/src/test/resources/devfile.yaml index c6c0420209..862f777131 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/devfile.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/devfile.yaml @@ -19,17 +19,15 @@ projects: type: git location: 'git@github.com:spring-projects/spring-petclinic.git' components: - - name: mvn-stack + - alias: mvn-stack type: chePlugin id: org.eclipse.chemaven-jdk8:1.0.0 - - name: theia-ide - type: cheEditor + - type: cheEditor id: org.eclipse.chetheia:0.0.3 - - name: jdt.ls + - alias: jdt.ls type: chePlugin id: org.eclipse.chetheia-jdtls:0.0.3 - - name: os-recipe - type: openshift + - type: openshift reference: petclinic.yaml selector: app.kubernetes.io/name: mysql diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_component_with_undeclared_field.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_component_with_undeclared_field.yaml index 507f149b1c..baf987d9d9 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_component_with_undeclared_field.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_component_with_undeclared_field.yaml @@ -15,6 +15,6 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - type: chePlugin - name: maven + alias: maven id: org.eclipse.chemaven-jdk8:1.0.0 unknown: blah-blah diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_missing_component_name.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_missing_component_name.yaml deleted file mode 100644 index 9a03447eed..0000000000 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_missing_component_name.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright (c) 2012-2018 Red Hat, Inc. -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# -# Contributors: -# Red Hat, Inc. - initial API and implementation -# - ---- -specVersion: 0.0.1 -name: petclinic-dev-environment -components: - - type: chePlugin - id: org.eclipse.chemaven-jdk8:1.0.0 diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_missing_component_type.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_missing_component_type.yaml index ba436e2975..d7396205f0 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_missing_component_type.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_missing_component_type.yaml @@ -14,5 +14,5 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: maven + - alias: maven id: org.eclipse.chemaven-jdk8:1.0.0 diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_without_any_component.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_without_any_component.yaml index b1c117479b..9a097d2a52 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_without_any_component.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_without_any_component.yaml @@ -13,7 +13,6 @@ --- specVersion: 0.0.1 name: petclinic-dev-environment -projects: projects: - name: petclinic source: diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_name.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_name.yaml index 18fdbb093b..e041993655 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_name.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_name.yaml @@ -13,5 +13,4 @@ --- specVersion: 0.0.1 components: - - name: maven - id: org.eclipse.chemaven-jdk8:1.0.0 + - id: org.eclipse.chemaven-jdk8:1.0.0 diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_spec_version.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_spec_version.yaml index c0e0545842..b8c08f95f3 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_spec_version.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_spec_version.yaml @@ -13,5 +13,4 @@ --- name: petclinic-dev-environment components: - - name: maven - id: org.eclipse.chemaven-jdk8:1.0.0 + - id: org.eclipse.chemaven-jdk8:1.0.0 diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_with_undeclared_field.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_with_undeclared_field.yaml index 7d1529c462..43087f2b49 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_with_undeclared_field.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_with_undeclared_field.yaml @@ -15,6 +15,5 @@ specVersion: 0.0.1 name: petclinic-dev-environment unknown: blah-blah components: - - name: maven - type: chePlugin + - type: chePlugin id: org.eclipse.chemaven-jdk8:1.0.0 diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component.yaml index 14dd257530..9a524275be 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component.yaml @@ -14,8 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: maven - type: dockerimage + - type: dockerimage image: eclipe/maven-jdk8:latest volumes: - name: maven-repo diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_indistinctive_field_selector.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_indistinctive_field_selector.yaml index b282b5cb78..93f3bbc603 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_indistinctive_field_selector.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_indistinctive_field_selector.yaml @@ -14,8 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: maven - type: dockerimage + - type: dockerimage image: eclipe/maven-jdk8:latest volumes: - name: maven-repo diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_image.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_image.yaml index c673985892..336542ddcd 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_image.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_image.yaml @@ -14,6 +14,5 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: maven - type: dockerimage + - type: dockerimage memoryLimit: 1G diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_memory_limit.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_memory_limit.yaml index a01bfa5fd9..28ecb24897 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_memory_limit.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_memory_limit.yaml @@ -14,6 +14,5 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: maven - type: dockerimage + - type: dockerimage image: org.eclipse.cheubuntu-jdk:latest diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_without_entry_point.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_without_entry_point.yaml index b043a5ce2c..68cbdbc19f 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_without_entry_point.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_without_entry_point.yaml @@ -14,8 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: maven - type: dockerimage + - type: dockerimage image: eclipe/maven-jdk8:latest volumes: - name: maven-repo diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_custom_registry.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_custom_registry.yaml index c8d66cf005..4296937263 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_custom_registry.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_custom_registry.yaml @@ -13,12 +13,9 @@ specVersion: 0.0.1 name: terminal-sample components: - - name: terminal-sample-plugin - type: chePlugin + - type: chePlugin id: https://raw.githubusercontent.com/eclipse/che-plugin-registry/master/terminal-sample:0.0.1 - - name: terminal-sample-plugin2 - type: chePlugin + - type: chePlugin id: http://raw.githubusercontent.com/eclipse/che-plugin-registry/master/terminal-sample:0.0.1 - - name: theia - type: cheEditor + - type: cheEditor id: https://che-plugin-registry.openshift.io/org.eclipse.theia-ide:0.0.1 diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_indistinctive_field_reference.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_indistinctive_field_reference.yaml index 54738d8a6a..a2f9ef125e 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_indistinctive_field_reference.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_indistinctive_field_reference.yaml @@ -14,7 +14,6 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: theia-ide - type: cheEditor + - type: cheEditor id: org.eclipse.theia:0.0.3 reference: petclinic.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_missing_id.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_missing_id.yaml index c5ec6de9d7..3a349e3993 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_missing_id.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_missing_id.yaml @@ -14,5 +14,4 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: theia-ide - type: cheEditor + - type: cheEditor diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_multiple_colons_in_id.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_multiple_colons_in_id.yaml index 4776bcf845..37ae12309a 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_multiple_colons_in_id.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_multiple_colons_in_id.yaml @@ -14,6 +14,5 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: theia-ide - type: cheEditor + - type: cheEditor id: org.eclipse.theia:dev:v1 diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_without_version.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_without_version.yaml index 5968184246..6c6e8f005f 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_without_version.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_without_version.yaml @@ -14,6 +14,5 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: theia-ide - type: cheEditor + - type: cheEditor id: org.eclipse.theia diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_plugins.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_plugins.yaml index 483452dc0d..f2a72cd69c 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_plugins.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_plugins.yaml @@ -19,14 +19,12 @@ projects: type: git location: 'git@github.com:spring-projects/spring-petclinic.git' components: - - name: theia-ide - type: cheEditor + - type: cheEditor id: org.eclipse.chetheia:0.0.3 - - name: mvn-stack + - alias: mvn-stack type: chePlugin id: org.eclipse.chemaven-jdk8:1.0.0 - - name: jdt.ls - type: chePlugin + - type: chePlugin id: org.eclipse.chetheia-jdtls:0.0.3 commands: - name: build diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_absolute_reference.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_absolute_reference.yaml index 69d2dcd28d..eb1b6be12c 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_absolute_reference.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_absolute_reference.yaml @@ -14,7 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: mysql + - alias: mysql type: kubernetes reference: https://github.com/redhat-developer/devfile/blob/master/samples/web-nodejs-with-db-sample/mongo-db.yaml selector: diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_content_without_reference.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_content_without_reference.yaml index 0649bf4009..445a6ec872 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_content_without_reference.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_content_without_reference.yaml @@ -14,7 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: mysql + - alias: mysql type: kubernetes referenceContent: petclinic.yaml selector: diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference.yaml index 572c676a1a..bb0ceda869 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference.yaml @@ -14,7 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: mysql + - alias: mysql type: kubernetes reference: petclinic.yaml selector: diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference_and_content_as_block.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference_and_content_as_block.yaml index f361043569..1de872d35e 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference_and_content_as_block.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference_and_content_as_block.yaml @@ -14,8 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: mysql - type: kubernetes + - type: kubernetes reference: petclinic.yaml referenceContent: | kind: List diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component.yaml index c065c8c02f..84f1a42afd 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component.yaml @@ -14,7 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: mysql + - alias: mysql type: openshift reference: petclinic.yaml selector: diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_content_without_reference.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_content_without_reference.yaml index 0d6d277822..4678537547 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_content_without_reference.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_content_without_reference.yaml @@ -14,7 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: mysql + - alias: mysql type: openshift referenceContent: this is content of file that is supposed to be in local field but it is missing selector: diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content.yaml index 165f4396e2..e14d0586d3 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content.yaml @@ -14,8 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: mysql - type: openshift + - type: openshift referenceContent: it is supposed to be a content of the file specified in the local field reference: petclinic.yaml selector: diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content_as_block.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content_as_block.yaml index 4d02fc230a..3527513f35 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content_as_block.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content_as_block.yaml @@ -14,8 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: mysql - type: openshift + - type: openshift referenceContent: | kind: List items: diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_indistinctive_field_id.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_indistinctive_field_id.yaml index 41b7f4a214..70c842ee00 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_indistinctive_field_id.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_indistinctive_field_id.yaml @@ -14,7 +14,7 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: mysql + - alias: mysql type: openshift reference: petclinic.yaml selector: diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_missing_reference.yaml b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_missing_reference.yaml index d44a4a946d..2aa29ebe4b 100644 --- a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_missing_reference.yaml +++ b/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_missing_reference.yaml @@ -14,5 +14,4 @@ specVersion: 0.0.1 name: petclinic-dev-environment components: - - name: mysql - type: openshift + - type: openshift diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/model/impl/devfile/ComponentImpl.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/model/impl/devfile/ComponentImpl.java index f115345faa..f5162bdf49 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/model/impl/devfile/ComponentImpl.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/model/impl/devfile/ComponentImpl.java @@ -27,7 +27,7 @@ import org.eclipse.che.api.core.model.workspace.devfile.Volume; /** @author Sergii Leshchenko */ public class ComponentImpl implements Component { - private String name; + private String alias; private String type; private String id; private String reference; @@ -45,20 +45,17 @@ public class ComponentImpl implements Component { public ComponentImpl() {} - public ComponentImpl(String type, String name, String id) { - this.name = name; + public ComponentImpl(String type, String id) { this.type = type; this.id = id; } public ComponentImpl( String type, - String name, String reference, String referenceContent, Map selector, List entrypoints) { - this.name = name; this.type = type; this.reference = reference; this.referenceContent = referenceContent; @@ -73,7 +70,7 @@ public class ComponentImpl implements Component { public ComponentImpl( String type, - String name, + String alias, String image, String memoryLimit, boolean mountSources, @@ -82,7 +79,7 @@ public class ComponentImpl implements Component { List volumes, List env, List endpoints) { - this.name = name; + this.alias = alias; this.type = type; this.image = image; this.memoryLimit = memoryLimit; @@ -103,7 +100,7 @@ public class ComponentImpl implements Component { public ComponentImpl( String type, - String name, + String alias, String id, String reference, String referenceContent, @@ -116,7 +113,7 @@ public class ComponentImpl implements Component { List volumes, List env, List endpoints) { - this.name = name; + this.alias = alias; this.type = type; this.id = id; this.reference = reference; @@ -145,7 +142,7 @@ public class ComponentImpl implements Component { public ComponentImpl(Component component) { this( component.getType(), - component.getName(), + component.getAlias(), component.getId(), component.getReference(), component.getReferenceContent(), @@ -161,12 +158,12 @@ public class ComponentImpl implements Component { } @Override - public String getName() { - return name; + public String getAlias() { + return alias; } - public void setName(String name) { - this.name = name; + public void setAlias(String alias) { + this.alias = alias; } @Override @@ -326,7 +323,7 @@ public class ComponentImpl implements Component { } ComponentImpl component = (ComponentImpl) o; return getMountSources() == component.getMountSources() - && Objects.equals(getName(), component.getName()) + && Objects.equals(getAlias(), component.getAlias()) && Objects.equals(getType(), component.getType()) && Objects.equals(getId(), component.getId()) && Objects.equals(getReference(), component.getReference()) @@ -346,7 +343,7 @@ public class ComponentImpl implements Component { public int hashCode() { return Objects.hash( - getName(), + getAlias(), getType(), getId(), getReference(), @@ -366,8 +363,8 @@ public class ComponentImpl implements Component { @Override public String toString() { return "ComponentImpl{" - + "name='" - + name + + "alias='" + + alias + '\'' + ", type='" + type