Search in sources :

Example 1 with OutputConsole

use of org.eclipse.che.ide.api.outputconsole.OutputConsole in project che by eclipse.

the class ProcessesPanelPresenterTest method shouldAddMachineWhenMachineCreating.

@Test
public void shouldAddMachineWhenMachineCreating() throws Exception {
    MachineEntity machine = mock(MachineEntity.class);
    MachineConfigDto machineConfigDto = mock(MachineConfigDto.class);
    OutputConsole outputConsole = mock(OutputConsole.class);
    when(machineConfigDto.getName()).thenReturn(MACHINE_NAME);
    when(machine.getConfig()).thenReturn(machineConfigDto);
    when(appContext.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(commandConsoleFactory.create(eq(MACHINE_NAME))).thenReturn(outputConsole);
    MachineStateEvent machineStateEvent = mock(MachineStateEvent.class);
    when(machineStateEvent.getMachine()).thenReturn(machine);
    verify(eventBus, times(8)).addHandler(anyObject(), machineStateHandlerCaptor.capture());
    MachineStateEvent.Handler machineStateHandler = machineStateHandlerCaptor.getAllValues().get(0);
    machineStateHandler.onMachineCreating(machineStateEvent);
    verify(outputConsole).go(acceptsOneWidgetCaptor.capture());
    IsWidget widget = mock(IsWidget.class);
    acceptsOneWidgetCaptor.getValue().setWidget(widget);
    verify(commandConsoleFactory).create(eq(MACHINE_NAME));
    verify(view).addWidget(anyString(), anyString(), anyObject(), anyObject(), anyBoolean());
    verify(view).setProcessesData(eq(presenter.rootNode));
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) IsWidget(com.google.gwt.user.client.ui.IsWidget) MachineStateEvent(org.eclipse.che.ide.api.machine.events.MachineStateEvent) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) OutputConsole(org.eclipse.che.ide.api.outputconsole.OutputConsole) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) Test(org.junit.Test)

Example 2 with OutputConsole

use of org.eclipse.che.ide.api.outputconsole.OutputConsole in project che by eclipse.

the class StopProcessAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    OutputConsole outputConsole = processesPanelPresenter.getContextOutputConsole();
    if (outputConsole != null && outputConsole instanceof CommandOutputConsolePresenter) {
        CommandOutputConsolePresenter commandOutputConsolePresenter = (CommandOutputConsolePresenter) outputConsole;
        commandOutputConsolePresenter.stopProcessButtonClicked();
    }
}
Also used : OutputConsole(org.eclipse.che.ide.api.outputconsole.OutputConsole) CommandOutputConsolePresenter(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsolePresenter)

Example 3 with OutputConsole

use of org.eclipse.che.ide.api.outputconsole.OutputConsole in project che by eclipse.

the class ProcessesPanelPresenter method onPreviewSsh.

@Override
public void onPreviewSsh(String machineId) {
    ProcessTreeNode machineTreeNode = findProcessTreeNodeById(machineId);
    if (machineTreeNode == null) {
        return;
    }
    Machine machine = (Machine) machineTreeNode.getData();
    final OutputConsole defaultConsole = commandConsoleFactory.create("SSH");
    addCommandOutput(machineId, defaultConsole);
    final String machineName = machine.getConfig().getName();
    String sshServiceAddress = getSshServerAddress(machine);
    final String machineHost;
    final String sshPort;
    if (sshServiceAddress != null) {
        String[] parts = sshServiceAddress.split(":");
        machineHost = parts[0];
        sshPort = (parts.length == 2) ? parts[1] : SSH_PORT;
    } else {
        sshPort = SSH_PORT;
        machineHost = "";
    }
    // user
    final String userName;
    String user = machine.getRuntime().getProperties().get("config.user");
    if (isNullOrEmpty(user)) {
        userName = "root";
    } else {
        userName = user;
    }
    // ssh key
    final String workspaceName = appContext.getWorkspace().getConfig().getName();
    Promise<SshPairDto> sshPairDtoPromise = sshServiceClient.getPair("workspace", machine.getWorkspaceId());
    sshPairDtoPromise.then(new Operation<SshPairDto>() {

        @Override
        public void apply(SshPairDto sshPairDto) throws OperationException {
            if (defaultConsole instanceof DefaultOutputConsole) {
                ((DefaultOutputConsole) defaultConsole).enableAutoScroll(false);
                ((DefaultOutputConsole) defaultConsole).printText(localizationConstant.sshConnectInfo(machineName, machineHost, sshPort, workspaceName, userName, localizationConstant.sshConnectInfoPrivateKey(sshPairDto.getPrivateKey())));
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            if (defaultConsole instanceof DefaultOutputConsole) {
                ((DefaultOutputConsole) defaultConsole).enableAutoScroll(false);
                ((DefaultOutputConsole) defaultConsole).printText(localizationConstant.sshConnectInfo(machineName, machineHost, sshPort, workspaceName, userName, localizationConstant.sshConnectInfoNoPrivateKey()));
            }
        }
    });
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) Operation(org.eclipse.che.api.promises.client.Operation) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) OutputConsole(org.eclipse.che.ide.api.outputconsole.OutputConsole) DefaultOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.DefaultOutputConsole) DefaultOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.DefaultOutputConsole) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 4 with OutputConsole

