-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Jetty HttpClient implementation
Signed-off-by: Marc Nuri <[email protected]>
- Loading branch information
Showing
48 changed files
with
2,923 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (C) 2015 Red Hat, Inc. | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>kubernetes-client-project</artifactId> | ||
<groupId>io.fabric8</groupId> | ||
<version>6.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>kubernetes-httpclient-jetty</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Fabric8 :: Kubernetes :: HttpClient :: Jetty</name> | ||
|
||
<properties> | ||
<maven.compiler.release>11</maven.compiler.release> | ||
<osgi.require-capability> | ||
osgi.extender; | ||
filter:="(osgi.extender=osgi.serviceloader.registrar)", | ||
</osgi.require-capability> | ||
<osgi.import> | ||
!android.util*, | ||
*, | ||
</osgi.import> | ||
<osgi.export> | ||
io.fabric8.kubernetes.client.jetty*;-noimport:=true, | ||
</osgi.export> | ||
<osgi.private> | ||
</osgi.private> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>kubernetes-client-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.http2</groupId> | ||
<artifactId>http2-http-client-transport</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.websocket</groupId> | ||
<artifactId>websocket-jetty-client</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>kubernetes-client-api</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>mockwebserver</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<!-- We cleanup system properties an env vars, so that we can test in a predictable env --> | ||
<environmentVariables> | ||
<KUBERNETES_MASTER /> | ||
<KUBERNETES_API_VERSION /> | ||
<KUBERNETES_TRUST_CERTIFICATES /> | ||
<KUBERNETES_CERTS_CA_FILE /> | ||
<KUBERNETES_CERTS_CA_DATA /> | ||
<KUBERNETES_CERTS_CLIENT_FILE /> | ||
<KUBERNETES_CERTS_CLIENT_DATA /> | ||
<KUBERNETES_CERTS_CLIENT_KEY_FILE /> | ||
<KUBERNETES_CERTS_CLIENT_KEY_DATA /> | ||
<KUBERNETES_CERTS_CLIENT_KEY_ALGO /> | ||
<KUBERNETES_CERTS_CLIENT_KEY_PASSPHRASE /> | ||
<KUBERNETES_AUTH_BASIC_USERNAME /> | ||
<KUBERNETES_AUTH_BASIC_PASSWORD /> | ||
<KUBERNETES_AUTH_TRYKUBECONFIG /> | ||
<KUBERNETES_AUTH_TRYSERVICEACCOUNT /> | ||
<KUBERNETES_AUTH_TOKEN /> | ||
<KUBERNETES_WATCH_RECONNECTINTERVAL /> | ||
<KUBERNETES_WATCH_RECONNECTLIMIT /> | ||
<KUBERNETES_REQUEST_TIMEOUT /> | ||
<KUBERNETES_NAMESPACE /> | ||
<KUBERNETES_TLS_VERSIONS>TLSv1.2,TLSv1.1,TLSv1</KUBERNETES_TLS_VERSIONS> | ||
</environmentVariables> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>3.0.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<classpathScope>test</classpathScope> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>report-aggregate</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>report-aggregate</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<version>${maven.bundle.plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>bundle</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>bundle</goal> | ||
</goals> | ||
<configuration> | ||
<instructions> | ||
<Bundle-Name>${project.name}</Bundle-Name> | ||
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> | ||
<Export-Package>${osgi.export}</Export-Package> | ||
<Import-Package>${osgi.import}</Import-Package> | ||
<DynamicImport-Package>${osgi.dynamic.import}</DynamicImport-Package> | ||
<Require-Capability>${osgi.require-capability}</Require-Capability> | ||
<Provide-Capability>${osgi.provide-capability}</Provide-Capability> | ||
<Private-Package>${osgi.private}</Private-Package> | ||
<Require-Bundle>${osgi.bundles}</Require-Bundle> | ||
<Bundle-Activator>${osgi.activator}</Bundle-Activator> | ||
<Export-Service>${osgi.export.service}</Export-Service> | ||
<Include-Resource> | ||
/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory=target/classes/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory, | ||
</Include-Resource> | ||
</instructions> | ||
<classifier>bundle</classifier> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
92 changes: 92 additions & 0 deletions
92
...nt-jetty/src/main/java/io/fabric8/kubernetes/client/jetty/JettyAsyncResponseListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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.fabric8.kubernetes.client.jetty; | ||
|
||
import io.fabric8.kubernetes.client.KubernetesClientException; | ||
import io.fabric8.kubernetes.client.http.HttpClient; | ||
import io.fabric8.kubernetes.client.http.HttpRequest; | ||
import io.fabric8.kubernetes.client.http.HttpResponse; | ||
import org.eclipse.jetty.client.api.Request; | ||
import org.eclipse.jetty.client.api.Response; | ||
import org.eclipse.jetty.client.api.Result; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
public abstract class JettyAsyncResponseListener<T> extends Response.Listener.Adapter implements HttpClient.AsyncBody { | ||
|
||
private final HttpRequest httpRequest; | ||
private final HttpClient.BodyConsumer<T> bodyConsumer; | ||
private final CompletableFuture<HttpResponse<HttpClient.AsyncBody>> asyncResponse; | ||
private final CompletableFuture<Void> asyncBodyDone; | ||
private final CountDownLatch consumeLock; | ||
|
||
JettyAsyncResponseListener(HttpRequest httpRequest, HttpClient.BodyConsumer<T> bodyConsumer) { | ||
this.httpRequest = httpRequest; | ||
this.bodyConsumer = bodyConsumer; | ||
asyncResponse = new CompletableFuture<>(); | ||
asyncBodyDone = new CompletableFuture<>(); | ||
consumeLock = new CountDownLatch(1); | ||
} | ||
|
||
@Override | ||
public void consume() { | ||
consumeLock.countDown(); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Void> done() { | ||
return asyncBodyDone; | ||
} | ||
|
||
@Override | ||
public void cancel() { | ||
asyncBodyDone.cancel(false); | ||
} | ||
|
||
@Override | ||
public void onBegin(Response response) { | ||
asyncResponse.complete(new JettyHttpResponse<>(httpRequest, response, this)); | ||
} | ||
|
||
@Override | ||
public void onComplete(Result result) { | ||
asyncBodyDone.complete(null); | ||
} | ||
|
||
public CompletableFuture<HttpResponse<HttpClient.AsyncBody>> listen(Request request) { | ||
request.send(this); | ||
return asyncResponse; | ||
} | ||
|
||
@Override | ||
public void onContent(Response response, ByteBuffer content) { | ||
try { | ||
consumeLock.await(); | ||
if (!asyncBodyDone.isCancelled()) { | ||
bodyConsumer.consume(process(response, content), this); | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw KubernetesClientException.launderThrowable(e); | ||
} catch (Exception e) { | ||
throw KubernetesClientException.launderThrowable(e); | ||
} | ||
} | ||
|
||
protected abstract T process(Response response, ByteBuffer content); | ||
} |
Oops, something went wrong.