use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl in project che-server by eclipse-che.
the class InternalRuntimeTest method shouldAddAWarningInsteadOfAServerIfURLRewritingFailed.
@Test
public void shouldAddAWarningInsteadOfAServerIfURLRewritingFailed() throws Exception {
// given
URLRewriter urlRewriter = spy(new URLRewriter.NoOpURLRewriter());
setRunningRuntime(urlRewriter);
Map<String, MachineImpl> expectedMachines = new HashMap<>();
Map<String, MachineImpl> internalMachines = new HashMap<>();
MachineImpl machine1 = createMachine();
MachineImpl machine2 = createMachine();
HashMap<String, ServerImpl> expectedServers = new HashMap<>(machine1.getServers());
String badServerName = "badServer";
String badServerURL = "ws://failing-rewriting:8000";
String badServerRewritingExcMessage = "test exc";
ServerImpl failingRewritingServer = createServer(badServerURL);
machine1.getServers().put(badServerName, failingRewritingServer);
internalMachines.put("m1", machine1);
internalMachines.put("m2", machine2);
expectedMachines.put("m1", new MachineImpl(machine1.getAttributes(), expectedServers, machine1.getStatus()));
expectedMachines.put("m2", machine2);
List<WarningImpl> expectedWarnings = new ArrayList<>();
expectedWarnings.add(new WarningImpl(InternalRuntime.MALFORMED_SERVER_URL_FOUND, "Malformed URL for " + badServerName + " : " + badServerRewritingExcMessage));
doReturn(internalMachines).when(internalRuntime).getInternalMachines();
doThrow(new InfrastructureException(badServerRewritingExcMessage)).when(urlRewriter).rewriteURL(any(RuntimeIdentity.class), any(), anyString(), eq(badServerURL));
// when
Map<String, ? extends Machine> actualMachines = internalRuntime.getMachines();
List<? extends Warning> actualWarnings = internalRuntime.getWarnings();
// then
assertEquals(actualMachines, expectedMachines);
assertEquals(actualWarnings, expectedWarnings);
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl in project che-server by eclipse-che.
the class InternalRuntimeTest method modifyMachines.
private void modifyMachines(HashMap<String, MachineImpl> originInternalMachines, String machineToModify, String serverToModify) throws Exception {
// add new machine
originInternalMachines.put("newM", createMachine());
MachineImpl originMachine = originInternalMachines.get(machineToModify);
// change properties of origin server
originMachine.getAttributes().put("new_prop", "new_value");
// add new server in origin machine
originMachine.getServers().put("newS", createServer(RUNNING));
ServerImpl originServer = originMachine.getServers().get(serverToModify);
// change status and URL of origin server
originServer.setStatus(RUNNING);
originServer.setUrl("http://localhost:9191/new_url");
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl in project che-server by eclipse-che.
the class InternalRuntimeTest method createMachines.
private HashMap<String, MachineImpl> createMachines(String expectedMachineName, Map<String, String> expectedProps, String expectedServerName, String expectedServerUrl, ServerStatus expectedServerStatus) throws Exception {
MachineImpl expectedMachine = new MachineImpl(expectedProps, singletonMap(expectedServerName, new ServerImpl().withUrl(expectedServerUrl).withStatus(expectedServerStatus)), MachineStatus.RUNNING);
HashMap<String, MachineImpl> result = new HashMap<>();
result.put("m1", createMachine());
result.put("m2", createMachine());
result.put(expectedMachineName, expectedMachine);
return result;
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl in project che-server by eclipse-che.
the class RouteServerResolverTest method testResolvingInternalServers.
@Test
public void testResolvingInternalServers() {
Service service = createService("service11", "machine", CONTAINER_PORT, singletonMap("http-server", new ServerConfigImpl("3054", "http", "api", ATTRIBUTES_MAP)));
Route route = createRoute("matched", "machine", null);
RouteServerResolver serverResolver = new RouteServerResolver(singletonList(service), singletonList(route));
Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
assertEquals(resolved.size(), 1);
assertEquals(resolved.get("http-server"), new ServerImpl().withUrl("http://service11:3054/api").withStatus(UNKNOWN).withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054", ServerConfig.ENDPOINT_ORIGIN, "/")));
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl in project devspaces-images by redhat-developer.
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;
}
Aggregations