forked from microcks/microcks
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: microcks#1020 Adding new async-minion-uber, enabling WebSocket …
…communication Signed-off-by: Laurent Broudoux <laurent.broudoux@gmail.com> Signed-off-by: Appadoo Apoorva Srinivas <apoorva.appadoo@orange.com>
- Loading branch information
Showing
11 changed files
with
407 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ | |
|
||
<modules> | ||
<module>uber</module> | ||
<module>uber-async-minion</module> | ||
</modules> | ||
</project> |
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,94 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.microcks</groupId> | ||
<artifactId>microcks-distro</artifactId> | ||
<version>1.8.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<name>Microcks Uber Async Minion</name> | ||
<artifactId>microcks-uber-async-minion</artifactId> | ||
|
||
<properties> | ||
<compiler-plugin.version>3.11.0</compiler-plugin.version> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id> | ||
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id> | ||
<quarkus.platform.version>3.1.3.Final</quarkus.platform.version> | ||
<quarkus-plugin.version>3.1.3.Final</quarkus-plugin.version> | ||
|
||
<surefire-plugin.version>3.0.0</surefire-plugin.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>${quarkus.platform.group-id}</groupId> | ||
<artifactId>${quarkus.platform.artifact-id}</artifactId> | ||
<version>${quarkus.platform.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.microcks</groupId> | ||
<artifactId>microcks-async-minion</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkiverse.reactivemessaging.http</groupId> | ||
<artifactId>quarkus-reactive-messaging-http</artifactId> | ||
<version>2.0.2</version> | ||
</dependency> | ||
|
||
<!-- Test related dependencies --> | ||
<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> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<version>${quarkus-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${compiler-plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${surefire-plugin.version}</version> | ||
<configuration> | ||
<systemProperties> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
</systemProperties> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,49 @@ | ||
#### | ||
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode | ||
# | ||
# Before building the docker image run: | ||
# | ||
# mvn package | ||
# | ||
# Then, build the image with: | ||
# | ||
# docker build -f src/main/docker/Dockerfile.jvm -t microcks/microcks-async-minion-jvm . | ||
# | ||
# Then run the container using: | ||
# | ||
# docker run -i --rm -p 8080:8080 microcks/microcks-async-minion-jvm | ||
# | ||
### | ||
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.2-691 | ||
|
||
ARG JAVA_PACKAGE=java-17-openjdk-headless | ||
ARG RUN_JAVA_VERSION=1.3.8 | ||
|
||
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' | ||
|
||
# Install java and the run-java script | ||
# Also set up permissions for user `1001` | ||
RUN microdnf install curl-minimal ca-certificates ${JAVA_PACKAGE} -y \ | ||
&& microdnf update -y \ | ||
&& microdnf clean all \ | ||
&& mkdir /deployments \ | ||
&& chown 1001 /deployments \ | ||
&& chmod "g+rwX" /deployments \ | ||
&& chown 1001:root /deployments \ | ||
&& curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ | ||
&& chown 1001 /deployments/run-java.sh \ | ||
&& chmod 550 /deployments/run-java.sh \ | ||
&& echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security | ||
|
||
# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. | ||
ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" | ||
|
||
COPY target/quarkus-app/lib/ /deployments/lib/ | ||
COPY target/quarkus-app/*.jar /deployments/ | ||
COPY target/quarkus-app/app/ /deployments/app/ | ||
COPY target/quarkus-app/quarkus/ /deployments/quarkus/ | ||
|
||
EXPOSE 8080 | ||
USER 1001 | ||
|
||
ENTRYPOINT [ "/deployments/run-java.sh" ] |
50 changes: 50 additions & 0 deletions
50
distro/uber-async-minion/src/main/docker/Dockerfile.legacy-jar
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,50 @@ | ||
#### | ||
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode | ||
# | ||
# Before building the docker image run: | ||
# | ||
# mvn package -Dquarkus.package.type=legacy-jar | ||
# | ||
# Then, build the image with: | ||
# | ||
# docker build -f src/main/docker/Dockerfile.legacy-jar -t microcks/microcks-async-minion-legacy-jar . | ||
# | ||
# Then run the container using: | ||
# | ||
# docker run -i --rm -p 8080:8080 microcks/microcks-async-minion-legacy-jar | ||
# | ||
### | ||
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.2-691 | ||
|
||
ARG JAVA_PACKAGE=java-17-openjdk-headless | ||
ARG RUN_JAVA_VERSION=1.3.8 | ||
|
||
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' | ||
|
||
# Install java and the run-java script | ||
# Also set up permissions for user `1001` | ||
RUN microdnf install curl-minimal ca-certificates ${JAVA_PACKAGE} -y \ | ||
&& microdnf update -y \ | ||
&& microdnf clean all \ | ||
&& mkdir /deployments \ | ||
&& chown 1001 /deployments \ | ||
&& chmod "g+rwX" /deployments \ | ||
&& chown 1001:root /deployments \ | ||
&& curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ | ||
&& chown 1001 /deployments/run-java.sh \ | ||
&& chmod 550 /deployments/run-java.sh \ | ||
&& echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security | ||
|
||
# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. | ||
ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" | ||
|
||
ENV JAVA_APP_DIR="/deployments" | ||
ENV JAVA_MAIN_CLASS="io.quarkus.runner.GeneratedMain" | ||
|
||
COPY target/lib/ /deployments/lib/ | ||
COPY target/*-runner.jar /deployments/ | ||
|
||
EXPOSE 8080 | ||
USER 1001 | ||
|
||
ENTRYPOINT [ "/deployments/run-java.sh" ] |
30 changes: 30 additions & 0 deletions
30
distro/uber-async-minion/src/main/docker/Dockerfile.native
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,30 @@ | ||
#### | ||
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode | ||
# | ||
# Before building the docker image run: | ||
# | ||
# mvn package -Pnative -Dquarkus.native.container-build=true | ||
# | ||
# Then, build the image with: | ||
# | ||
# docker build -f src/main/docker/Dockerfile.native -t microcks/microcks-async-minion . | ||
# | ||
# Then run the container using: | ||
# | ||
# docker run -i --rm -p 8080:8080 microcks/microcks-async-minion | ||
# | ||
### | ||
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.4-212 | ||
WORKDIR /work/ | ||
COPY --chown=1001:root target/*-runner /work/application | ||
|
||
# set up permissions for user `1001` | ||
RUN chmod 775 /work /work/application \ | ||
&& chown -R 1001 /work \ | ||
&& chmod -R "g+rwX" /work \ | ||
&& chown -R 1001:root /work | ||
|
||
EXPOSE 8080 | ||
USER 1001 | ||
|
||
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] |
110 changes: 110 additions & 0 deletions
110
...ion/src/main/java/io/github/microcks/minions/async/client/MicrocksWebSocketConnector.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,110 @@ | ||
/* | ||
* Copyright The Microcks 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.github.microcks.minions.async.client; | ||
|
||
import io.github.microcks.event.ServiceViewChangeEvent; | ||
import io.github.microcks.minion.async.AsyncMockDefinitionUpdater; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.runtime.StartupEvent; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
import jakarta.inject.Inject; | ||
import jakarta.websocket.ClientEndpoint; | ||
import jakarta.websocket.ContainerProvider; | ||
import jakarta.websocket.DeploymentException; | ||
import jakarta.websocket.OnMessage; | ||
import jakarta.websocket.OnOpen; | ||
import jakarta.websocket.Session; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.jboss.logging.Logger; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
@Unremovable | ||
@ApplicationScoped | ||
/** | ||
* This is a connector to Microcks app WebScoket endpoints. It listens to /api/services-updates endpoint | ||
* for incoming {@code ServiceViewChangeEvent} and propagate them to the {@code AsyncMockDefinitionUpdater}. | ||
* @author laurent | ||
*/ | ||
public class MicrocksWebSocketConnector { | ||
|
||
/** Get a JBoss logging logger. */ | ||
private static final Logger logger = Logger.getLogger(MicrocksWebSocketConnector.class); | ||
|
||
@ConfigProperty(name = "minion.microcks-host-port") | ||
String microcksHostAndPort; | ||
|
||
/** Application startup method. */ | ||
void onStart(@Observes StartupEvent event) throws URISyntaxException, DeploymentException, IOException { | ||
URI uri = null; | ||
|
||
try { | ||
uri = new URI("ws://" + microcksHostAndPort + "/api/services-updates"); | ||
ContainerProvider.getWebSocketContainer().connectToServer(WebSocketClient.class, uri); | ||
logger.debug("Now connected to Microcks /api/services-updates WS endpoint"); | ||
} catch (URISyntaxException e) { | ||
logger.error("Exception while building the Microcks WebSocket URI, check your settings", e); | ||
throw e; | ||
} catch (DeploymentException e) { | ||
logger.error("Caught a WebSocket DeploymentException", e); | ||
throw e; | ||
} catch (IOException e) { | ||
logger.info("Caught an IOException while connecting Microcks WebSocket endpoint", e); | ||
throw e; | ||
} | ||
} | ||
|
||
@ClientEndpoint | ||
public static class WebSocketClient { | ||
|
||
@Inject | ||
AsyncMockDefinitionUpdater definitionUpdater; | ||
|
||
@Inject | ||
ObjectMapper mapper; | ||
|
||
@OnOpen | ||
public void open(Session session) { | ||
logger.debug("Opening a WebSocket Session on Microcks server"); | ||
// Send a message to indicate that we are ready, | ||
// as the message handler may not be registered immediately after this callback. | ||
session.getAsyncRemote().sendText("_ready_"); | ||
} | ||
|
||
@OnMessage | ||
public void message(String message) { | ||
logger.debugf("Received this WebSocket message: " + message); | ||
try { | ||
ServiceViewChangeEvent serviceViewChangeEvent = mapper.readValue(message, ServiceViewChangeEvent.class); | ||
logger.infof("Received a new change event [%s] for '%s', at %d", | ||
serviceViewChangeEvent.getChangeType(), | ||
serviceViewChangeEvent.getServiceId(), | ||
serviceViewChangeEvent.getTimestamp()); | ||
|
||
definitionUpdater.applyServiceChangeEvent(serviceViewChangeEvent); | ||
} catch (Exception e) { | ||
logger.error("WebSocket message cannot be converted into a ServiceViewChangeEvent", e); | ||
logger.error("Ignoring this WebSocket message"); | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
distro/uber-async-minion/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,16 @@ | ||
# Configure the log level. | ||
quarkus.log.level=INFO | ||
quarkus.log.console.level=INFO | ||
|
||
# Access to Microcks API server. | ||
io.github.microcks.minion.async.client.MicrocksAPIConnector/mp-rest/url=http://${MICROCKS_HOST_PORT:localhost:8080} | ||
|
||
# Only support WebSocket by default. | ||
minion.supported-bindings=WS | ||
|
||
minion.microcks-host-port=${MICROCKS_HOST_PORT:localhost:8080} | ||
|
||
# Override microcks-services-updates reactive messaging channel | ||
mp.messaging.incoming.microcks-services-updates.connector=quarkus-websocket | ||
mp.messaging.incoming.microcks-services-updates.url=ws://${MICROCKS_HOST_PORT:localhost:8080}/ | ||
mp.messaging.incoming.microcks-services-updates.path=/api/services-updates |
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.