Skip to content

Commit

Permalink
Neo4j integration (#2692)
Browse files Browse the repository at this point in the history
* Neo4j integration
  • Loading branch information
dalexandrov authored Feb 26, 2021
1 parent 0dc4b02 commit 9566c69
Show file tree
Hide file tree
Showing 65 changed files with 3,804 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,22 @@
<artifactId>helidon-logging-log4j</artifactId>
<version>${helidon.version}</version>
</dependency>
<!-- Neo4j -->
<dependency>
<groupId>io.helidon.integrations.neo4j</groupId>
<artifactId>helidon-integrations-neo4j</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.neo4j</groupId>
<artifactId>helidon-integrations-neo4j-health</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.neo4j</groupId>
<artifactId>helidon-integrations-neo4j-metrics</artifactId>
<version>${helidon.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
17 changes: 17 additions & 0 deletions common/common/src/main/java/io/helidon/common/FeatureCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,23 @@ final class FeatureCatalog {
"Zipkin",
"Zipkin tracer integration",
"Tracing", "Zipkin");
add("io.helidon.integrations.neo4j",
FeatureDescriptor.builder()
.name("Neo4j integration")
.description("Integration with Neo4j driver")
.path("Neo4j")
.experimental(true)
.nativeSupported(true));
add("io.helidon.integrations.neo4j.health",
FeatureDescriptor.builder()
.name("Neo4j Health")
.description("Health check for Neo4j integration")
.path("Neo4j", "Health"));
add("io.helidon.integrations.neo4j.metrics",
FeatureDescriptor.builder()
.name("Neo4j Metrics")
.description("Metrics for Neo4j integration")
.path("Neo4j", "Metrics"));
add("io.helidon.webclient",
FeatureDescriptor.builder()
.name("Web Client")
Expand Down
7 changes: 7 additions & 0 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<version.lib.mockito>2.23.4</version.lib.mockito>
<version.lib.mongodb.reactivestreams>1.11.0</version.lib.mongodb.reactivestreams>
<version.lib.mssql-jdbc>8.4.1.jre8</version.lib.mssql-jdbc>
<version.lib.neo4j>4.2.0</version.lib.neo4j>
<version.lib.mysql-connector-java>8.0.22</version.lib.mysql-connector-java>
<version.lib.narayana>5.9.3.Final</version.lib.narayana>
<version.lib.netty>4.1.59.Final</version.lib.netty>
Expand Down Expand Up @@ -1014,6 +1015,12 @@
<artifactId>micronaut-aop</artifactId>
<version>${version.lib.micronaut}</version>
</dependency>
<!-- Neo4j -->
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>${version.lib.neo4j}</version>
</dependency>
<!-- END OF Section 1: direct third party dependencies -->

<!-- Section 2: third party dependencies used by examples -->
Expand Down
1 change: 1 addition & 0 deletions examples/integrations/neo4j/neo4j-mp/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/*
44 changes: 44 additions & 0 deletions examples/integrations/neo4j/neo4j-mp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# Copyright (c) 2021 Oracle and/or its affiliates.
#
# 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.
#

# 1st stage, build the app
FROM maven:3.6-jdk-11 as build

WORKDIR /helidon

# Create a first layer to cache the "Maven World" in the local repository.
# Incremental docker builds will always resume after that, unless you update
# the pom
ADD pom.xml .
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip

# Do the Maven build!
# Incremental docker builds will resume here when you change sources
ADD src src
RUN mvn package -DskipTests
RUN echo "done!"

# 2nd stage, build the runtime image
FROM openjdk:11-jre-slim
WORKDIR /helidon

# Copy the binary built in the 1st stage
COPY --from=build /helidon/target/helidon-examples-integration-neo4j-mp.jar ./
COPY --from=build /helidon/target/libs ./libs

CMD ["java", "-jar", "helidon-examples-integration-neo4j-mp.jar"]

EXPOSE 8080
40 changes: 40 additions & 0 deletions examples/integrations/neo4j/neo4j-mp/Dockerfile.jlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (c) 2021 Oracle and/or its affiliates.
#
# 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.
#

# 1st stage, build the app
FROM maven:3.6.3-jdk-11-slim as build

WORKDIR /helidon

# Create a first layer to cache the "Maven World" in the local repository.
# Incremental docker builds will always resume after that, unless you update
# the pom
ADD pom.xml .
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip

# Do the Maven build to create the custom Java Runtime Image
# Incremental docker builds will resume here when you change sources
ADD src src
RUN mvn -Ddocker.build=true package -Pjlink-image -DskipTests
RUN echo "done!"

# 2nd stage, build the final image with the JRI built in the 1st stage

FROM debian:stretch-slim
WORKDIR /helidon
COPY --from=build /helidon/target/helidon-examples-integration-neo4j-mp-jri ./
ENTRYPOINT ["/bin/bash", "/helidon/bin/start"]
EXPOSE 8080
44 changes: 44 additions & 0 deletions examples/integrations/neo4j/neo4j-mp/Dockerfile.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# Copyright (c) 2021 Oracle and/or its affiliates.
#
# 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.
#

# 1st stage, build the app
FROM helidon/jdk11-graalvm-maven:20.2.0 as build

WORKDIR /helidon

# Create a first layer to cache the "Maven World" in the local repository.
# Incremental docker builds will always resume after that, unless you update
# the pom
ADD pom.xml .
RUN mvn package -Pnative-image -Dnative.image.skip -Dmaven.test.skip -Declipselink.weave.skip

# Do the Maven build!
# Incremental docker builds will resume here when you change sources
ADD src src
RUN mvn package -Pnative-image -Dnative.image.buildStatic -DskipTests

RUN echo "done!"

# 2nd stage, build the runtime image
FROM scratch
WORKDIR /helidon

# Copy the binary built in the 1st stage
COPY --from=build /helidon/target/helidon-examples-integration-neo4j-mp .

ENTRYPOINT ["./helidon-examples-integration-neo4j-mp"]

EXPOSE 8080
167 changes: 167 additions & 0 deletions examples/integrations/neo4j/neo4j-mp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Helidon Quickstart MP Example

This example implements a simple Neo4j REST service using MicroProfile.

## Build and run

Bring up a Neo4j instance via Docker

```bash
docker run --publish=7474:7474 --publish=7687:7687 -e 'NEO4J_AUTH=neo4j/secret' neo4j:4.0
```

Goto the Neo4j browser and play the first step of the movies graph: [`:play movies`](http://localhost:7474/browser/?cmd=play&arg=movies).


Then build with JDK11+
```bash
mvn package
java -jar target/helidon-integrations-neo4j-mp.jar
```

## Exercise the application

```
curl -X GET http://localhost:8080/movies
```

## Try health and metrics

```
curl -s -X GET http://localhost:8080/health
{"outcome":"UP",...
. . .
# Prometheus Format
curl -s -X GET http://localhost:8080/metrics
# TYPE base:gc_g1_young_generation_count gauge
. . .
# JSON Format
curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
{"base":...
. . .
```

## Build the Docker Image

```
docker build -t helidon-integrations-neo4j-mp .
```

## Start the application with Docker

```
docker run --rm -p 8080:8080 helidon-integrations-neo4j-mp:latest
```

Exercise the application as described above

## Deploy the application to Kubernetes

```
kubectl cluster-info # Verify which cluster
kubectl get pods # Verify connectivity to cluster
kubectl create -f app.yaml # Deploy application
kubectl get service helidon-integrations-neo4j-mp # Verify deployed service
```

## Build a native image with GraalVM

GraalVM allows you to compile your programs ahead-of-time into a native
executable. See https://www.graalvm.org/docs/reference-manual/aot-compilation/
for more information.

You can build a native executable in 2 different ways:
* With a local installation of GraalVM
* Using Docker

### Local build

Download Graal VM at https://www.graalvm.org/downloads. We recommend
version `20.1.0` or later.

```
# Setup the environment
export GRAALVM_HOME=/path
# build the native executable
mvn package -Pnative-image
```

You can also put the Graal VM `bin` directory in your PATH, or pass
`-DgraalVMHome=/path` to the Maven command.

See https://github.com/oracle/helidon-build-tools/tree/master/helidon-maven-plugin#goal-native-image
for more information.

Start the application:

```
./target/helidon-quickstart-mp
```

### Multi-stage Docker build

Build the "native" Docker Image

```
docker build -t helidon-integrations-neo4j-mp-native -f Dockerfile.native .
```

Start the application:

```
docker run --rm -p 8080:8080 helidon-integrations-neo4j-mp-native:latest
```


## Build a Java Runtime Image using jlink

You can build a custom Java Runtime Image (JRI) containing the application jars and the JDK modules
on which they depend. This image also:

* Enables Class Data Sharing by default to reduce startup time.
* Contains a customized `start` script to simplify CDS usage and support debug and test modes.

You can build a custom JRI in two different ways:
* Local
* Using Docker


### Local build

```
# build the JRI
mvn package -Pjlink-image
```

See https://github.com/oracle/helidon-build-tools/tree/master/helidon-maven-plugin#goal-jlink-image
for more information.

Start the application:

```
./target/helidon-integrations-neo4j-mp-jri/bin/start
```

### Multi-stage Docker build

Build the JRI as a Docker Image

```
docker build -t helidon-integrations-neo4j-mp-jri -f Dockerfile.jlink .
```

Start the application:

```
docker run --rm -p 8080:8080 helidon-integrations-neo4j-mp-jri:latest
```

See the start script help:

```
docker run --rm helidon-integrations-neo4j-mp-jri:latest --help
```
Loading

0 comments on commit 9566c69

Please sign in to comment.