Skip to content

Commit

Permalink
Merge pull request redhat-appstudio#2199 from tecarter94/domain-proxy…
Browse files Browse the repository at this point in the history
…-standalone-improvements

Domain proxy standalone improvements
  • Loading branch information
tecarter94 authored Oct 23, 2024
2 parents a64e540 + f5dd234 commit 1544273
Show file tree
Hide file tree
Showing 31 changed files with 568 additions and 359 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/java-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4
with:
distribution: 'temurin'
java-version: 17
java-version: 21
- name: Set up Maven
uses: stCarolas/setup-maven@d6af6abeda15e98926a57b5aa970a96bb37f97d1 # v5
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM registry.access.redhat.com/ubi8/openjdk-17@sha256:06edd8c82406da7466b73d589a07a10bf121ae5677b0f32e76120213d5303824 AS builder
FROM registry.access.redhat.com/ubi8/openjdk-21@sha256:a10b277c0f16283bb45b0e6cfca3ae9ecf155178f7f731df4a1f744ebd35af70 AS builder
USER 0
WORKDIR /work
COPY ./ .

RUN mvn -V -B package -pl build-request-processor -am -Dmaven.test.skip

FROM registry.access.redhat.com/ubi8/openjdk-17-runtime@sha256:8e863153659dba9ee288b97b7cdf7a83274dd78b26da1e5da6798d0bd45166e8
FROM registry.access.redhat.com/ubi8/openjdk-21-runtime@sha256:c1bf8370627eaed6711ea22915b476d4216517c35c8f8268c0d39ed983bceaff
USER 0
WORKDIR /work/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void visit(int version, int access, String name, String signature, String
super.visit(version - 1, access, name, signature, superName, interfaces);
}

}, List.of(new ExpectedChange(ChangeType.MODIFY, "version:61.0>60.0")));
}, List.of(new ExpectedChange(ChangeType.MODIFY, "version:65.0>64.0")));
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions java-components/cache/src/main/docker/Dockerfile.all-in-one
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.access.redhat.com/ubi8/openjdk-17@sha256:06edd8c82406da7466b73d589a07a10bf121ae5677b0f32e76120213d5303824 AS builder
FROM registry.access.redhat.com/ubi8/openjdk-21@sha256:a10b277c0f16283bb45b0e6cfca3ae9ecf155178f7f731df4a1f744ebd35af70 AS builder
USER 0
WORKDIR /work
COPY ./ .
Expand All @@ -7,7 +7,7 @@ RUN mkdir -p /work/cache/target/classes

RUN mvn -V -B package -pl cache -am -Dmaven.test.skip

FROM registry.access.redhat.com/ubi8/openjdk-17-runtime@sha256:8e863153659dba9ee288b97b7cdf7a83274dd78b26da1e5da6798d0bd45166e8
FROM registry.access.redhat.com/ubi8/openjdk-21-runtime@sha256:c1bf8370627eaed6711ea22915b476d4216517c35c8f8268c0d39ed983bceaff
USER 0
WORKDIR /work/

Expand Down
4 changes: 2 additions & 2 deletions java-components/cli/src/main/docker/Dockerfile.all-in-one
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM registry.access.redhat.com/ubi8/openjdk-17@sha256:06edd8c82406da7466b73d589a07a10bf121ae5677b0f32e76120213d5303824 AS builder
FROM registry.access.redhat.com/ubi8/openjdk-21@sha256:a10b277c0f16283bb45b0e6cfca3ae9ecf155178f7f731df4a1f744ebd35af70 AS builder

WORKDIR /work
COPY ./ .

RUN mvn -V -B package -pl cli -am -DskipTests

FROM registry.access.redhat.com/ubi8/openjdk-17-runtime@sha256:8e863153659dba9ee288b97b7cdf7a83274dd78b26da1e5da6798d0bd45166e8
FROM registry.access.redhat.com/ubi8/openjdk-21-runtime@sha256:c1bf8370627eaed6711ea22915b476d4216517c35c8f8268c0d39ed983bceaff
WORKDIR /work/

COPY --from=builder /work/cli/target/quarkus-app/lib/ /deployments/lib/
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions java-components/domain-proxy/Dockerfile
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,19 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>domainproxy-parent</artifactId>
<artifactId>domain-proxy-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>domainproxy-client</artifactId>
<artifactId>domain-proxy-client</artifactId>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>domain-proxy-common</artifactId>
</dependency>
</dependencies>

Expand All @@ -37,7 +31,6 @@
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
Expand Down
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();
}
}
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}
18 changes: 18 additions & 0 deletions java-components/domain-proxy/common/pom.xml
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>
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);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>jvm-build-service-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>domainproxy-parent</artifactId>
<artifactId>domain-proxy-parent</artifactId>
<packaging>pom</packaging>
<properties>
<skipITs>true</skipITs>
Expand All @@ -16,8 +16,19 @@
<modules>
<module>server</module>
<module>client</module>
<module>common</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>domain-proxy-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<profiles>
<profile>
<id>native</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>domainproxy-parent</artifactId>
<artifactId>domain-proxy-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>domainproxy-server</artifactId>
<artifactId>domain-proxy-server</artifactId>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId>
<artifactId>quarkus-vertx</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -28,9 +28,14 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>common-maven</artifactId>
<artifactId>domain-proxy-common</artifactId>
</dependency>
</dependencies>

Expand Down
Loading

0 comments on commit 1544273

Please sign in to comment.