Search in sources :

Example 21 with FileContentProvider

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

the class GithubAuthorizingFileContentProviderTest method shouldPreserveAbsolutePaths.

@Test
public void shouldPreserveAbsolutePaths() throws Exception {
    URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
    GithubUrl githubUrl = new GithubUrl().withUsername("eclipse").withRepository("che");
    FileContentProvider fileContentProvider = new GithubAuthorizingFileContentProvider(githubUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
    String url = "https://raw.githubusercontent.com/foo/bar/devfile.yaml";
    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 22 with FileContentProvider

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

the class DevfileConverterTest method shouldConvertComponentsDuringConvertingDevfileToWorkspaceConfig.

@Test
public void shouldConvertComponentsDuringConvertingDevfileToWorkspaceConfig() throws Exception {
    // given
    DevfileImpl devfile = newDevfile("petclinic");
    ComponentImpl component = new ComponentImpl();
    component.setType(COMPONENT_TYPE);
    devfile.getComponents().add(component);
    FileContentProvider fileContentProvider = mock(FileContentProvider.class);
    // when
    WorkspaceConfigImpl workspaceConfig = devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
    // then
    verify(componentToWorkspaceApplier).apply(workspaceConfig, component, fileContentProvider);
}
Also used : 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) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 23 with FileContentProvider

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

the class DevfileConverterTest method shouldProvisionDevfileAttributesAsConfigAttributesDuringConvertingDevfileToWorkspaceConfig.

@Test
public void shouldProvisionDevfileAttributesAsConfigAttributesDuringConvertingDevfileToWorkspaceConfig() throws Exception {
    // given
    FileContentProvider fileContentProvider = mock(FileContentProvider.class);
    Map<String, String> devfileAttributes = new HashMap<>();
    devfileAttributes.put(PERSIST_VOLUMES_ATTRIBUTE, "false");
    devfileAttributes.put("anotherAttribute", "value");
    DevfileImpl devfile = newDevfile("petclinic");
    devfile.getAttributes().putAll(devfileAttributes);
    // when
    WorkspaceConfigImpl config = devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
    // then
    assertEquals(config.getAttributes(), devfileAttributes);
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) HashMap(java.util.HashMap) 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 24 with FileContentProvider

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

the class DevfileConverterTest method shouldThrowAnExceptionIfDevfileApiVersionIsMissingDuringConvertingDevfileToWorkspaceConfig.

@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Provided Devfile has no API version specified")
public void shouldThrowAnExceptionIfDevfileApiVersionIsMissingDuringConvertingDevfileToWorkspaceConfig() throws Exception {
    // given
    FileContentProvider fileContentProvider = mock(FileContentProvider.class);
    DevfileImpl devfile = new DevfileImpl();
    devfile.setName("petclinic");
    // when
    devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Test(org.testng.annotations.Test)

Example 25 with FileContentProvider

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

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)

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