use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl in project che-server by eclipse-che.
the class WorkspaceServiceTest method shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasEmptyValue.
@Test
public void shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasEmptyValue() 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", "").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.MachineImpl in project che-server by eclipse-che.
the class WorkspaceServiceTest method shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasNoValue.
@Test
public void shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasNoValue() 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").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.MachineImpl 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.MachineImpl 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.MachineImpl in project che-server by eclipse-che.
the class InternalRuntimeTest method getMachinesResultShouldNotBeAffectedByFollowingModificationOfResultOfGetInternalMachines.
@Test
public void getMachinesResultShouldNotBeAffectedByFollowingModificationOfResultOfGetInternalMachines() throws Exception {
// given
setRunningRuntime(new URLRewriter.NoOpURLRewriter());
String originMachineName = "exp_m";
String originServerName = "exp_s";
ServerStatus originServerStatus = ServerStatus.UNKNOWN;
String originServerUrl = "https://expected.url:1000";
Map<String, String> originProps = ImmutableMap.of("origProp1", "value1");
int initialPropsSize = originProps.size();
HashMap<String, MachineImpl> originInternalMachines = createMachines(originMachineName, originProps, originServerName, originServerUrl, originServerStatus);
int initialMachinesAmount = originInternalMachines.size();
int initialServersAmountInOriginMachine = originInternalMachines.get(originMachineName).getServers().size();
doReturn(originInternalMachines).when(internalRuntime).getInternalMachines();
// when
Map<String, ? extends Machine> actualMachines = internalRuntime.getMachines();
// verify that retrieved state is equal to the origin one
assertValues(actualMachines, initialMachinesAmount, originMachineName, initialPropsSize, initialServersAmountInOriginMachine, originServerName, originServerUrl, originServerStatus);
// modify origin machines
modifyMachines(originInternalMachines, originMachineName, originServerName);
// then
// ensure actual values retrieved from runtime
// are not changed automatically after changes in origin internal runtime
assertValues(actualMachines, initialMachinesAmount, originMachineName, initialPropsSize, initialServersAmountInOriginMachine, originServerName, originServerUrl, originServerStatus);
}
Aggregations