Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Polaris Apprunner Gradle and Maven Plugins #785

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

snazy
Copy link
Member

@snazy snazy commented Jan 15, 2025

This change introduces Gradle and Maven plugins to run Polaris Quarkus server for integration tests. This work is based on projectnessie's apprunner.

The Gradle plugin can be used in other project and in the Polaris "main" code base.

Integration tests of the plugin still use Nessie artifacts to satisfy the need for integration tests of the plugins against binary released available on Maven Central. The actual application, whether it's Polaris or Nessie or any other Quarkus (web) application, not really matter - all work, as long as the syntax of the log message emitted by Quarkus is the same.

Noting that this is intentionally implemented as a "Gradle included build", so that the Polaris "main" build can actually use the Plugin and that it could be released independently, if needed.

Hopefully extensive documentation is included in the README.md in tools/apprunner.

@snazy
Copy link
Member Author

snazy commented Jan 15, 2025

Well, it actually works from an included-build :)

The below patch, running ./gradlew :polaris-quarkus-server:demoTest --info shows the Polaris server starting up (and being shutdown).

diff --git a/quarkus/server/build.gradle.kts b/quarkus/server/build.gradle.kts
index 83e94435d..94f39b026 100644
--- a/quarkus/server/build.gradle.kts
+++ b/quarkus/server/build.gradle.kts
@@ -17,14 +17,22 @@
  * under the License.
  */
 
+import io.quarkus.gradle.tasks.QuarkusBuild
+
 plugins {
   alias(libs.plugins.quarkus)
   alias(libs.plugins.openapi.generator)
   id("polaris-server")
   id("polaris-license-report")
   id("distribution")
+  id("org.apache.polaris.apprunner")
 }
 
+val quarkusRunner by
+  configurations.creating {
+    description = "Used to reference the generated runner-jar (either fast-jar or uber-jar)"
+  }
+
 dependencies {
   implementation(project(":polaris-core"))
   implementation(project(":polaris-api-management-service"))
@@ -38,6 +46,8 @@ dependencies {
 
   // override dnsjava version in dependencies due to https://github.com/dnsjava/dnsjava/issues/329
   implementation(platform(libs.dnsjava))
+
+  polarisQuarkusServer(project(":polaris-quarkus-server", "quarkusRunner"))
 }
 
 quarkus {
@@ -71,3 +81,44 @@ distributions {
     }
   }
 }
+
+testing {
+  suites {
+    val demoTest by registering(JvmTestSuite::class)
+  }
+}
+
+val quarkusFatJar = project.hasProperty("uber-jar")
+val quarkusBuild = tasks.named<QuarkusBuild>("quarkusBuild")
+
+// Expose runnable jar via quarkusRunner configuration for integration-tests that require the
+// server.
+artifacts {
+  add(
+    quarkusRunner.name,
+    provider {
+      if (quarkusFatJar) quarkusBuild.get().runnerJar
+      else quarkusBuild.get().fastJar.resolve("quarkus-run.jar")
+    },
+  ) {
+    builtBy(quarkusBuild)
+  }
+}
+
+// Add the uber-jar, if built, to the Maven publication
+if (quarkusFatJar) {
+  afterEvaluate {
+    publishing {
+      publications {
+        named<MavenPublication>("maven") {
+          artifact(quarkusBuild.get().runnerJar) {
+            classifier = "runner"
+            builtBy(quarkusBuild)
+          }
+        }
+      }
+    }
+  }
+}
+
+polarisQuarkusApp { includeTask(tasks.named("demoTest")) }
diff --git a/quarkus/server/src/demoTest/java/foo/DemoTest.java b/quarkus/server/src/demoTest/java/foo/DemoTest.java
new file mode 100644
index 000000000..e2e2dd81a
--- /dev/null
+++ b/quarkus/server/src/demoTest/java/foo/DemoTest.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 foo;
+
+import org.junit.jupiter.api.Test;
+
+public class DemoTest {
+    @Test
+    public void test() {}
+}

