use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl in project che-server by eclipse-che.
the class WorkspaceServiceTest method shouldGetWorkspaceWithInternalServers.
@Test
public void shouldGetWorkspaceWithInternalServers() throws Exception {
// given
WorkspaceImpl workspace = createWorkspace(createConfigDto());
String externalServerKey = "server2";
String internalServerKey = "server1";
ServerImpl externalServer = createExternalServer();
ServerImpl internalServer = createInternalServer();
Map<String, Server> servers = ImmutableMap.of(internalServerKey, createInternalServer(), externalServerKey, externalServer);
Map<String, Machine> machines = singletonMap("machine1", new MachineImpl(singletonMap("key", "value"), servers, RUNNING));
workspace.setRuntime(new RuntimeImpl("activeEnv", machines, "user123"));
when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
Map<String, MachineDto> expected = singletonMap("machine1", newDto(MachineDto.class).withAttributes(singletonMap("key", "value")).withStatus(RUNNING).withServers(ImmutableMap.of(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()), internalServerKey, newDto(ServerDto.class).withUrl(createInternalServer().getUrl()).withStatus(internalServer.getStatus()).withAttributes(internalServer.getAttributes()))));
// when
Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).queryParam("includeInternalServers", Boolean.TRUE.toString()).when().get(SECURE_PATH + "/workspace/" + workspace.getId());
// then
assertEquals(response.getStatusCode(), 200);
RuntimeDto retrievedRuntime = unwrapDto(response, WorkspaceDto.class).getRuntime();
assertNotNull(retrievedRuntime);
assertEquals(expected, retrievedRuntime.getMachines());
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl in project che-server by eclipse-che.
the class InternalRuntime method rewriteExternalServers.
/**
* Convenient method to rewrite incoming external servers in a loop
*
* @param incoming servers
* @return rewritten Map of Servers (name -> Server)
*/
private Map<String, Server> rewriteExternalServers(String machineName, Map<String, ? extends Server> incoming) {
Map<String, Server> outgoing = new HashMap<>();
RuntimeIdentity identity = context.getIdentity();
for (Map.Entry<String, ? extends Server> entry : incoming.entrySet()) {
String name = entry.getKey();
Server incomingServer = entry.getValue();
if (ServerConfig.isInternal(incomingServer.getAttributes())) {
outgoing.put(name, incomingServer);
} else {
try {
ServerImpl server = new ServerImpl(incomingServer).withUrl(urlRewriter.rewriteURL(identity, machineName, name, incomingServer.getUrl()));
outgoing.put(name, server);
} catch (InfrastructureException e) {
context.getEnvironment().getWarnings().add(new WarningImpl(MALFORMED_SERVER_URL_FOUND, "Malformed URL for " + name + " : " + e.getMessage()));
}
}
}
return outgoing;
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl in project che-server by eclipse-che.
the class IngressServerResolverTest method testResolvingInternalServersWithPortWithTransportProtocol.
@Test
public void testResolvingInternalServersWithPortWithTransportProtocol() {
Service service = createService("service11", "machine", CONTAINER_PORT, singletonMap("http-server", new ServerConfigImpl("3054/udp", "xxx", "api", ATTRIBUTES_MAP)));
ServerResolver serverResolver = new IngressServerResolver(new NoopPathTransformInverter(), singletonList(service), emptyList());
Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
assertEquals(resolved.size(), 1);
assertEquals(resolved.get("http-server"), new ServerImpl().withUrl("xxx://service11:3054/api").withStatus(ServerStatus.UNKNOWN).withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054", ServerConfig.ENDPOINT_ORIGIN, "/")));
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl in project che-server by eclipse-che.
the class IngressServerResolverTest method testResolvingServersWhenThereIsNoTheCorrespondingServiceAndIngressForTheSpecifiedMachine.
@Test
public void testResolvingServersWhenThereIsNoTheCorrespondingServiceAndIngressForTheSpecifiedMachine() {
// given
Service nonMatchedByPodService = createService("nonMatched", "foreignMachine", CONTAINER_PORT, null);
Ingress ingress = createIngress("nonMatched", "foreignMachine", Pair.of("http-server", new ServerConfigImpl("3054", "http", "/api", ATTRIBUTES_MAP)));
ServerResolver serverResolver = new IngressServerResolver(new NoopPathTransformInverter(), singletonList(nonMatchedByPodService), singletonList(ingress));
// when
Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
// then
assertTrue(resolved.isEmpty());
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl in project che-server by eclipse-che.
the class IngressServerResolverTest method testResolvingServersWhenThereIsMatchedIngressForTheSpecifiedMachine.
@Test
public void testResolvingServersWhenThereIsMatchedIngressForTheSpecifiedMachine() {
Ingress ingress = createIngress("matched", "machine", Pair.of("http-server", new ServerConfigImpl("3054", "http", "/api/", ATTRIBUTES_MAP)));
ServerResolver serverResolver = new IngressServerResolver(new NoopPathTransformInverter(), emptyList(), singletonList(ingress));
Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
assertEquals(resolved.size(), 1);
assertEquals(resolved.get("http-server"), new ServerImpl().withUrl("http://" + INGRESS_IP + INGRESS_RULE_PATH_PREFIX + "/api/").withStatus(ServerStatus.UNKNOWN).withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054", ServerConfig.ENDPOINT_ORIGIN, INGRESS_PATH_PREFIX + "/")));
}
Aggregations