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

Upgrade JDK toolchain/target version to 17 and add GraalJS #1207

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b00c63b
Upgrade JDK toolchain and target version for most packages to 17 to g…
gregschohn Dec 20, 2024
56b9bd0
Add a pure JavascriptTransformer that can run initialization and per-…
gregschohn Dec 22, 2024
4816155
Merge branch 'main' into liquidJsTransforms
AndreKurait Jan 8, 2025
7b4cecd
Merge remote-tracking branch 'upstream/main' into liquidJsTransforms
AndreKurait Jan 9, 2025
ed2a0a8
Update javascript transformations to handle Object IJsonTransformer c…
AndreKurait Jan 9, 2025
7e12bac
Remove LiquidJs due to performance slowdown over Javascript
AndreKurait Jan 9, 2025
1fe744a
Create JsonJSTransformerProvider for custom scripts
AndreKurait Jan 9, 2025
efc4df2
Update TypeMappingSanitizationTransformerProvider to share logic with…
AndreKurait Jan 9, 2025
397d72e
Revert vscode settings
AndreKurait Jan 9, 2025
738cf2b
Update project (except capture proxy and dependencies) to Java 17 for…
AndreKurait Jan 10, 2025
4091797
Enable error prone for JDK 17
AndreKurait Jan 10, 2025
ae06216
re-enable task tree
AndreKurait Jan 10, 2025
4515ed3
Update readme and transformation type mapping parameter input
AndreKurait Jan 10, 2025
bc6e289
Fix javascript typemapping sanitization
AndreKurait Jan 10, 2025
a1c3a6a
Restrict polyglot host access
AndreKurait Jan 11, 2025
7be2a63
Refactor javascript transformers with graaljs community, security set…
AndreKurait Jan 14, 2025
a3fd9d7
Update Java Version docs
AndreKurait Jan 14, 2025
313d768
Add comment on task tree
AndreKurait Jan 14, 2025
9a48175
Retain compatibility for spotless with jdk 11
AndreKurait Jan 14, 2025
5b6fc2a
Support arbritrary static bindings object
AndreKurait Jan 14, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

env:
python-version: '3.11'
java-version: '11'
java-version: '17'
gradle-version: '8.0.2'
node-version: '18.x'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
tags:
- "*"
env:
java-version: '11'
java-version: '17'
gradle-version: '8.0.2'

permissions:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonar-qube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:

env:
java-version: '11'
java-version: '17'
gradle-version: '8.0.2'

