Search in sources :

Example 6 with DevfileException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.

the class URLFileContentProvider method fetchContent.

@Override
public String fetchContent(String fileURL) throws IOException, DevfileException {
    URI fileURI;
    String requestURL;
    try {
        fileURI = new URI(fileURL);
    } catch (URISyntaxException e) {
        throw new DevfileException(e.getMessage(), e);
    }
    if (fileURI.isAbsolute()) {
        requestURL = fileURL;
    } else {
        if (devfileLocation == null) {
            throw new DevfileException(format("It is unable to fetch a file %s as relative to devfile, since devfile location" + " is unknown. Try specifying absolute URL.", fileURL));
        }
        requestURL = devfileLocation.resolve(fileURI).toString();
    }
    try {
        return urlFetcher.fetch(requestURL);
    } catch (IOException e) {
        throw new IOException(format("Failed to fetch a file from URL %s. Make sure the URL" + " of the devfile points to the raw content of it (e.g. not to the webpage" + " showing it but really just its contents). Additionally, if you're using " + " relative form, make sure the referenced files are actually stored" + " relative to the devfile on the same host," + " or try to specify URL in absolute form. The current attempt to download" + " the file failed with the following error message: %s", fileURL, e.getMessage()), e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)

Example 7 with DevfileException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException 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 8 with DevfileException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.

the class DefaultEditorProvisioner method provisionAsyncStoragePlugin.

/**
 * Provision the for async storage service, it will provide ability backup and restore project
 * source using special storage. Will torn on only if workspace start in Ephemeral mode and has
 * attribute 'asyncPersist = true'
 *
 * @param components The set of components currently present in the Devfile
 * @param contentProvider content provider for plugin references retrieval
 * @throws DevfileException - A DevfileException containing any caught InfrastructureException
 */
private void provisionAsyncStoragePlugin(List<ComponentImpl> components, FileContentProvider contentProvider) throws DevfileException {
    try {
        Map<String, String> missingPluginsIdToRef = Collections.singletonMap(componentFQNParser.getPluginPublisherAndName(asyncStoragePluginRef), asyncStoragePluginRef);
        addMissingPlugins(components, contentProvider, missingPluginsIdToRef);
    } catch (InfrastructureException e) {
        throw new DevfileException(e.getMessage(), e);
    }
}
Also used : DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 9 with DevfileException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.

the class DefaultEditorProvisioner method provisionDefaultPlugins.

/**
 * Provision the default editor plugins and add them to the the Devfile's component list
 *
 * @param components The set of components currently present in the Devfile
 * @param contentProvider content provider for plugin references retrieval
 * @throws DevfileException - A DevfileException containing any caught InfrastructureException
 */
private void provisionDefaultPlugins(List<ComponentImpl> components, FileContentProvider contentProvider) throws DevfileException {
    Map<String, String> missingPluginsIdToRef = new HashMap<>(defaultPluginsToRefs);
    removeAlreadyAddedPlugins(components, contentProvider, missingPluginsIdToRef);
    try {
        addMissingPlugins(components, contentProvider, missingPluginsIdToRef);
    } catch (InfrastructureException e) {
        throw new DevfileException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 10 with DevfileException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.

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

DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)52 Test (org.testng.annotations.Test)22 IOException (java.io.IOException)20 ApiException (org.eclipse.che.api.core.ApiException)18 FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)18 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)16 HashMap (java.util.HashMap)14 List (java.util.List)14 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)14 Map (java.util.Map)12 Optional (java.util.Optional)12 ServerException (org.eclipse.che.api.core.ServerException)12 ExtendedError (org.eclipse.che.api.core.rest.shared.dto.ExtendedError)12 ScmCommunicationException (org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException)12 ScmUnauthorizedException (org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException)12 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 Collections (java.util.Collections)10 UnauthorizedException (org.eclipse.che.api.core.UnauthorizedException)10 UnknownScmProviderException (org.eclipse.che.api.factory.server.scm.exception.UnknownScmProviderException)10