Search in sources :

Example 11 with MachineConfigImpl

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

the class DockerimageComponentToWorkspaceApplierTest method shouldProvisionMachineConfigWithConfiguredServers.

@Test
public void shouldProvisionMachineConfigWithConfiguredServers() throws Exception {
    // given
    EndpointImpl endpoint = new EndpointImpl("jdk-ls", 4923, ImmutableMap.of("protocol", "http", "path", "/ls", PUBLIC_ENDPOINT_ATTRIBUTE, "false", "secure", "false"));
    ComponentImpl dockerimageComponent = new ComponentImpl();
    dockerimageComponent.setAlias("jdk");
    dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
    dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
    dockerimageComponent.setMemoryLimit("1G");
    dockerimageComponent.setEndpoints(singletonList(endpoint));
    // 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);
    assertEquals(machineConfig.getServers().size(), 1);
    ServerConfigImpl serverConfig = machineConfig.getServers().get("jdk-ls");
    assertEquals(serverConfig.getProtocol(), "http");
    assertEquals(serverConfig.getPath(), "/ls");
    assertEquals(serverConfig.getPort(), "4923");
    Map<String, String> attributes = serverConfig.getAttributes();
    assertEquals(attributes.get(ServerConfig.INTERNAL_SERVER_ATTRIBUTE), "true");
    assertEquals(attributes.get("secure"), "false");
    assertEquals(attributes.get(ServerConfig.REQUIRE_SUBDOMAIN), "true");
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 12 with MachineConfigImpl

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

the class DockerimageComponentToWorkspaceApplierTest method shouldProvisionK8sEnvironmentWithMachineConfigAndGeneratedDeploymentForSpecifiedDockerimage.

@Test
public void shouldProvisionK8sEnvironmentWithMachineConfigAndGeneratedDeploymentForSpecifiedDockerimage() throws Exception {
    // given
    ComponentImpl dockerimageComponent = new ComponentImpl();
    dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
    dockerimageComponent.setAlias("jdk");
    dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
    dockerimageComponent.setMemoryLimit("1G");
    // 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);
    List<HasMetadata> objects = objectsCaptor.getValue();
    assertEquals(objects.size(), 1);
    assertTrue(objects.get(0) instanceof Deployment);
    Deployment deployment = (Deployment) objects.get(0);
    PodTemplateSpec podTemplate = deployment.getSpec().getTemplate();
    ObjectMeta podMeta = podTemplate.getMetadata();
    assertEquals(podMeta.getName(), "jdk");
    Map<String, String> deploymentSelector = deployment.getSpec().getSelector().getMatchLabels();
    assertFalse(deploymentSelector.isEmpty());
    assertTrue(podMeta.getLabels().entrySet().containsAll(deploymentSelector.entrySet()));
    Container container = podTemplate.getSpec().getContainers().get(0);
    assertEquals(container.getName(), "jdk");
    assertEquals(container.getImage(), "eclipse/ubuntu_jdk8:latest");
    assertEquals(container.getImagePullPolicy(), "Always");
    assertEquals(Names.machineName(podMeta, container), "jdk");
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Container(io.fabric8.kubernetes.api.model.Container) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 13 with MachineConfigImpl

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

the class DockerimageComponentToWorkspaceApplierTest method serverMustHaveRequireSubdomainWhenNonSinglehostDevfileExpose.

@Test
public void serverMustHaveRequireSubdomainWhenNonSinglehostDevfileExpose() throws DevfileException {
    dockerimageComponentApplier = new DockerimageComponentToWorkspaceApplier(PROJECTS_MOUNT_PATH, "Always", MULTI_HOST_STRATEGY, k8sEnvProvisioner);
    // given
    EndpointImpl endpoint = new EndpointImpl("jdk-ls", 4923, emptyMap());
    ComponentImpl dockerimageComponent = new ComponentImpl();
    dockerimageComponent.setAlias("jdk");
    dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
    dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
    dockerimageComponent.setMemoryLimit("100M");
    dockerimageComponent.setEndpoints(Arrays.asList(new EndpointImpl("e1", 1111, emptyMap()), new EndpointImpl("e2", 2222, emptyMap())));
    // 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);
    assertEquals(machineConfig.getServers().size(), 2);
    assertTrue(ServerConfig.isRequireSubdomain(machineConfig.getServers().get("e1").getAttributes()));
    assertTrue(ServerConfig.isRequireSubdomain(machineConfig.getServers().get("e2").getAttributes()));
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 14 with MachineConfigImpl

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

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 15 with MachineConfigImpl

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

the class DockerimageComponentToWorkspaceApplierTest method shouldBeAbleToSetupSpecificImagePullPolicy.

@Test
public void shouldBeAbleToSetupSpecificImagePullPolicy() throws DevfileException {
    ComponentImpl dockerimageComponent = new ComponentImpl();
    dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
    dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
    dockerimageComponent.setMemoryLimit("1G");
    dockerimageComponentApplier = new DockerimageComponentToWorkspaceApplier(PROJECTS_MOUNT_PATH, "Never", MULTI_HOST_STRATEGY, k8sEnvProvisioner);
    // when
    dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null);
    // then
    verify(k8sEnvProvisioner).provision(any(), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture());
    MachineConfigImpl machineConfig = machinesCaptor.getValue().get("eclipse-ubuntu_jdk8-latest");
    assertNotNull(machineConfig);
    List<HasMetadata> objects = objectsCaptor.getValue();
    assertEquals(objects.size(), 1);
    assertTrue(objects.get(0) instanceof Deployment);
    Deployment deployment = (Deployment) objects.get(0);
    PodTemplateSpec podTemplate = deployment.getSpec().getTemplate();
    ObjectMeta podMeta = podTemplate.getMetadata();
    assertEquals(podMeta.getName(), "eclipse-ubuntu_jdk8-latest");
    Map<String, String> deploymentSelector = deployment.getSpec().getSelector().getMatchLabels();
    assertFalse(deploymentSelector.isEmpty());
    assertTrue(podMeta.getLabels().entrySet().containsAll(deploymentSelector.entrySet()));
    Container container = podTemplate.getSpec().getContainers().get(0);
    assertEquals(container.getName(), "eclipse-ubuntu_jdk8-latest");
    assertEquals(container.getImagePullPolicy(), "Never");
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Container(io.fabric8.kubernetes.api.model.Container) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Aggregations

MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)70 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)44 Test (org.testng.annotations.Test)44 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)26 EndpointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl)26 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)22 Map (java.util.Map)20 ArrayList (java.util.ArrayList)18 RecipeImpl (org.eclipse.che.api.workspace.server.model.impl.RecipeImpl)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 ImmutableMap (com.google.common.collect.ImmutableMap)16 Container (io.fabric8.kubernetes.api.model.Container)16 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)16 Collections.emptyMap (java.util.Collections.emptyMap)16 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)16 Collections.singletonMap (java.util.Collections.singletonMap)14 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)12 ArgumentMatchers.anyMap (org.mockito.ArgumentMatchers.anyMap)12 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10