jobs:
Expand All @@ -32,7 +32,7 @@ jobs:
with:
distribution: 'corretto'
java-version: |
11
17
- name: Cache SonarQube Scanner
uses: actions/cache@v3
with:
Expand Down
3 changes: 0 additions & 3 deletions CreateSnapshot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ plugins {
id 'org.opensearch.migrations.java-application-conventions'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
implementation project(':coreUtilities')
implementation project(":RFS")
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

## Prerequisites

- Java Development Kit (JDK) 11
- Java Development Kit (JDK) 17
- Gradle 8
- Python3
- Docker and Docker Compose (for local deployment)
Expand Down
3 changes: 0 additions & 3 deletions DataGenerator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ plugins {
id 'io.freefair.lombok'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
implementation project(":coreUtilities")
implementation project(":RFS")
Expand Down
3 changes: 0 additions & 3 deletions DocumentsFromSnapshotMigration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import groovy.transform.Canonical
import org.opensearch.migrations.common.CommonUtils

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

@Canonical
class DockerServiceProps {
String projectName = ""
Expand Down
2 changes: 1 addition & 1 deletion DocumentsFromSnapshotMigration/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Using same base image as other Java containers in this repo
FROM amazoncorretto:11-al2023-headless
FROM amazoncorretto:17-al2023-headless

# Install the AWS CLI in the container
RUN dnf install -y aws-cli --setopt=install_weak_deps=False && \
Expand Down
3 changes: 0 additions & 3 deletions MetadataMigration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ plugins {
id 'io.freefair.lombok'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
implementation project(":coreUtilities")
implementation project(":RFS")
Expand Down
3 changes: 0 additions & 3 deletions RFS/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ plugins {
id 'me.champeau.jmh'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

ext {
awsSdkVersion = '2.25.16'
dataset = findProperty('dataset') ?: 'skip_dataset'
Expand Down
23 changes: 16 additions & 7 deletions TrafficCapture/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,25 @@ subprojects {
// TODO: Expand to do more static checking in more projects
if (project.name == "trafficReplayer" || project.name == "trafficCaptureProxyServer") {
dependencies {
annotationProcessor group: 'com.google.errorprone', name: 'error_prone_core', version: '2.26.1'
annotationProcessor group: 'com.google.errorprone', name: 'error_prone_core', version: '2.32.0'
}
tasks.named('compileJava', JavaCompile) {
if (project.name == "trafficReplayer" || project.name == "trafficCaptureProxyServer") {
options.fork = true
// Taken from https://errorprone.info/docs/installation
options.forkOptions.jvmArgs += [
'--add-exports', 'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
'--add-opens', 'jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-opens', 'jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
]

options.compilerArgs += [
"-XDcompilePolicy=simple",
"-Xplugin:ErrorProne -XepDisableAllChecks -Xep:MustBeClosed:ERROR -XepDisableWarningsInGeneratedCode",
Expand All @@ -25,12 +40,6 @@ subprojects {
allprojects {
apply plugin: 'java'
apply plugin: 'org.owasp.dependencycheck'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
}

subprojects {
Expand Down
3 changes: 2 additions & 1 deletion TrafficCapture/dockerSolution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ within the final yaml configuration that is being output.

## Compatibility

The tools in this directory can only be built if you have Java version 11 installed.
The tools in this directory can only be built if you have Java version 17
installed.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't true, right? Gradle download 17 if it wasn't present - so you really just need whatever the minimum version of java is to run ../../gradlew

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified this is the case and updated. We need Java 8-17 (until bumping gradle up to 8.4 when we'll gain 21 support)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performed more verification and found that spotless fails for Java 17 language usage when the host is Java 11. Junit and build downloads and runs as expected when the host is java 8 or 11

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed spotless temporarily, will address root cause with https://opensearch.atlassian.net/browse/MIGRATIONS-2344


The version is specified in `TrafficCapture/build.gradle` using a Java toolchain, which allows us
to decouple the Java version used by Gradle itself from Java version used by the tools here.
Expand Down
91 changes: 91 additions & 0 deletions TrafficCapture/trafficCaptureProxyServer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,94 @@ application {
// Define the main class for the application.
mainClass = 'org.opensearch.migrations.trafficcapture.proxyserver.CaptureProxy'
}

tasks.register("verifyCompatibilityWithJDK11") {
AndreKurait marked this conversation as resolved.
Show resolved Hide resolved
group = "verification"
description = "Verify Java major versions of compiled classes and dependencies for compatibility with JDK 11."

// Declare task inputs
inputs.files(fileTree("${buildDir}/classes/java/main")).withPropertyName("compiledClasses")
inputs.files(configurations.compileClasspath).withPropertyName("compileClasspath")
inputs.files(configurations.runtimeClasspath).withPropertyName("runtimeClasspath")

// Declare outputs (optional if no files are written, just up-to-date checking)
outputs.upToDateWhen { true }

doLast {
// Task implementation logic
def isCompatible = true
def analyzedFiles = [] // To avoid duplicate processing

def getMajorVersion = { InputStream inputStream ->
inputStream.skip(6)
def majorVersion = inputStream.read() << 8 | inputStream.read()
inputStream.close()
return majorVersion
}

def processClassFile = { InputStream inputStream, String name, String source ->
def majorVersion = getMajorVersion(inputStream)
if (majorVersion > 55) {
isCompatible = false
println "Incompatible class file in ${source}: ${name} (Java major version ${majorVersion})"
}
}

def analyzeCompiledClasses = {
def outputDir = file("${buildDir}/classes/java/main")
if (outputDir.exists()) {
println "Analyzing compiled classes in ${outputDir}..."
fileTree(dir: outputDir, include: '**/*.class').forEach { classFile ->
classFile.withInputStream { inputStream ->
processClassFile(inputStream, classFile.name, outputDir.toString())
}
}
} else {
println "No compiled classes found in ${outputDir}."
}
}

def analyzeDependencies = { configuration ->
println "\nAnalyzing ${configuration.name} dependencies..."
configuration.files.each { dependency ->
if (dependency.name.endsWith(".jar") && !analyzedFiles.contains(dependency)) {
analyzedFiles.add(dependency)
def zipStream = new java.util.zip.ZipInputStream(new FileInputStream(dependency))
def entry
while ((entry = zipStream.nextEntry) != null) {
if (entry.name.endsWith(".class")) {
if (entry.name.startsWith("META-INF/versions/")) {
def versionDir = entry.name.split("/")[2]
def versionNumber = versionDir.isInteger() ? versionDir.toInteger() : 0
if (versionNumber > 11) {
continue
}
}
def tempFile = File.createTempFile("class", ".tmp")
tempFile.deleteOnExit()
tempFile.withOutputStream { it << zipStream }
tempFile.withInputStream { inputStream ->
processClassFile(inputStream, entry.name, dependency.name)
}
}
}
zipStream.close()
}
}
}

analyzeCompiledClasses()
analyzeDependencies(configurations.compileClasspath)
analyzeDependencies(configurations.runtimeClasspath)

if (!isCompatible) {
throw new GradleException("Incompatible class files detected! Ensure all classes are compatible with JDK 11 (major version ≤ 55).")
}
}
dependsOn tasks.named("assemble")
}

// Add class version verification to slowTest
tasks.named("slowTest") {
finalizedBy("verifyCompatibilityWithJDK11")
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testTransformsPropagateExceptionProperly() throws JsonProcessingExce
+ "}\n";

var transformer = new TransformationLoader().getTransformerFactoryLoader("newhost", null,
"[{\"TypeMappingSanitizationTransformerProvider\":\"\"}]");
"[{\"TypeMappingSanitizationTransformerProvider\":{}}]");
var e = Assertions.assertThrows(Exception.class,
() -> transformer.transformJson(FAULTING_MAP));
Assertions.assertTrue(((PayloadAccessFaultingMap)FAULTING_MAP.payload()).missingPayloadWasAccessed());
Expand Down
3 changes: 0 additions & 3 deletions awsUtilities/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ plugins {
id 'java'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
implementation group: 'software.amazon.awssdk', name: 'arns'
implementation group: 'software.amazon.awssdk', name: 'auth'
Expand Down
38 changes: 37 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "com.dorongold.task-tree" version "2.1.1"
id "com.dorongold.task-tree" version "2.1.1"
AndreKurait marked this conversation as resolved.
Show resolved Hide resolved
id 'io.freefair.lombok' version '8.6' apply false
id "com.diffplug.spotless" version '6.25.0'
id 'me.champeau.jmh' version '0.7.2' apply false
Expand All @@ -13,6 +13,35 @@ allprojects {
}
}


// Ensure Capture Proxy and Dependencies are built with JDK 11 for On Node Install

// Cache dependencies during the configuration phase
ext.captureProxyDependencies = []
gradle.projectsEvaluated {
def captureProxyProject = rootProject.project(":TrafficCapture:trafficCaptureProxyServer")
captureProxyDependencies = captureProxyProject.configurations.collectMany { configuration ->
configuration.dependencies.findAll { it instanceof ProjectDependency }.collect { it.dependencyProject.path }
}
// Add the TrafficCaptureProxyServer project itself
captureProxyDependencies << captureProxyProject.path
AndreKurait marked this conversation as resolved.
Show resolved Hide resolved
}

// Modify sourceCompatibility during the execution phase
gradle.taskGraph.whenReady { taskGraph ->
allprojects {
tasks.withType(JavaCompile).configureEach {
if (project.path in rootProject.captureProxyDependencies) {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
} else {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
}
}

// Define version properties
ext {
// support -Dbuild.version, but include default
Expand Down Expand Up @@ -85,6 +114,13 @@ subprojects {
apply plugin: 'maven-publish'
apply plugin: "com.diffplug.spotless"

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
vendor.set(JvmVendorSpec.AMAZON)
}
}

// See https://github.com/diffplug/spotless/tree/main/plugin-gradle#java for some documentation,
// though what '#' does is still undocumented from what I can tell
spotless {
Expand Down
3 changes: 0 additions & 3 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ plugins {
id 'org.owasp.dependencycheck' version '8.2.1'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

repositories {
// Use the plugin portal to apply community plugins in convention plugins.
gradlePluginPortal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CommonUtils {
runCommand("sed -i -e \"s|mirrorlist=|#mirrorlist=|g\" /etc/yum.repos.d/CentOS-* ; sed -i -e \"s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g\" /etc/yum.repos.d/CentOS-*")
}
} else {
from 'amazoncorretto:11-al2023-headless'
from 'amazoncorretto:17-al2023-headless'
}

copyFile("jars", "/jars")
Expand Down
9 changes: 6 additions & 3 deletions commonDependencyVersionConstraints/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ plugins {
id "java-library"
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

ext {
protobufVersion='3.25.5'
}
Expand Down Expand Up @@ -124,6 +121,12 @@ dependencies {
def json = '20240303'
api group: 'org.json', name: 'json', version: json

def graalVersion = '24.1.1'

api group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.13'
api group: "org.graalvm.js", name: 'js', version: graalVersion
AndreKurait marked this conversation as resolved.
Show resolved Hide resolved
api group: "org.graalvm.js", name: 'js-scriptengine', version: graalVersion

// ************************************************************
// The following constraints are for mitigating transitive CVEs
// ************************************************************
Expand Down
3 changes: 0 additions & 3 deletions coreUtilities/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ plugins {
id 'java-test-fixtures'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
implementation group: "com.google.protobuf", name: "protobuf-java"
implementation group: 'org.slf4j', name: 'slf4j-api'
Expand Down
6 changes: 0 additions & 6 deletions dashboardsSanitizer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ plugins {
id 'java'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
}

dependencies {
implementation project(':coreUtilities')
implementation project(":RFS")

implementation group: 'com.fasterxml.jackson.core', name:'jackson-databind'
implementation group: 'org.slf4j', name: 'slf4j-api'
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j2-impl'
Expand Down
Loading
Loading