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");
}
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()));
}
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
}
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
}
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
}
Aggregations