use of org.eclipse.che.api.machine.shared.dto.MachineDto in project che by eclipse.
the class WorkspaceEventsHandlerTest method onWsAgentOutputEventReceivedTest.
@Test
public void onWsAgentOutputEventReceivedTest() throws Exception {
WorkspaceRuntimeDto runtime = mock(WorkspaceRuntimeDto.class);
WorkspaceConfigDto workspaceConfig = mock(WorkspaceConfigDto.class);
when(workspace.getRuntime()).thenReturn(runtime);
MachineDto devMachine = mock(MachineDto.class);
when(devMachine.getWorkspaceId()).thenReturn(WORKSPACE_ID);
when(devMachine.getId()).thenReturn(MACHINE_NAME);
when(runtime.getDevMachine()).thenReturn(devMachine);
when(runtime.getActiveEnv()).thenReturn(ACTIVE_ENV);
when(workspace.getConfig()).thenReturn(workspaceConfig);
Map<String, EnvironmentDto> environments = new HashMap<>(3);
EnvironmentDto environment = mock(EnvironmentDto.class);
environments.put(ACTIVE_ENV, environment);
when(workspaceConfig.getEnvironments()).thenReturn(environments);
MachineConfigDto devMachineConfig = mock(MachineConfigDto.class);
when(devMachineConfig.getName()).thenReturn(MACHINE_NAME);
workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
workspaceEventsHandler.wsAgentLogSubscriptionHandler.onMessageReceived("");
verify(eventBus).fireEvent(Matchers.<EnvironmentOutputEvent>anyObject());
}
use of org.eclipse.che.api.machine.shared.dto.MachineDto in project che by eclipse.
the class ProcessesPanelPresenter method getMachines.
private List<MachineEntity> getMachines(Workspace workspace) {
WorkspaceRuntime workspaceRuntime = workspace.getRuntime();
if (workspaceRuntime == null) {
return emptyList();
}
List<? extends Machine> runtimeMachines = workspaceRuntime.getMachines();
List<MachineEntity> machines = new ArrayList<>(runtimeMachines.size());
for (Machine machine : runtimeMachines) {
if (machine instanceof MachineDto) {
MachineEntity machineEntity = entityFactory.createMachine((MachineDto) machine);
machines.add(machineEntity);
}
}
return machines;
}
use of org.eclipse.che.api.machine.shared.dto.MachineDto in project che by eclipse.
the class ProcessesPanelPresenterTest method shouldAddTerminal.
@Test
public void shouldAddTerminal() throws Exception {
MachineDto machineDto = mock(MachineDto.class);
MachineEntity machine = mock(MachineEntity.class);
when(machine.getId()).thenReturn(MACHINE_ID);
MachineConfigDto machineConfigDto = mock(MachineConfigDto.class);
when(machine.getConfig()).thenReturn(machineConfigDto);
when(machineConfigDto.isDev()).thenReturn(true);
when(machine.getStatus()).thenReturn(MachineStatus.RUNNING);
List<MachineDto> machines = new ArrayList<>(1);
machines.add(machineDto);
when(workspaceRuntime.getMachines()).thenReturn(machines);
when(entityFactory.createMachine(machineDto)).thenReturn(machine);
presenter.rootNode = new ProcessTreeNode(ROOT_NODE, null, null, null, new ArrayList<ProcessTreeNode>());
TerminalPresenter terminal = mock(TerminalPresenter.class);
when(terminalFactory.create(machine, presenter)).thenReturn(terminal);
IsWidget terminalWidget = mock(IsWidget.class);
when(terminal.getView()).thenReturn(terminalWidget);
when(terminalWidget.asWidget()).thenReturn(widget);
presenter.onAddTerminal(MACHINE_ID, presenter);
verify(terminalFactory).create(eq(machine), eq(presenter));
verify(workspaceAgent).setActivePart(presenter);
verify(terminal).getView();
verify(view, times(2)).setProcessesData(anyObject());
verify(view).selectNode(anyObject());
verify(view).addWidget(anyString(), anyString(), anyObject(), eq(terminalWidget), anyBoolean());
verify(view).addProcessNode(anyObject());
verify(terminal).setVisible(eq(true));
verify(terminal).connect();
verify(terminal).setListener(anyObject());
}
use of org.eclipse.che.api.machine.shared.dto.MachineDto in project che by eclipse.
the class ProcessesPanelPresenterTest method commandShouldBeRestoredWhenWsAgentIsStarted.
@Test
public void commandShouldBeRestoredWhenWsAgentIsStarted() throws Exception {
WsAgentStateEvent event = mock(WsAgentStateEvent.class);
MachineEntity machineEntity = mock(MachineEntity.class);
MachineDto machine = mock(MachineDto.class);
when(machineEntity.getId()).thenReturn(MACHINE_ID);
when(machineEntity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
when(entityFactory.createMachine(machine)).thenReturn(machineEntity);
MachineConfigDto machineConfigDto = mock(MachineConfigDto.class);
when(machine.getConfig()).thenReturn(machineConfigDto);
when(machineConfigDto.isDev()).thenReturn(true);
when(machine.getStatus()).thenReturn(MachineStatus.RUNNING);
List<MachineDto> machines = new ArrayList<>(2);
machines.add(machine);
when(workspaceRuntime.getMachines()).thenReturn(machines);
MachineProcessDto machineProcessDto = mock(MachineProcessDto.class);
when(machineProcessDto.getOutputChannel()).thenReturn(OUTPUT_CHANNEL);
when(machineProcessDto.getPid()).thenReturn(PID);
List<MachineProcessDto> processes = new ArrayList<>(1);
processes.add(machineProcessDto);
CommandOutputConsole outputConsole = mock(CommandOutputConsole.class);
CommandType commandType = mock(CommandType.class);
when(commandTypeRegistry.getCommandTypeById(anyString())).thenReturn(commandType);
when(commandConsoleFactory.create(anyObject(), any(org.eclipse.che.api.core.model.machine.Machine.class))).thenReturn(outputConsole);
presenter.onWsAgentStarted(event);
}
use of org.eclipse.che.api.machine.shared.dto.MachineDto in project che by eclipse.
the class WorkspaceServiceLinksInjector method injectRuntimeLinks.
protected void injectRuntimeLinks(WorkspaceDto workspace, URI ideUri, UriBuilder uriBuilder, ServiceContext serviceContext) {
final WorkspaceRuntimeDto runtime = workspace.getRuntime();
// add links for running workspace
if (workspace.getStatus() == RUNNING && runtime != null) {
runtime.getLinks().add(createLink("DELETE", uriBuilder.clone().path(WorkspaceService.class, "stop").build(workspace.getId()).toString(), LINK_REL_STOP_WORKSPACE));
runtime.getMachines().forEach(machine -> injectMachineLinks(machine, serviceContext));
final MachineDto devMachine = runtime.getDevMachine();
if (devMachine != null) {
final Collection<ServerDto> servers = devMachine.getRuntime().getServers().values();
servers.stream().filter(server -> WSAGENT_REFERENCE.equals(server.getRef())).findAny().ifPresent(wsAgent -> {
runtime.getLinks().add(createLink("GET", wsAgent.getUrl(), WSAGENT_REFERENCE));
runtime.getLinks().add(createLink("GET", UriBuilder.fromUri(wsAgent.getUrl()).path("ws").scheme("https".equals(ideUri.getScheme()) ? "wss" : "ws").build().toString(), WSAGENT_WEBSOCKET_REFERENCE));
devMachine.getLinks().add(createLink("GET", UriBuilder.fromUri(wsAgent.getUrl()).scheme("https".equals(ideUri.getScheme()) ? "wss" : "ws").path("/ws").build().toString(), WSAGENT_WEBSOCKET_REFERENCE));
});
servers.stream().filter(server -> TERMINAL_REFERENCE.equals(server.getRef())).findAny().ifPresent(terminal -> {
devMachine.getLinks().add(createLink("GET", UriBuilder.fromUri(terminal.getUrl()).scheme("https".equals(ideUri.getScheme()) ? "wss" : "ws").path("/pty").build().toString(), TERMINAL_REFERENCE));
devMachine.getLinks().add(createLink("GET", UriBuilder.fromUri(terminal.getUrl()).scheme("https".equals(ideUri.getScheme()) ? "wss" : "ws").path("/connect").build().toString(), EXEC_AGENT_REFERENCE));
});
}
}
}
Aggregations