Search in sources :

Example 11 with ProcessTreeNode

use of org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode in project che by eclipse.

the class ProcessesPanelPresenter method addCommandOutput.

/**
     * Adds command node to process tree and displays command output
     *
     * @param machineId
     *         id of machine in which the command will be executed
     * @param outputConsole
     *         the console for command output
     */
public void addCommandOutput(String machineId, OutputConsole outputConsole) {
    ProcessTreeNode machineTreeNode = findProcessTreeNodeById(machineId);
    if (machineTreeNode == null) {
        notificationManager.notify(localizationConstant.failedToExecuteCommand(), localizationConstant.machineNotFound(machineId), FAIL, FLOAT_MODE);
        Log.error(getClass(), localizationConstant.machineNotFound(machineId));
        return;
    }
    String commandId;
    String outputConsoleTitle = outputConsole.getTitle();
    ProcessTreeNode processTreeNode = getProcessTreeNodeByName(outputConsoleTitle, machineTreeNode);
    if (processTreeNode != null && isCommandStopped(processTreeNode.getId())) {
        // 'reuse' already existing console
        // actually - remove 'already used' console
        commandId = processTreeNode.getId();
        view.hideProcessOutput(commandId);
    }
    ProcessTreeNode commandNode = new ProcessTreeNode(COMMAND_NODE, machineTreeNode, outputConsoleTitle, outputConsole.getTitleIcon(), null);
    commandId = commandNode.getId();
    addChildToMachineNode(commandNode, machineTreeNode);
    addOutputConsole(commandId, commandNode, outputConsole, false);
    refreshStopButtonState(commandId);
    workspaceAgent.setActivePart(this);
}
Also used : ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode)

Example 12 with ProcessTreeNode

use of org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode 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 13 with ProcessTreeNode

use of org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode in project che by eclipse.

the class ProcessesPanelPresenter method onWorkspaceStopped.

@Override
public void onWorkspaceStopped(WorkspaceStoppedEvent event) {
    try {
        for (ProcessTreeNode node : rootNode.getChildren()) {
            if (MACHINE_NODE == node.getType()) {
                node.setRunning(false);
                ArrayList<ProcessTreeNode> children = new ArrayList<>();
                children.addAll(node.getChildren());
                for (ProcessTreeNode child : children) {
                    if (COMMAND_NODE == child.getType()) {
                        closeCommandOutput(child, new SubPanel.RemoveCallback() {

                            @Override
                            public void remove() {
                            }
                        });
                    } else if (TERMINAL_NODE == child.getType()) {
                        closeTerminal(child);
                    }
                    view.hideProcessOutput(child.getId());
                    view.removeProcessNode(child);
                }
            }
        }
    } catch (Exception e) {
        Log.error(getClass(), e);
    }
    view.setProcessesData(rootNode);
    selectDevMachine();
}
Also used : ArrayList(java.util.ArrayList) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) SubPanel(org.eclipse.che.ide.ui.multisplitpanel.SubPanel) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 14 with ProcessTreeNode

use of org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode in project che by eclipse.

the class ProcessesPanelPresenter method updateMachineList.

/**
     * Updates list of the machines from application context.
     */
public void updateMachineList() {
    if (appContext.getWorkspace() == null) {
        return;
    }
    List<MachineEntity> machines = getMachines(appContext.getWorkspace());
    if (machines.isEmpty()) {
        return;
    }
    ProcessTreeNode machineToSelect = null;
    for (MachineEntity machine : machines) {
        if (machine.isDev()) {
            provideMachineNode(machine, true);
            machines.remove(machine);
            break;
        }
    }
    for (MachineEntity machine : machines) {
        provideMachineNode(machine, true);
    }
    if (machineToSelect == null) {
        machineToSelect = machineNodes.entrySet().iterator().next().getValue();
    }
    view.selectNode(machineToSelect);
    notifyTreeNodeSelected(machineToSelect);
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode)

Example 15 with ProcessTreeNode

use of org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode in project che by eclipse.

the class ProcessesPanelPresenter method onAddTerminal.

/**
     * Adds new terminal to the processes panel
     *
     * @param machineId
     *         id of machine in which the terminal will be added
     */
@Override
public void onAddTerminal(final String machineId, Object source) {
    final MachineEntity machine = getMachine(machineId);
    if (machine == null) {
        notificationManager.notify(localizationConstant.failedToConnectTheTerminal(), localizationConstant.machineNotFound(machineId), FAIL, FLOAT_MODE);
        Log.error(getClass(), localizationConstant.machineNotFound(machineId));
        return;
    }
    final ProcessTreeNode machineTreeNode = provideMachineNode(machine, false);
    final TerminalPresenter newTerminal = terminalFactory.create(machine, source);
    final IsWidget terminalWidget = newTerminal.getView();
    final String terminalName = getUniqueTerminalName(machineTreeNode);
    final ProcessTreeNode terminalNode = new ProcessTreeNode(TERMINAL_NODE, machineTreeNode, terminalName, resources.terminalTreeIcon(), null);
    addChildToMachineNode(terminalNode, machineTreeNode);
    final String terminalId = terminalNode.getId();
    terminals.put(terminalId, newTerminal);
    view.addProcessNode(terminalNode);
    terminalWidget.asWidget().ensureDebugId(terminalName);
    view.addWidget(terminalId, terminalName, terminalNode.getTitleIcon(), terminalWidget, false);
    refreshStopButtonState(terminalId);
    workspaceAgent.setActivePart(this);
    newTerminal.setVisible(true);
    newTerminal.connect();
    newTerminal.setListener(new TerminalPresenter.TerminalStateListener() {

        @Override
        public void onExit() {
            String terminalId = terminalNode.getId();
            if (terminals.containsKey(terminalId)) {
                onStopProcess(terminalNode);
                terminals.remove(terminalId);
            }
            view.hideProcessOutput(terminalId);
        }
    });
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) IsWidget(com.google.gwt.user.client.ui.IsWidget) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) TerminalPresenter(org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter)

Aggregations

ProcessTreeNode (org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode)36 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)12 IsWidget (com.google.gwt.user.client.ui.IsWidget)8 MachineEntity (org.eclipse.che.ide.api.machine.MachineEntity)8 TerminalPresenter (org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter)5 MachineConfigDto (org.eclipse.che.api.machine.shared.dto.MachineConfigDto)3 OutputConsole (org.eclipse.che.ide.api.outputconsole.OutputConsole)3 CommandOutputConsole (org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole)3 SubPanel (org.eclipse.che.ide.ui.multisplitpanel.SubPanel)3 Machine (org.eclipse.che.api.core.model.machine.Machine)2 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)2 MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 CommandOutputConsolePresenter (org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsolePresenter)2 DefaultOutputConsole (org.eclipse.che.ide.extension.machine.client.outputspanel.console.DefaultOutputConsole)2 WidgetToShow (org.eclipse.che.ide.ui.multisplitpanel.WidgetToShow)2 AcceptsOneWidget (com.google.gwt.user.client.ui.AcceptsOneWidget)1 Focusable (com.google.gwt.user.client.ui.Focusable)1 Date (java.util.Date)1