use of org.eclipse.che.api.core.model.workspace.runtime.Server in project che-server by eclipse-che.
the class WorkspaceServiceTest method shouldGetWorkspaceWithExternalServersByDefault.
@Test
public void shouldGetWorkspaceWithExternalServersByDefault() throws Exception {
// given
WorkspaceImpl workspace = createWorkspace(createConfigDto());
String externalServerKey = "server2";
ServerImpl externalServer = createExternalServer();
Map<String, Server> servers = ImmutableMap.of("server1", 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(singletonMap(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()))));
// when
Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).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.core.model.workspace.runtime.Server in project che-server by eclipse-che.
the class WorkspaceServiceTest method shouldTreatServerWithInternalServerAttributeNotEqualToTrueExternal.
@Test
public void shouldTreatServerWithInternalServerAttributeNotEqualToTrueExternal() throws Exception {
// given
WorkspaceImpl workspace = createWorkspace(createConfigDto());
String externalServerKey = "server2";
ServerImpl externalServer = createInternalServer().withAttributes(singletonMap(ServerConfig.INTERNAL_SERVER_ATTRIBUTE, ""));
Map<String, Server> servers = ImmutableMap.of("server1", 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(singletonMap(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()))));
// when
Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).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.core.model.workspace.runtime.Server 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.core.model.workspace.runtime.Server 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.core.model.workspace.runtime.Server in project devspaces-images by redhat-developer.
the class WorkspaceServiceTest method shouldGetWorkspaceWithExternalServersByDefault.
@Test
public void shouldGetWorkspaceWithExternalServersByDefault() throws Exception {
// given
WorkspaceImpl workspace = createWorkspace(createConfigDto());
String externalServerKey = "server2";
ServerImpl externalServer = createExternalServer();
Map<String, Server> servers = ImmutableMap.of("server1", 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(singletonMap(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()))));
// when
Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).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());
}
Aggregations