MachineResolver { public InternalMachineConfig resolve() throws InfrastructureException { InternalMachineConfig machineConfig = new InternalMachineConfig( toServers(containerEndpoints), emptyMap(), resolveMachineAttributes(), toWorkspaceVolumes(cheContainer)); applyDevfileVolumes(machineConfig); applyDevfileEndpoints(machineConfig); normalizeMemory(container, machineConfig); normalizeCpu(container, machineConfig); return machineConfig; } MachineResolver(
      Pair<String, String> projectsRootPathEnvVar,
      Container container,
      CheContainer cheContainer,
      String defaultSidecarMemoryLimitBytes,
      String defaultSidecarMemoryRequestBytes,
      String defaultSidecarCpuLimitCores,
      String defaultSidecarCpuRequestCores,
      List<ChePluginEndpoint> containerEndpoints,
      Component component); InternalMachineConfig resolve();  }
@Test(dataProvider = "serverProvider") public void shouldSetServersInMachineConfig( List<ChePluginEndpoint> containerEndpoints, Map<String, ServerConfig> expected) throws InfrastructureException { endpoints.addAll(containerEndpoints); InternalMachineConfig machineConfig = resolver.resolve(); assertEquals(machineConfig.getServers(), expected); }
@Test public void shouldSetDefaultMemLimitAndRequestIfSidecarDoesNotHaveOne() throws InfrastructureException { InternalMachineConfig machineConfig = resolver.resolve(); assertEquals(machineConfig.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE), DEFAULT_MEM_LIMIT); assertEquals(machineConfig.getAttributes().get(MEMORY_REQUEST_ATTRIBUTE), DEFAULT_MEM_REQUEST); }
@Test public void shouldSetDefaultCPULimitAndRequestIfSidecarDoesNotHaveOne() throws InfrastructureException { InternalMachineConfig machineConfig = resolver.resolve(); assertEquals(machineConfig.getAttributes().get(CPU_LIMIT_ATTRIBUTE), DEFAULT_CPU_LIMIT); assertEquals(machineConfig.getAttributes().get(CPU_REQUEST_ATTRIBUTE), DEFAULT_CPU_REQUEST); }
@Test(dataProvider = "memoryLimitAttributeProvider") public void shouldSetMemoryLimitOfASidecarIfCorrespondingComponentFieldIsSet( String memoryLimit, String expectedMemLimit) throws InfrastructureException { component.setMemoryLimit(memoryLimit); InternalMachineConfig machineConfig = resolver.resolve(); assertEquals(machineConfig.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE), expectedMemLimit); }
@Test(dataProvider = "memoryRequestAttributeProvider") public void shouldSetMemoryRequestOfASidecarIfCorrespondingComponentFieldIsSet( String memoryRequest, String expectedMemRequest) throws InfrastructureException { component.setMemoryRequest(memoryRequest); InternalMachineConfig machineConfig = resolver.resolve(); assertEquals(machineConfig.getAttributes().get(MEMORY_REQUEST_ATTRIBUTE), expectedMemRequest); }
@Test(dataProvider = "cpuAttributeLimitProvider") public void shouldSetCPULimitOfASidecarIfCorrespondingComponentFieldIsSet( String cpuLimit, String expectedCpuLimit) throws InfrastructureException { component.setCpuLimit(cpuLimit); InternalMachineConfig machineConfig = resolver.resolve(); assertEquals(machineConfig.getAttributes().get(CPU_LIMIT_ATTRIBUTE), expectedCpuLimit); }
@Test(dataProvider = "cpuAttributeRequestProvider") public void shouldSetCPURequestOfASidecarIfCorrespondingComponentFieldIsSet( String cpuRequest, String expectedCpuRequest) throws InfrastructureException { component.setCpuRequest(cpuRequest); InternalMachineConfig machineConfig = resolver.resolve(); assertEquals(machineConfig.getAttributes().get(CPU_REQUEST_ATTRIBUTE), expectedCpuRequest); }
@Test public void shouldOverrideMemoryLimitOfASidecarIfCorrespondingWSConfigAttributeIsSet() throws InfrastructureException { String memoryLimit = "300Mi"; String expectedMemLimit = toBytesString(memoryLimit); Containers.addRamLimit(container, 123456789); component.setMemoryLimit(memoryLimit); InternalMachineConfig machineConfig = resolver.resolve(); assertEquals(machineConfig.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE), expectedMemLimit); }
@Test public void shouldNotSetMemLimitAttributeIfLimitIsInContainer() throws InfrastructureException { Containers.addRamLimit(container, 123456789); InternalMachineConfig machineConfig = resolver.resolve(); assertNull(machineConfig.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE)); }
@Test(expectedExceptions = InfrastructureException.class) public void shouldRefuseToMountProjectsManually() throws InfrastructureException { cheContainer.setMountSources(false); Volume volume = new Volume(); volume.setName(Constants.PROJECTS_VOLUME_NAME); volume.setMountPath("anything, like"); cheContainer.getVolumes().add(volume); resolver.resolve(); }
@Test public void shouldAddProjectMountPointWhenMountSources() throws InfrastructureException { cheContainer.setMountSources(true); InternalMachineConfig config = resolver.resolve(); assertEquals(1, config.getVolumes().size()); assertEquals( PROJECTS_MOUNT_PATH, config.getVolumes().get(Constants.PROJECTS_VOLUME_NAME).getPath()); }
@Test public void shouldAddVolumesFromDevfileComponent() throws InfrastructureException { component.setVolumes( asList( new org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl("foo", "/bar"), new org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl( "test", "/foo/test"))); InternalMachineConfig config = resolver.resolve(); assertEquals(2, config.getVolumes().size()); assertEquals("/bar", config.getVolumes().get("foo").getPath()); assertEquals("/foo/test", config.getVolumes().get("test").getPath()); }
@Test(expectedExceptions = InfrastructureException.class) public void shouldFailWhenEndpointNameAlreadyExist() throws InfrastructureException { ChePluginEndpoint pluginEndpoint = new ChePluginEndpoint(); pluginEndpoint.setName("test-endpoint"); endpoints.add(pluginEndpoint); component.setEndpoints( Collections.singletonList(new EndpointImpl("test-endpoint", 8080, Collections.emptyMap()))); resolver.resolve(); }
@Test public void shouldAddEndpointsFromDevfileComponent() throws InfrastructureException { component.setEndpoints( asList( new EndpointImpl("endpoint8080", 8080, Collections.emptyMap()), new EndpointImpl("endpoint9999", 9999, ImmutableMap.of("secure", "true")))); InternalMachineConfig config = resolver.resolve(); assertEquals(config.getServers().size(), 2); assertEquals(config.getServers().get("endpoint8080").getPort(), "8080"); assertEquals(config.getServers().get("endpoint9999").getPort(), "9999"); assertEquals(config.getServers().get("endpoint9999").getAttributes().get("secure"), "true"); }