Search in sources :

Example 16 with FileContentProvider

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

the class DevfileConverterTest method shouldConvertCommandsDuringConvertingDevfileToWorkspaceConfig.

@Test
public void shouldConvertCommandsDuringConvertingDevfileToWorkspaceConfig() throws Exception {
    // given
    FileContentProvider fileContentProvider = mock(FileContentProvider.class);
    DevfileImpl devfile = newDevfile("petclinic");
    CommandImpl devfileCommand = mock(CommandImpl.class);
    devfile.getCommands().add(devfileCommand);
    org.eclipse.che.api.workspace.server.model.impl.CommandImpl workspaceCommand = mock(org.eclipse.che.api.workspace.server.model.impl.CommandImpl.class);
    when(commandConverter.toWorkspaceCommand(any(), any())).thenReturn(workspaceCommand);
    // when
    WorkspaceConfigImpl workspaceConfig = devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
    // then
    assertEquals(workspaceConfig.getCommands().size(), 1);
    assertSame(workspaceConfig.getCommands().get(0), workspaceCommand);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) Test(org.testng.annotations.Test)

Example 17 with FileContentProvider

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

the class DockerimageComponentToWorkspaceApplier method apply.

/**
 * Applies changes on workspace config according to the specified dockerimage component.
 *
 * <p>Dockerimage component is provisioned as Deployment in Kubernetes recipe.<br>
 * Generated deployment contains container with environment variables, memory limit, docker image,
 * arguments and commands specified in component.<br>
 * Also, environment is provisioned with machine config with volumes and servers specified, then
 * Kubernetes infra will created needed PVC, Services, Ingresses, Routes according to specified
 * configuration.
 *
 * @param workspaceConfig workspace config on which changes should be applied
 * @param dockerimageComponent dockerimage component that should be applied
 * @param contentProvider optional content provider that may be used for external component
 *     resource fetching
 * @throws DevfileException if specified workspace config already has default environment where
 *     dockerimage component should be stored
 * @throws IllegalArgumentException if specified workspace config or plugin component is null
 * @throws IllegalArgumentException if specified component has type different from dockerimage
 */
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl dockerimageComponent, FileContentProvider contentProvider) throws DevfileException {
    checkArgument(workspaceConfig != null, "Workspace config must not be null");
    checkArgument(dockerimageComponent != null, "Component must not be null");
    checkArgument(DOCKERIMAGE_COMPONENT_TYPE.equals(dockerimageComponent.getType()), format("Plugin must have `%s` type", DOCKERIMAGE_COMPONENT_TYPE));
    String componentAlias = dockerimageComponent.getAlias();
    String machineName = componentAlias == null ? toMachineName(dockerimageComponent.getImage()) : componentAlias;
    MachineConfigImpl machineConfig = createMachineConfig(dockerimageComponent, componentAlias);
    List<HasMetadata> componentObjects = createComponentObjects(dockerimageComponent, machineName);
    k8sEnvProvisioner.provision(workspaceConfig, KubernetesEnvironment.TYPE, componentObjects, ImmutableMap.of(machineName, machineConfig));
    workspaceConfig.getCommands().stream().filter(c -> componentAlias != null && componentAlias.equals(c.getAttributes().get(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE))).forEach(c -> c.getAttributes().put(MACHINE_NAME_ATTRIBUTE, machineName));
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) DEVFILE_COMPONENT_ALIAS_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.MachineConfig.DEVFILE_COMPONENT_ALIAS_ATTRIBUTE) 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) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ComponentToWorkspaceApplier(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ComponentToWorkspaceApplier.convertEndpointsIntoServers(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier.convertEndpointsIntoServers) Names(org.eclipse.che.workspace.infrastructure.kubernetes.Names) Containers(org.eclipse.che.workspace.infrastructure.kubernetes.util.Containers) MACHINE_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Named(javax.inject.Named) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) DOCKERIMAGE_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE) ImmutableMap(com.google.common.collect.ImmutableMap) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) List(java.util.List) SINGLE_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.SingleHostExternalServiceExposureStrategy.SINGLE_HOST_STRATEGY) PROJECTS_VOLUME_NAME(org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME) Constants(org.eclipse.che.api.workspace.server.devfile.Constants) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesSize(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSize) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)

Example 18 with FileContentProvider

use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider 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 19 with FileContentProvider

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

the class GitlabAuthorizingFileContentProviderTest method shouldPreserveAbsolutePaths.

@Test
public void shouldPreserveAbsolutePaths() throws Exception {
    URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
    GitlabUrl gitlabUrl = new GitlabUrl().withHostName("gitlab.net").withUsername("eclipse").withProject("che");
    FileContentProvider fileContentProvider = new GitlabAuthorizingFileContentProvider(gitlabUrl, urlFetcher, gitCredentialsManager, personalAccessTokenManager);
    String url = "https://gitlab.net/api/v4/projects/eclipse%2Fche/repository/files/devfile.yaml/raw";
    fileContentProvider.fetchContent(url);
    verify(urlFetcher).fetch(eq(url));
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) Test(org.testng.annotations.Test)

Example 20 with FileContentProvider

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

the class GithubAuthorizingFileContentProviderTest method shouldExpandRelativePaths.

@Test
public void shouldExpandRelativePaths() throws Exception {
    URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
    GithubUrl githubUrl = new GithubUrl().withUsername("eclipse").withRepository("che");
    FileContentProvider fileContentProvider = new GithubAuthorizingFileContentProvider(githubUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
    fileContentProvider.fetchContent("devfile.yaml");
    verify(urlFetcher).fetch(eq("https://raw.githubusercontent.com/eclipse/che/HEAD/devfile.yaml"));
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) Test(org.testng.annotations.Test)

Aggregations

FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)38 Test (org.testng.annotations.Test)30 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)18 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)14 URLFetcher (org.eclipse.che.api.workspace.server.devfile.URLFetcher)10 DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)8 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)8 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)6 Inject (javax.inject.Inject)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Named (javax.inject.Named)4 DevfileLocation (org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation)4 EDITOR_COMPONENT_TYPE (org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE)4 ComponentFQNParser (org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser)4 ExtendedPluginFQN (org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 String.format (java.lang.String.format)3 ComponentToWorkspaceApplier (org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier)3