From 501db5c38edee4b1be37cbc7fb1ce2a2430ec0ea Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 10 Jul 2025 20:21:20 +0100 Subject: [PATCH 1/3] Upgrade AWS Java SDK to 2.31.78 This picks up the fix for the locale bug reported at https://github.com/aws/aws-sdk-java-v2/issues/5968. This reverts the patching of the library added in commit 2697a3a87215c92efb3c9bd6c42b99ae8a63f2a7, except for the test enhancement. Fix confirmed in e.g. locale `ar-ER` with ./gradlew ":plugins:discovery-ec2:test" \ --tests "org.elasticsearch.discovery.ec2.Ec2DiscoveryTests.testFilterByTags" \ -Dtests.seed=596874EED28A2B92 -Dtests.locale=ar-ER -Dtests.timezone=NET \ -Druntime.java=24 --- .../patches/awsv2sdk/Awsv2ClassPatcher.java | 61 ------ .../StringFormatInPathResolverPatcher.java | 89 -------- build-tools-internal/version.properties | 2 +- gradle/verification-metadata.xml | 204 +++++++++--------- plugins/discovery-ec2/build.gradle | 36 ---- 5 files changed, 103 insertions(+), 289 deletions(-) delete mode 100644 build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/awsv2sdk/Awsv2ClassPatcher.java delete mode 100644 build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/awsv2sdk/StringFormatInPathResolverPatcher.java diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/awsv2sdk/Awsv2ClassPatcher.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/awsv2sdk/Awsv2ClassPatcher.java deleted file mode 100644 index 1e515afd8404b..0000000000000 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/awsv2sdk/Awsv2ClassPatcher.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.gradle.internal.dependencies.patches.awsv2sdk; - -import org.elasticsearch.gradle.internal.dependencies.patches.PatcherInfo; -import org.elasticsearch.gradle.internal.dependencies.patches.Utils; -import org.gradle.api.artifacts.transform.CacheableTransform; -import org.gradle.api.artifacts.transform.InputArtifact; -import org.gradle.api.artifacts.transform.TransformAction; -import org.gradle.api.artifacts.transform.TransformOutputs; -import org.gradle.api.artifacts.transform.TransformParameters; -import org.gradle.api.file.FileSystemLocation; -import org.gradle.api.provider.Provider; -import org.gradle.api.tasks.Classpath; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.util.List; - -import static org.elasticsearch.gradle.internal.dependencies.patches.PatcherInfo.classPatcher; - -@CacheableTransform -public abstract class Awsv2ClassPatcher implements TransformAction { - - private static final String JAR_FILE_TO_PATCH = "aws-query-protocol"; - - private static final List CLASS_PATCHERS = List.of( - // This patcher is needed because of this AWS bug: https://github.com/aws/aws-sdk-java-v2/issues/5968 - // As soon as the bug is resolved and we upgrade our AWS SDK v2 libraries, we can remove this. - classPatcher( - "software/amazon/awssdk/protocols/query/internal/marshall/ListQueryMarshaller.class", - "213e84d9a745bdae4b844334d17aecdd6499b36df32aa73f82dc114b35043009", - StringFormatInPathResolverPatcher::new - ) - ); - - @Classpath - @InputArtifact - public abstract Provider getInputArtifact(); - - @Override - public void transform(@NotNull TransformOutputs outputs) { - File inputFile = getInputArtifact().get().getAsFile(); - - if (inputFile.getName().startsWith(JAR_FILE_TO_PATCH)) { - System.out.println("Patching " + inputFile.getName()); - File outputFile = outputs.file(inputFile.getName().replace(".jar", "-patched.jar")); - Utils.patchJar(inputFile, outputFile, CLASS_PATCHERS); - } else { - System.out.println("Skipping " + inputFile.getName()); - outputs.file(getInputArtifact()); - } - } -} diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/awsv2sdk/StringFormatInPathResolverPatcher.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/awsv2sdk/StringFormatInPathResolverPatcher.java deleted file mode 100644 index 506dab001dbe7..0000000000000 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/patches/awsv2sdk/StringFormatInPathResolverPatcher.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.gradle.internal.dependencies.patches.awsv2sdk; - -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Type; - -import java.util.Locale; - -import static org.objectweb.asm.Opcodes.ASM9; -import static org.objectweb.asm.Opcodes.GETSTATIC; -import static org.objectweb.asm.Opcodes.INVOKESTATIC; - -class StringFormatInPathResolverPatcher extends ClassVisitor { - - StringFormatInPathResolverPatcher(ClassWriter classWriter) { - super(ASM9, classWriter); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { - return new ReplaceCallMethodVisitor(super.visitMethod(access, name, descriptor, signature, exceptions)); - } - - /** - * Replaces calls to String.format(format, args); with calls to String.format(Locale.ROOT, format, args); - */ - private static class ReplaceCallMethodVisitor extends MethodVisitor { - private static final String CLASS_INTERNAL_NAME = Type.getInternalName(String.class); - private static final String METHOD_NAME = "format"; - private static final String OLD_METHOD_DESCRIPTOR = Type.getMethodDescriptor( - Type.getType(String.class), - Type.getType(String.class), - Type.getType(Object[].class) - ); - private static final String NEW_METHOD_DESCRIPTOR = Type.getMethodDescriptor( - Type.getType(String.class), - Type.getType(Locale.class), - Type.getType(String.class), - Type.getType(Object[].class) - ); - - private boolean foundFormatPattern = false; - - ReplaceCallMethodVisitor(MethodVisitor methodVisitor) { - super(ASM9, methodVisitor); - } - - @Override - public void visitLdcInsn(Object value) { - if (value instanceof String s && s.startsWith("%s")) { - if (foundFormatPattern) { - throw new IllegalStateException( - "A previous string format constant was not paired with a String.format() call. " - + "Patching would generate an unbalances stack" - ); - } - // Push the extra arg on the stack - mv.visitFieldInsn(GETSTATIC, Type.getInternalName(Locale.class), "ROOT", Type.getDescriptor(Locale.class)); - foundFormatPattern = true; - } - super.visitLdcInsn(value); - } - - @Override - public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) { - if (opcode == INVOKESTATIC - && foundFormatPattern - && CLASS_INTERNAL_NAME.equals(owner) - && METHOD_NAME.equals(name) - && OLD_METHOD_DESCRIPTOR.equals(descriptor)) { - // Replace the call with String.format(Locale.ROOT, format, args) - mv.visitMethodInsn(INVOKESTATIC, CLASS_INTERNAL_NAME, METHOD_NAME, NEW_METHOD_DESCRIPTOR, false); - foundFormatPattern = false; - } else { - super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); - } - } - } -} diff --git a/build-tools-internal/version.properties b/build-tools-internal/version.properties index c443b280e3dd2..c552581a81738 100644 --- a/build-tools-internal/version.properties +++ b/build-tools-internal/version.properties @@ -17,7 +17,7 @@ jna = 5.12.1 netty = 4.1.118.Final commons_lang3 = 3.9 google_oauth_client = 1.34.1 -awsv2sdk = 2.30.38 +awsv2sdk = 2.31.78 reactive_streams = 1.0.4 antlr4 = 4.13.1 diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 7e147eff76dbd..0eedfc37ca1a9 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -4954,174 +4954,174 @@ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + diff --git a/plugins/discovery-ec2/build.gradle b/plugins/discovery-ec2/build.gradle index 454508d0298f9..f4eb1d3a90f01 100644 --- a/plugins/discovery-ec2/build.gradle +++ b/plugins/discovery-ec2/build.gradle @@ -15,31 +15,6 @@ esplugin { classname ='org.elasticsearch.discovery.ec2.Ec2DiscoveryPlugin' } -def patched = Attribute.of('patched', Boolean) - -configurations { - compileClasspath { - attributes { - attribute(patched, true) - } - } - runtimeClasspath { - attributes { - attribute(patched, true) - } - } - testCompileClasspath { - attributes { - attribute(patched, true) - } - } - testRuntimeClasspath { - attributes { - attribute(patched, true) - } - } -} - dependencies { implementation "software.amazon.awssdk:annotations:${versions.awsv2sdk}" @@ -90,17 +65,6 @@ dependencies { testImplementation project(':test:fixtures:ec2-imds-fixture') internalClusterTestImplementation project(':test:fixtures:ec2-imds-fixture') - - attributesSchema { - attribute(patched) - } - artifactTypes.getByName("jar") { - attributes.attribute(patched, false) - } - registerTransform(org.elasticsearch.gradle.internal.dependencies.patches.awsv2sdk.Awsv2ClassPatcher) { - from.attribute(patched, false) - to.attribute(patched, true) - } } tasks.named("dependencyLicenses").configure { From 50ce91c379d0ac138a0aa93e52c58dbf2a4864a4 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 10 Jul 2025 20:49:24 +0100 Subject: [PATCH 2/3] Update docs/changelog/131050.yaml --- docs/changelog/131050.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/131050.yaml diff --git a/docs/changelog/131050.yaml b/docs/changelog/131050.yaml new file mode 100644 index 0000000000000..12fec083bcfde --- /dev/null +++ b/docs/changelog/131050.yaml @@ -0,0 +1,5 @@ +pr: 131050 +summary: Upgrade AWS Java SDK to 2.31.78 +area: "Snapshot/Restore, Discovery-Plugins" +type: upgrade +issues: [] From 45ffec3e519d12a12506f3e5549ab642056d6228 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 10 Jul 2025 21:32:31 +0100 Subject: [PATCH 3/3] Fix changelog --- docs/changelog/131050.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog/131050.yaml b/docs/changelog/131050.yaml index 12fec083bcfde..f8c932b464dba 100644 --- a/docs/changelog/131050.yaml +++ b/docs/changelog/131050.yaml @@ -1,5 +1,6 @@ pr: 131050 summary: Upgrade AWS Java SDK to 2.31.78 -area: "Snapshot/Restore, Discovery-Plugins" +area: "Snapshot/Restore" type: upgrade issues: [] +