Skip to content

Commit 7ea44eb

Browse files
committed
Address comments.
1 parent 6c42315 commit 7ea44eb

File tree

8 files changed

+109
-211
lines changed

8 files changed

+109
-211
lines changed

examples/src/main/java/io/kubernetes/client/examples/Example.java

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
Copyright 2017 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+
*/
113
package io.kubernetes.client.examples;
214

315
import io.kubernetes.client.ApiClient;

examples/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
Copyright 2017 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+
*/
113
package io.kubernetes.client.examples;
214

315
import io.kubernetes.client.ApiClient;
@@ -13,7 +25,7 @@
1325
public class WebSocketsExample {
1426
public static void main(String... args) throws ApiException, IOException {
1527
final ApiClient client = Config.defaultClient();
16-
WebSockets.stream(args[0], "POST", client, new WebSockets.SocketListener() {
28+
WebSockets.stream(args[0], "GET", client, new WebSockets.SocketListener() {
1729
public void open() {}
1830
public void close() {
1931
// Trigger shutdown of the dispatcher's executor so this process can exit cleanly.

util/pom.xml

+21-16
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
<artifactId>okhttp-ws</artifactId>
3030
<version>2.7.5</version>
3131
</dependency>
32+
<dependency>
33+
<groupId>com.google.guava</groupId>
34+
<artifactId>guava</artifactId>
35+
<version>22.0</version>
36+
</dependency>
3237
<!-- test dependencies -->
3338
<dependency>
3439
<groupId>junit</groupId>
@@ -53,22 +58,22 @@
5358
<target>1.7</target>
5459
</configuration>
5560
</plugin>
56-
<plugin>
57-
<groupId>org.apache.maven.plugins</groupId>
58-
<artifactId>maven-surefire-plugin</artifactId>
59-
<version>2.12</version>
60-
<configuration>
61-
<systemProperties>
62-
<property>
63-
<name>loggerPath</name>
64-
<value>conf/log4j.properties</value>
65-
</property>
66-
</systemProperties>
67-
<argLine>-Xms512m -Xmx1500m</argLine>
68-
<parallel>methods</parallel>
69-
<forkMode>pertest</forkMode>
70-
</configuration>
71-
</plugin>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-surefire-plugin</artifactId>
64+
<version>2.12</version>
65+
<configuration>
66+
<systemProperties>
67+
<property>
68+
<name>loggerPath</name>
69+
<value>conf/log4j.properties</value>
70+
</property>
71+
</systemProperties>
72+
<argLine>-Xms512m -Xmx1500m</argLine>
73+
<parallel>methods</parallel>
74+
<forkMode>pertest</forkMode>
75+
</configuration>
76+
</plugin>
7277
</plugins>
7378
</build>
7479
<properties>

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

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
Copyright 2017 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+
*/
113
package io.kubernetes.client.util;
214

315
import io.kubernetes.client.ApiClient;

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

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
Copyright 2017 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+
*/
113
package io.kubernetes.client.util;
214

315
import java.io.File;

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

-188
This file was deleted.

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

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
/*
2+
Copyright 2017 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+
*/
113
package io.kubernetes.client.util;
214

315
import io.kubernetes.client.ApiClient;
416
import io.kubernetes.client.ApiException;
517
import io.kubernetes.client.Pair;
618

19+
import com.google.common.net.HttpHeaders;
720
import com.squareup.okhttp.MediaType;
821
import com.squareup.okhttp.Request;
922
import com.squareup.okhttp.Response;
1023
import com.squareup.okhttp.ResponseBody;
1124
import com.squareup.okhttp.ws.WebSocket;
25+
import com.squareup.okhttp.ws.WebSocketCall;
1226
import com.squareup.okhttp.ws.WebSocketListener;
27+
import okio.Buffer;
1328

1429
import static com.squareup.okhttp.ws.WebSocket.BINARY;
1530
import static com.squareup.okhttp.ws.WebSocket.TEXT;
@@ -20,9 +35,14 @@
2035
import java.util.ArrayList;
2136
import java.util.HashMap;
2237

23-
import okio.Buffer;
24-
2538
public class WebSockets {
39+
public static final String V4_STREAM_PROTOCOL = "v4.channel.k8s.io";
40+
public static final String V3_STREAM_PROTOCOL = "v3.channel.k8s.io";
41+
public static final String V2_STREAM_PROTOCOL = "v2.channel.k8s.io";
42+
public static final String V1_STREAM_PROTOCOL = "channel.k8s.io";
43+
public static final String STREAM_PROTOCOL_HEADER = "X-Stream-Protocol-Version";
44+
public static final String SPDY_3_1 = "SPDY/3.1";
45+
2646
/**
2747
* A simple interface for a listener on a web socket
2848
*/
@@ -59,9 +79,10 @@ public interface SocketListener {
5979
*/
6080
public static void stream(String path, String method, ApiClient client, SocketListener listener) throws ApiException, IOException {
6181
HashMap<String, String> headers = new HashMap<String, String>();
62-
headers.put("X-Stream-Protocol-Version", "v4.channel.k8s.io,v3.channel.k8s.io,v2.channel.k8s.io,channel.k8s.io");
63-
headers.put("Connection", "Upgrade");
64-
headers.put("Upgrade", "SPDY/3.1");
82+
String allProtocols = String.format("%s,%s,%s,%s", V4_STREAM_PROTOCOL, V3_STREAM_PROTOCOL, V2_STREAM_PROTOCOL, V1_STREAM_PROTOCOL);
83+
headers.put(STREAM_PROTOCOL_HEADER, allProtocols);
84+
headers.put(HttpHeaders.CONNECTION, HttpHeaders.UPGRADE);
85+
headers.put(HttpHeaders.UPGRADE, SPDY_3_1);
6586

6687
Request request = client.buildRequest(path, method, new ArrayList<Pair>(), null, headers, new HashMap<String, Object>(), new String[0], null);
6788
WebSocketCall.create(client.getHttpClient(), request).enqueue(new Listener(listener));
@@ -104,4 +125,4 @@ public void onFailure(IOException e, Response res) {
104125
listener.close();
105126
}
106127
}
107-
}
128+
}

util/src/test/java/io/kuberentes/client/util/ConfigTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
Copyright 2017 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+
*/
113
package io.kubernetes.client.util;
214

315
import io.kubernetes.client.ApiClient;

0 commit comments

Comments
 (0)