use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl 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.MachineImpl in project devspaces-images by redhat-developer.
the class RamResourceUsageTrackerTest method createWorkspace.
/**
* Creates users workspace object based on the status and machines RAM.
*/
private static WorkspaceImpl createWorkspace(WorkspaceStatus status, Integer... machineRams) {
final Map<String, MachineImpl> machines = new HashMap<>(machineRams.length - 1);
final Map<String, MachineConfigImpl> machineConfigs = new HashMap<>(machineRams.length - 1);
byte i = 1;
for (Integer machineRam : machineRams) {
final String machineName = "machine_" + i++;
machines.put(machineName, createMachine(machineRam));
machineConfigs.put(machineName, createMachineConfig(machineRam));
}
return WorkspaceImpl.builder().setConfig(WorkspaceConfigImpl.builder().setEnvironments(ImmutableBiMap.of(ACTIVE_ENV_NAME, new EnvironmentImpl(null, machineConfigs))).build()).setRuntime(new RuntimeImpl(ACTIVE_ENV_NAME, machines, null)).setStatus(status).build();
}
use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl in project devspaces-images by redhat-developer.
the class WorkspaceRuntimesTest method shouldInjectRuntime.
@Test
public void shouldInjectRuntime() throws Exception {
// given
WorkspaceImpl workspace = new WorkspaceImpl();
workspace.setId("ws123");
when(statuses.get("ws123")).thenReturn(WorkspaceStatus.RUNNING);
ImmutableMap<String, Machine> machines = ImmutableMap.of("machine", new MachineImpl(emptyMap(), emptyMap(), MachineStatus.STARTING));
RuntimeIdentity identity = new RuntimeIdentityImpl("ws123", "my-env", "myId", "infraNamespace");
RuntimeContext context = mockContext(identity);
ConcurrentHashMap<String, InternalRuntime<?>> runtimesStorage = new ConcurrentHashMap<>();
TestInternalRuntime testRuntime = new TestInternalRuntime(context, machines, WorkspaceStatus.STARTING);
runtimesStorage.put("ws123", testRuntime);
WorkspaceRuntimes localRuntimes = new WorkspaceRuntimes(runtimesStorage, eventService, ImmutableMap.of(TEST_ENVIRONMENT_TYPE, testEnvFactory), infrastructure, sharedPool, workspaceDao, dbInitializer, probeScheduler, statuses, lockService, devfileConverter, false);
// when
localRuntimes.injectRuntime(workspace);
// then
assertEquals(workspace.getStatus(), WorkspaceStatus.RUNNING);
assertEquals(workspace.getRuntime(), asRuntime(testRuntime));
}
use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl in project devspaces-images by redhat-developer.
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.MachineImpl in project devspaces-images by redhat-developer.
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