Skip to content

Commit 16612e6

Browse files
Merge pull request #217 from rjeberhard/exec-finalreview
Minor cleanups to Exec
2 parents 9bb6621 + 6f6684c commit 16612e6

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

util/src/main/java/io/kubernetes/client/Exec.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package io.kubernetes.client;
1414

15+
import static io.kubernetes.client.KubernetesConstants.*;
16+
1517
import com.google.common.io.CharStreams;
1618
import com.google.gson.reflect.TypeToken;
1719
import io.kubernetes.client.models.V1Pod;
@@ -202,15 +204,15 @@ static int parseExitCode(ApiClient client, InputStream inputStream) {
202204
}
203205

204206
V1Status status = client.getJSON().deserialize(body, returnType);
205-
if ("Success".equals(status.getStatus())) return 0;
207+
if (V1STATUS_SUCCESS.equals(status.getStatus())) return 0;
206208

207-
if ("NonZeroExitCode".equals(status.getReason())) {
209+
if (V1STATUS_REASON_NONZEROEXITCODE.equals(status.getReason())) {
208210
V1StatusDetails details = status.getDetails();
209211
if (details != null) {
210212
List<V1StatusCause> causes = details.getCauses();
211213
if (causes != null) {
212214
for (V1StatusCause cause : causes) {
213-
if ("ExitCode".equals(cause.getReason())) {
215+
if (V1STATUS_CAUSE_REASON_EXITCODE.equals(cause.getReason())) {
214216
try {
215217
return Integer.parseInt(cause.getMessage());
216218
} catch (NumberFormatException nfe) {
@@ -239,7 +241,7 @@ public ExecProcess() throws IOException {
239241
this.streamHandler =
240242
new WebSocketStreamHandler() {
241243
@Override
242-
protected void handleMessage(int stream, InputStream inStream) {
244+
protected void handleMessage(int stream, InputStream inStream) throws IOException {
243245
if (stream == 3) {
244246
int exitCode = parseExitCode(apiClient, inStream);
245247
if (exitCode >= 0) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client;
14+
15+
public final class KubernetesConstants {
16+
private KubernetesConstants() {}
17+
18+
// V1Status values
19+
public static final String V1STATUS_SUCCESS = "Success";
20+
public static final String V1STATUS_FAILURE = "Failure";
21+
22+
// V1Status reason values
23+
public static final String V1STATUS_REASON_NONZEROEXITCODE = "NonZeroExitCode";
24+
25+
// V1Status cause reason values
26+
public static final String V1STATUS_CAUSE_REASON_EXITCODE = "ExitCode";
27+
}

util/src/main/java/io/kubernetes/client/util/WebSocketStreamHandler.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,9 @@ public void textMessage(Reader in) {
8383
}
8484
}
8585

86-
protected void handleMessage(int stream, InputStream inStream) {
87-
try {
88-
OutputStream out = getSocketInputOutputStream(stream);
89-
ByteStreams.copy(inStream, out);
90-
} catch (IOException ex) {
91-
log.error("Error handling message", ex);
92-
}
86+
protected void handleMessage(int stream, InputStream inStream) throws IOException {
87+
OutputStream out = getSocketInputOutputStream(stream);
88+
ByteStreams.copy(inStream, out);
9389
}
9490

9591
@Override

0 commit comments

Comments
 (0)