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 Azure repository SDK to v12 #65140

Merged
merged 43 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e6c2396
Upgrade azure sdk
fcofdez Jul 10, 2020
01c744e
Fix tests
fcofdez Nov 17, 2020
f3ef260
Delegate to regular scheduler instead of into a custom one
fcofdez Nov 18, 2020
782ac90
Update default max connections.
fcofdez Nov 18, 2020
1eb89fd
More efficient blob reading
fcofdez Nov 19, 2020
61039c9
Merge remote-tracking branch 'origin/master' into azure-sdk-upgrade
fcofdez Nov 19, 2020
9bd2455
Take into account retries during reads
fcofdez Nov 20, 2020
5325997
Merge remote-tracking branch 'origin/master' into azure-sdk-upgrade
fcofdez Nov 20, 2020
f380443
Fix failing test
fcofdez Nov 20, 2020
d9f2e88
Grant permissions to tasks executed in reactor schedulers.
fcofdez Nov 23, 2020
b839a28
Merge remote-tracking branch 'origin/master' into azure-sdk-upgrade
fcofdez Nov 23, 2020
dded822
Merge remote-tracking branch 'origin/master' into azure-sdk-upgrade
fcofdez Nov 24, 2020
0e8049f
Use regular delete requests instead of the batch API
fcofdez Nov 24, 2020
c47fcf4
Initialize jackson parser during AzureRepositoryPlugin class
fcofdez Nov 26, 2020
0f522ad
Force azure impl to be public
rjernst Dec 2, 2020
49ec9f5
Make public additional sdk interfaces to avoid permission issues
fcofdez Dec 2, 2020
a27c23b
Fix precommit error
fcofdez Dec 2, 2020
16a0dc9
Fix wiring of tasks
rjernst Dec 2, 2020
eff0b69
Handle timeout configuration correctly
fcofdez Dec 3, 2020
ea047b4
Merge remote-tracking branch 'origin/master' into azure-sdk-upgrade
fcofdez Dec 4, 2020
6569f18
Remove unused dependency
fcofdez Dec 4, 2020
302c366
Add tests for LocationMode configurations
fcofdez Dec 4, 2020
8791953
Make InnerClass marker public too durin the azure sdk services rewrite.
fcofdez Dec 4, 2020
3449e3b
Add tests for using SECONDARY_ONLY endpoints
fcofdez Dec 4, 2020
fde3984
Add min values to AzureClientProvider settings
fcofdez Dec 4, 2020
cb72104
Cleanup publicifier
rjernst Dec 4, 2020
f2c17b5
restore docker maybe...
rjernst Dec 4, 2020
8f9f715
Read eagerly on AzureInputStream
fcofdez Dec 4, 2020
eae2cee
Add tests for retry strategies
fcofdez Dec 4, 2020
32e0161
Merge remote-tracking branch 'fcofdez/azure-sdk-upgrade-new' into azu…
fcofdez Dec 4, 2020
993e761
Fix checkStyle
fcofdez Dec 4, 2020
9001110
Merge remote-tracking branch 'origin/master' into azure-sdk-upgrade
fcofdez Dec 8, 2020
904c60a
Move to read the entire stream instead of reading it in chunks
fcofdez Dec 11, 2020
59f6ab3
Merge remote-tracking branch 'origin/master' into azure-sdk-upgrade
fcofdez Dec 13, 2020
2c3eefa
Use a concurrent queue
fcofdez Dec 14, 2020
974bc38
Use the proper max chunk size
fcofdez Dec 14, 2020
2c19d71
Remove unnecessary settings
fcofdez Dec 14, 2020
8295186
Merge remote-tracking branch 'origin/master' into azure-sdk-upgrade
fcofdez Dec 14, 2020
5ab14d3
Revert line break
fcofdez Dec 15, 2020
e5563f2
Merge remote-tracking branch 'origin/master' into azure-sdk-upgrade
fcofdez Dec 15, 2020
8db3d00
Remove dead code
fcofdez Dec 15, 2020
9c6ea82
Remove unused import
fcofdez Dec 15, 2020
e1ff337
Merge remote-tracking branch 'origin/master' into azure-sdk-upgrade
fcofdez Dec 15, 2020
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: 2 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ dependencies {
api 'com.avast.gradle:gradle-docker-compose-plugin:0.13.4'
api 'org.apache.maven:maven-model:3.6.2'
api 'com.networknt:json-schema-validator:1.0.36'
api 'org.ow2.asm:asm:9.0'
api 'org.ow2.asm:asm-tree:9.0'
api "org.apache.httpcomponents:httpclient:${props.getProperty('httpclient')}"
api "org.apache.httpcomponents:httpcore:${props.getProperty('httpcore')}"
compileOnly "com.puppycrawl.tools:checkstyle:${props.getProperty('checkstyle')}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you 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.
*/

package org.elasticsearch.gradle;

import org.gradle.api.DefaultTask;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InnerClassNode;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.List;
import java.util.function.Consumer;

import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;

/**
* A task to manipulate an existing class file.
*/
public class JavaClassPublicifier extends DefaultTask {

private List<String> classFiles;
private DirectoryProperty inputDir;
private DirectoryProperty outputDir;

public JavaClassPublicifier() {
this.inputDir = getProject().getObjects().directoryProperty();
this.outputDir = getProject().getObjects().directoryProperty();
}

@Input
public List<String> getClassFiles() {
return classFiles;
}

public void setClassFiles(List<String> classFiles) {
this.classFiles = classFiles;
}

@InputDirectory
public DirectoryProperty getInputDir() {
return inputDir;
}

@OutputDirectory
public DirectoryProperty getOutputDir() {
return outputDir;
}

@TaskAction
public void adapt() throws IOException {

for (String classFile : classFiles) {
adjustClass(classFile, classNode -> {
classNode.access &= ~ACC_PRIVATE;
classNode.access |= ACC_PUBLIC;

if (classFile.contains("$")) {
// java inexplicably has an inner class contain itself as an inner class...
makeInnerClassPublic(classNode, classNode.name.split("\\$")[1]);
}
});

if (classFile.contains("$")) {
// for inner classes, also need to adjust the parent
String[] parts = classFile.split("\\$");
String parentClassFile = parts[0] + ".class";
String innerClass = parts[1].split("\\.")[0];
adjustClass(parentClassFile, classNode -> makeInnerClassPublic(classNode, innerClass));
}
}
}

private static void makeInnerClassPublic(ClassNode classNode, String innerClass) {
InnerClassNode innerClassNode = classNode.innerClasses.stream().filter(node -> node.innerName.equals(innerClass)).findFirst().get();
innerClassNode.access &= ~ACC_PRIVATE;
innerClassNode.access |= ACC_PUBLIC;
}

private void writeClass(String classFile, ClassNode classNode) throws IOException {
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
classNode.accept(classWriter);

File outputFile = outputDir.get().file(classFile).getAsFile();
outputFile.getParentFile().mkdirs();
Files.write(outputFile.toPath(), classWriter.toByteArray());
}

private void adjustClass(String classFile, Consumer<ClassNode> adjustor) throws IOException {
try (InputStream is = Files.newInputStream(inputDir.get().file(classFile).getAsFile().toPath())) {
ClassReader classReader = new ClassReader(is);
ClassNode classNode = new ClassNode();
classReader.accept(classNode, ClassReader.EXPAND_FRAMES);
adjustor.accept(classNode);
writeClass(classFile, classNode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,33 @@ public class LicenseAnalyzer {
Pattern.DOTALL
)
),
new LicenseMatcher(
"MIT-0",
true,
false,
Pattern.compile(
("MIT No Attribution\n"
+ "Copyright .+\n"
+ "\n"
+ "Permission is hereby granted, free of charge, to any person obtaining a copy of "
+ "this software and associated documentation files \\(the \"Software\"\\), to deal in the Software without "
+ "restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, "
+ "and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so.\n"
+ "\n"
+ "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, "
+ "INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND "
+ "NONINFRINGEMENT\\. IN NO EVENT SHALL THE AUTHORS OR "
+ "COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR "
+ "OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n")
.replaceAll("\\s+", "\\\\s*"),
Pattern.DOTALL
)
),
new LicenseMatcher("MPL-1.1", true, false, Pattern.compile("Mozilla Public License.*Version 1.1", Pattern.DOTALL)),
new LicenseMatcher("MPL-2.0", true, false, Pattern.compile("Mozilla\\s*Public\\s*License\\s*Version\\s*2\\.0", Pattern.DOTALL)),
new LicenseMatcher("XZ", false, false, Pattern.compile("Licensing of XZ for Java", Pattern.DOTALL)),
new LicenseMatcher("EPL-2.0", true, false, Pattern.compile("Eclipse Public License - v 2.0", Pattern.DOTALL)),
new LicenseMatcher("EDL-1.0", true, false, Pattern.compile("Eclipse Distribution License - v 1.0", Pattern.DOTALL)),
new LicenseMatcher("LGPL-2.1", true, true, Pattern.compile("GNU LESSER GENERAL PUBLIC LICENSE.*Version 2.1", Pattern.DOTALL)),
new LicenseMatcher("LGPL-3.0", true, true, Pattern.compile("GNU LESSER GENERAL PUBLIC LICENSE.*Version 3", Pattern.DOTALL)) };

Expand Down
48 changes: 48 additions & 0 deletions plugins/repository-azure/azure-storage-blob/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import org.elasticsearch.gradle.JavaClassPublicifier;

apply plugin: 'elasticsearch.java'
apply plugin: 'com.github.johnrengelman.shadow'

configurations {
originalJar {
transitive = false
}
}

dependencies {
originalJar "com.azure:azure-storage-blob:${project.parent.versions.azure}"
implementation "com.azure:azure-storage-blob:${project.parent.versions.azure}"
}

// We have to rewrite the service classes to make them public to avoid
// granting the permission "java.lang.reflect.ReflectPermission" "newProxyInPackage"
// to this plugin.
//
// There are plans to make those public in the azure sdk side, but in the meanwhile
// we just do this workaround
// https://github.com/Azure/azure-sdk-for-java/issues/12829#issuecomment-736755543
List<String> classesToRewrite = ['com/azure/storage/blob/implementation/AppendBlobsImpl$AppendBlobsService.class',
'com/azure/storage/blob/implementation/BlobsImpl$BlobsService.class',
'com/azure/storage/blob/implementation/BlockBlobsImpl$BlockBlobsService.class',
'com/azure/storage/blob/implementation/ContainersImpl$ContainersService.class',
'com/azure/storage/blob/implementation/DirectorysImpl$DirectorysService.class',
'com/azure/storage/blob/implementation/PageBlobsImpl$PageBlobsService.class',
'com/azure/storage/blob/implementation/ServicesImpl$ServicesService.class']

tasks.create('extractClientClasses', Copy).configure {
from({ zipTree(configurations.originalJar.singleFile) }) {
include "com/azure/storage/blob/implementation/**"
}
into project.file('build/original')
}

def modifiedOutput = project.layout.buildDirectory.dir('modified')
def makePublic = tasks.create('makeClientClassesPublic', JavaClassPublicifier)
makePublic.configure {
dependsOn 'extractClientClasses'
classFiles = classesToRewrite
inputDir = project.layout.buildDirectory.dir('original')
outputDir = modifiedOutput
}

sourceSets.main.output.dir(modifiedOutput, builtBy: makePublic)
Loading