Search in sources :

Example 76 with DevfileImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project devspaces-images by redhat-developer.

the class URLFactoryBuilder method createFactory.

/**
 * Converts given devfile json into factory based on the devfile version.
 *
 * @param overrideProperties map of overridden properties to apply in devfile
 * @param fileContentProvider service-specific devfile related file content provider
 * @param location devfile's location
 * @return new factory created from the given devfile
 * @throws OverrideParameterException when any issue when overriding parameters occur
 * @throws DevfileException when devfile is not valid or we can't work with it
 */
private FactoryMetaDto createFactory(JsonNode devfileJson, Map<String, String> overrideProperties, FileContentProvider fileContentProvider, DevfileLocation location) throws OverrideParameterException, DevfileException {
    if (devfileVersionDetector.devfileMajorVersion(devfileJson) == 1) {
        DevfileImpl devfile = devfileParser.parseJsonNode(devfileJson, overrideProperties);
        devfileParser.resolveReference(devfile, fileContentProvider);
        devfile = ensureToUseGenerateName(devfile);
        return newDto(FactoryDto.class).withV(CURRENT_VERSION).withDevfile(DtoConverter.asDto(devfile)).withSource(location.filename().isPresent() ? location.filename().get() : null);
    } else {
        return newDto(FactoryDevfileV2Dto.class).withV(CURRENT_VERSION).withDevfile(devfileParser.convertYamlToMap(devfileJson)).withSource(location.filename().isPresent() ? location.filename().get() : null);
    }
}
Also used : FactoryDevfileV2Dto(org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto)

Example 77 with DevfileImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project devspaces-images by redhat-developer.

the class WorkspaceManager method updateWorkspace.

/**
 * Updates an existing workspace with a new configuration.
 *
 * <p>
 *
 * <p>Replace strategy is used for workspace update, it means that existing workspace data will be
 * replaced with given {@code update}.
 *
 * @param update workspace update
 * @return updated instance of the workspace
 * @throws NullPointerException when either {@code workspaceId} or {@code update} is null
 * @throws NotFoundException when workspace with given id doesn't exist
 * @throws ConflictException when any conflict occurs (e.g Workspace with such name already exists
 *     in {@code namespace})
 * @throws ServerException when any other error occurs
 */
public WorkspaceImpl updateWorkspace(String id, Workspace update) throws ConflictException, ServerException, NotFoundException, ValidationException {
    requireNonNull(id, "Required non-null workspace id");
    requireNonNull(update, "Required non-null workspace update");
    checkArgument(update.getConfig() != null ^ update.getDevfile() != null, "Required non-null workspace configuration or devfile update but not both");
    if (update.getConfig() != null) {
        validator.validateConfig(update.getConfig());
    }
    WorkspaceImpl workspace = workspaceDao.get(id);
    validator.validateUpdateAttributes(workspace.getAttributes(), update.getAttributes());
    if (workspace.getConfig() != null) {
        workspace.setConfig(new WorkspaceConfigImpl(update.getConfig()));
    }
    if (workspace.getDevfile() != null) {
        workspace.setDevfile(new DevfileImpl(update.getDevfile()));
    }
    workspace.setAttributes(update.getAttributes());
    workspace.getAttributes().put(UPDATED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis()));
    workspace.setTemporary(update.isTemporary());
    return normalizeState(workspaceDao.update(workspace), true);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)

Example 78 with DevfileImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project devspaces-images by redhat-developer.

the class WorkspaceManager method generateNameIfNeeded.

/**
 * If 'generateName' is defined and 'name' is not, we generate name using 'generateName' as a
 * prefix following {@link Constants#WORKSPACE_GENERATE_NAME_CHARS_APPEND} random characters and
 * set it to 'name'.
 */
private Devfile generateNameIfNeeded(Devfile origDevfile) {
    if (origDevfile.getMetadata() != null) {
        MetadataImpl metadata = new MetadataImpl(origDevfile.getMetadata());
        if (metadata.getName() == null && metadata.getGenerateName() != null) {
            metadata.setName(NameGenerator.generate(metadata.getGenerateName(), WORKSPACE_GENERATE_NAME_CHARS_APPEND));
            DevfileImpl devfileWithGeneratedName = new DevfileImpl(origDevfile);
            devfileWithGeneratedName.setMetadata(metadata);
            return devfileWithGeneratedName;
        }
    }
    return origDevfile;
}
Also used : MetadataImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)

Example 79 with DevfileImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl 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 80 with DevfileImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project devspaces-images by redhat-developer.

the class DevfileConverter method devFileToWorkspaceConfig.

/**
 * Converts given {@link Devfile} into {@link WorkspaceConfigImpl workspace config}.
 *
 * @param devfile initial devfile
 * @param contentProvider content provider for recipe-type component or plugin references
 * @return constructed workspace config
 * @throws DevfileException when general devfile error occurs
 * @throws DevfileException when devfile requires additional files content but the specified
 *     content provider does not support it
 * @throws DevfileFormatException when devfile format is invalid
 * @throws DevfileRecipeFormatException when content of the file specified in recipe type
 *     component is empty or its format is invalid
 */
public WorkspaceConfigImpl devFileToWorkspaceConfig(DevfileImpl devfile, FileContentProvider contentProvider) throws DevfileException {
    checkArgument(devfile != null, "Devfile must not be null");
    checkArgument(contentProvider != null, "Content provider must not be null");
    // make copy to avoid modification of original devfile
    devfile = new DevfileImpl(devfile);
    validateCurrentVersion(devfile);
    defaultEditorProvisioner.apply(devfile, contentProvider);
    WorkspaceConfigImpl config = new WorkspaceConfigImpl();
    config.setName(devfile.getName());
    for (Command command : devfile.getCommands()) {
        CommandImpl com = commandConverter.toWorkspaceCommand(command, contentProvider);
        if (com != null) {
            config.getCommands().add(com);
        }
    }
    // so, commands should be already converted
    for (ComponentImpl component : devfile.getComponents()) {
        ComponentToWorkspaceApplier applier = componentTypeToApplier.get(component.getType());
        if (applier == null) {
            throw new DevfileException(String.format("Devfile contains component `%s` with type `%s` that can not be converted to workspace", getIdentifiableComponentName(component), component.getType()));
        }
        applier.apply(config, component, contentProvider);
    }
    for (ProjectImpl project : devfile.getProjects()) {
        ProjectConfigImpl projectConfig = projectConverter.toWorkspaceProject(project);
        config.getProjects().add(projectConfig);
    }
    config.getAttributes().putAll(devfile.getAttributes());
    config.setDevfile(devfile);
    return config;
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) Command(org.eclipse.che.api.core.model.workspace.devfile.Command) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) ProjectImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) ComponentToWorkspaceApplier(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Aggregations

DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)162 Test (org.testng.annotations.Test)126 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)76 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)22 FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)20 MetadataImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl)20 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)18 ActionImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl)16 ProjectImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl)16 Container (io.fabric8.kubernetes.api.model.Container)14 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl)14 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 EndpointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl)12 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)10 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)10 Secret (io.fabric8.kubernetes.api.model.Secret)10 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)10 HashMap (java.util.HashMap)10 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)10