/** * Copy some files by executing a tar command to the stdout and return the InputStream that contains the tar * contents. * <p> * Unfortunately due to the fact that any error handling happens on another thread, if the tar command fails the * InputStream will simply be empty and it will close. It won't propagate an Exception to the reader of the * InputStream. */ @Override public InputStream copyFiles(String containerId, String folderName) { ByteArrayOutputStream stderr = new ByteArrayOutputStream(); String[] command = new String[] { "tar", "-C", folderName, "-c", "." }; CopyFilesExecListener listener = new CopyFilesExecListener(stderr, command, containerId); ExecWatch exec = client.pods().withName(containerId).redirectingOutput().writingError(stderr).usingListener(listener).exec(command); // FIXME: This is a bit dodgy, but we need the listener to be able to close the ExecWatch in failure conditions, // because it doesn't cleanup properly and deadlocks. // Needs bugs fixed inside kubernetes-client. listener.setExecWatch(exec); // When zalenium is under high load sometimes the stdout isn't connected by the time we try to read from it. // Let's wait until it is connected before proceeding. listener.waitForInputStreamToConnect(); return exec.getOutput(); }
pump = new InputStreamPumper(watch.getOutput(), new SystemOutCallback()); executorService.submit(pump); Future<String> outPumpFuture = executorService.submit(pump, "Done");
.redirectingErrorChannel() .exec(); InputStreamPumper pump = new InputStreamPumper(watch.getOutput(), new SystemOutCallback()))
@Override public InputStream getStdout() { return watch.getOutput(); }
@Override public InputStream getStdout() { return watch.getOutput(); }
@Override public InputStream getStderr() { return watch.getOutput(); }
private void openReaderThreads(Session session, SessionExecModel sessionExecModel) { // TODO: if there is a leak, this might be a suspect.. close those? sessionExecModel.getExecutor().execute(() -> WebsocketWriter.readCharsFromStreamToSession(sessionExecModel.getExecWatch().getOutput(), session)); sessionExecModel.getExecutor().execute(() -> WebsocketWriter.readCharsFromStreamToSession(sessionExecModel.getExecWatch().getError(), session)); } }