forked from redhat-appstudio/jvm-build-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request redhat-appstudio#2199 from tecarter94/domain-proxy…
…-standalone-improvements Domain proxy standalone improvements
- Loading branch information
Showing
31 changed files
with
568 additions
and
359 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
4 changes: 2 additions & 2 deletions
4
java-components/build-request-processor/src/main/docker/Dockerfile.all-in-one
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
File renamed without changes.
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,4 @@ | ||
FROM quay.io/redhat-appstudio/buildah:v1.35.4@sha256:3d3575bb7d0df64abcf1f22f06e82101a945d03317db1f3caac12814f796d01c | ||
RUN dnf install -y iproute | ||
COPY client/target/domain-proxy-client-999-SNAPSHOT-runner /app/domain-proxy-client-runner | ||
COPY server/target/domain-proxy-server-999-SNAPSHOT-runner /app/domain-proxy-server-runner |
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
58 changes: 58 additions & 0 deletions
58
...ain-proxy/client/src/main/java/com/redhat/hacbs/domainproxy/client/DomainProxyClient.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,58 @@ | ||
package com.redhat.hacbs.domainproxy.client; | ||
|
||
import static com.redhat.hacbs.domainproxy.common.CommonIOUtil.createChannelToSocketWriter; | ||
import static com.redhat.hacbs.domainproxy.common.CommonIOUtil.createSocketToChannelWriter; | ||
|
||
import java.io.IOException; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
import java.net.UnixDomainSocketAddress; | ||
import java.nio.channels.SocketChannel; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.quarkus.logging.Log; | ||
import io.quarkus.runtime.Quarkus; | ||
import io.quarkus.runtime.Startup; | ||
|
||
@Startup | ||
@Singleton | ||
public class DomainProxyClient { | ||
|
||
@Inject | ||
@ConfigProperty(name = "client-domain-socket") | ||
String domainSocket; | ||
|
||
@Inject | ||
@ConfigProperty(name = "client-http-port") | ||
int clientHttpPort; | ||
|
||
@Inject | ||
@ConfigProperty(name = "byte-buffer-size") | ||
int byteBufferSize; | ||
|
||
@PostConstruct | ||
public void start() { | ||
Log.info("Starting domain proxy client..."); | ||
new Thread(() -> { | ||
try (final ServerSocket serverSocket = new ServerSocket(clientHttpPort)) { | ||
while (true) { | ||
final Socket socket = serverSocket.accept(); | ||
final UnixDomainSocketAddress address = UnixDomainSocketAddress.of(domainSocket); | ||
final SocketChannel channel = SocketChannel.open(address); | ||
// Write from socket to channel | ||
Thread.startVirtualThread(createSocketToChannelWriter(byteBufferSize, socket, channel)); | ||
// Write from channel to socket | ||
Thread.startVirtualThread(createChannelToSocketWriter(byteBufferSize, channel, socket)); | ||
} | ||
} catch (final IOException e) { | ||
Log.errorf(e, "Error initialising domain proxy client"); | ||
} | ||
Quarkus.asyncExit(); | ||
}).start(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
java-components/domain-proxy/client/src/main/resources/application.properties
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,3 @@ | ||
client-domain-socket=${DOMAIN_SOCKET:/tmp/domainserver} | ||
client-http-port=8080 | ||
byte-buffer-size=${BYTE_BUFFER_SIZE:1024} |
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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.redhat-appstudio.jvmbuild</groupId> | ||
<artifactId>domain-proxy-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>domain-proxy-common</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.logging</groupId> | ||
<artifactId>jboss-logging</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
84 changes: 84 additions & 0 deletions
84
...s/domain-proxy/common/src/main/java/com/redhat/hacbs/domainproxy/common/CommonIOUtil.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,84 @@ | ||
package com.redhat.hacbs.domainproxy.common; | ||
|
||
import java.io.IOException; | ||
import java.net.Socket; | ||
import java.net.SocketException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.AsynchronousCloseException; | ||
import java.nio.channels.SocketChannel; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
public final class CommonIOUtil { | ||
|
||
private static final Logger LOG = Logger.getLogger(CommonIOUtil.class); | ||
|
||
public static Runnable createSocketToChannelWriter(final int byteBufferSize, final Socket socket, | ||
final SocketChannel channel) { | ||
// Write from socket to channel | ||
return () -> { | ||
int r; | ||
final byte[] buf = new byte[byteBufferSize]; | ||
int bytesWritten = 0; | ||
LOG.info("Writing from socket to channel"); | ||
try { | ||
while ((r = socket.getInputStream().read(buf)) > 0) { | ||
channel.write(ByteBuffer.wrap(buf, 0, r)); | ||
bytesWritten += r; | ||
} | ||
} catch (final SocketException ignore) { | ||
LOG.info("Socket closed"); | ||
} catch (final IOException e) { | ||
LOG.errorf(e, "Error writing from socket to channel"); | ||
} finally { | ||
try { | ||
channel.close(); | ||
} catch (final Exception e) { | ||
LOG.errorf(e, "Error closing channel"); | ||
} | ||
try { | ||
socket.close(); | ||
} catch (final IOException e) { | ||
LOG.errorf(e, "Error closing socket"); | ||
} | ||
} | ||
LOG.infof("Wrote %d bytes from socket to channel", bytesWritten); | ||
}; | ||
} | ||
|
||
public static Runnable createChannelToSocketWriter(final int byteBufferSize, final SocketChannel channel, | ||
final Socket socket) { | ||
// Write from channel to socket | ||
return () -> { | ||
int r; | ||
final ByteBuffer buf = ByteBuffer.allocate(byteBufferSize); | ||
buf.clear(); | ||
int bytesWritten = 0; | ||
LOG.info("Writing from channel to socket"); | ||
try { | ||
while ((r = channel.read(buf)) > 0) { | ||
buf.flip(); | ||
socket.getOutputStream().write(buf.array(), buf.arrayOffset(), buf.remaining()); | ||
buf.clear(); | ||
bytesWritten += r; | ||
} | ||
} catch (final AsynchronousCloseException ignore) { | ||
LOG.info("Channel closed"); | ||
} catch (final Exception e) { | ||
LOG.errorf(e, "Error writing from channel to socket"); | ||
} finally { | ||
try { | ||
channel.close(); | ||
} catch (final IOException e) { | ||
LOG.errorf(e, "Error closing channel"); | ||
} | ||
try { | ||
socket.close(); | ||
} catch (final IOException e) { | ||
LOG.errorf(e, "Error closing socket"); | ||
} | ||
} | ||
LOG.infof("Wrote %d bytes from channel to socket", bytesWritten); | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.