Skip to content

Commit 3117b1b

Browse files
committed
Update Gradle Wrapper to 8.2.1 for Enhanced JDK20 Compatibility
- **Reason for Upgrade**: The migration to JDK20 ([reference](https://github.com/opensearch-project/opensearch-build/blob/aa65a8ecd69f77c3d3104043dd1c48dff708bffa/manifests/3.0.0/opensearch-3.0.0.yml#L9)) rendered the current Gradle version (7.6.1) incompatible. - **Actions Taken**: - **Gradle Wrapper Update**: Upgraded the Gradle wrapper to version 8.2.1 to maintain compatibility with JDK20. The gradle wrapper files are generated using the `./gradlew wrapper` command. - Applied `spotless` due to new formatting requirements in Gradle 8. - Resolved test "jar hell" issues. Gradle 8 introduced internal JARs to the test classpath that conflicted with dependencies from `org.junit.vintage:junit-vintage-engine`. As a remedy, these conflicting JARs have been excluded. - **Relevant Pull Requests**: - [Alerting#893](https://github.com/opensearch-project/alerting/pull/893/files) - [ML-Commons#892](opensearch-project/ml-commons#892) - [Security PR](opensearch-project/security#2978) - **Verification**: Successfully verified the changes using `gradle build`. Signed-off-by: Kaituo Li <kaituo@amazon.com>
1 parent 5ac6390 commit 3117b1b

File tree

71 files changed

+510
-740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+510
-740
lines changed

.github/workflows/test_build_multi_platform.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
Build-ad-windows:
1212
strategy:
1313
matrix:
14-
java: [ 11, 17 ]
14+
java: [ 11, 17, 20 ]
1515
name: Build and Test Anomaly Detection Plugin on Windows
1616
runs-on: windows-latest
1717
steps:
@@ -39,7 +39,7 @@ jobs:
3939
Build-ad:
4040
strategy:
4141
matrix:
42-
java: [11,17]
42+
java: [11,17,20]
4343
os: [ubuntu-latest, macos-latest]
4444
fail-fast: false
4545

.github/workflows/test_bwc.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
Build-ad:
1212
strategy:
1313
matrix:
14-
java: [11,17]
14+
java: [11,17,20]
1515
fail-fast: false
1616

1717
name: Test Anomaly detection BWC
@@ -42,4 +42,4 @@ jobs:
4242
- name: Run AD Backwards Compatibility Tests
4343
run: |
4444
echo "Running backwards compatibility tests ..."
45-
./gradlew bwcTestSuite -Dtests.security.manager=false
45+
./gradlew bwcTestSuite -Dtests.security.manager=false

.github/workflows/test_security.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
Build-ad:
1212
strategy:
1313
matrix:
14-
java: [11,17]
14+
java: [11,17,20]
1515
fail-fast: false
1616

1717
name: Security test workflow for Anomaly Detection

build.gradle

+28-34
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ buildscript {
6464
}
6565

6666
plugins {
67-
id 'nebula.ospackage' version "8.3.0" apply false
68-
id "com.diffplug.gradle.spotless" version "3.26.1"
67+
id 'com.netflix.nebula.ospackage' version "11.0.0"
68+
id "com.diffplug.spotless" version "6.18.0"
6969
id 'java-library'
7070
// Gradle 7.6 support was added in test-retry 1.4.0.
7171
id 'org.gradle.test-retry' version '1.4.1'
@@ -149,22 +149,17 @@ dependencies {
149149
}
150150

151151
testImplementation group: 'pl.pragmatists', name: 'JUnitParams', version: '1.1.1'
152-
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.25.0'
153-
testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.2'
154-
testImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.2'
155-
testImplementation group: 'org.powermock', name: 'powermock-module-junit4-common', version: '2.0.2'
156-
testImplementation group: 'org.powermock', name: 'powermock-core', version: '2.0.2'
157-
testImplementation group: 'org.powermock', name: 'powermock-api-support', version: '2.0.2'
158-
testImplementation group: 'org.powermock', name: 'powermock-reflect', version: '2.0.2'
152+
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.3.1'
159153
testImplementation group: 'org.objenesis', name: 'objenesis', version: '3.0.1'
160-
testImplementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.9.15'
161-
testImplementation group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.9.15'
154+
testImplementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.14.6'
155+
testImplementation group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.14.6'
162156
testCompileOnly 'org.apiguardian:apiguardian-api:1.1.0'
163-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
164-
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.2'
165-
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
157+
// jupiter is required to run unit tests not inherited from OpenSearchTestCase (e.g., PreviousValueImputerTests)
158+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
159+
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.2'
160+
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
166161
testImplementation "org.opensearch:opensearch-core:${opensearch_version}"
167-
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.7.2'
162+
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.9.2")
168163
testCompileOnly 'junit:junit:4.13.2'
169164
}
170165

@@ -187,11 +182,16 @@ allprojects {
187182

188183
version = "${opensearch_build}"
189184

190-
plugins.withId('java') {
191-
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11
185+
plugins.withId('jacoco') {
186+
jacoco.toolVersion = '0.8.10'
192187
}
193188
}
194189

190+
java {
191+
targetCompatibility = JavaVersion.VERSION_11
192+
sourceCompatibility = JavaVersion.VERSION_11
193+
}
194+
195195
ext {
196196
projectSubstitutions = [:]
197197
licenseFile = rootProject.file('LICENSE.txt')
@@ -215,10 +215,10 @@ configurations.all {
215215
force "org.apache.httpcomponents.client5:httpclient5:${versions.httpclient5}"
216216
force "commons-codec:commons-codec:${versions.commonscodec}"
217217

218-
force "org.mockito:mockito-core:2.25.0"
218+
force "org.mockito:mockito-core:5.3.1"
219219
force "org.objenesis:objenesis:3.0.1"
220-
force "net.bytebuddy:byte-buddy:1.9.15"
221-
force "net.bytebuddy:byte-buddy-agent:1.9.15"
220+
force "net.bytebuddy:byte-buddy:1.14.6"
221+
force "net.bytebuddy:byte-buddy-agent:1.14.6"
222222
force "com.google.code.gson:gson:2.8.9"
223223
force "junit:junit:4.13.2"
224224
}
@@ -711,8 +711,8 @@ jacocoTestCoverageVerification {
711711

712712
jacocoTestReport {
713713
reports {
714-
xml.enabled = true
715-
html.enabled = true
714+
xml.required = true // for coverlay
715+
html.required = true // human readable
716716
}
717717
}
718718

@@ -721,11 +721,7 @@ jacocoTestCoverageVerification.dependsOn jacocoTestReport
721721

722722
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
723723

724-
test {
725-
useJUnitPlatform()
726-
}
727-
728-
apply plugin: 'nebula.ospackage'
724+
apply plugin: 'com.netflix.nebula.ospackage'
729725

730726
// This is afterEvaluate because the bundlePlugin ZIP task is updated afterEvaluate and changes the ZIP name to match the plugin name
731727
afterEvaluate {
@@ -735,7 +731,7 @@ afterEvaluate {
735731
version = "${project.version}" - "-SNAPSHOT"
736732

737733
into '/usr/share/opensearch/plugins'
738-
from(zipTree(bundlePlugin.archivePath)) {
734+
from(zipTree(bundlePlugin.archiveFile)) {
739735
into opensearchplugin.name
740736
}
741737

@@ -766,9 +762,8 @@ afterEvaluate {
766762
task renameRpm(type: Copy) {
767763
from("$buildDir/distributions")
768764
into("$buildDir/distributions")
769-
include archiveName
770-
rename archiveName, "${packageName}-${version}.rpm"
771-
doLast { delete file("$buildDir/distributions/$archiveName") }
765+
rename "$archiveFileName", "${packageName}-${archiveVersion}.rpm"
766+
doLast { delete file("$buildDir/distributions/$archiveFileName") }
772767
}
773768
}
774769

@@ -779,9 +774,8 @@ afterEvaluate {
779774
task renameDeb(type: Copy) {
780775
from("$buildDir/distributions")
781776
into("$buildDir/distributions")
782-
include archiveName
783-
rename archiveName, "${packageName}-${version}.deb"
784-
doLast { delete file("$buildDir/distributions/$archiveName") }
777+
rename "$archiveFileName", "${packageName}-${archiveVersion}.deb"
778+
doLast { delete file("$buildDir/distributions/$archiveFileName") }
785779
}
786780
}
787781

gradle.properties

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright OpenSearch Contributors
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
# Enable build caching
7+
org.gradle.caching=true
8+
org.gradle.warning.mode=none
9+
org.gradle.parallel=true
10+
org.gradle.jvmargs=-Xmx3g -XX:+HeapDumpOnOutOfMemoryError -Xss2m \
11+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
12+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
13+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
14+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
15+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
16+
options.forkOptions.memoryMaximumSize=3g
17+
18+
# Disable duplicate project id detection
19+
# See https://docs.gradle.org/current/userguide/upgrading_version_6.html#duplicate_project_names_may_cause_publication_to_fail
20+
systemProp.org.gradle.dependency.duplicate.project.detection=false
21+
22+
# Enforce the build to fail on deprecated gradle api usage
23+
systemProp.org.gradle.warning.mode=fail
24+
25+
# forcing to use TLS1.2 to avoid failure in vault
26+
# see https://github.com/hashicorp/vault/issues/8750#issuecomment-631236121
27+
systemProp.jdk.tls.client.protocols=TLSv1.2
28+
29+
# jvm args for faster test execution by default
30+
systemProp.tests.jvm.argline=-XX:TieredStopAtLevel=1 -XX:ReservedCodeCacheSize=64m

gradle/wrapper/gradle-wrapper.jar

1.76 KB
Binary file not shown.
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
44
networkTimeout=10000
5+
validateDistributionUrl=true
56
zipStoreBase=GRADLE_USER_HOME
67
zipStorePath=wrapper/dists

gradlew

+10-6
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ done
8585
APP_BASE_NAME=${0##*/}
8686
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
8787

88-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90-
9188
# Use the maximum available, or set MAX_FD != -1 to use that value.
9289
MAX_FD=maximum
9390

@@ -133,26 +130,29 @@ location of your Java installation."
133130
fi
134131
else
135132
JAVACMD=java
136-
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
133+
if ! command -v java >/dev/null 2>&1
134+
then
135+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137136
138137
Please set the JAVA_HOME variable in your environment to match the
139138
location of your Java installation."
139+
fi
140140
fi
141141

142142
# Increase the maximum file descriptors if we can.
143143
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144144
case $MAX_FD in #(
145145
max*)
146146
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147-
# shellcheck disable=SC3045
147+
# shellcheck disable=SC3045
148148
MAX_FD=$( ulimit -H -n ) ||
149149
warn "Could not query maximum file descriptor limit"
150150
esac
151151
case $MAX_FD in #(
152152
'' | soft) :;; #(
153153
*)
154154
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155-
# shellcheck disable=SC3045
155+
# shellcheck disable=SC3045
156156
ulimit -n "$MAX_FD" ||
157157
warn "Could not set maximum file descriptor limit to $MAX_FD"
158158
esac
@@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
197197
done
198198
fi
199199

200+
201+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
202+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
203+
200204
# Collect all arguments for the java command;
201205
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
202206
# shell script including quotes and variable substitutions, so put them in

src/main/java/org/opensearch/ad/AnomalyDetectorJobRunner.java

+8-37
Original file line numberDiff line numberDiff line change
@@ -307,38 +307,11 @@ private void runAnomalyDetectionJob(
307307
detectionStartTime.toEpochMilli(),
308308
executionStartTime.toEpochMilli()
309309
);
310-
client
311-
.execute(
312-
AnomalyResultAction.INSTANCE,
313-
request,
314-
ActionListener
315-
.wrap(
316-
response -> {
317-
indexAnomalyResult(
318-
jobParameter,
319-
lockService,
320-
lock,
321-
detectionStartTime,
322-
executionStartTime,
323-
response,
324-
recorder,
325-
detector
326-
);
327-
},
328-
exception -> {
329-
handleAdException(
330-
jobParameter,
331-
lockService,
332-
lock,
333-
detectionStartTime,
334-
executionStartTime,
335-
exception,
336-
recorder,
337-
detector
338-
);
339-
}
340-
)
341-
);
310+
client.execute(AnomalyResultAction.INSTANCE, request, ActionListener.wrap(response -> {
311+
indexAnomalyResult(jobParameter, lockService, lock, detectionStartTime, executionStartTime, response, recorder, detector);
312+
}, exception -> {
313+
handleAdException(jobParameter, lockService, lock, detectionStartTime, executionStartTime, exception, recorder, detector);
314+
}));
342315
} catch (Exception e) {
343316
indexAnomalyResultException(
344317
jobParameter,
@@ -672,11 +645,9 @@ private void releaseLock(Job jobParameter, LockService lockService, LockModel lo
672645
lockService
673646
.release(
674647
lock,
675-
ActionListener
676-
.wrap(
677-
released -> { log.info("Released lock for AD job {}", jobParameter.getName()); },
678-
exception -> { log.error("Failed to release lock for AD job: " + jobParameter.getName(), exception); }
679-
)
648+
ActionListener.wrap(released -> { log.info("Released lock for AD job {}", jobParameter.getName()); }, exception -> {
649+
log.error("Failed to release lock for AD job: " + jobParameter.getName(), exception);
650+
})
680651
);
681652
}
682653
}

src/main/java/org/opensearch/ad/AnomalyDetectorRunner.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ public void executeDetector(
8484
listener.onResponse(Collections.emptyList());
8585
return;
8686
}
87-
ActionListener<EntityAnomalyResult> entityAnomalyResultListener = ActionListener
88-
.wrap(
89-
entityAnomalyResult -> { listener.onResponse(entityAnomalyResult.getAnomalyResults()); },
90-
e -> onFailure(e, listener, detector.getId())
91-
);
87+
ActionListener<EntityAnomalyResult> entityAnomalyResultListener = ActionListener.wrap(entityAnomalyResult -> {
88+
listener.onResponse(entityAnomalyResult.getAnomalyResults());
89+
}, e -> onFailure(e, listener, detector.getId()));
9290
MultiResponsesDelegateActionListener<EntityAnomalyResult> multiEntitiesResponseListener =
9391
new MultiResponsesDelegateActionListener<EntityAnomalyResult>(
9492
entityAnomalyResultListener,

src/main/java/org/opensearch/ad/caching/PriorityCache.java

+11-18
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,9 @@ public PriorityCache(
133133
Duration inactiveEntityTtl = DateUtils.toDuration(checkpointTtl.get(settings));
134134

135135
this.inActiveEntities = createInactiveCache(inactiveEntityTtl, maxInactiveStates);
136-
clusterService
137-
.getClusterSettings()
138-
.addSettingsUpdateConsumer(
139-
checkpointTtl,
140-
it -> { this.inActiveEntities = createInactiveCache(DateUtils.toDuration(it), maxInactiveStates); }
141-
);
136+
clusterService.getClusterSettings().addSettingsUpdateConsumer(checkpointTtl, it -> {
137+
this.inActiveEntities = createInactiveCache(DateUtils.toDuration(it), maxInactiveStates);
138+
});
142139

143140
this.threadPool = threadPool;
144141
this.random = new Random(42);
@@ -163,19 +160,15 @@ public ModelState<EntityModel> get(String modelId, AnomalyDetector detector) {
163160
// during maintenance period, stop putting new entries
164161
if (!maintenanceLock.isLocked() && modelState == null) {
165162
if (ADEnabledSetting.isDoorKeeperInCacheEnabled()) {
166-
DoorKeeper doorKeeper = doorKeepers
167-
.computeIfAbsent(
168-
detectorId,
169-
id -> {
170-
// reset every 60 intervals
171-
return new DoorKeeper(
172-
TimeSeriesSettings.DOOR_KEEPER_FOR_CACHE_MAX_INSERTION,
173-
TimeSeriesSettings.DOOR_KEEPER_FALSE_POSITIVE_RATE,
174-
detector.getIntervalDuration().multipliedBy(TimeSeriesSettings.DOOR_KEEPER_MAINTENANCE_FREQ),
175-
clock
176-
);
177-
}
163+
DoorKeeper doorKeeper = doorKeepers.computeIfAbsent(detectorId, id -> {
164+
// reset every 60 intervals
165+
return new DoorKeeper(
166+
TimeSeriesSettings.DOOR_KEEPER_FOR_CACHE_MAX_INSERTION,
167+
TimeSeriesSettings.DOOR_KEEPER_FALSE_POSITIVE_RATE,
168+
detector.getIntervalDuration().multipliedBy(TimeSeriesSettings.DOOR_KEEPER_MAINTENANCE_FREQ),
169+
clock
178170
);
171+
});
179172

180173
// first hit, ignore
181174
// since door keeper may get reset during maintenance, it is possible

0 commit comments

Comments
 (0)