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);
}
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()));
}
}
});
}
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();
}
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);
}
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);
}
});
}
Aggregations