Skip to content

Commit

Permalink
Server code on Java 21, client code on Java 11 (apache#106)
Browse files Browse the repository at this point in the history
According to the discussion apache#100, this change enforces Java release 21 for server code and 11 for client consumable code.

Using Java 11 requires some changes to `:polaris-core`. One new BSD-3-Clause licensed test dependency `org.threeten:threeten-extra` was added to provide a mutable clock to replace `java.time.InstantSource`.
  • Loading branch information
snazy authored Aug 7, 2024
1 parent 7ce0945 commit c07e687
Show file tree
Hide file tree
Showing 20 changed files with 272 additions and 211 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Base Image
# Use a non-docker-io registry, because pulling images from docker.io is
# subject to aggressive request rate limiting and bandwidth shaping.
FROM registry.access.redhat.com/ubi9/openjdk-21-runtime as build
FROM registry.access.redhat.com/ubi9/openjdk-21:1.20-2.1721752936 as build

# Copy the REST catalog into the container
COPY --chown=default:root . /app
Expand All @@ -28,7 +28,7 @@ RUN rm -rf build
# Build the rest catalog
RUN ./gradlew --no-daemon --info clean shadowJar

FROM registry.access.redhat.com/ubi9/openjdk-21-runtime
FROM registry.access.redhat.com/ubi9/openjdk-21-runtime:1.20-2.1721752928
WORKDIR /app
COPY --from=build /app/polaris-service/build/libs/polaris-service-1.0.0-all.jar /app
COPY --from=build /app/polaris-server.yml /app
Expand Down
21 changes: 21 additions & 0 deletions build-logic/src/main/kotlin/polaris-client.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Snowflake Computing Inc.
*
* 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.
*/

import org.gradle.api.tasks.compile.JavaCompile

plugins { id("polaris-java") }

tasks.withType(JavaCompile::class.java).configureEach { options.release = 11 }
74 changes: 74 additions & 0 deletions build-logic/src/main/kotlin/polaris-java.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2024 Snowflake Computing Inc.
*
* 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.
*/

import net.ltgt.gradle.errorprone.errorprone
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.named

plugins {
id("jacoco")
id("java")
id("com.diffplug.spotless")
id("jacoco-report-aggregation")
id("net.ltgt.errorprone")
}

tasks.withType(JavaCompile::class.java).configureEach {
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
options.errorprone.disableAllWarnings = true
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.error("StringCaseLocaleUsage")
}

tasks.register("format").configure { dependsOn("spotlessApply") }

tasks.named<Test>("test").configure {
useJUnitPlatform()
jvmArgs("-Duser.language=en")
}

spotless {
val disallowWildcardImports = { text: String ->
val regex = "~/import .*\\.\\*;/".toRegex()
if (regex.matches(text)) {
throw GradleException("Wildcard imports disallowed - ${regex.findAll(text)}")
}
text
}
java {
target("src/main/java/**/*.java", "src/testFixtures/java/**/*.java", "src/test/java/**/*.java")
googleJavaFormat()
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"))
endWithNewline()
custom("disallowWildcardImports", disallowWildcardImports)
}
kotlinGradle {
ktfmt().googleStyle()
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
target("*.gradle.kts")
}
format("xml") {
target("src/**/*.xml", "src/**/*.xsd")
targetExclude("codestyle/copyright-header.xml")
eclipseWtp(com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.XML)
.configFile(rootProject.file("codestyle/org.eclipse.wst.xml.core.prefs"))
// getting the license-header delimiter right is a bit tricky.
// licenseHeaderFile(rootProject.file("codestyle/copyright-header.xml"), '<^[!?].*$')
}
}

dependencies { errorprone(versionCatalogs.named("libs").findLibrary("errorprone").get()) }
60 changes: 2 additions & 58 deletions build-logic/src/main/kotlin/polaris-server.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,8 @@
* limitations under the License.
*/

import net.ltgt.gradle.errorprone.errorprone
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.named

plugins {
id("jacoco")
id("java")
id("com.diffplug.spotless")
id("jacoco-report-aggregation")
id("net.ltgt.errorprone")
}
plugins { id("polaris-java") }

tasks.withType(JavaCompile::class.java).configureEach {
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
options.errorprone.disableAllWarnings = true
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.error("StringCaseLocaleUsage")

// TODO Disabled until the code is only Java 11/17/21, see #76
// options.release = 17
}

tasks.register("format").configure { dependsOn("spotlessApply") }

tasks.named<Test>("test").configure {
useJUnitPlatform()
jvmArgs("-Duser.language=en")
}

spotless {
val disallowWildcardImports = { text: String ->
val regex = "~/import .*\\.\\*;/".toRegex()
if (regex.matches(text)) {
throw GradleException("Wildcard imports disallowed - ${regex.findAll(text)}")
}
text
}
java {
target("src/main/java/**/*.java", "src/testFixtures/java/**/*.java", "src/test/java/**/*.java")
googleJavaFormat()
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"))
endWithNewline()
custom("disallowWildcardImports", disallowWildcardImports)
}
kotlinGradle {
ktfmt().googleStyle()
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
target("*.gradle.kts")
}
format("xml") {
target("src/**/*.xml", "src/**/*.xsd")
targetExclude("codestyle/copyright-header.xml")
eclipseWtp(com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.XML)
.configFile(rootProject.file("codestyle/org.eclipse.wst.xml.core.prefs"))
// getting the license-header delimiter right is a bit tricky.
// licenseHeaderFile(rootProject.file("codestyle/copyright-header.xml"), '<^[!?].*$')
}
}

dependencies { errorprone(versionCatalogs.named("libs").findLibrary("errorprone").get()) }
tasks.withType(JavaCompile::class.java).configureEach { options.release = 21 }
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ sqllite-jdbc = { module = "org.xerial:sqlite-jdbc", version = "3.45.1.0" }
swagger-annotations = { module = "io.swagger:swagger-annotations", version.ref = "swagger" }
swagger-jaxrs = { module = "io.swagger:swagger-jaxrs", version.ref = "swagger" }
testcontainers-bom = { module = "org.testcontainers:testcontainers-bom", version = "1.20.0" }
threeten-extra = { module = "org.threeten:threeten-extra", version = "1.8.0" }

[plugins]
openapi-generator = { id = "org.openapi.generator", version = "7.6.0" }
Expand Down
3 changes: 2 additions & 1 deletion polaris-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.openapitools.generator.gradle.plugin.tasks.GenerateTask

plugins {
alias(libs.plugins.openapi.generator)
id("polaris-server")
id("polaris-client")
id("java-library")
id("java-test-fixtures")
}
Expand Down Expand Up @@ -113,6 +113,7 @@ dependencies {
testFixturesApi("com.fasterxml.jackson.core:jackson-core")
testFixturesApi("com.fasterxml.jackson.core:jackson-databind")
testFixturesApi(libs.commons.lang3)
testFixturesApi(libs.threeten.extra)
testFixturesApi(libs.jetbrains.annotations)
testFixturesApi(platform(libs.jackson.bom))
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.polaris.core.entity.PolarisEntity;
import java.util.List;
import java.util.stream.Collectors;

/**
* Holds fully-resolved path of PolarisEntities representing the targetEntity with all its grants
Expand Down Expand Up @@ -54,7 +55,7 @@ public List<PolarisEntity> getRawFullPath() {
if (resolvedPath == null) {
return null;
}
return resolvedPath.stream().map(ResolvedPolarisEntity::getEntity).toList();
return resolvedPath.stream().map(ResolvedPolarisEntity::getEntity).collect(Collectors.toList());
}

public List<ResolvedPolarisEntity> getResolvedParentPath() {
Expand All @@ -68,7 +69,9 @@ public List<PolarisEntity> getRawParentPath() {
if (resolvedPath == null) {
return null;
}
return getResolvedParentPath().stream().map(ResolvedPolarisEntity::getEntity).toList();
return getResolvedParentPath().stream()
.map(ResolvedPolarisEntity::getEntity)
.collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.polaris.core.entity.PolarisBaseEntity;
import io.polaris.core.entity.PolarisGrantRecord;
import java.util.List;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;

/** An entry in our entity cache. Note, this is fully immutable */
Expand Down Expand Up @@ -108,13 +109,15 @@ public long getLastAccessedNanoTimestamp() {
}

public @NotNull List<PolarisGrantRecord> getGrantRecordsAsGrantee() {
return grantRecords.stream().filter(record -> record.getGranteeId() == entity.getId()).toList();
return grantRecords.stream()
.filter(record -> record.getGranteeId() == entity.getId())
.collect(Collectors.toList());
}

public @NotNull List<PolarisGrantRecord> getGrantRecordsAsSecurable() {
return grantRecords.stream()
.filter(record -> record.getSecurableId() == entity.getId())
.toList();
.collect(Collectors.toList());
}

public void updateLastAccess() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public PolarisResolvedPathWrapper getPassthroughResolvedPath(Object key) {
"Returning null for key {} due to size mismatch from getPassthroughResolvedPath "
+ "resolvedPath: {}, requestedPath.getEntityNames(): {}",
key,
resolvedPath.stream().map(ResolvedPolarisEntity::new).toList(),
resolvedPath.stream().map(ResolvedPolarisEntity::new).collect(Collectors.toList()),
requestedPath.getEntityNames());
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public ResolverStatus resolveAll() {
"resolver_must_be_successful");
this.diagnostics.check(this.resolvedPaths.size() == 1, "only_if_single");

return resolvedPaths.getFirst();
return resolvedPaths.get(0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import io.polaris.core.storage.aws.AwsStorageConfigurationInfo;
import io.polaris.core.storage.azure.AzureStorageConfigurationInfo;
import io.polaris.core.storage.gcp.GcpStorageConfigurationInfo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
Expand Down Expand Up @@ -136,8 +138,11 @@ public static Optional<PolarisStorageConfigurationInfo> forEntityPath(
.get(PolarisEntityConstants.getStorageConfigInfoPropertyName())))
.map(
configInfo -> {
List<PolarisEntity> entityPathReversed = new ArrayList<>(entityPath);
Collections.reverse(entityPathReversed);

String baseLocation =
entityPath.reversed().stream()
entityPathReversed.stream()
.flatMap(
e ->
Optional.ofNullable(
Expand All @@ -160,25 +165,27 @@ public static Optional<PolarisStorageConfigurationInfo> forEntityPath(
&& baseLocation != null) {
LOGGER.debug(
"Not allowing unstructured table location for entity: {}",
entityPath.getLast().getName());
entityPathReversed.get(0).getName());
return new StorageConfigurationOverride(configInfo, List.of(baseLocation));
} else {
LOGGER.debug(
"Allowing unstructured table location for entity: {}",
entityPath.getLast().getName());
entityPathReversed.get(0).getName());
return configInfo;
}
});
}

private static @NotNull Optional<PolarisEntity> findStorageInfoFromHierarchy(
List<PolarisEntity> entityPath) {
return entityPath.reversed().stream()
.filter(
e ->
e.getInternalPropertiesAsMap()
.containsKey(PolarisEntityConstants.getStorageConfigInfoPropertyName()))
.findFirst();
for (int i = entityPath.size() - 1; i >= 0; i--) {
PolarisEntity e = entityPath.get(i);
if (e.getInternalPropertiesAsMap()
.containsKey(PolarisEntityConstants.getStorageConfigInfoPropertyName())) {
return Optional.of(e);
}
}
return Optional.empty();
}

/** Subclasses must provide the Iceberg FileIO impl associated with their type in this method. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.polaris.core.persistence.cache.EntityCacheEntry;
import io.polaris.core.persistence.cache.EntityCacheLookupResult;
import java.util.List;
import java.util.stream.Collectors;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand Down Expand Up @@ -213,9 +214,9 @@ void testGetOrLoadEntityByName() {
.filter(
grantRecord ->
grantRecord.getPrivilegeCode() == PolarisPrivilege.TABLE_READ_DATA.getCode())
.toList();
.collect(Collectors.toList());
Assertions.assertThat(matchPriv).hasSize(1);
gr = matchPriv.getFirst();
gr = matchPriv.get(0);
Assertions.assertThat(gr.getGranteeId()).isEqualTo(cacheEntry_R1.getEntity().getId());
Assertions.assertThat(gr.getGranteeCatalogId())
.isEqualTo(cacheEntry_R1.getEntity().getCatalogId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void testConsistency() {

// now grant R3 to PR2
Assertions.assertThat(resolver.getResolvedCallerPrincipalRoles()).hasSize(1);
PolarisBaseEntity PR2 = resolver.getResolvedCallerPrincipalRoles().getFirst().getEntity();
PolarisBaseEntity PR2 = resolver.getResolvedCallerPrincipalRoles().get(0).getEntity();
this.tm.grantToGrantee(TEST, R3, PR2, PolarisPrivilege.CATALOG_ROLE_USAGE);

// now resolve again with only PR2 activated, should see the new catalog role R3
Expand Down Expand Up @@ -321,7 +321,7 @@ void testPathConsistency() {
// get the various entities in the path
Assertions.assertThat(resolver.getResolvedPath()).isNotNull();
Assertions.assertThat(resolver.getResolvedPath()).hasSize(3);
PolarisBaseEntity N1 = resolver.getResolvedPath().getFirst().getEntity();
PolarisBaseEntity N1 = resolver.getResolvedPath().get(0).getEntity();
PolarisBaseEntity N2 = resolver.getResolvedPath().get(1).getEntity();
PolarisBaseEntity T1 = resolver.getResolvedPath().get(2).getEntity();

Expand Down Expand Up @@ -494,8 +494,11 @@ private void resolvePrincipalAndPrincipalRole(
principalRolesResolved.sort(Comparator.comparing(p -> p.getEntity().getName()));

// ensure they are PR1 and PR2
this.ensureResolved(principalRolesResolved.getFirst(), PolarisEntityType.PRINCIPAL_ROLE, "PR1");
this.ensureResolved(principalRolesResolved.getLast(), PolarisEntityType.PRINCIPAL_ROLE, "PR2");
this.ensureResolved(principalRolesResolved.get(0), PolarisEntityType.PRINCIPAL_ROLE, "PR1");
this.ensureResolved(
principalRolesResolved.get(principalRolesResolved.size() - 1),
PolarisEntityType.PRINCIPAL_ROLE,
"PR2");

// if a principal role was passed-in, ensure it exists
if (principalRoleName != null) {
Expand Down
Loading

0 comments on commit c07e687

Please sign in to comment.