Search in sources :

Example 1 with MachineDto

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());
}
Also used : WorkspaceRuntimeDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) HashMap(java.util.HashMap) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with MachineDto

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;
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) WorkspaceRuntime(org.eclipse.che.api.core.model.workspace.WorkspaceRuntime) ArrayList(java.util.ArrayList) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine)

Example 3 with MachineDto

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());
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) IsWidget(com.google.gwt.user.client.ui.IsWidget) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) ArrayList(java.util.ArrayList) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) TerminalPresenter(org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter) Test(org.junit.Test)

Example 4 with MachineDto

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);
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) ArrayList(java.util.ArrayList) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) MachineProcessDto(org.eclipse.che.api.machine.shared.dto.MachineProcessDto) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) CommandType(org.eclipse.che.ide.api.command.CommandType) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) WsAgentStateEvent(org.eclipse.che.ide.api.machine.events.WsAgentStateEvent) Test(org.junit.Test)

Example 5 with MachineDto

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));
            });
        }
    }
}
Also used : WorkspaceRuntimeDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto) ServerDto(org.eclipse.che.api.machine.shared.dto.ServerDto) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto)

Aggregations

MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)13 ArrayList (java.util.ArrayList)7 MachineConfigDto (org.eclipse.che.api.machine.shared.dto.MachineConfigDto)6 MachineEntity (org.eclipse.che.ide.api.machine.MachineEntity)6 Test (org.junit.Test)5 Machine (org.eclipse.che.api.core.model.machine.Machine)4 WorkspaceRuntime (org.eclipse.che.api.core.model.workspace.WorkspaceRuntime)3 WorkspaceRuntimeDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto)3 IsWidget (com.google.gwt.user.client.ui.IsWidget)2 HashMap (java.util.HashMap)2 ServerDto (org.eclipse.che.api.machine.shared.dto.ServerDto)2 EnvironmentDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentDto)2 WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)2 DevMachine (org.eclipse.che.ide.api.machine.DevMachine)2 CommandOutputConsole (org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole)2 TerminalPresenter (org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter)2 ProcessTreeNode (org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1