use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class KubernetesServerExposerTest method assertThatExternalServersAreExposed.
@SuppressWarnings("SameParameterValue")
private void assertThatExternalServersAreExposed(String machineName, String portProtocol, Integer port, Map<String, ServerConfig> expectedServers) {
// then
assertThatContainerPortIsExposed(portProtocol, port);
// ensure that service is created
Service service = findContainerRelatedService();
assertNotNull(service);
// ensure that required service port is exposed
ServicePort servicePort = assertThatServicePortIsExposed(port, service);
Annotations.Deserializer serviceAnnotations = Annotations.newDeserializer(service.getMetadata().getAnnotations());
assertEquals(serviceAnnotations.machineName(), machineName);
// check that we did not create servers for public endpoints
assertFalse(serviceAnnotations.servers().keySet().stream().anyMatch(key -> expectedServers.containsKey(key)));
verify(externalServerExposer).expose(eq(kubernetesEnvironment), eq(machineName), eq(service.getMetadata().getName()), any(), eq(servicePort), eq(expectedServers));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class KubernetesServerExposerTest method shouldCreateIngressForServerWhenTwoServersHasTheSamePort.
@Test
public void shouldCreateIngressForServerWhenTwoServersHasTheSamePort() throws InfrastructureException {
// given
ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
ServerConfigImpl wsServerConfig = new ServerConfigImpl("8080/tcp", "ws", "/connect", ATTRIBUTES_MAP);
IntOrString targetPort = new IntOrString(8080);
ServicePort servicePort = new ServicePortBuilder().withName("server-8080").withPort(8080).withProtocol("TCP").withTargetPort(targetPort).build();
Map<String, ServerConfig> serversToExpose = ImmutableMap.of("http-server", httpServerConfig, "ws-server", wsServerConfig);
// when
serverExposer.expose(serversToExpose);
// then
assertThatExternalServersAreExposed(MACHINE_NAME, "tcp", 8080, ImmutableMap.of("http-server", new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP), "ws-server", new ServerConfigImpl(wsServerConfig).withAttributes(ATTRIBUTES_MAP)));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class KubernetesServerExposerTest method assertThatSecureServerIsExposed.
@SuppressWarnings("SameParameterValue")
private void assertThatSecureServerIsExposed(String machineName, String portProtocol, Integer port, String serverName, ServerConfig serverConfig) throws Exception {
// then
assertThatContainerPortIsExposed(portProtocol, port);
// ensure that service is created
Service service = findContainerRelatedService();
assertNotNull(service);
// ensure that no service port is exposed
assertTrue(service.getSpec().getPorts().stream().noneMatch(p -> p.getTargetPort().getIntVal().equals(port)));
ServicePort servicePort = new ServicePortBuilder().withName("server-" + port).withPort(port).withProtocol(portProtocol.toUpperCase()).withNewTargetPort(port).build();
verify(secureServerExposer).expose(eq(kubernetesEnvironment), any(), eq(machineName), // no service exists for the backed server
isNull(), // a non-unique server
isNull(), eq(servicePort), eq(ImmutableMap.of(serverName, serverConfig)));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class KubernetesServerExposerTest method testExposeUniqueSecureServersWithOnlyMatchingServers.
@Test
public void testExposeUniqueSecureServersWithOnlyMatchingServers() throws InfrastructureException {
// https://github.com/eclipse/che/issues/16330
// given 2 servers which one of them is unique
ServerConfigImpl theiaSC = new ServerConfigImpl("3100/tcp", "https", null, ImmutableMap.of("internal", "false", "discoverable", "false", "secure", "true", "type", "ide"));
ServerConfigImpl webviewsSC = new ServerConfigImpl("3100/tcp", "https", null, ImmutableMap.of("internal", "false", "discoverable", "false", "unique", "true", "secure", "true", "type", "webview"));
Map<String, ServerConfigImpl> serversToExpose = ImmutableMap.of("theia", theiaSC, "webviews", webviewsSC);
// when
serverExposer.expose(serversToExpose);
// then expose is called twice with only one server each
ArgumentCaptor<Map<String, ServerConfig>> serversCaptor = ArgumentCaptor.forClass(Map.class);
verify(secureServerExposer, times(2)).expose(any(), any(), any(), any(), any(), any(), serversCaptor.capture());
for (Map<String, ServerConfig> captures : serversCaptor.getAllValues()) {
assertEquals(captures.size(), 1);
}
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class MachineConfigsValidator method validateMachine.
private void validateMachine(String machineName, InternalMachineConfig machineConfig) throws ValidationException {
checkArgument(MACHINE_NAME_PATTERN.matcher(machineName).matches(), "Name of machine '%s' in environment is invalid", machineName);
if (machineConfig.getServers() != null) {
for (Map.Entry<String, ? extends ServerConfig> serverEntry : machineConfig.getServers().entrySet()) {
String serverName = serverEntry.getKey();
ServerConfig server = serverEntry.getValue();
checkArgument(server.getPort() != null && SERVER_PORT_PATTERN.matcher(server.getPort()).matches(), "Machine '%s' in environment contains server conf '%s' with invalid port '%s'", machineName, serverName, server.getPort());
checkArgument(server.getProtocol() == null || SERVER_PROTOCOL_PATTERN.matcher(server.getProtocol()).matches(), "Machine '%s' in environment contains server conf '%s' with invalid protocol '%s'", machineName, serverName, server.getProtocol());
}
}
if (machineConfig.getAttributes() != null) {
String memoryLimit = machineConfig.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE);
String memoryRequest = machineConfig.getAttributes().get(MEMORY_REQUEST_ATTRIBUTE);
if (memoryLimit != null && memoryRequest != null) {
checkArgument(Long.parseLong(memoryLimit) >= Long.parseLong(memoryRequest), "Machine '%s' in environment contains inconsistent memory attributes: Memory limit: '%s', Memory request: '%s'", machineName, Long.parseLong(memoryLimit), Long.parseLong(memoryRequest));
}
}
}
Aggregations