use of org.eclipse.che.ide.extension.machine.client.outputspanel.console.DefaultOutputConsole 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.outputspanel.console.DefaultOutputConsole in project che by eclipse.
the class ProcessesPanelPresenter method printMachineOutput.
/**
* Prints text to the machine console.
*
* @param machineName
* machine name
* @param text
* text to be printed
*/
public void printMachineOutput(final String machineName, final String text) {
// Create a temporary machine node to display outputs.
if (!consoles.containsKey(machineName)) {
MachineDto machineDto = dtoFactory.createDto(MachineDto.class).withId(machineName).withStatus(CREATING).withConfig(dtoFactory.createDto(MachineConfigDto.class).withDev("dev-machine".equals(machineName)).withName(machineName).withType("docker"));
provideMachineNode(new MachineItem(machineDto), true);
}
OutputConsole console = consoles.get(machineName);
if (console != null && console instanceof DefaultOutputConsole) {
((DefaultOutputConsole) console).printText(text);
}
}
Aggregations