Skip to content

Commit c78c1a4

Browse files
authored
Merge pull request #1045 from giannello/exec-ws-fixes
Support `error` websocket channel
2 parents cf61c6d + 454406b commit c78c1a4

File tree

9 files changed

+133
-36
lines changed

9 files changed

+133
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.fabric8.kubernetes.client.dsl;
18+
19+
/**
20+
* @param <O> Where to write errorChannel to.
21+
* @param <P> Where to read errorChannel from.
22+
* @param <T> The return type.
23+
*/
24+
public interface ErrorChannelable<O, P, T> {
25+
26+
T writingErrorChannel(O in);
27+
28+
T readingErrorChannel(P in);
29+
30+
T redirectingErrorChannel();
31+
}

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/ExecWatch.java

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public interface ExecWatch extends Closeable {
2727

2828
InputStream getError();
2929

30+
InputStream getErrorChannel();
31+
3032
/**
3133
* Close the Watch.
3234
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.kubernetes.client.dsl;
17+
18+
/**
19+
* @param <X> The exec input.
20+
* @param <O> Where to write err channel to.
21+
* @param <P> Where to read err channel from.
22+
* @param <T> The exec output.
23+
*/
24+
public interface TtyExecErrorChannelable<X, O, P, T> extends
25+
TtyExecable<X, T>,
26+
ErrorChannelable<O, P, TtyExecable<X, T>> {
27+
}

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/TtyExecErrorable.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @param <T> The exec output.
2525
*/
2626
public interface TtyExecErrorable<X, O, P, T> extends
27-
TtyExecable<X, T>,
28-
Errorable<O, P, TtyExecable<X, T>> {
27+
TtyExecErrorChannelable<X, O, P, T>,
28+
Errorable<O, P, TtyExecErrorChannelable<X, O, P, T>> {
2929

3030
}

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ExecWebSocketListener.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ public class ExecWebSocketListener extends WebSocketListener implements ExecWatc
6666
private final InputStream in;
6767
private final OutputStream out;
6868
private final OutputStream err;
69+
private final OutputStream errChannel;
6970

7071
private final PipedOutputStream input;
7172
private final PipedInputStream output;
7273
private final PipedInputStream error;
74+
private final PipedInputStream errorChannel;
7375

7476
private final AtomicReference<WebSocket> webSocketRef = new AtomicReference<>();
7577
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
@@ -92,16 +94,23 @@ public ExecWebSocketListener(InputStream in, OutputStream out, OutputStream err,
9294
this(new Config(), in, out, err, inputPipe, outputPipe, errorPipe, listener);
9395
}
9496

97+
@Deprecated
9598
public ExecWebSocketListener(Config config, InputStream in, OutputStream out, OutputStream err, PipedOutputStream inputPipe, PipedInputStream outputPipe, PipedInputStream errorPipe, ExecListener listener) {
99+
this(config, in, out, err, null, inputPipe, outputPipe, errorPipe, null, listener);
100+
}
101+
102+
public ExecWebSocketListener(Config config, InputStream in, OutputStream out, OutputStream err, OutputStream errChannel, PipedOutputStream inputPipe, PipedInputStream outputPipe, PipedInputStream errorPipe, PipedInputStream errorChannelPipe, ExecListener listener) {
96103
this.config = config;
97104
this.listener = listener;
98105
this.in = inputStreamOrPipe(in, inputPipe, toClose);
99106
this.out = outputStreamOrPipe(out, outputPipe, toClose);
100107
this.err = outputStreamOrPipe(err, errorPipe, toClose);
108+
this.errChannel = outputStreamOrPipe(errChannel, errorChannelPipe, toClose);
101109

102110
this.input = inputPipe;
103111
this.output = outputPipe;
104112
this.error = errorPipe;
113+
this.errorChannel = errorChannelPipe;
105114
this.pumper = new NonBlockingInputStreamPumper(this.in, new Callback<byte[]>() {
106115
@Override
107116
public void call(byte[] data) {
@@ -182,6 +191,9 @@ public void onOpen(WebSocket webSocket, Response response) {
182191
if (err instanceof PipedOutputStream && error != null) {
183192
error.connect((PipedOutputStream) err);
184193
}
194+
if (errChannel instanceof PipedOutputStream && errorChannel != null) {
195+
errorChannel.connect((PipedOutputStream) errChannel);
196+
}
185197

186198
webSocketRef.set(webSocket);
187199
executorService.submit(pumper);
@@ -242,8 +254,8 @@ public void onMessage(WebSocket webSocket, ByteString bytes) {
242254
}
243255
break;
244256
case 3:
245-
if (err != null) {
246-
err.write(byteString.toByteArray());
257+
if (errChannel != null) {
258+
errChannel.write(byteString.toByteArray());
247259
}
248260
break;
249261
default:
@@ -290,6 +302,10 @@ public InputStream getError() {
290302
return error;
291303
}
292304

305+
public InputStream getErrorChannel() {
306+
return errorChannel;
307+
}
308+
293309
private void send(byte[] bytes) throws IOException {
294310
if (bytes.length > 0) {
295311
WebSocket ws = webSocketRef.get();

0 commit comments

Comments
 (0)