Search in sources :

Example 1 with EDITOR_COMPONENT_TYPE

use of org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE in project che-server by eclipse-che.

the class DefaultEditorProvisioner method apply.

/**
 * Provision default editor if there is no editor. Also provisions default plugins for default
 * editor regardless whether it is provisioned or set by user.
 *
 * @param devfile devfile where editor and plugins should be provisioned
 * @param contentProvider content provider for plugin references retrieval
 */
public void apply(DevfileImpl devfile, FileContentProvider contentProvider) throws DevfileException {
    if (defaultEditorRef == null) {
        // there is no default editor configured
        return;
    }
    if ("true".equals(devfile.getAttributes().get(EDITOR_FREE_DEVFILE_ATTRIBUTE))) {
        return;
    }
    List<ComponentImpl> components = devfile.getComponents();
    Optional<ComponentImpl> editorOpt = components.stream().filter(t -> EDITOR_COMPONENT_TYPE.equals(t.getType())).findFirst();
    boolean isDefaultEditorUsed;
    if (!editorOpt.isPresent()) {
        components.add(new ComponentImpl(EDITOR_COMPONENT_TYPE, defaultEditorRef));
        isDefaultEditorUsed = true;
    } else {
        Component editor = editorOpt.get();
        String editorPublisherAndName = getPluginPublisherAndName(editor, contentProvider);
        isDefaultEditorUsed = defaultEditor.equals(editorPublisherAndName);
    }
    if (isDefaultEditorUsed) {
        provisionDefaultPlugins(components, contentProvider);
    }
    if ("false".equals(devfile.getAttributes().get(PERSIST_VOLUMES_ATTRIBUTE)) && "true".equals(devfile.getAttributes().get(ASYNC_PERSIST_ATTRIBUTE))) {
        provisionAsyncStoragePlugin(components, contentProvider);
    }
}
Also used : ASYNC_PERSIST_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.ASYNC_PERSIST_ATTRIBUTE) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) PluginFQNParser(org.eclipse.che.api.workspace.server.wsplugins.PluginFQNParser) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) PLUGIN_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) Nullable(org.eclipse.che.commons.annotation.Nullable) Inject(javax.inject.Inject) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) PERSIST_VOLUMES_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.PERSIST_VOLUMES_ATTRIBUTE) Map(java.util.Map) EDITOR_FREE_DEVFILE_ATTRIBUTE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_FREE_DEVFILE_ATTRIBUTE) Optional(java.util.Optional) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Named(javax.inject.Named) EDITOR_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE) Collections(java.util.Collections) ComponentFQNParser(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)

Example 2 with EDITOR_COMPONENT_TYPE

use of org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE in project che-server by eclipse-che.

the class DevfileIntegrityValidator method validateComponents.

