Skip to content

Commit 11625d6

Browse files
authored
Merge pull request #202 from yanaga/master
Quarkus implementation of customer, preference, and recommendation
2 parents 7ac4f2b + 8854593 commit 11625d6

File tree

30 files changed

+865
-0
lines changed

30 files changed

+865
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ target/
22
!.mvn/wrapper/maven-wrapper.jar
33
audit.log
44
.cache/
5+
*.log
56

67
docs/
78
gh-pages/

customer/java/quarkus/.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!target/*-runner
3+
!target/*-runner.jar
4+
!target/lib/*

customer/java/quarkus/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM fabric8/java-jboss-openjdk8-jdk
2+
ENV JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0
3+
ENV JAEGER_SERVICE_NAME=customer\
4+
JAEGER_ENDPOINT=http://jaeger-collector.istio-system.svc:14268/api/traces\
5+
JAEGER_PROPAGATION=b3\
6+
JAEGER_SAMPLER_TYPE=const\
7+
JAEGER_SAMPLER_PARAM=1
8+
EXPOSE 8080 8778 9779
9+
COPY target/lib/* /deployments/lib/
10+
COPY target/*-runner.jar /deployments/app.jar
11+
ENTRYPOINT [ "/deployments/run-java.sh" ]

customer/java/quarkus/pom.xml

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?xml version="1.0"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.redhat.developer.demos.customer.rest</groupId>
7+
<artifactId>customer</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<properties>
10+
<surefire-plugin.version>2.22.0</surefire-plugin.version>
11+
<maven.compiler.target>1.8</maven.compiler.target>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<quarkus.version>0.12.0</quarkus.version>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
<dependencyManagement>
17+
<dependencies>
18+
<dependency>
19+
<groupId>io.quarkus</groupId>
20+
<artifactId>quarkus-bom</artifactId>
21+
<version>${quarkus.version}</version>
22+
<type>pom</type>
23+
<scope>import</scope>
24+
</dependency>
25+
</dependencies>
26+
</dependencyManagement>
27+
<dependencies>
28+
<dependency>
29+
<groupId>io.quarkus</groupId>
30+
<artifactId>quarkus-resteasy</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>io.quarkus</groupId>
34+
<artifactId>quarkus-junit5</artifactId>
35+
<scope>test</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>io.rest-assured</groupId>
39+
<artifactId>rest-assured</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>io.quarkus</groupId>
44+
<artifactId>quarkus-smallrye-rest-client</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>io.quarkus</groupId>
48+
<artifactId>quarkus-smallrye-opentracing</artifactId>
49+
</dependency>
50+
<dependency>
51+
<groupId>io.quarkus</groupId>
52+
<artifactId>quarkus-smallrye-health</artifactId>
53+
</dependency>
54+
</dependencies>
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>io.quarkus</groupId>
59+
<artifactId>quarkus-maven-plugin</artifactId>
60+
<version>${quarkus.version}</version>
61+
<executions>
62+
<execution>
63+
<goals>
64+
<goal>build</goal>
65+
</goals>
66+
</execution>
67+
</executions>
68+
</plugin>
69+
<plugin>
70+
<artifactId>maven-surefire-plugin</artifactId>
71+
<version>${surefire-plugin.version}</version>
72+
<configuration>
73+
<systemProperties>
74+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
75+
</systemProperties>
76+
</configuration>
77+
</plugin>
78+
</plugins>
79+
</build>
80+
<profiles>
81+
<profile>
82+
<id>native</id>
83+
<activation>
84+
<property>
85+
<name>native</name>
86+
</property>
87+
</activation>
88+
<build>
89+
<plugins>
90+
<plugin>
91+
<groupId>io.quarkus</groupId>
92+
<artifactId>quarkus-maven-plugin</artifactId>
93+
<version>${quarkus.version}</version>
94+
<executions>
95+
<execution>
96+
<goals>
97+
<goal>native-image</goal>
98+
</goals>
99+
<configuration>
100+
<enableHttpUrlHandler>true</enableHttpUrlHandler>
101+
</configuration>
102+
</execution>
103+
</executions>
104+
</plugin>
105+
<plugin>
106+
<artifactId>maven-failsafe-plugin</artifactId>
107+
<version>${surefire-plugin.version}</version>
108+
<executions>
109+
<execution>
110+
<goals>
111+
<goal>integration-test</goal>
112+
<goal>verify</goal>
113+
</goals>
114+
<configuration>
115+
<systemProperties>
116+
<native.image.path>
117+
${project.build.directory}/${project.build.finalName}-runner
118+
</native.image.path>
119+
</systemProperties>
120+
</configuration>
121+
</execution>
122+
</executions>
123+
</plugin>
124+
</plugins>
125+
</build>
126+
</profile>
127+
</profiles>
128+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
####
2+
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
3+
#
4+
# Before building the docker image run:
5+
#
6+
# mvn package
7+
#
8+
# Then, build the image with:
9+
#
10+
# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/customer-jvm .
11+
#
12+
# Then run the container using:
13+
#
14+
# docker run -i --rm -p 8080:8080 quarkus/customer-jvm
15+
#
16+
###
17+
FROM fabric8/java-jboss-openjdk8-jdk
18+
ENV JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0
19+
COPY target/lib/* /deployments/lib/
20+
COPY target/*-runner.jar /deployments/app.jar
21+
ENTRYPOINT [ "/deployments/run-java.sh" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
####
2+
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode
3+
#
4+
# Before building the docker image run:
5+
#
6+
# mvn package -Pnative -Dnative-image.docker-build=true
7+
#
8+
# Then, build the image with:
9+
#
10+
# docker build -f src/main/docker/Dockerfile.native -t quarkus/customer .
11+
#
12+
# Then run the container using:
13+
#
14+
# docker run -i --rm -p 8080:8080 quarkus/customer
15+
#
16+
###
17+
FROM registry.fedoraproject.org/fedora-minimal
18+
WORKDIR /work/
19+
COPY target/*-runner /work/application
20+
RUN chmod 775 /work
21+
EXPOSE 8080
22+
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.redhat.developer.demos.customer.rest;
2+
3+
import org.eclipse.microprofile.rest.client.inject.RestClient;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
import javax.inject.Inject;
8+
import javax.ws.rs.*;
9+
import javax.ws.rs.core.MediaType;
10+
import javax.ws.rs.core.Response;
11+
12+
@Path("/")
13+
public class CustomerResource {
14+
15+
private static final String RESPONSE_STRING_FORMAT = "customer => %s\n";
16+
17+
private final Logger logger = LoggerFactory.getLogger(getClass());
18+
19+
@Inject
20+
@RestClient
21+
PreferenceService preferenceService;
22+
23+
@GET
24+
@Produces(MediaType.TEXT_PLAIN)
25+
public Response getCustomer() {
26+
try {
27+
String response = preferenceService.getPreference();
28+
return Response.ok(String.format(RESPONSE_STRING_FORMAT, response)).build();
29+
} catch (WebApplicationException ex) {
30+
Response response = ex.getResponse();
31+
logger.warn("Non HTTP 20x trying to get the response from preference service: " + response.getStatus());
32+
return Response
33+
.status(Response.Status.SERVICE_UNAVAILABLE)
34+
.entity(String.format(RESPONSE_STRING_FORMAT,
35+
String.format("Error: %d - %s", response.getStatus(), response.readEntity(String.class)))
36+
)
37+
.build();
38+
} catch (ProcessingException ex) {
39+
logger.warn("Exception trying to get the response from preference service.", ex);
40+
return Response
41+
.status(Response.Status.SERVICE_UNAVAILABLE)
42+
.entity(String.format(RESPONSE_STRING_FORMAT, ex.getCause().getClass().getSimpleName() + ": " + ex.getCause().getMessage()))
43+
.build();
44+
}
45+
}
46+
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.redhat.developer.demos.customer.rest;
2+
3+
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
4+
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
5+
6+
import javax.ws.rs.GET;
7+
import javax.ws.rs.HeaderParam;
8+
import javax.ws.rs.Path;
9+
import javax.ws.rs.Produces;
10+
import javax.ws.rs.core.Response;
11+
12+
@RegisterClientHeaders
13+
@RegisterRestClient
14+
public interface PreferenceService {
15+
16+
@Path("/")
17+
@GET
18+
@Produces("text/plain")
19+
public String getPreference();
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.eclipse.microprofile.rest.client.propagateHeaders=User-Agent
2+
com.redhat.developer.demos.customer.rest.PreferenceService/mp-rest/url=http://preference:8080
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.redhat.developer.demos.customer.rest;
2+
3+
import io.quarkus.test.junit.QuarkusTest;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static io.restassured.RestAssured.given;
7+
import static org.hamcrest.CoreMatchers.is;
8+
import static org.hamcrest.CoreMatchers.startsWith;
9+
10+
@QuarkusTest
11+
public class CustomerResourceTest {
12+
13+
@Test
14+
public void testHelloEndpoint() {
15+
given()
16+
.when().get("/")
17+
.then()
18+
.statusCode(503)
19+
.body(startsWith("customer =>"));
20+
}
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.redhat.developer.demos.customer.rest;
2+
3+
import io.quarkus.test.junit.SubstrateTest;
4+
5+
@SubstrateTest
6+
public class NativeCustomerResourceIT extends CustomerResourceTest {
7+
8+
// Execute the same tests but in native mode.
9+
}

preference/java/quarkus/.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!target/*-runner
3+
!target/*-runner.jar
4+
!target/lib/*

preference/java/quarkus/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM fabric8/java-jboss-openjdk8-jdk
2+
ENV JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0
3+
ENV JAEGER_SERVICE_NAME=preference \
4+
JAEGER_ENDPOINT=http://jaeger-collector.istio-system.svc:14268/api/traces \
5+
JAEGER_PROPAGATION=b3 \
6+
JAEGER_SAMPLER_TYPE=const \
7+
JAEGER_SAMPLER_PARAM=1
8+
EXPOSE 8080 8778 9779
9+
COPY target/lib/* /deployments/lib/
10+
COPY target/*-runner.jar /deployments/app.jar
11+
ENTRYPOINT [ "/deployments/run-java.sh" ]

0 commit comments

Comments
 (0)