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

[DE-818] Update dependencies versions #1

Merged
merged 6 commits into from
Jun 10, 2024
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
46 changes: 46 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Native CI

on: push

jobs:

verify:
timeout-minutes: 10
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
shaded:
- 'true'
- 'false'

steps:
- uses: actions/checkout@v2
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21.0.2'
distribution: 'graalvm-community'
cache: 'maven'
native-image-job-reports: 'true'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Info
run: mvn -version
- name: Deps tree
run: mvn dependency:tree -Dshaded=${{matrix.shaded}}
- name: Start Database
run: ./docker/start_db.sh
env:
SSL: true
- name: test
run: mvn test
- name: package-native
run: mvn -Dpackaging=native-image -Dshaded=${{matrix.shaded}} package
- name: start-native
run: ./target/demo &
- name: wait
run: sleep 1
- name: test-version
run: curl -v --fail http://localhost:8080/version
- name: test-serde
run: curl -v --fail http://localhost:8080/order
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Example application using ArangoDB Java driver integrated with:
Start a local database:

```shell script
./docker/start_db.sh
SSL=true ./docker/start_db.sh
```

## test
Expand All @@ -19,6 +19,12 @@ Start a local database:
mvn test
```

## test shaded

```shell script
mvn test -Dshaded
```

## native image

```shell script
Expand All @@ -27,3 +33,12 @@ mvn package -Dpackaging=native-image
curl -X GET http://localhost:8080/version
curl -X GET http://localhost:8080/order
```

## native image shaded

```shell script
mvn package -Dpackaging=native-image -Dshaded
./target/demo
curl -X GET http://localhost:8080/version
curl -X GET http://localhost:8080/order
```
1 change: 1 addition & 0 deletions docker/start_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ docker run -d \
-e ARANGO_LICENSE_KEY="$ARANGO_LICENSE_KEY" \
$STARTER_DOCKER_IMAGE \
$STARTER_ARGS \
--docker.net-mode=default \
--docker.container=adb \
--auth.jwt-secret=/jwtSecret \
--starter.address="${GW}" \
Expand Down
79 changes: 74 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,28 @@
<micronaut.runtime>netty</micronaut.runtime>
<exec.mainClass>com.example.ApplicationKt</exec.mainClass>
<kotlinVersion>1.9.23</kotlinVersion>
<adb.version>7.7.0</adb.version>
<graalvm.version>24.0.1</graalvm.version>
</properties>

<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
<repository>
<id>arangodb-snapshots</id>
<url>https://oss.sonatype.org/content/groups/staging</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.arangodb</groupId>
<artifactId>arangodb-java-driver</artifactId>
<version>7.6.0</version>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-server-netty</artifactId>
Expand Down Expand Up @@ -296,4 +303,66 @@
</plugins>
</build>

<profiles>
<profile>
<id>plain</id>
<activation>
<property>
<name>shaded</name>
<value>!true</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.arangodb</groupId>
<artifactId>arangodb-java-driver</artifactId>
<version>${adb.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>24.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/native/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>shaded</id>
<activation>
<property>
<name>shaded</name>
<value>true</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.arangodb</groupId>
<artifactId>arangodb-java-driver-shaded</artifactId>
<version>${adb.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
19 changes: 19 additions & 0 deletions src/main/kotlin/com/example/ArangoConfig.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example


import com.arangodb.Protocol
import com.arangodb.config.ArangoConfigProperties
import com.arangodb.config.HostDescription
import io.micronaut.context.annotation.ConfigurationProperties
Expand All @@ -10,6 +11,16 @@ import java.util.*
class ArangoConfig {
var hosts: Optional<List<String>> = Optional.empty()
var password: Optional<String> = Optional.empty()
var protocol: Optional<Protocol> = Optional.empty()
var useSsl: Optional<Boolean> = Optional.empty()
var ssl: SslConfig = SslConfig()

@ConfigurationProperties("ssl")
class SslConfig {
lateinit var trustStoreFile: String
lateinit var trustStorePassword: String
lateinit var trustStoreType: String
}
}

class ArangoConfigAdapter(private val config: ArangoConfig) : ArangoConfigProperties {
Expand All @@ -20,4 +31,12 @@ class ArangoConfigAdapter(private val config: ArangoConfig) : ArangoConfigProper
override fun getPassword(): Optional<String> {
return config.password
}

override fun getProtocol(): Optional<Protocol> {
return config.protocol
}

override fun getUseSsl(): Optional<Boolean> {
return config.useSsl
}
}
44 changes: 44 additions & 0 deletions src/main/kotlin/com/example/ArangoProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example

import com.arangodb.ArangoDB
import com.arangodb.serde.ArangoSerde
import io.micronaut.context.annotation.Factory
import io.micronaut.serde.ObjectMapper
import jakarta.inject.Singleton
import java.security.KeyStore
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManagerFactory

@Factory
class ArangoProvider {
@Singleton
fun arangoDB(config: ArangoConfig, mapper: ObjectMapper): ArangoDB = ArangoDB.Builder()
.loadProperties(ArangoConfigAdapter(config))
.sslContext(createSslContext(config))

// ArangoSerde implementation based on Micronaut serialization
.serde(object : ArangoSerde {
override fun serialize(value: Any?): ByteArray {
return mapper.writeValueAsBytes(value)
}

override fun <T : Any?> deserialize(content: ByteArray, clazz: Class<T>): T? {
return mapper.readValue(content, clazz)
}
})
.build()


private fun createSslContext(config: ArangoConfig): SSLContext {
val ks = KeyStore.getInstance(config.ssl.trustStoreType)
ks.load(
Thread.currentThread().contextClassLoader.getResourceAsStream(config.ssl.trustStoreFile),
config.ssl.trustStorePassword.toCharArray()
)
val tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
tmf.init(ks)
val sc = SSLContext.getInstance("TLS")
sc.init(null, tmf.trustManagers, null)
return sc
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.micronaut.serde.annotation.SerdeImport

@Controller("/")
@SerdeImport(ArangoDBVersion::class)
class HelloController(private val svc: ArangoService) {
class ArangoResource(private val svc: ArangoService) {

@Get("/version")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
17 changes: 1 addition & 16 deletions src/main/kotlin/com/example/ArangoService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,11 @@ package com.example

import com.arangodb.ArangoDB
import com.arangodb.entity.ArangoDBVersion
import com.arangodb.serde.ArangoSerde
import io.micronaut.serde.ObjectMapper
import jakarta.inject.Singleton
import java.util.*

@Singleton
class ArangoService(config: ArangoConfig, mapper: ObjectMapper) {

private val adb: ArangoDB = ArangoDB.Builder()
.loadProperties(ArangoConfigAdapter(config))
.serde(object : ArangoSerde {
override fun serialize(value: Any?): ByteArray {
return mapper.writeValueAsBytes(value)
}

override fun <T : Any?> deserialize(content: ByteArray, clazz: Class<T>): T? {
return mapper.readValue(content, clazz)
}
})
.build()
class ArangoService(private val adb: ArangoDB) {

fun getVersion(): ArangoDBVersion {
return adb.version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Args=\
-Dio.netty.noUnsafe=true \
-Dio.netty.leakDetection.level=DISABLED \
--initialize-at-build-time=\
com.example,\
ch.qos.logback,\
org.slf4j,\
io.netty \
--initialize-at-run-time=\
io.netty.buffer.PooledByteBufAllocator,\
io.netty.buffer.ByteBufAllocator,\
io.netty.buffer.ByteBufUtil,\
io.netty.buffer.AbstractReferenceCountedByteBuf,\
io.netty.handler.ssl.JdkSslServerContext,\
io.netty.handler.codec.compression.BrotliDecoder,\
io.netty.handler.codec.compression.ZstdConstants,\
io.netty.handler.codec.http2.Http2CodecUtil,\
io.netty.handler.codec.http2.Http2ClientUpgradeCodec,\
io.netty.handler.codec.http2.Http2ConnectionHandler,\
io.netty.handler.codec.http2.DefaultHttp2FrameWriter,\
io.netty.handler.codec.http.HttpObjectEncoder,\
io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,\
io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder,\
io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler,\
io.netty.handler.codec.http2.Http2ServerUpgradeCodec,\
io.netty.handler.pcap.PcapWriteHandler$WildcardAddressHolder,\
io.netty.util.AbstractReferenceCounted,\
io.netty.util.concurrent.GlobalEventExecutor,\
io.netty.util.concurrent.ImmediateEventExecutor,\
io.netty.util.concurrent.ScheduledFutureTask,\
io.netty.util.internal.ThreadLocalRandom,\
io.netty.util.NetUtilSubstitutions$NetUtilLocalhost4LazyHolder,\
io.netty.util.NetUtilSubstitutions$NetUtilLocalhost6LazyHolder,\
io.netty.util.NetUtilSubstitutions$NetUtilLocalhostLazyHolder,\
io.netty.util.NetUtilSubstitutions$NetUtilNetworkInterfacesLazyHolder,\
io.netty.handler.ssl.util.ThreadLocalInsecureRandom,\
io.netty.resolver.dns.DefaultDnsServerAddressStreamProvider,\
io.netty.resolver.dns.DnsServerAddressStreamProviders$DefaultProviderHolder,\
io.netty.resolver.dns.DnsNameResolver,\
io.netty.resolver.HostsFileEntriesResolver,\
io.netty.resolver.dns.ResolvConf$ResolvConfLazy,\
io.netty.resolver.dns.DefaultDnsServerAddressStreamProvider,\
io.vertx.core.buffer.impl.VertxByteBufAllocator
Binary file not shown.
6 changes: 5 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
micronaut.application.name=demo

adb.hosts=127.0.0.1:8529
adb.hosts=localhost:8529
adb.password=test
adb.useSsl=true
adb.ssl.trustStoreFile=META-INF/resources/adb.truststore
adb.ssl.trustStorePassword=12345678
adb.ssl.trustStoreType=pkcs12
20 changes: 20 additions & 0 deletions src/native/java/graal/BrotliSubstitutions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package graal;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

public class BrotliSubstitutions {

@TargetClass(className = "io.netty.handler.codec.compression.Brotli")
static final class Target_io_netty_handler_codec_compression_Brotli {
@Substitute
public static boolean isAvailable() {
return false;
}

@Substitute
public static void ensureAvailability() throws Throwable {
throw new UnsupportedOperationException();
}
}
}
Loading
Loading