use of org.eclipse.che.ide.api.outputconsole.OutputConsole in project che by eclipse.

the class ProcessesPanelPresenterTest method shouldShowErrorWhenMachineNodeIsNull.

@Test
public void shouldShowErrorWhenMachineNodeIsNull() throws Exception {
    List<ProcessTreeNode> children = new ArrayList<>();
    presenter.rootNode = new ProcessTreeNode(ROOT_NODE, null, null, null, children);
    OutputConsole outputConsole = mock(OutputConsole.class);
    presenter.addCommandOutput(MACHINE_ID, outputConsole);
    verify(notificationManager).notify(anyString(), anyString(), any(StatusNotification.Status.class), any(DisplayMode.class));
    verify(localizationConstant, times(2)).machineNotFound(eq(MACHINE_ID));
}
Also used : MachineStatus(org.eclipse.che.api.core.model.machine.MachineStatus) DisplayMode(org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) OutputConsole(org.eclipse.che.ide.api.outputconsole.OutputConsole) ArrayList(java.util.ArrayList) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) Test(org.junit.Test)

Example 5 with OutputConsole

use of org.eclipse.che.ide.api.outputconsole.OutputConsole in project che by eclipse.

the class ProcessesPanelPresenter method closeCommandOutput.

private void closeCommandOutput(ProcessTreeNode node, SubPanel.RemoveCallback removeCallback) {
    String commandId = node.getId();
    OutputConsole console = consoles.get(commandId);
    if (console == null) {
        removeCallback.remove();
        return;
    }
    if (console.isFinished()) {
        console.close();
        onStopProcess(node);
        consoles.remove(commandId);
        consoleCommands.remove(console);
        removeCallback.remove();
        return;
    }
    dialogFactory.createConfirmDialog("", localizationConstant.outputsConsoleViewStopProcessConfirmation(console.getTitle()), getConfirmCloseConsoleCallback(console, node, removeCallback), null).show();
}
Also used : CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) OutputConsole(org.eclipse.che.ide.api.outputconsole.OutputConsole) DefaultOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.DefaultOutputConsole)

Aggregations

OutputConsole (org.eclipse.che.ide.api.outputconsole.OutputConsole)8 CommandOutputConsole (org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole)6 DefaultOutputConsole (org.eclipse.che.ide.extension.machine.client.outputspanel.console.DefaultOutputConsole)4 ProcessTreeNode (org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode)3 CommandOutputConsolePresenter (org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsolePresenter)2 Test (org.junit.Test)2 IsWidget (com.google.gwt.user.client.ui.IsWidget)1 ArrayList (java.util.ArrayList)1 Machine (org.eclipse.che.api.core.model.machine.Machine)1 MachineStatus (org.eclipse.che.api.core.model.machine.MachineStatus)1 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)1 MachineConfigDto (org.eclipse.che.api.machine.shared.dto.MachineConfigDto)1 MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 SshPairDto (org.eclipse.che.api.ssh.shared.dto.SshPairDto)1 MachineEntity (org.eclipse.che.ide.api.machine.MachineEntity)1 MachineStateEvent (org.eclipse.che.ide.api.machine.events.MachineStateEvent)1 DisplayMode (org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode)1