From a1398045ac2a904f685f11f34cd2fcf3aeeea6e0 Mon Sep 17 00:00:00 2001 From: Walter Oggioni Date: Wed, 26 Feb 2025 17:42:02 +0800 Subject: [PATCH] fixed native image configuration task --- rbcs-cli/build.gradle | 12 +- rbcs-cli/conf/rbcs-client.xml | 15 +++ rbcs-cli/native-image/resource-config.json | 116 +++++++----------- .../native-image/serialization-config.json | 3 + .../graal/GraalNativeImageConfiguration.kt | 44 +++++-- .../cli/impl/commands/BenchmarkCommand.kt | 10 +- .../rbcs/cli/impl/commands/GetCommand.kt | 26 ++-- .../cli/impl/commands/HealthCheckCommand.kt | 4 +- .../rbcs/cli/impl/commands/PutCommand.kt | 22 +++- 9 files changed, 144 insertions(+), 108 deletions(-) create mode 100644 rbcs-cli/conf/rbcs-client.xml rename rbcs-cli/src/{graal => configureNativeImage}/kotlin/net/woggioni/rbcs/cli/graal/GraalNativeImageConfiguration.kt (79%) diff --git a/rbcs-cli/build.gradle b/rbcs-cli/build.gradle index a2fd332..2f04bb6 100644 --- a/rbcs-cli/build.gradle +++ b/rbcs-cli/build.gradle @@ -90,13 +90,21 @@ Provider envelopeJarTaskProvider = tasks.named(EnvelopePlugin.E } tasks.named(NativeImagePlugin.CONFIGURE_NATIVE_IMAGE_TASK_NAME, NativeImageConfigurationTask) { + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + vendor = JvmVendorSpec.ORACLE + } + mainClass = "net.woggioni.rbcs.cli.graal.GraalNativeImageConfiguration" - setClasspath(configurations.configureNativeImageRuntimeClasspath + sourceSets.graal.output.classesDirs) + classpath = project.files( + configurations.configureNativeImageRuntimeClasspath, + sourceSets.configureNativeImage.output + ) mergeConfiguration = false systemProperty('logback.configurationFile', 'classpath:net/woggioni/rbcs/cli/logback.xml') systemProperty('io.netty.leakDetectionLevel', 'DISABLED') modularity.inferModulePath = false - enabled = false + enabled = true } nativeImage { diff --git a/rbcs-cli/conf/rbcs-client.xml b/rbcs-cli/conf/rbcs-client.xml new file mode 100644 index 0000000..fa1e504 --- /dev/null +++ b/rbcs-cli/conf/rbcs-client.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/rbcs-cli/native-image/resource-config.json b/rbcs-cli/native-image/resource-config.json index 0a373b4..2b8f65f 100644 --- a/rbcs-cli/native-image/resource-config.json +++ b/rbcs-cli/native-image/resource-config.json @@ -1,74 +1,46 @@ { - "resources": { - "includes": [ - { - "pattern": "\\QMETA-INF/MANIFEST.MF\\E" - }, - { - "pattern": "\\QMETA-INF/services/ch.qos.logback.classic.spi.Configurator\\E" - }, - { - "pattern": "\\QMETA-INF/services/java.lang.System$LoggerFinder\\E" - }, - { - "pattern": "\\QMETA-INF/services/java.net.spi.InetAddressResolverProvider\\E" - }, - { - "pattern": "\\QMETA-INF/services/java.net.spi.URLStreamHandlerProvider\\E" - }, - { - "pattern": "\\QMETA-INF/services/java.nio.channels.spi.SelectorProvider\\E" - }, - { - "pattern": "\\QMETA-INF/services/java.time.zone.ZoneRulesProvider\\E" - }, - { - "pattern": "\\QMETA-INF/services/javax.xml.parsers.DocumentBuilderFactory\\E" - }, - { - "pattern": "\\QMETA-INF/services/javax.xml.parsers.SAXParserFactory\\E" - }, - { - "pattern": "\\QMETA-INF/services/net.woggioni.rbcs.api.CacheProvider\\E" - }, - { - "pattern": "\\QMETA-INF/services/org.slf4j.spi.SLF4JServiceProvider\\E" - }, - { - "pattern": "\\Qclasspath:net/woggioni/rbcs/cli/logback.xml\\E" - }, - { - "pattern": "\\Qlogback-test.scmo\\E" - }, - { - "pattern": "\\Qlogback.scmo\\E" - }, - { - "pattern": "\\Qnet/woggioni/rbcs/cli/logback.xml\\E" - }, - { - "pattern": "\\Qnet/woggioni/rbcs/server/rbcs-default.xml\\E" - }, - { - "pattern": "\\Qnet/woggioni/rbcs/server/schema/rbcs-server.xsd\\E" - }, - { - "pattern": "\\Qnet/woggioni/rbcs/client/schema/rbcs-client.xsd\\E" - }, - { - "pattern": "\\Q/net/woggioni/rbcs/server/memcache/schema/rbcs-memcache.xsd\\E" - }, - { - "pattern": "java.base:\\Qsun/text/resources/LineBreakIteratorData\\E" - } - ] - }, - "bundles": [ - { - "name": "com.sun.org.apache.xerces.internal.impl.xpath.regex.message", - "locales": [ - "" - ] - } - ] + "resources":{ + "includes":[{ + "pattern":"\\QMETA-INF/MANIFEST.MF\\E" + }, { + "pattern":"\\QMETA-INF/services/ch.qos.logback.classic.spi.Configurator\\E" + }, { + "pattern":"\\QMETA-INF/services/java.lang.System$LoggerFinder\\E" + }, { + "pattern":"\\QMETA-INF/services/java.net.spi.InetAddressResolverProvider\\E" + }, { + "pattern":"\\QMETA-INF/services/java.net.spi.URLStreamHandlerProvider\\E" + }, { + "pattern":"\\QMETA-INF/services/java.nio.channels.spi.SelectorProvider\\E" + }, { + "pattern":"\\QMETA-INF/services/java.time.zone.ZoneRulesProvider\\E" + }, { + "pattern":"\\QMETA-INF/services/javax.xml.parsers.DocumentBuilderFactory\\E" + }, { + "pattern":"\\QMETA-INF/services/javax.xml.parsers.SAXParserFactory\\E" + }, { + "pattern":"\\QMETA-INF/services/net.woggioni.rbcs.api.CacheProvider\\E" + }, { + "pattern":"\\QMETA-INF/services/org.slf4j.spi.SLF4JServiceProvider\\E" + }, { + "pattern":"\\Qclasspath:net/woggioni/rbcs/cli/logback.xml\\E" + }, { + "pattern":"\\Qlogback-test.scmo\\E" + }, { + "pattern":"\\Qlogback.scmo\\E" + }, { + "pattern":"\\Qnet/woggioni/rbcs/cli/logback.xml\\E" + }, { + "pattern":"\\Qnet/woggioni/rbcs/client/schema/rbcs-client.xsd\\E" + }, { + "pattern":"\\Qnet/woggioni/rbcs/server/rbcs-default.xml\\E" + }, { + "pattern":"\\Qnet/woggioni/rbcs/server/schema/rbcs-server.xsd\\E" + }, { + "pattern":"java.base:\\Qsun/text/resources/LineBreakIteratorData\\E" + }]}, + "bundles":[{ + "name":"com.sun.org.apache.xerces.internal.impl.xpath.regex.message", + "locales":[""] + }] } diff --git a/rbcs-cli/native-image/serialization-config.json b/rbcs-cli/native-image/serialization-config.json index d82df4f..eeca1e0 100644 --- a/rbcs-cli/native-image/serialization-config.json +++ b/rbcs-cli/native-image/serialization-config.json @@ -1,5 +1,8 @@ { "types":[ + { + "name":"java.lang.String" + }, { "name":"net.woggioni.rbcs.api.CacheValueMetadata" } diff --git a/rbcs-cli/src/graal/kotlin/net/woggioni/rbcs/cli/graal/GraalNativeImageConfiguration.kt b/rbcs-cli/src/configureNativeImage/kotlin/net/woggioni/rbcs/cli/graal/GraalNativeImageConfiguration.kt similarity index 79% rename from rbcs-cli/src/graal/kotlin/net/woggioni/rbcs/cli/graal/GraalNativeImageConfiguration.kt rename to rbcs-cli/src/configureNativeImage/kotlin/net/woggioni/rbcs/cli/graal/GraalNativeImageConfiguration.kt index fb10590..2da3fcb 100644 --- a/rbcs-cli/src/graal/kotlin/net/woggioni/rbcs/cli/graal/GraalNativeImageConfiguration.kt +++ b/rbcs-cli/src/configureNativeImage/kotlin/net/woggioni/rbcs/cli/graal/GraalNativeImageConfiguration.kt @@ -1,12 +1,14 @@ package net.woggioni.rbcs.cli.graal +import net.woggioni.jwo.NullOutputStream import net.woggioni.rbcs.api.Configuration import net.woggioni.rbcs.api.Configuration.User import net.woggioni.rbcs.api.Role import net.woggioni.rbcs.cli.RemoteBuildCacheServerCli import net.woggioni.rbcs.cli.impl.commands.BenchmarkCommand +import net.woggioni.rbcs.cli.impl.commands.GetCommand import net.woggioni.rbcs.cli.impl.commands.HealthCheckCommand -import net.woggioni.rbcs.client.RemoteBuildCacheClient +import net.woggioni.rbcs.cli.impl.commands.PutCommand import net.woggioni.rbcs.common.HostAndPort import net.woggioni.rbcs.common.PasswordSecurity.hashPassword import net.woggioni.rbcs.common.RBCS @@ -16,12 +18,15 @@ import net.woggioni.rbcs.server.cache.FileSystemCacheConfiguration import net.woggioni.rbcs.server.cache.InMemoryCacheConfiguration import net.woggioni.rbcs.server.configuration.Parser import net.woggioni.rbcs.server.memcache.MemcacheCacheConfiguration +import java.io.ByteArrayInputStream import java.net.URI import java.nio.file.Path import java.time.Duration import java.time.temporal.ChronoUnit import java.util.concurrent.ExecutionException import java.util.zip.Deflater +import net.woggioni.rbcs.client.Configuration as ClientConfiguration +import net.woggioni.rbcs.client.impl.Parser as ClientConfigurationParser object GraalNativeImageConfiguration { @JvmStatic @@ -30,15 +35,16 @@ object GraalNativeImageConfiguration { val serverDoc = RemoteBuildCacheServer.DEFAULT_CONFIGURATION_URL.openStream().use { Xml.parseXml(RemoteBuildCacheServer.DEFAULT_CONFIGURATION_URL, it) } - Parser.parse(doc) + Parser.parse(serverDoc) - val clientDoc = RemoteBuildCacheClient.Configuration.openStream().use { - Xml.parseXml(RemoteBuildCacheServer.DEFAULT_CONFIGURATION_URL, it) + val url = URI.create("file:conf/rbcs-client.xml").toURL() + val clientDoc = url.openStream().use { + Xml.parseXml(url, it) } - Parser.parse(doc) + ClientConfigurationParser.parse(clientDoc) val PASSWORD = "password" - val readersGroup = Configuration.Group("readers", setOf(Role.Reader), null, null) + val readersGroup = Configuration.Group("readers", setOf(Role.Reader, Role.Healthcheck), null, null) val writersGroup = Configuration.Group("writers", setOf(Role.Writer), null, null) @@ -126,30 +132,44 @@ object GraalNativeImageConfiguration { val serverHandle = RemoteBuildCacheServer(serverConfiguration).run() - val clientProfile = RemoteBuildCacheClient.Configuration.Profile( + val clientProfile = ClientConfiguration.Profile( URI.create("http://127.0.0.1:$serverPort/"), null, - RemoteBuildCacheClient.Configuration.Authentication.BasicAuthenticationCredentials("user3", PASSWORD), + ClientConfiguration.Authentication.BasicAuthenticationCredentials("user3", PASSWORD), Duration.ofSeconds(3), 10, true, - RemoteBuildCacheClient.Configuration.RetryPolicy( + ClientConfiguration.RetryPolicy( 3, 1000, 1.2 ), - RemoteBuildCacheClient.Configuration.TrustStore(null, null, false, false) + ClientConfiguration.TrustStore(null, null, false, false) ) - HealthCheckCommand.run(clientProfile) + HealthCheckCommand.execute(clientProfile) - BenchmarkCommand.run( + BenchmarkCommand.execute( clientProfile, 1000, 0x100, true ) + PutCommand.execute( + clientProfile, + "some-file.bin", + ByteArrayInputStream(ByteArray(0x1000) { it.toByte() }), + "application/octet-setream", + "attachment; filename=\"some-file.bin\"" + ) + + GetCommand.execute( + clientProfile, + "some-file.bin", + NullOutputStream() + ) + serverHandle.sendShutdownSignal() try { serverHandle.get() diff --git a/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/BenchmarkCommand.kt b/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/BenchmarkCommand.kt index b447497..5d36b20 100644 --- a/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/BenchmarkCommand.kt +++ b/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/BenchmarkCommand.kt @@ -30,10 +30,10 @@ class BenchmarkCommand : RbcsCommand() { companion object { private val log = createLogger() - fun run(profile : Configuration.Profile, - numberOfEntries : Int, - entrySize : Int, - useRandomValue : Boolean, + fun execute(profile : Configuration.Profile, + numberOfEntries : Int, + entrySize : Int, + useRandomValue : Boolean, ) { val progressThreshold = LongMath.ceilDiv(numberOfEntries.toLong(), 20) RemoteBuildCacheClient(profile).use { client -> @@ -176,7 +176,7 @@ class BenchmarkCommand : RbcsCommand() { clientCommand.configuration.profiles[profileName] ?: throw IllegalArgumentException("Profile $profileName does not exist in configuration") } - run( + execute( profile, numberOfEntries, size, diff --git a/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/GetCommand.kt b/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/GetCommand.kt index 2aeae17..e7d2d45 100644 --- a/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/GetCommand.kt +++ b/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/GetCommand.kt @@ -1,9 +1,11 @@ package net.woggioni.rbcs.cli.impl.commands import net.woggioni.rbcs.cli.impl.RbcsCommand +import net.woggioni.rbcs.client.Configuration import net.woggioni.rbcs.client.RemoteBuildCacheClient import net.woggioni.rbcs.common.createLogger import picocli.CommandLine +import java.io.OutputStream import java.nio.file.Files import java.nio.file.Path @@ -13,8 +15,20 @@ import java.nio.file.Path showDefaultValues = true ) class GetCommand : RbcsCommand() { - companion object{ + companion object { private val log = createLogger() + + fun execute(profile : Configuration.Profile, key : String, outputStream: OutputStream) { + RemoteBuildCacheClient(profile).use { client -> + client.get(key).thenApply { value -> + value?.let { + outputStream.use { + it.write(value) + } + } ?: throw NoSuchElementException("No value found for key $key") + }.get() + } + } } @CommandLine.Spec @@ -40,14 +54,6 @@ class GetCommand : RbcsCommand() { clientCommand.configuration.profiles[profileName] ?: throw IllegalArgumentException("Profile $profileName does not exist in configuration") } - RemoteBuildCacheClient(profile).use { client -> - client.get(key).thenApply { value -> - value?.let { - (output?.let(Files::newOutputStream) ?: System.out).use { - it.write(value) - } - } ?: throw NoSuchElementException("No value found for key $key") - }.get() - } + execute(profile, key, (output?.let(Files::newOutputStream) ?: System.out)) } } \ No newline at end of file diff --git a/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/HealthCheckCommand.kt b/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/HealthCheckCommand.kt index 2177c31..08154d3 100644 --- a/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/HealthCheckCommand.kt +++ b/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/HealthCheckCommand.kt @@ -17,7 +17,7 @@ class HealthCheckCommand : RbcsCommand() { companion object{ private val log = createLogger() - fun run(profile : Configuration.Profile) { + fun execute(profile : Configuration.Profile) { RemoteBuildCacheClient(profile).use { client -> val random = Random(SecureRandom.getInstance("NativePRNGNonBlocking").nextLong()) val nonce = ByteArray(0xa0) @@ -48,6 +48,6 @@ class HealthCheckCommand : RbcsCommand() { clientCommand.configuration.profiles[profileName] ?: throw IllegalArgumentException("Profile $profileName does not exist in configuration") } - run(profile) + execute(profile) } } \ No newline at end of file diff --git a/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/PutCommand.kt b/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/PutCommand.kt index dc0fcc5..cdd6fbd 100644 --- a/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/PutCommand.kt +++ b/rbcs-cli/src/main/kotlin/net/woggioni/rbcs/cli/impl/commands/PutCommand.kt @@ -5,6 +5,7 @@ import net.woggioni.jwo.JWO import net.woggioni.jwo.NullOutputStream import net.woggioni.rbcs.api.CacheValueMetadata import net.woggioni.rbcs.cli.impl.RbcsCommand +import net.woggioni.rbcs.client.Configuration import net.woggioni.rbcs.client.RemoteBuildCacheClient import net.woggioni.rbcs.common.createLogger import picocli.CommandLine @@ -19,8 +20,22 @@ import java.util.UUID showDefaultValues = true ) class PutCommand : RbcsCommand() { - companion object{ + companion object { private val log = createLogger() + + fun execute(profile: Configuration.Profile, + actualKey : String, + inputStream: InputStream, + mimeType : String?, + contentDisposition: String? + ) { + RemoteBuildCacheClient(profile).use { client -> + inputStream.use { + client.put(actualKey, it.readAllBytes(), CacheValueMetadata(contentDisposition, mimeType)) + }.get() + println(profile.serverURI.resolve(actualKey)) + } + } } @@ -92,10 +107,7 @@ class PutCommand : RbcsCommand() { } actualKey = key ?: UUID.randomUUID().toString() } - inputStream.use { - client.put(actualKey, it.readAllBytes(), CacheValueMetadata(contentDisposition, mimeType)) - }.get() - println(profile.serverURI.resolve(actualKey)) + execute(profile, actualKey, inputStream, mimeType, contentDisposition) } } } \ No newline at end of file