private Set<String> validateComponents(Devfile devfile) throws DevfileFormatException {
    Set<String> definedAliases = new HashSet<>();
    Component editorComponent = null;
    Map<String, Set<String>> idsPerComponentType = new HashMap<>();
    for (Component component : devfile.getComponents()) {
        if (component.getAlias() != null && !definedAliases.add(component.getAlias())) {
            throw new DevfileFormatException(format("Duplicate component alias found:'%s'", component.getAlias()));
        }
        Optional<Map.Entry<String, Long>> duplicatedEndpoint = component.getEndpoints().stream().map(Endpoint::getName).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().filter(e -> e.getValue() > 1L).findFirst();
        if (duplicatedEndpoint.isPresent()) {
            throw new DevfileFormatException(format("Duplicated endpoint name '%s' found in '%s' component", duplicatedEndpoint.get().getKey(), getIdentifiableComponentName(component)));
        }
        Set<String> tempSet = new HashSet<>();
        for (Env env : component.getEnv()) {
            if (!tempSet.add(env.getName())) {
                throw new DevfileFormatException(format("Duplicate environment variable '%s' found in component '%s'", env.getName(), getIdentifiableComponentName(component)));
            }
        }
        if (!idsPerComponentType.computeIfAbsent(component.getType(), __ -> new HashSet<>()).add(getIdentifiableComponentName(component))) {
            throw new DevfileFormatException(format("There are multiple components '%s' of type '%s' that cannot be uniquely" + " identified. Please add aliases that would distinguish the components.", getIdentifiableComponentName(component), component.getType()));
        }
        if (component.getAutomountWorkspaceSecrets() != null && component.getAlias() == null) {
            throw new DevfileFormatException(format("The 'automountWorkspaceSecrets' property cannot be used in component which doesn't have alias. " + "Please add alias to component '%s' that would allow to distinguish its containers.", getIdentifiableComponentName(component)));
        }
        switch(component.getType()) {
            case EDITOR_COMPONENT_TYPE:
                if (editorComponent != null) {
                    throw new DevfileFormatException(format("Multiple editor components found: '%s', '%s'", getIdentifiableComponentName(editorComponent), getIdentifiableComponentName(component)));
                }
                editorComponent = component;
                break;
            case PLUGIN_COMPONENT_TYPE:
            case KUBERNETES_COMPONENT_TYPE:
            case OPENSHIFT_COMPONENT_TYPE:
            case DOCKERIMAGE_COMPONENT_TYPE:
                // do nothing
                break;
            default:
                throw new DevfileFormatException(format("One of the components has unsupported component type: '%s'", component.getType()));
        }
    }
    return definedAliases;
}
Also used : KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Env(org.eclipse.che.api.core.model.workspace.devfile.Env) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) PLUGIN_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE) Function(java.util.function.Function) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Map(java.util.Map) Components.getIdentifiableComponentName(org.eclipse.che.api.workspace.server.devfile.Components.getIdentifiableComponentName) EDITOR_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE) DOCKERIMAGE_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) Devfile(org.eclipse.che.api.core.model.workspace.devfile.Devfile) OPENSHIFT_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) Optional(java.util.Optional) Command(org.eclipse.che.api.core.model.workspace.devfile.Command) Project(org.eclipse.che.api.core.model.workspace.devfile.Project) Pattern(java.util.regex.Pattern) Action(org.eclipse.che.api.core.model.workspace.devfile.Action) Endpoint(org.eclipse.che.api.core.model.workspace.devfile.Endpoint) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Env(org.eclipse.che.api.core.model.workspace.devfile.Env) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) HashSet(java.util.HashSet)

Example 3 with EDITOR_COMPONENT_TYPE

use of org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE in project devspaces-images by redhat-developer.

the class DefaultEditorProvisioner method apply.

/**
 * Provision default editor if there is no editor. Also provisions default plugins for default
 * editor regardless whether it is provisioned or set by user.
 *
 * @param devfile devfile where editor and plugins should be provisioned
 * @param contentProvider content provider for plugin references retrieval
 */
public void apply(DevfileImpl devfile, FileContentProvider contentProvider) throws DevfileException {
    if (defaultEditorRef == null) {
        // there is no default editor configured
        return;
    }
    if ("true".equals(devfile.getAttributes().get(EDITOR_FREE_DEVFILE_ATTRIBUTE))) {
        return;
    }
    List<ComponentImpl> components = devfile.getComponents();
    Optional<ComponentImpl> editorOpt = components.stream().filter(t -> EDITOR_COMPONENT_TYPE.equals(t.getType())).findFirst();
    boolean isDefaultEditorUsed;
    if (!editorOpt.isPresent()) {
        components.add(new ComponentImpl(EDITOR_COMPONENT_TYPE, defaultEditorRef));
        isDefaultEditorUsed = true;
    } else {
        Component editor = editorOpt.get();
        String editorPublisherAndName = getPluginPublisherAndName(editor, contentProvider);
        isDefaultEditorUsed = defaultEditor.equals(editorPublisherAndName);
    }
    if (isDefaultEditorUsed) {
        provisionDefaultPlugins(components, contentProvider);
    }
    if ("false".equals(devfile.getAttributes().get(PERSIST_VOLUMES_ATTRIBUTE)) && "true".equals(devfile.getAttributes().get(ASYNC_PERSIST_ATTRIBUTE))) {
        provisionAsyncStoragePlugin(components, contentProvider);
    }
}
Also used : ASYNC_PERSIST_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.ASYNC_PERSIST_ATTRIBUTE) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) PluginFQNParser(org.eclipse.che.api.workspace.server.wsplugins.PluginFQNParser) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) PLUGIN_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) Nullable(org.eclipse.che.commons.annotation.Nullable) Inject(javax.inject.Inject) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) PERSIST_VOLUMES_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.PERSIST_VOLUMES_ATTRIBUTE) Map(java.util.Map) EDITOR_FREE_DEVFILE_ATTRIBUTE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_FREE_DEVFILE_ATTRIBUTE) Optional(java.util.Optional) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Named(javax.inject.Named) EDITOR_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE) Collections(java.util.Collections) ComponentFQNParser(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)

Example 4 with EDITOR_COMPONENT_TYPE

