Skip to content

Commit

Permalink
Isolate Dropwizard and HK2 dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
adutra committed Dec 10, 2024
1 parent 99e128a commit 73dd313
Show file tree
Hide file tree
Showing 149 changed files with 357 additions and 236 deletions.
4 changes: 1 addition & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# under the License.
#

polaris-service/logs
polaris-service/build
polaris-core/build
polaris-service/dropwizard/logs
build
.idea
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
name: upload-test-artifacts
path: |
polaris-core/build/test-results/test
polaris-service/build/test-results/test
polaris-service/dropwizard/build/test-results/test
# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
Expand Down
2 changes: 1 addition & 1 deletion aggregated-license-report/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.gradle.kotlin.dsl.support.unzipTo
val licenseReports by configurations.creating { description = "Used to generate license reports" }

dependencies {
licenseReports(project(":polaris-service", "licenseReports"))
licenseReports(project(":polaris-service-dropwizard", "licenseReports"))
}

val collectLicenseReportJars by
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ tasks.named<RatTask>("rat").configure {
excludes.add("gradle/wrapper/gradle-wrapper*.jar*")

excludes.add("logs/**")
excludes.add("polaris-service/src/**/banner.txt")
excludes.add("polaris-service/logs")
excludes.add("polaris-service/common/src/**/banner.txt")
excludes.add("polaris-service/dropwizard/logs")

excludes.add("site/node_modules/**")
excludes.add("site/layouts/robots.txt")
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ iceberg-bom = { module = "org.apache.iceberg:iceberg-bom", version.ref = "iceber
jackson-bom = { module = "com.fasterxml.jackson:jackson-bom", version = "2.17.2" }
jakarta-annotation-api = { module = "jakarta.annotation:jakarta.annotation-api", version = "3.0.0" }
jakarta-inject-api = { module = "jakarta.inject:jakarta.inject-api", version = "2.0.1" }
jakarta-validation-api = { module = "jakarta.validation:jakarta.validation-api", version = "3.1.0" }
jakarta-persistence-api = { module = "jakarta.persistence:jakarta.persistence-api", version = "3.1.0" }
jakarta-servlet-api = { module = "jakarta.servlet:jakarta.servlet-api", version = "6.1.0" }
jakarta-validation-api = { module = "jakarta.validation:jakarta.validation-api", version = "3.0.2" }
jakarta-ws-rs-api = { module = "jakarta.ws.rs:jakarta.ws.rs-api", version = "3.1.0" }
javax-annotation-api = { module = "javax.annotation:javax.annotation-api", version = "1.3.2" }
javax-inject = { module = "javax.inject:javax.inject", version = "1" }
jetbrains-annotations = { module = "org.jetbrains:annotations", version = "24.1.0" }
junit-bom = { module = "org.junit:junit-bom", version = "5.10.3" }
logback-core = { module = "ch.qos.logback:logback-core", version = "1.4.14" }
Expand Down
3 changes: 2 additions & 1 deletion gradle/projects.main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#

polaris-core=polaris-core
polaris-service=polaris-service
polaris-service-common=polaris-service/common
polaris-service-dropwizard=polaris-service/dropwizard
polaris-eclipselink=extension/persistence/eclipselink
polaris-jpa-model=extension/persistence/jpa-model
aggregated-license-report=aggregated-license-report
1 change: 0 additions & 1 deletion polaris-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ dependencies {
}
}

implementation(libs.javax.inject)
implementation(libs.swagger.annotations)
implementation(libs.swagger.jaxrs)
implementation(libs.jakarta.inject.api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@
* under the License.
*/

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask

plugins {
alias(libs.plugins.openapi.generator)
id("polaris-server")
id("polaris-license-report")
id("polaris-shadow-jar")
id("application")
}

dependencies {
Expand All @@ -35,6 +31,7 @@ dependencies {
implementation("org.apache.iceberg:iceberg-api")
implementation("org.apache.iceberg:iceberg-core")
implementation("org.apache.iceberg:iceberg-aws")

implementation(libs.hadoop.common) {
exclude("org.slf4j", "slf4j-reload4j")
exclude("org.slf4j", "slf4j-log4j12")
Expand All @@ -48,36 +45,26 @@ dependencies {
exclude("com.sun.jersey", "jersey-servlet")
}
implementation(libs.hadoop.hdfs.client)
implementation(libs.smallrye.common.annotation)

implementation(platform(libs.dropwizard.bom))
implementation("io.dropwizard:dropwizard-core")
implementation("io.dropwizard:dropwizard-auth")
implementation("io.dropwizard:dropwizard-json-logging")
compileOnly(libs.jakarta.annotation.api)
compileOnly(libs.jakarta.inject.api)
compileOnly(libs.jakarta.servlet.api)
compileOnly(libs.jakarta.validation.api)
compileOnly(libs.jakarta.ws.rs.api)

compileOnly(libs.smallrye.common.annotation)

implementation(platform(libs.jackson.bom))
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
implementation("com.fasterxml.jackson.core:jackson-annotations")

implementation(platform(libs.opentelemetry.bom))
implementation("io.opentelemetry:opentelemetry-api")
implementation("io.opentelemetry:opentelemetry-sdk-trace")
implementation("io.opentelemetry:opentelemetry-exporter-logging")
implementation(libs.opentelemetry.semconv)

implementation(libs.caffeine)
implementation(libs.guava)
implementation(libs.slf4j.api)

implementation(libs.prometheus.metrics.exporter.servlet.jakarta)
implementation(platform(libs.micrometer.bom))
implementation("io.micrometer:micrometer-core")
implementation("io.micrometer:micrometer-registry-prometheus")

compileOnly(libs.swagger.annotations)
compileOnly(libs.spotbugs.annotations)
implementation(libs.swagger.jaxrs)
implementation(libs.javax.annotation.api)

implementation(libs.hadoop.client.api)

Expand All @@ -86,49 +73,16 @@ dependencies {
implementation(libs.logback.core)
implementation(libs.bouncycastle.bcprov)

compileOnly(libs.jakarta.annotation.api)
compileOnly(libs.spotbugs.annotations)

implementation(platform(libs.google.cloud.storage.bom))
implementation("com.google.cloud:google-cloud-storage")

implementation(platform(libs.awssdk.bom))
implementation("software.amazon.awssdk:sts")
implementation("software.amazon.awssdk:iam-policy-builder")
implementation("software.amazon.awssdk:s3")

implementation(platform(libs.azuresdk.bom))
implementation("com.azure:azure-core")

testImplementation("org.apache.iceberg:iceberg-api:${libs.versions.iceberg.get()}:tests")
testImplementation("org.apache.iceberg:iceberg-core:${libs.versions.iceberg.get()}:tests")
testImplementation("io.dropwizard:dropwizard-testing")
testImplementation(platform(libs.testcontainers.bom))
testImplementation("org.testcontainers:testcontainers")
testImplementation(libs.s3mock.testcontainers)

testImplementation("org.apache.iceberg:iceberg-spark-3.5_2.12")
testImplementation("org.apache.iceberg:iceberg-spark-extensions-3.5_2.12")
testImplementation("org.apache.spark:spark-sql_2.12:3.5.1") {
// exclude log4j dependencies
exclude("org.apache.logging.log4j", "log4j-slf4j2-impl")
exclude("org.apache.logging.log4j", "log4j-api")
exclude("org.apache.logging.log4j", "log4j-1.2-api")
}

testImplementation("software.amazon.awssdk:glue")
testImplementation("software.amazon.awssdk:kms")
testImplementation("software.amazon.awssdk:dynamodb")

testImplementation(platform(libs.junit.bom))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation(libs.assertj.core)
testImplementation(libs.mockito.core)
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

testImplementation(project(":polaris-eclipselink"))
}

if (project.properties.get("eclipseLink") == "true") {
dependencies { implementation(project(":polaris-eclipselink")) }
}

openApiGenerate {
Expand Down Expand Up @@ -223,57 +177,3 @@ listOf("sourcesJar", "compileJava").forEach { task ->
sourceSets {
main { java { srcDir(project.layout.buildDirectory.dir("generated/src/main/java")) } }
}

tasks.named<Test>("test").configure {
if (System.getenv("AWS_REGION") == null) {
environment("AWS_REGION", "us-west-2")
}
jvmArgs("--add-exports", "java.base/sun.nio.ch=ALL-UNNAMED")
useJUnitPlatform()
maxParallelForks = 4
}

tasks.register<JavaExec>("runApp").configure {
if (System.getenv("AWS_REGION") == null) {
environment("AWS_REGION", "us-west-2")
}
classpath = sourceSets["main"].runtimeClasspath
mainClass = "org.apache.polaris.service.PolarisApplication"
args("server", "$rootDir/polaris-server.yml")
}

application { mainClass = "org.apache.polaris.service.PolarisApplication" }

tasks.named<Jar>("jar") {
manifest { attributes["Main-Class"] = "org.apache.polaris.service.PolarisApplication" }
}

tasks.register<Jar>("testJar") {
archiveClassifier.set("tests")
from(sourceSets.test.get().output)
}

val shadowJar =
tasks.named<ShadowJar>("shadowJar") {
manifest { attributes["Main-Class"] = "org.apache.polaris.service.PolarisApplication" }
mergeServiceFiles()
append("META-INF/hk2-locator/default")
isZip64 = true
finalizedBy("startScripts")
}

val startScripts =
tasks.named<CreateStartScripts>("startScripts") {
classpath = files(provider { shadowJar.get().archiveFileName })
}

tasks.register<Sync>("prepareDockerDist") {
into(project.layout.buildDirectory.dir("docker-dist"))
from(startScripts) { into("bin") }
from(shadowJar) { into("lib") }
doFirst { delete(project.layout.buildDirectory.dir("regtest-dist")) }
}

tasks.named("build").configure { dependsOn("prepareDockerDist") }

tasks.named("assemble").configure { dependsOn("testJar") }
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.polaris.service.config;
package org.apache.polaris.service.auth;

import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
import java.security.Principal;
import java.util.Optional;

public interface HasMetaStoreManagerFactory {
void setMetaStoreManagerFactory(MetaStoreManagerFactory metaStoreManagerFactory);
public interface Authenticator<C, P extends Principal> {

Optional<P> authenticate(String credentials);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.polaris.service.auth;

import io.dropwizard.auth.Authenticator;
import jakarta.inject.Inject;
import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -40,12 +39,11 @@
import org.slf4j.LoggerFactory;

/**
* Base implementation of {@link DiscoverableAuthenticator} constructs a {@link
* AuthenticatedPolarisPrincipal} from the token parsed by subclasses. The {@link
* AuthenticatedPolarisPrincipal} is read from the {@link PolarisMetaStoreManager} for the current
* {@link RealmContext}. If the token defines a non-empty set of scopes, only the principal roles
* specified in the scopes will be active for the current principal. Only the grants assigned to
* these roles will be active in the current request.
* Base implementation of {@link Authenticator} constructs a {@link AuthenticatedPolarisPrincipal}
* from the token parsed by subclasses. The {@link AuthenticatedPolarisPrincipal} is read from the
* {@link PolarisMetaStoreManager} for the current {@link RealmContext}. If the token defines a
* non-empty set of scopes, only the principal roles specified in the scopes will be active for the
* current principal. Only the grants assigned to these roles will be active in the current request.
*/
public abstract class BasePolarisAuthenticator
implements Authenticator<String, AuthenticatedPolarisPrincipal> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.polaris.service.auth;

import com.google.common.base.Splitter;
import io.dropwizard.auth.AuthenticationException;
import io.smallrye.common.annotation.Identifier;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -35,8 +34,8 @@
import org.slf4j.LoggerFactory;

/**
* {@link io.dropwizard.auth.Authenticator} that parses a token as a sequence of key/value pairs.
* Specifically, we expect to find
* {@link Authenticator} that parses a token as a sequence of key/value pairs. Specifically, we
* expect to find
*
* <ul>
* <li>principal - the clientId of the principal
Expand All @@ -52,8 +51,7 @@ public class TestInlineBearerTokenPolarisAuthenticator extends BasePolarisAuthen
LoggerFactory.getLogger(TestInlineBearerTokenPolarisAuthenticator.class);

@Override
public Optional<AuthenticatedPolarisPrincipal> authenticate(String credentials)
throws AuthenticationException {
public Optional<AuthenticatedPolarisPrincipal> authenticate(String credentials) {
Map<String, String> properties = extractPrincipal(credentials);
PolarisMetaStoreManager metaStoreManager =
metaStoreManagerFactory.getOrCreateMetaStoreManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@
*/
package org.apache.polaris.service.exception;

import io.dropwizard.jersey.validation.JerseyViolationException;
import jakarta.validation.ConstraintViolationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import org.apache.iceberg.rest.responses.ErrorResponse;

/**
* Override of the default JerseyViolationExceptionMapper to provide an Iceberg ErrorResponse with
* the exception details.
*/
@Provider
public class IcebergJerseyViolationExceptionMapper
implements ExceptionMapper<JerseyViolationException> {
public class IcebergConstraintViolationExceptionMapper
implements ExceptionMapper<ConstraintViolationException> {
@Override
public Response toResponse(JerseyViolationException exception) {
public Response toResponse(ConstraintViolationException exception) {
final String message = "Invalid value: " + exception.getMessage();
ErrorResponse icebergErrorResponse =
ErrorResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import java.util.Arrays;
import java.util.Collection;
import java.util.Locale;
Expand Down Expand Up @@ -56,6 +57,7 @@
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.s3.model.S3Exception;

@Provider
public class IcebergExceptionMapper implements ExceptionMapper<RuntimeException> {
private static final Logger LOGGER = LoggerFactory.getLogger(IcebergExceptionMapper.class);

Expand Down
Loading

0 comments on commit 73dd313

Please sign in to comment.