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