use of org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE in project che-server by eclipse-che.

the class EditorComponentToWorkspaceApplier method apply.

/**
 * Applies changes on workspace config according to the specified editor component.
 *
 * @param workspaceConfig workspace config on which changes should be applied
 * @param editorComponent plugin component that should be applied
 * @param contentProvider optional content provider that may be used for external component
 *     resource fetching
 * @throws IllegalArgumentException if specified workspace config or plugin component is null
 * @throws IllegalArgumentException if specified component has type different from cheEditor
 */
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl editorComponent, FileContentProvider contentProvider) throws DevfileException {
    checkArgument(workspaceConfig != null, "Workspace config must not be null");
    checkArgument(editorComponent != null, "Component must not be null");
    checkArgument(EDITOR_COMPONENT_TYPE.equals(editorComponent.getType()), format("Plugin must have `%s` type", EDITOR_COMPONENT_TYPE));
    final String editorComponentAlias = editorComponent.getAlias();
    final String editorId = editorComponent.getId();
    final String registryUrl = editorComponent.getRegistryUrl();
    final ExtendedPluginFQN fqn = componentFQNParser.evaluateFQN(editorComponent, contentProvider);
    if (!isNullOrEmpty(fqn.getReference())) {
        workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, fqn.getReference());
    } else {
        workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, componentFQNParser.getCompositeId(registryUrl, editorId));
    }
    workspaceConfig.getCommands().stream().filter(c -> editorComponentAlias != null && editorComponentAlias.equals(c.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE))).forEach(c -> c.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId()));
    // make sure id is set to be able to match component with plugin broker result
    // when referenceContent is used
    editorComponent.setId(fqn.getId());
}
Also used : PLUGIN_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) WORKSPACE_TOOLING_EDITOR_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE) String.format(java.lang.String.format) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) ComponentToWorkspaceApplier(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) COMPONENT_ALIAS_COMMAND_ATTRIBUTE(org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE) EDITOR_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE) ComponentFQNParser(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)

Example 5 with EDITOR_COMPONENT_TYPE

use of org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE in project devspaces-images by redhat-developer.

the class EditorComponentToWorkspaceApplier method apply.

/**
 * Applies changes on workspace config according to the specified editor component.
 *
 * @param workspaceConfig workspace config on which changes should be applied
 * @param editorComponent plugin component that should be applied
 * @param contentProvider optional content provider that may be used for external component
 *     resource fetching
 * @throws IllegalArgumentException if specified workspace config or plugin component is null
 * @throws IllegalArgumentException if specified component has type different from cheEditor
 */
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl editorComponent, FileContentProvider contentProvider) throws DevfileException {
    checkArgument(workspaceConfig != null, "Workspace config must not be null");
    checkArgument(editorComponent != null, "Component must not be null");
    checkArgument(EDITOR_COMPONENT_TYPE.equals(editorComponent.getType()), format("Plugin must have `%s` type", EDITOR_COMPONENT_TYPE));
    final String editorComponentAlias = editorComponent.getAlias();
    final String editorId = editorComponent.getId();
    final String registryUrl = editorComponent.getRegistryUrl();
    final ExtendedPluginFQN fqn = componentFQNParser.evaluateFQN(editorComponent, contentProvider);
    if (!isNullOrEmpty(fqn.getReference())) {
        workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, fqn.getReference());
    } else {
        workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, componentFQNParser.getCompositeId(registryUrl, editorId));
    }
    workspaceConfig.getCommands().stream().filter(c -> editorComponentAlias != null && editorComponentAlias.equals(c.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE))).forEach(c -> c.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId()));
    // make sure id is set to be able to match component with plugin broker result
    // when referenceContent is used
    editorComponent.setId(fqn.getId());
}
Also used : PLUGIN_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) WORKSPACE_TOOLING_EDITOR_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE) String.format(java.lang.String.format) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) ComponentToWorkspaceApplier(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) COMPONENT_ALIAS_COMMAND_ATTRIBUTE(org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE) EDITOR_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE) ComponentFQNParser(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)

Aggregations

Inject (javax.inject.Inject)6 EDITOR_COMPONENT_TYPE (org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE)6 FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)6 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)4 String.format (java.lang.String.format)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Component (org.eclipse.che.api.core.model.workspace.devfile.Component)4 PLUGIN_COMPONENT_TYPE (org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE)4 ComponentFQNParser (org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser)4 DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)4 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)4 ExtendedPluginFQN (org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Function (java.util.function.Function)2