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

CRaC POC #5616

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<version.lib.gson>2.9.0</version.lib.gson>
<version.lib.grpc>1.49.2</version.lib.grpc>
<version.lib.guava>31.1-jre</version.lib.guava>
<version.lib.crac>0.1.3</version.lib.crac>
<version.lib.h2>2.1.212</version.lib.h2>
<version.lib.hamcrest>1.3</version.lib.hamcrest>
<version.lib.hibernate>6.1.4.Final</version.lib.hibernate>
Expand Down Expand Up @@ -823,6 +824,11 @@
<artifactId>jakarta.validation-api</artifactId>
<version>${version.lib.jakarta.validation-api}</version>
</dependency>
<dependency>
<groupId>io.github.crac</groupId>
<artifactId>org-crac</artifactId>
<version>${version.lib.crac}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
18 changes: 18 additions & 0 deletions examples/crac/Dockerfile.buildtime_crac
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2022 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.
#


# TODO: docker buildx with priviledged access? - https://docs.docker.com/engine/reference/commandline/buildx_build/#allow
17 changes: 17 additions & 0 deletions examples/crac/Dockerfile.native_image
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 2022 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.
#

# TODO: native image for comparison
40 changes: 40 additions & 0 deletions examples/crac/Dockerfile.runtime_crac
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (c) 2022 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.
#
FROM ubuntu:22.04 as ubuntu-crac

WORKDIR /usr/share

ENV CRAC_ARTEFACT=openjdk-17-crac+3_linux-x64
ENV JAVA_HOME=/usr/share/$CRAC_ARTEFACT

# Install CRaC
RUN apt-get -qq update && apt-get install -y wget \
&& wget -q https://github.com/CRaC/openjdk-builds/releases/download/17-crac%2B3/$CRAC_ARTEFACT.tar.gz \
&& tar zxf $CRAC_ARTEFACT.tar.gz \
&& ln -s $JAVA_HOME/bin/java /bin/

FROM ubuntu-crac
WORKDIR /helidon

ADD target/*.jar .
ADD target/libs libs
ADD runtimeCRaC.sh .
RUN chmod +x ./runtimeCRaC.sh

ENTRYPOINT ["./runtimeCRaC.sh"]

EXPOSE 7001

28 changes: 28 additions & 0 deletions examples/crac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Helidon MP on CRaC
[Coordinated Restore at Checkpoint](https://wiki.openjdk.org/display/crac)


## Runtime CRaC
Standard docker build doesn't support privileged access to the host machine kernel,
therefore CRaC checkpoint needs to be created in runtime.

```bash
mvn clean package
docker build -t crac-runtime-helloworld . -f Dockerfile.runtime_crac
# First time ran, checkpoint is created, stop with Ctrl-C
docker run --privileged -p 7001:7001 --name crac-runtime-helloworld crac-runtime-helloworld
# Second time starting from checkpoint, stop with Ctrl-C
docker start -i crac-runtime-helloworld
```

## Buildtime CRaC
Docker buildx ...

[//]: # (TODO docker buildx with privileged access?)

### Exercise the app
```
curl -X GET http://localhost:7001/helloworld
curl -X GET http://localhost:7001/helloworld/earth
curl -X GET http://localhost:7001/another
```
79 changes: 79 additions & 0 deletions examples/crac/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2018, 2022 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.

-->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.helidon.applications</groupId>
<artifactId>helidon-mp</artifactId>
<version>3.0.3-SNAPSHOT</version>
<relativePath>../../../applications/mp/pom.xml</relativePath>
</parent>
<groupId>io.helidon.examples.microprofile</groupId>
<artifactId>helidon-examples-microprofile-hello-world-implicit</artifactId>
<name>Helidon Microprofile Examples Implicit Hello World</name>

<description>
Microprofile example with implicit bootstrapping (cdi.Main(new String[0])
</description>

<dependencies>
<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile</artifactId>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.tests</groupId>
<artifactId>helidon-microprofile-tests-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libs</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
43 changes: 43 additions & 0 deletions examples/crac/runtimeCRaC.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash -e

#
# Copyright (c) 2022 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.
#

if [ ! -d "./cr" ];
then
echo "==== Creating CRaC checkpoint ===="
echo "=== Checking CRIU compatibility(don't forget --privileged) ==="
$JAVA_HOME/lib/criu check

echo "=== Checking glibc version ==="
# glibc version higher than 2.34.9000-29 are known to have problems with rseq
# on some kernels, workaround GLIBC_TUNABLES=glibc.pthread.rseq=0
ldd --version | grep ldd
# Workaround for https://github.com/checkpoint-restore/criu/issues/1696
# see https://github.com/checkpoint-restore/criu/pull/1706
export GLIBC_TUNABLES=glibc.pthread.rseq=0

echo "=== Pre-starting Helidon MP app ==="
set +e
$JAVA_HOME/bin/java -XX:CRaCCheckpointTo=cr -jar ./*.jar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Lurking. I wonder if, since you're doing this java run already, you might also combine it with class data sharing. Or maybe you want to keep things pure for this PoC.)

set -e

echo "=== CRaC checkpoint created, checking log dump for errors ==="
cat ./cr/dump*.log | grep "Warn\|Err\|succ"
fi
echo "==== Starting directly from CRaC checkpoint ===="
exec $JAVA_HOME/bin/java -XX:CRaCRestoreFrom=cr

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2018,2020 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.
*/

package io.helidon.microprofile.example.helloworld.implicit;

import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperty;

/**
* Resource showing all possible configuration injections.
*/
@Path("another")
@RequestScoped
public class AnotherResource {
@Inject
@ConfigProperty(name = "app.nonExistent", defaultValue = "145")
private int defaultValue;

@Inject
@ConfigProperty(name = "app.nonExistent")
private Optional<String> empty;

@Inject
@ConfigProperty(name = "app.uri")
private Optional<URI> full;

@Inject
@ConfigProperty(name = "app.someInt")
private Provider<Integer> provider;

@Inject
@ConfigProperty(name = "app.ints")
private List<Integer> ints;

@Inject
@ConfigProperty(name = "app.ints")
private Optional<List<Integer>> optionalInts;

@Inject
@ConfigProperty(name = "app.ints")
private Provider<List<Integer>> providedInts;

@Inject
@ConfigProperty(name = "app.ints")
private int[] intsArray;

@Inject
@ConfigProperty(name = "app")
private Map<String, String> detached;

@Inject
private Config mpConfig;

@Inject
private io.helidon.config.Config helidonConfig;

/**
* Get method to validate that all injections worked.
*
* @return data from all fields of this class
*/
@GET
public String get() {
return toString();
}

@Override
public String toString() {
return "AnotherResource{"
+ "defaultValue=" + defaultValue
+ ", empty=" + empty
+ ", full=" + full
+ ", provider=" + provider + "(" + provider.get() + ")"
+ ", ints=" + ints
+ ", optionalInts=" + optionalInts
+ ", providedInts=" + providedInts + "(" + providedInts.get() + ")"
+ ", detached=" + detached
+ ", microprofileConfig=" + mpConfig
+ ", helidonConfig=" + helidonConfig
+ ", intsArray=" + Arrays.toString(intsArray)
+ '}';
}
}
Loading