Search in sources :

Example 36 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 shouldProvisionCommandAndArgs.

@Test
public void shouldProvisionCommandAndArgs() throws Exception {
    // given
    List<String> command = singletonList("/usr/bin/rf");
    List<String> args = Arrays.asList("-r", "f");
    ComponentImpl dockerimageComponent = new ComponentImpl();
    dockerimageComponent.setAlias("jdk");
    dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
    dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
    dockerimageComponent.setMemoryLimit("1G");
    dockerimageComponent.setCommand(command);
    dockerimageComponent.setArgs(args);
    // 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);
    assertEquals(container.getCommand(), command);
    assertEquals(container.getArgs(), args);
}
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) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 37 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 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 38 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 shouldProvisionContainerWithMemoryResourcesSpecified.

@Test
public void shouldProvisionContainerWithMemoryResourcesSpecified() 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.setMemoryRequest("128M");
    // 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 memoryLimit = container.getResources().getLimits().get("memory");
    assertEquals(memoryLimit.getAmount(), "1");
    assertEquals(memoryLimit.getFormat(), "G");
    Quantity memoryRequest = container.getResources().getRequests().get("memory");
    assertEquals(memoryRequest.getAmount(), "128");
    assertEquals(memoryRequest.getFormat(), "M");
}
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 39 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 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)

Example 40 with ComponentImpl

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

the class KubernetesComponentToWorkspaceApplierTest method shouldNotSetMachineNameAttributeToCommandConfiguredInOpenShiftComponentWithMultipleContainers.

@Test
public void shouldNotSetMachineNameAttributeToCommandConfiguredInOpenShiftComponentWithMultipleContainers() throws Exception {
    // given
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(OPENSHIFT_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setAlias(COMPONENT_NAME);
    CommandImpl command = new CommandImpl();
    command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, COMPONENT_NAME);
    workspaceConfig.getCommands().add(command);
    // when
    applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
    // then
    CommandImpl actualCommand = workspaceConfig.getCommands().get(0);
    assertNull(actualCommand.getAttributes().get(MACHINE_NAME_ATTRIBUTE));
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) 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)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