Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanburns committed Jun 15, 2017
1 parent 6c42315 commit 7ea44eb
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 211 deletions.
12 changes: 12 additions & 0 deletions examples/src/main/java/io/kubernetes/client/examples/Example.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package io.kubernetes.client.examples;

import io.kubernetes.client.ApiClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package io.kubernetes.client.examples;

import io.kubernetes.client.ApiClient;
Expand All @@ -13,7 +25,7 @@
public class WebSocketsExample {
public static void main(String... args) throws ApiException, IOException {
final ApiClient client = Config.defaultClient();
WebSockets.stream(args[0], "POST", client, new WebSockets.SocketListener() {
WebSockets.stream(args[0], "GET", client, new WebSockets.SocketListener() {
public void open() {}
public void close() {
// Trigger shutdown of the dispatcher's executor so this process can exit cleanly.
Expand Down
37 changes: 21 additions & 16 deletions util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<artifactId>okhttp-ws</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
Expand All @@ -53,22 +58,22 @@
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
</plugins>
</build>
<properties>
Expand Down
12 changes: 12 additions & 0 deletions util/src/main/java/io/kubernetes/client/util/Config.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package io.kubernetes.client.util;

import io.kubernetes.client.ApiClient;
Expand Down
12 changes: 12 additions & 0 deletions util/src/main/java/io/kubernetes/client/util/KubeConfig.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package io.kubernetes.client.util;

import java.io.File;
Expand Down
188 changes: 0 additions & 188 deletions util/src/main/java/io/kubernetes/client/util/WebSocketCall.java

This file was deleted.

33 changes: 27 additions & 6 deletions util/src/main/java/io/kubernetes/client/util/WebSockets.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package io.kubernetes.client.util;

import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.Pair;

import com.google.common.net.HttpHeaders;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
import com.squareup.okhttp.ws.WebSocket;
import com.squareup.okhttp.ws.WebSocketCall;
import com.squareup.okhttp.ws.WebSocketListener;
import okio.Buffer;

import static com.squareup.okhttp.ws.WebSocket.BINARY;
import static com.squareup.okhttp.ws.WebSocket.TEXT;
Expand All @@ -20,9 +35,14 @@
import java.util.ArrayList;
import java.util.HashMap;

import okio.Buffer;

public class WebSockets {
public static final String V4_STREAM_PROTOCOL = "v4.channel.k8s.io";
public static final String V3_STREAM_PROTOCOL = "v3.channel.k8s.io";
public static final String V2_STREAM_PROTOCOL = "v2.channel.k8s.io";
public static final String V1_STREAM_PROTOCOL = "channel.k8s.io";
public static final String STREAM_PROTOCOL_HEADER = "X-Stream-Protocol-Version";
public static final String SPDY_3_1 = "SPDY/3.1";

/**
* A simple interface for a listener on a web socket
*/
Expand Down Expand Up @@ -59,9 +79,10 @@ public interface SocketListener {
*/
public static void stream(String path, String method, ApiClient client, SocketListener listener) throws ApiException, IOException {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("X-Stream-Protocol-Version", "v4.channel.k8s.io,v3.channel.k8s.io,v2.channel.k8s.io,channel.k8s.io");
headers.put("Connection", "Upgrade");
headers.put("Upgrade", "SPDY/3.1");
String allProtocols = String.format("%s,%s,%s,%s", V4_STREAM_PROTOCOL, V3_STREAM_PROTOCOL, V2_STREAM_PROTOCOL, V1_STREAM_PROTOCOL);
headers.put(STREAM_PROTOCOL_HEADER, allProtocols);
headers.put(HttpHeaders.CONNECTION, HttpHeaders.UPGRADE);
headers.put(HttpHeaders.UPGRADE, SPDY_3_1);

Request request = client.buildRequest(path, method, new ArrayList<Pair>(), null, headers, new HashMap<String, Object>(), new String[0], null);
WebSocketCall.create(client.getHttpClient(), request).enqueue(new Listener(listener));
Expand Down Expand Up @@ -104,4 +125,4 @@ public void onFailure(IOException e, Response res) {
listener.close();
}
}
}
}
12 changes: 12 additions & 0 deletions util/src/test/java/io/kuberentes/client/util/ConfigTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package io.kubernetes.client.util;

import io.kubernetes.client.ApiClient;
Expand Down

0 comments on commit 7ea44eb

Please sign in to comment.