Search in sources :

Example 26 with ComponentImpl

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

the class DockerimageComponentToWorkspaceApplierTest method shouldProvisionContainerWithCpuLimitsSpecified.

@Test
public void shouldProvisionContainerWithCpuLimitsSpecified() 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.setCpuRequest("1576m");
    dockerimageComponent.setCpuLimit("2.22");
    // when
    dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null);
    // then
    verify(k8sEnvProvisioner).provision(eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture());
    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();
    assertEquals(podTemplate.getSpec().getContainers().size(), 1);
    Container container = podTemplate.getSpec().getContainers().get(0);
    Quantity cpuLimit = container.getResources().getLimits().get("cpu");
    Quantity cpuRequest = container.getResources().getRequests().get("cpu");
    assertEquals(cpuRequest.getAmount(), "1.576");
    assertEquals(cpuLimit.getAmount(), "2.22");
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Container(io.fabric8.kubernetes.api.model.Container) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Quantity(io.fabric8.kubernetes.api.model.Quantity) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 27 with ComponentImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl 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 28 with ComponentImpl

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

the class KubernetesComponentIntegrityValidatorTest method shouldValidateContainerMatchingEntrypointInPodMatchingSelector.

@Test
public void shouldValidateContainerMatchingEntrypointInPodMatchingSelector() throws Exception {
    // given
    when(kubernetesRecipeParser.parse(any(String.class))).thenReturn(Arrays.asList(new PodBuilder().withNewMetadata().addToLabels("app", "test").endMetadata().withNewSpec().addNewContainer().withName("container_a").endContainer().endSpec().build(), new PodBuilder().withNewMetadata().addToLabels("app", "other").endMetadata().withNewSpec().addNewContainer().withName("container_a").endContainer().endSpec().build()));
    Map<String, String> selector = new HashMap<>();
    selector.put("app", "test");
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference("ref");
    component.setSelector(selector);
    component.setReferenceContent("content");
    EntrypointImpl entrypoint = new EntrypointImpl();
    entrypoint.setContainerName("container_a");
    component.setEntrypoints(Collections.singletonList(entrypoint));
    // when
    validator.validateComponent(component, __ -> "");
// then no exception is thrown
}
Also used : EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) HashMap(java.util.HashMap) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 29 with ComponentImpl

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

the class KubernetesComponentIntegrityValidatorTest method shouldThrowExceptionOnEntrypointNotMatchingAnyContainer.

@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Failed to validate content reference of component 'ref' of type 'kubernetes': Component 'ref' of type 'kubernetes' contains an entry point that doesn't match any container.")
public void shouldThrowExceptionOnEntrypointNotMatchingAnyContainer() throws Exception {
    // given
    when(kubernetesRecipeParser.parse(any(String.class))).thenReturn(Collections.singletonList(new PodBuilder().withNewSpec().addNewContainer().withName("container").endContainer().endSpec().build()));
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReferenceContent("content");
    component.setReference("ref");
    EntrypointImpl entrypoint = new EntrypointImpl();
    entrypoint.setContainerName("not that container");
    component.setEntrypoints(Collections.singletonList(entrypoint));
    // when
    validator.validateComponent(component, __ -> "");
// then exception is thrown
}
Also used : EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 30 with ComponentImpl

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

the class KubernetesComponentIntegrityValidatorTest method shouldThrowExceptionOnEntrypointNotMatchingAnyContainerOfPodsMatchingSelector.

@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Failed to validate content reference of component 'ref' of type 'kubernetes': Component 'ref' of type 'kubernetes' contains an entry point that doesn't match any container.")
public void shouldThrowExceptionOnEntrypointNotMatchingAnyContainerOfPodsMatchingSelector() throws Exception {
    // given
    when(kubernetesRecipeParser.parse(any(String.class))).thenReturn(Arrays.asList(new PodBuilder().withNewMetadata().addToLabels("app", "test").endMetadata().withNewSpec().addNewContainer().withName("container_a").endContainer().endSpec().build(), new PodBuilder().withNewMetadata().addToLabels("app", "other").endMetadata().withNewSpec().addNewContainer().withName("container_b").endContainer().endSpec().build()));
    Map<String, String> selector = new HashMap<>();
    selector.put("app", "test");
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReferenceContent("content");
    component.setReference("ref");
    component.setSelector(selector);
    EntrypointImpl entrypoint = new EntrypointImpl();
    entrypoint.setContainerName("container_b");
    component.setEntrypoints(Collections.singletonList(entrypoint));
    // when
    validator.validateComponent(component, __ -> "");
// then exception is thrown
}
Also used : EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) HashMap(java.util.HashMap) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) 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)218 Test (org.testng.annotations.Test)184 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)76 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)56 Container (io.fabric8.kubernetes.api.model.Container)48 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)44 EndpointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl)42 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)38 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)36 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)26 EntrypointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl)26 Map (java.util.Map)24 EnvImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl)24 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)22 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)20 Collections.emptyMap (java.util.Collections.emptyMap)18 DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)18 ImmutableMap (com.google.common.collect.ImmutableMap)16 ArrayList (java.util.ArrayList)14 List (java.util.List)14