Search in sources :

Example 6 with VolumeImpl

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

the class KubernetesComponentToWorkspaceApplierTest method shouldThrowExceptionWhenDevfileVolumeNameExists.

@Test(expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = "Conflicting volume with same name \\('foo_volume'\\) but different path \\('/foo1'\\) found for component 'foo' and its container 'server'.")
public void shouldThrowExceptionWhenDevfileVolumeNameExists() throws Exception {
    // given
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
    doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setAlias(COMPONENT_NAME);
    component.setVolumes(Collections.singletonList(new VolumeImpl("foo_volume", "/foo1")));
    // when
    applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 7 with VolumeImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl in project che-server by eclipse-che.

the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionDevfileVolumesIfSpecifiedIntoMachineConfig.

@Test
public void shouldProvisionDevfileVolumesIfSpecifiedIntoMachineConfig() throws Exception {
    // given
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
    doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setAlias(COMPONENT_NAME);
    component.setVolumes(asList(new VolumeImpl("foo", "/foo1"), new VolumeImpl("bar", "/bar1")));
    ArgumentCaptor<Map<String, MachineConfigImpl>> mapCaptor = ArgumentCaptor.forClass(Map.class);
    // when
    applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
    // then
    verify(k8sEnvProvisioner).provision(any(), any(), any(), mapCaptor.capture());
    Map<String, MachineConfigImpl> configMaps = mapCaptor.getValue();
    for (MachineConfig config : configMaps.values()) {
        assertEquals(config.getVolumes().size(), 2);
        assertTrue(config.getVolumes().entrySet().stream().anyMatch(entry -> entry.getKey().equals("foo") && entry.getValue().getPath().equals("/foo1")));
        assertTrue(config.getVolumes().entrySet().stream().anyMatch(entry -> entry.getKey().equals("bar") && entry.getValue().getPath().equals("/bar1")));
    }
}
Also used : Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) MachineConfig(org.eclipse.che.api.core.model.workspace.config.MachineConfig) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) EnvVars(org.eclipse.che.workspace.infrastructure.kubernetes.util.EnvVars) Test(org.testng.annotations.Test) Files(org.testng.reporters.Files) Collections.singletonList(java.util.Collections.singletonList) Mockito.doThrow(org.mockito.Mockito.doThrow) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) REQUIRE_SUBDOMAIN(org.eclipse.che.api.core.model.workspace.config.ServerConfig.REQUIRE_SUBDOMAIN) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertFalse(org.testng.Assert.assertFalse) Serialization.unmarshal(io.fabric8.kubernetes.client.utils.Serialization.unmarshal) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ImmutableMap(com.google.common.collect.ImmutableMap) MULTI_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.MultiHostExternalServiceExposureStrategy.MULTI_HOST_STRATEGY) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) Stream(java.util.stream.Stream) PROJECTS_VOLUME_NAME(org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Assert.assertNull(org.testng.Assert.assertNull) Container(io.fabric8.kubernetes.api.model.Container) DEVFILE_COMPONENT_ALIAS_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.MachineConfig.DEVFILE_COMPONENT_ALIAS_ATTRIBUTE) Mock(org.mockito.Mock) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) Assert.assertEquals(org.testng.Assert.assertEquals) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Captor(org.mockito.Captor) ValidationException(org.eclipse.che.api.core.ValidationException) ArrayList(java.util.ArrayList) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) MACHINE_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE) Collections.singletonMap(java.util.Collections.singletonMap) COMPONENT_ALIAS_COMMAND_ATTRIBUTE(org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Collections.emptyMap(java.util.Collections.emptyMap) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider) OPENSHIFT_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) Mockito.verify(org.mockito.Mockito.verify) EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) SINGLE_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.SingleHostExternalServiceExposureStrategy.SINGLE_HOST_STRATEGY) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Assert.assertTrue(org.testng.Assert.assertTrue) KubernetesRecipeParser(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) MachineConfig(org.eclipse.che.api.core.model.workspace.config.MachineConfig) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.testng.annotations.Test)

Example 8 with VolumeImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl in project che-server by eclipse-che.

the class KubernetesComponentToWorkspaceApplierTest method shouldThrowExceptionWhenDevfileVolumePathExists.

@Test(expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = "Conflicting volume with same path \\('/foo/bar'\\) but different name \\('foo'\\) found for component 'foo' and its container 'server'.")
public void shouldThrowExceptionWhenDevfileVolumePathExists() throws Exception {
    // given
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
    doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setAlias(COMPONENT_NAME);
    component.setVolumes(Collections.singletonList(new VolumeImpl("foo", "/foo/bar")));
    // when
    applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 9 with VolumeImpl

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

the class DockerimageComponentToWorkspaceApplierTest method shouldProvisionMachineConfigWithConfiguredVolumes.

@Test
public void shouldProvisionMachineConfigWithConfiguredVolumes() throws Exception {
    // given
    ComponentImpl dockerimageComponent = new ComponentImpl();
    dockerimageComponent.setAlias("jdk");
    dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
    dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
    dockerimageComponent.setMemoryLimit("1G");
    dockerimageComponent.setVolumes(singletonList(new VolumeImpl("data", "/tmp/data/")));
    // when
    dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null);
    // then
    verify(k8sEnvProvisioner).provision(eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture());
    MachineConfigImpl machineConfig = machinesCaptor.getValue().get("jdk");
    assertNotNull(machineConfig);
    org.eclipse.che.api.workspace.server.model.impl.VolumeImpl volume = machineConfig.getVolumes().get("data");
    assertNotNull(volume);
    assertEquals(volume.getPath(), "/tmp/data/");
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 10 with VolumeImpl

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

the class KubernetesComponentToWorkspaceApplierTest method shouldThrowExceptionWhenDevfileVolumePathExists.

@Test(expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = "Conflicting volume with same path \\('/foo/bar'\\) but different name \\('foo'\\) found for component 'foo' and its container 'server'.")
public void shouldThrowExceptionWhenDevfileVolumePathExists() throws Exception {
    // given
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
    doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setAlias(COMPONENT_NAME);
    component.setVolumes(Collections.singletonList(new VolumeImpl("foo", "/foo/bar")));
    // when
    applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Aggregations

ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)10 VolumeImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl)10 Test (org.testng.annotations.Test)10 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 Container (io.fabric8.kubernetes.api.model.Container)4 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)2 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)2 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)2 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)2 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 Volume (io.fabric8.kubernetes.api.model.Volume)2 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)2