@snazy snazy changed the title Polaris Apprunner Gradle Plugin Polaris Apprunner Gradle and Maven Plugins Jan 16, 2025
snazy added a commit to snazy/polaris that referenced this pull request Jan 16, 2025
The publishing-helper in Polaris derives the name and description used in the parent POM from ASF's published project information. If an Apache projects wants to publish the parent pom for a _related_ project, the name and description in the pom (may) need to be different (as for apache#785). This change allows this.
snazy added a commit to snazy/polaris that referenced this pull request Jan 16, 2025
When adding an included build to the Polaris main repo, the (Maven) group ID _must_ be different. This change allows sharing (symling) the `gradle.properties` file with an included build (apache#785 in this case).
@snazy snazy force-pushed the apprunner branch 2 times, most recently from 8eb98f5 to 1c3fba8 Compare January 16, 2025 09:49
@snazy snazy force-pushed the apprunner branch 2 times, most recently from b2f65fd to 018fa4f Compare January 16, 2025 13:13
snazy added a commit that referenced this pull request Jan 16, 2025
When adding an included build to the Polaris main repo, the (Maven) group ID _must_ be different. This change allows sharing (symling) the `gradle.properties` file with an included build (#785 in this case).
@collado-mike
Copy link
Contributor

When this PR is ready for review, can you update the description or add an issue explaining why this build change is necessary? This seems like it radically complicates the build to something that is much harder to understand and I think it would be good to clarify why that complexity is needed over the blackbox test setup that @dimas-b added previously.

@snazy
Copy link
Member Author

snazy commented Jan 17, 2025

When this PR is ready for review, can you update the description or add an issue explaining why this build change is necessary? This seems like it radically complicates the build to something that is much harder to understand and I think it would be good to clarify why that complexity is needed over the blackbox test setup that @dimas-b added previously.

I've added a README to the PR hopefully explaining lots of it.
The reason is to be able to use the plugin in the main Polaris code base - it completely separates any kind of tests against the in-tree Polaris server. Another reason is that there is (naturally) no release of these plugins yet - so it would be impossible to use those. We can certainly later decide to move this stuff into a separate Git repo - but for now this is the actually only way to use the plugin(s).

snazy added a commit that referenced this pull request Jan 21, 2025
The publishing-helper in Polaris derives the name and description used in the parent POM from ASF's published project information. If an Apache projects wants to publish the parent pom for a _related_ project, the name and description in the pom (may) need to be different (as for #785). This change allows this.
@snazy snazy force-pushed the apprunner branch 3 times, most recently from 5003c21 to cd9a3e7 Compare January 27, 2025 13:24
@snazy
Copy link
Member Author

snazy commented Jan 27, 2025

Updated the "actual" change w/ changes for polaris-quarkus-server + added a demo (just for review purposes) as a separate commit. That demo can be run with

./gradlew :apprunner-demo:demoTest --info --rerun

and shows something like this illustrating that the actual HTTP ports are available in the test to be run. Noteworthy: the server is only started, when the Gradle test task needs to run. (line wraps by me)

Starting process: [.../java, -Dquarkus.http.port=0, -Dquarkus.management.port=0, -Dquarkus.log.level=INFO, -Dquarkus.log.console.level=INFO, -jar, /home/snazy/devel/polaris/polaris/quarkus/server/build/quarkus-app/quarkus-run.jar]
[output] realm: POLARIS root principal credentials: fbd8c4aea9fd96ac:2710f409041047ecad21aeb791f114a8
[output] 
[output]  @@@@   @@@  @       @    @@@@   @  @@@@    @@@@    @  @@@@@  @    @     @@@   @@@@
[output]  @   @ @   @ @      @ @   @   @  @  @@     @       @ @   @   @ @   @    @   @ @     
[output]  @@@@  @   @ @     @@@@@  @@@@   @    @@   @      @@@@@  @  @@@@@  @    @   @ @  @@@
[output]  @      @@@  @@@@ @     @ @  @@  @  @@@@    @@@@ @     @ @ @@   @@ @@@@  @@@   @@@@ 
[output]                                                                                     
[output]                      *
[output]                                                                                     
[output]                                                                                     
[output]                                       /////\                                        
[output]                                    //\\///T\\\                                      
[output]                                 ///\\\////\\\\\\                                    
[output]                                //\\\\T////\\\\\\\\\                                 
[output]                           /T\ //\\\\\T///T\\//T\\\\\\                               
[output]                         //\\\/////T\\////\\/////\\\\\\\  //\\                       
[output]                      //\\\\\\T///////////////////T\\\\\\\T\\\\\                     
[output]                   //\\\\/////T\//////////\///////T\\\\\T\\\\\\\\                    
[output]                  //\\\\\/////\\\T////////////////\\\\\\/\\\\\\\\\                   
[output] ,,..,,,..,,,..,//\\\\////////\\\\\\\\\\/////////\\\\\///\\\\\\\\\\,,,..,,..,,,..,,,.
[output] ,,..,,,..,,,..,,,..,,,..,,,..,,,..,,,..,,,..,,,..,,,..,,,..,,,..,,,..,,,.,,,..,,,..,
[output] 
[output]                                                            Powered by Quarkus 3.17.8
[output] 2025-01-27 14:20:59,121 INFO  [io.quarkus] [,] [,,,] (main) Apache Polaris Server (incubating) 1.0.0-incubating-SNAPSHOT on JVM (powered by Quarkus 3.17.8) started in 1.270s. 
    Listening on: http://0.0.0.0:38495. Management interface listening on http://0.0.0.0:37345.
...
Starting process 'Gradle Test Executor 17'. Working directory: /home/snazy/devel/polaris/polaris/apprunner-demo Command: /home/snazy/.sdkman/candidates/java/23.0.2-zulu/bin/java 
   -Dquarkus.http.test-port=38495 -Dquarkus.http.test-url=http://0.0.0.0:38495
   -Dquarkus.management.test-port=37345 -Dquarkus.management.test-url=http://0.0.0.0:37345 ...
Successfully started process 'Gradle Test Executor 17'

DemoTest > test() STANDARD_ERROR
    38495
    http://0.0.0.0:38495
    37345
    http://0.0.0.0:37345

@snazy
Copy link
Member Author

snazy commented Jan 27, 2025

Depending on whether an uber-jar (#797) or a distribution tarball/zip would be released to Maven Central additional changes might be necessary to let the apprunner deal with released distributables. The latter would also depend on how the contents of an (extracted) distributable tarball/zip looks like.

@snazy snazy force-pushed the apprunner branch 2 times, most recently from 36aa13f to c0a2c0f Compare February 2, 2025 12:16
@ajantha-bhat
Copy link
Member

This can be helpful for the test framework of catalog migrator. Are we planning to merge this soon?

@snazy
Copy link
Member Author

snazy commented Feb 27, 2025

Extracted the 2nd commit as #1082

snazy added 2 commits March 22, 2025 11:25
This change introduces Gradle and Maven plugins to run Polaris Quarkus server for integration tests. This work is based on [projectnessie's apprunner](https://github.com/projectnessie/nessie-apprunner).

The Gradle plugin can be used in other project and in the Polaris "main" code base.

Integration tests of the plugin still use Nessie artifacts to satisfy the need for integration tests of the plugins against binary released available on Maven Central. The actual application, whether it's Polaris or Nessie or any other Quarkus (web) application, not really matter - all work, as long as the syntax of the log message emitted by Quarkus is the same.

Noting that this is intentionally implemented as a "Gradle included build", so that the Polaris "main" build can actually use the Plugin and that it could be released independently, if needed.

Hopefully extensive documentation is included in the `README.md` in `tools/apprunner`.
Adds the tar+zip distribution archives as publishable artifacts to Maven publication.

Also updates polaris-quarkus-admin to build as a "fast-jar" instead of an "uber-jar".
@snazy snazy force-pushed the apprunner branch 2 times, most recently from ab7806a to ce418f6 Compare March 22, 2025 10:39
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants