Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarkus implementation of customer, preference, and recommendation #202

Merged
merged 3 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ target/
!.mvn/wrapper/maven-wrapper.jar
audit.log
.cache/
*.log

docs/
gh-pages/
Expand Down
4 changes: 4 additions & 0 deletions customer/java/quarkus/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
11 changes: 11 additions & 0 deletions customer/java/quarkus/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM fabric8/java-jboss-openjdk8-jdk
ENV JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0
ENV JAEGER_SERVICE_NAME=customer\
JAEGER_ENDPOINT=http://jaeger-collector.istio-system.svc:14268/api/traces\
JAEGER_PROPAGATION=b3\
JAEGER_SAMPLER_TYPE=const\
JAEGER_SAMPLER_PARAM=1
EXPOSE 8080 8778 9779
COPY target/lib/* /deployments/lib/
COPY target/*-runner.jar /deployments/app.jar
ENTRYPOINT [ "/deployments/run-java.sh" ]
128 changes: 128 additions & 0 deletions customer/java/quarkus/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.redhat.developer.demos.customer.rest</groupId>
<artifactId>customer</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<quarkus.version>0.12.0</quarkus.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</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>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-opentracing</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</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>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<enableHttpUrlHandler>true</enableHttpUrlHandler>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemProperties>
<native.image.path>
${project.build.directory}/${project.build.finalName}-runner
</native.image.path>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
21 changes: 21 additions & 0 deletions customer/java/quarkus/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
####
# 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 quarkus/customer-jvm .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/customer-jvm
#
###
FROM fabric8/java-jboss-openjdk8-jdk
ENV JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0
COPY target/lib/* /deployments/lib/
COPY target/*-runner.jar /deployments/app.jar
ENTRYPOINT [ "/deployments/run-java.sh" ]
22 changes: 22 additions & 0 deletions customer/java/quarkus/src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
####
# 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 -Dnative-image.docker-build=true
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.native -t quarkus/customer .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/customer
#
###
FROM registry.fedoraproject.org/fedora-minimal
WORKDIR /work/
COPY target/*-runner /work/application
RUN chmod 775 /work
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.redhat.developer.demos.customer.rest;

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/")
public class CustomerResource {

private static final String RESPONSE_STRING_FORMAT = "customer => %s\n";

private final Logger logger = LoggerFactory.getLogger(getClass());

@Inject
@RestClient
PreferenceService preferenceService;

@GET
@Produces(MediaType.TEXT_PLAIN)
public Response getCustomer() {
try {
String response = preferenceService.getPreference();
return Response.ok(String.format(RESPONSE_STRING_FORMAT, response)).build();
} catch (WebApplicationException ex) {
Response response = ex.getResponse();
logger.warn("Non HTTP 20x trying to get the response from preference service: " + response.getStatus());
return Response
.status(Response.Status.SERVICE_UNAVAILABLE)
.entity(String.format(RESPONSE_STRING_FORMAT,
String.format("Error: %d - %s", response.getStatus(), response.readEntity(String.class)))
)
.build();
} catch (ProcessingException ex) {
logger.warn("Exception trying to get the response from preference service.", ex);
return Response
.status(Response.Status.SERVICE_UNAVAILABLE)
.entity(String.format(RESPONSE_STRING_FORMAT, ex.getCause().getClass().getSimpleName() + ": " + ex.getCause().getMessage()))
.build();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.redhat.developer.demos.customer.rest;

import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

@RegisterClientHeaders
@RegisterRestClient
public interface PreferenceService {

@Path("/")
@GET
@Produces("text/plain")
public String getPreference();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.eclipse.microprofile.rest.client.propagateHeaders=User-Agent
com.redhat.developer.demos.customer.rest.PreferenceService/mp-rest/url=http://preference:8080
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.redhat.developer.demos.customer.rest;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;

@QuarkusTest
public class CustomerResourceTest {

@Test
public void testHelloEndpoint() {
given()
.when().get("/")
.then()
.statusCode(503)
.body(startsWith("customer =>"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.redhat.developer.demos.customer.rest;

import io.quarkus.test.junit.SubstrateTest;

@SubstrateTest
public class NativeCustomerResourceIT extends CustomerResourceTest {

// Execute the same tests but in native mode.
}
4 changes: 4 additions & 0 deletions preference/java/quarkus/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
11 changes: 11 additions & 0 deletions preference/java/quarkus/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM fabric8/java-jboss-openjdk8-jdk
ENV JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0
ENV JAEGER_SERVICE_NAME=preference \
JAEGER_ENDPOINT=http://jaeger-collector.istio-system.svc:14268/api/traces \
JAEGER_PROPAGATION=b3 \
JAEGER_SAMPLER_TYPE=const \
JAEGER_SAMPLER_PARAM=1
EXPOSE 8080 8778 9779
COPY target/lib/* /deployments/lib/
COPY target/*-runner.jar /deployments/app.jar
ENTRYPOINT [ "/deployments/run-java.sh" ]
Loading