Skip to content

Commit aedc141

Browse files
committed
Address comments.
1 parent 6c42315 commit aedc141

File tree

7 files changed

+108
-23
lines changed

7 files changed

+108
-23
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/WebSockets.java

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
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;
1225
import com.squareup.okhttp.ws.WebSocketListener;
26+
import okio.Buffer;
1327

1428
import static com.squareup.okhttp.ws.WebSocket.BINARY;
1529
import static com.squareup.okhttp.ws.WebSocket.TEXT;
@@ -20,9 +34,14 @@
2034
import java.util.ArrayList;
2135
import java.util.HashMap;
2236

23-
import okio.Buffer;
24-
2537
public class WebSockets {
38+
public static final String V4_STREAM_PROTOCOL = "v4.channel.k8s.io";
39+
public static final String V3_STREAM_PROTOCOL = "v3.channel.k8s.io";
40+
public static final String V2_STREAM_PROTOCOL = "v2.channel.k8s.io";
41+
public static final String V1_STREAM_PROTOCOL = "channel.k8s.io";
42+
public static final String STREAM_PROTOCOL_HEADER = "X-Stream-Protocol-Version";
43+
public static final String SPDY_3_1 = "SPDY/3.1";
44+
2645
/**
2746
* A simple interface for a listener on a web socket
2847
*/
@@ -59,9 +78,10 @@ public interface SocketListener {
5978
*/
6079
public static void stream(String path, String method, ApiClient client, SocketListener listener) throws ApiException, IOException {
6180
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");
81+
String allProtocols = String.format("%s,%s,%s,%s", V4_STREAM_PROTOCOL, V3_STREAM_PROTOCOL, V2_STREAM_PROTOCOL, V1_STREAM_PROTOCOL);
82+
headers.put(STREAM_PROTOCOL_HEADER, allProtocols);
83+
headers.put(HttpHeaders.CONNECTION, HttpHeaders.UPGRADE);
84+
headers.put(HttpHeaders.UPGRADE, SPDY_3_1);
6585

6686
Request request = client.buildRequest(path, method, new ArrayList<Pair>(), null, headers, new HashMap<String, Object>(), new String[0], null);
6787
WebSocketCall.create(client.getHttpClient(), request).enqueue(new Listener(listener));
@@ -104,4 +124,4 @@ public void onFailure(IOException e, Response res) {
104124
listener.close();
105125
}
106126
}
107-
}
127+
}

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)