use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.
the class MachinePanelPresenter method onMachineDestroyed.
/**
* {@inheritDoc}
*/
@Override
public void onMachineDestroyed(MachineStateEvent event) {
Machine machine = event.getMachine();
MachineTreeNode deletedNode = existingMachineNodes.get(machine.getId());
machineNodes.remove(deletedNode);
existingMachineNodes.remove(machine.getId());
view.setData(rootNode);
selectFirstNode();
}
use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.
the class CheEnvironmentEngineTest method devMachineStopShouldThrowException.
@Test(expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "Stop of dev machine is not allowed. Please, stop whole environment")
public void devMachineStopShouldThrowException() throws Exception {
// given
List<Instance> instances = startEnv();
Optional<Instance> instanceOpt = instances.stream().filter(machine -> machine.getConfig().isDev()).findAny();
assertTrue(instanceOpt.isPresent(), "Required for test dev machine is not found");
Instance instance = instanceOpt.get();
// when
engine.stopMachine(instance.getWorkspaceId(), instance.getId());
}
use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToStopMachine.
@Test
public void shouldBeAbleToStopMachine() throws Exception {
// given
List<Instance> instances = startEnv();
Optional<Instance> instanceOpt = instances.stream().filter(machine -> !machine.getConfig().isDev()).findAny();
assertTrue(instanceOpt.isPresent(), "Required for test non-dev machine is not found");
Instance instance = instanceOpt.get();
// when
engine.stopMachine(instance.getWorkspaceId(), instance.getId());
// then
verify(instance).destroy();
}
use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToStartNonDockerMachine.
@Test
public void shouldBeAbleToStartNonDockerMachine() throws Exception {
// given
ServerConf2 serverConf2 = mock(ServerConf2.class);
when(serverConf2.getPort()).thenReturn("1111/tcp");
when(serverConf2.getProtocol()).thenReturn("http");
when(serverConf2.getProperties()).thenReturn(singletonMap("path", "some path"));
when(agent.getServers()).thenAnswer(invocation -> singletonMap("ssh", serverConf2));
List<Instance> instances = startEnv();
String workspaceId = instances.get(0).getWorkspaceId();
when(engine.generateMachineId()).thenReturn("newMachineId");
Instance newMachine = mock(Instance.class);
when(newMachine.getId()).thenReturn("newMachineId");
when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
when(machineInstanceProviders.getProvider("anotherType")).thenReturn(instanceProvider);
doReturn(newMachine).when(instanceProvider).createInstance(any(Machine.class), any(LineConsumer.class));
MachineConfigImpl config = MachineConfigImpl.builder().fromConfig(createConfig(false)).setType("anotherType").build();
// when
Instance actualInstance = engine.startMachine(workspaceId, config, singletonList("agent"));
// then
assertEquals(actualInstance, newMachine);
ArgumentCaptor<Machine> argumentCaptor = ArgumentCaptor.forClass(Machine.class);
verify(instanceProvider).createInstance(argumentCaptor.capture(), any(LineConsumer.class));
MachineConfigImpl newConfig = new MachineConfigImpl(config);
newConfig.setServers(singletonList(new ServerConfImpl("ssh", "1111/tcp", "http", "some path")));
assertEquals(argumentCaptor.getValue().getConfig(), newConfig);
}
use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToStartEnvironmentWithRecover.
@Test
public void shouldBeAbleToStartEnvironmentWithRecover() throws Exception {
// given
SnapshotImpl snapshot = mock(SnapshotImpl.class);
MachineSourceImpl machineSource = new MachineSourceImpl("image", "registry.com/snapshot123:latest@sha256:abc1234567890", null);
when(snapshotDao.getSnapshot(anyString(), anyString(), anyString())).thenReturn(snapshot);
when(snapshot.getMachineSource()).thenReturn(machineSource);
// given
EnvironmentImpl env = createEnv();
String envName = "env-1";
String workspaceId = "wsId";
List<Instance> expectedMachines = new ArrayList<>();
when(machineProvider.startService(anyString(), eq(workspaceId), eq(envName), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenAnswer(invocationOnMock -> {
Object[] arguments = invocationOnMock.getArguments();
String machineName = (String) arguments[3];
boolean isDev = (boolean) arguments[4];
CheServiceImpl service = (CheServiceImpl) arguments[6];
Machine machine = createMachine(workspaceId, envName, service, machineName, isDev);
NoOpMachineInstance instance = spy(new NoOpMachineInstance(machine));
expectedMachines.add(instance);
return instance;
});
when(environmentParser.parse(env)).thenReturn(createCheServicesEnv());
// when
List<Instance> machines = engine.start(workspaceId, envName, env, true, messageConsumer);
// then
assertEquals(machines, expectedMachines);
ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
verify(machineProvider).startService(anyString(), anyString(), anyString(), anyString(), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
CheServiceImpl actualService = captor.getValue();
assertEquals(actualService.getImage(), "registry.com/snapshot123:latest");
}
Aggregations