-
Notifications
You must be signed in to change notification settings - Fork 708
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 #202 from yanaga/master
Quarkus implementation of customer, preference, and recommendation
- Loading branch information
Showing
30 changed files
with
865 additions
and
0 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ target/ | |
!.mvn/wrapper/maven-wrapper.jar | ||
audit.log | ||
.cache/ | ||
*.log | ||
|
||
docs/ | ||
gh-pages/ | ||
|
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 @@ | ||
* | ||
!target/*-runner | ||
!target/*-runner.jar | ||
!target/lib/* |
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,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" ] |
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,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> |
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,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" ] |
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,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"] |
47 changes: 47 additions & 0 deletions
47
...java/quarkus/src/main/java/com/redhat/developer/demos/customer/rest/CustomerResource.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,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(); | ||
} | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...ava/quarkus/src/main/java/com/redhat/developer/demos/customer/rest/PreferenceService.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,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(); | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
customer/java/quarkus/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,2 @@ | ||
org.eclipse.microprofile.rest.client.propagateHeaders=User-Agent | ||
com.redhat.developer.demos.customer.rest.PreferenceService/mp-rest/url=http://preference:8080 |
22 changes: 22 additions & 0 deletions
22
.../quarkus/src/test/java/com/redhat/developer/demos/customer/rest/CustomerResourceTest.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,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 =>")); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...rkus/src/test/java/com/redhat/developer/demos/customer/rest/NativeCustomerResourceIT.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,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. | ||
} |
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 @@ | ||
* | ||
!target/*-runner | ||
!target/*-runner.jar | ||
!target/lib/* |
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,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" ] |
Oops, something went wrong.