Skip to content

Commit 2cf6740

Browse files
Add shading suppport
1 parent e0bfc6e commit 2cf6740

Some content is hidden

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

47 files changed

+219
-18
lines changed

README.md

+2-2

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ build_script:
3030
Write-Host “Found git tag."
3131
}
3232
else {
33-
$buildNumber = "1.6.2-$env:APPVEYOR_BUILD_NUMBER"
33+
$buildNumber = "1.7.1-$env:APPVEYOR_BUILD_NUMBER"
3434
Write-Host “git tag not found. Setting package suffix to '$buildNumber'"
3535
}
3636
.\package.ps1 -buildNumber $buildNumber

azure-pipelines.yml

+18-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ steps:
1919
Write-Host “Found git tag."
2020
}
2121
else {
22-
$buildNumber = "1.6.2-$(Build.BuildId)"
22+
$buildNumber = "1.7.1-$(Build.BuildId)"
2323
Write-Host “git tag not found. Setting package suffix to '$buildNumber'"
2424
}
25-
.\package.ps1 -buildNumber $buildNumber
25+
.\package-pipeline.ps1 -buildNumber $buildNumber
2626
displayName: 'Executing build script'
2727
- task: CopyFiles@2
2828
inputs:
@@ -49,6 +49,22 @@ steps:
4949
SBQueueName: $(SBQueueName)
5050
displayName: 'Build & Run tests for java 8'
5151
continueOnError: false
52+
- pwsh: |
53+
.\build-run-tests-pipeline.ps1
54+
env:
55+
JAVA_REVERSE_LIB_LOADING: 'True'
56+
AzureWebJobsStorage: $(AzureWebJobsStorage)
57+
AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString)
58+
AzureWebJobsServiceBus: $(AzureWebJobsServiceBus)
59+
AzureWebJobsEventHubReceiver: $(AzureWebJobsEventHubReceiver)
60+
AzureWebJobsEventHubSender: $(AzureWebJobsEventHubSender)
61+
AzureWebJobsEventHubPath: $(AzureWebJobsEventHubPath)
62+
SBTopicName: $(SBTopicName)
63+
SBTopicSubName: $(SBTopicSubName)
64+
CosmosDBDatabaseName: $(CosmosDBDatabaseName)
65+
SBQueueName: $(SBQueueName)
66+
displayName: 'Build & Run tests for java 8 Customer jar loaded first'
67+
continueOnError: false
5268
- pwsh: |
5369
.\build-run-tests-pipeline.ps1
5470
env:

e2e-nightly-cli-azure-pipelines.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ steps:
1919
Write-Host “Found git tag."
2020
}
2121
else {
22-
$buildNumber = "1.6.2-$(Build.BuildId)"
22+
$buildNumber = "1.7.1-$(Build.BuildId)"
2323
Write-Host “git tag not found. Setting package suffix to '$buildNumber'"
2424
}
2525
.\package.ps1 -buildNumber $buildNumber

endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/HttpEndToEndTests.cs

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Net;
56
using System.Threading.Tasks;
67
using Xunit;
@@ -33,5 +34,20 @@ public async Task HttpTrigger_ReturnsCustomCode()
3334
{
3435
Assert.True(await Utilities.InvokeHttpTrigger("HttpTriggerCustomCode", "?&name=Test", HttpStatusCode.OK, "Test", 209));
3536
}
37+
38+
[Fact]
39+
public async Task HttpTriggerJavaClassLoader()
40+
{
41+
String value = Environment.GetEnvironmentVariable("JAVA_REVERSE_LIB_LOADING");
42+
String java_home = Environment.GetEnvironmentVariable("JAVA_HOME");
43+
if (java_home.Contains("zulu-11") || (value != null && value.ToLower().Equals("true")))
44+
{
45+
Assert.True(await Utilities.InvokeHttpTrigger("HttpTriggerJavaClassLoader", "?&name=Test", HttpStatusCode.OK, "Test"));
46+
}
47+
else
48+
{
49+
Assert.True(await Utilities.InvokeHttpTrigger("HttpTriggerJavaClassLoader", "?&name=Test", HttpStatusCode.InternalServerError, ""));
50+
}
51+
}
3652
}
3753
}

endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/HttpTriggerTests.java

+27-5
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ public HttpResponseMessage HttpTriggerJava(
4747
}
4848

4949
Gson a = new Gson();
50-
51-
// if(!SystemUtils.IS_JAVA_15) {
52-
// context.getLogger().info("Java version not 15");
53-
// }
54-
5550
get("https://httpstat.us/200");
5651

5752
if (name == null ) {
@@ -108,4 +103,31 @@ public HttpResponseMessage HttpTriggerCustomCode(
108103
return request.createResponseBuilder(HttpStatusType.custom(209)).body("Hello, " + name).build();
109104
}
110105
}
106+
107+
@FunctionName("HttpTriggerJavaClassLoader")
108+
public HttpResponseMessage HttpTriggerJavaDefault(
109+
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
110+
final ExecutionContext context
111+
) throws Exception {
112+
context.getLogger().info("Java HTTP trigger processed a request.");
113+
114+
// Parse query parameters
115+
String query = request.getQueryParameters().get("name");
116+
String name = request.getBody().orElse(query);
117+
String readEnv = System.getenv("AzureWebJobsStorage");
118+
119+
Gson a = new Gson();
120+
121+
if(!SystemUtils.IS_JAVA_15) {
122+
context.getLogger().info("Java version not 15");
123+
}
124+
125+
if (name == null ) {
126+
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
127+
}
128+
if (readEnv == null ) {
129+
return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR).body("AzureWebJobsStorage is empty").build();
130+
}
131+
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
132+
}
111133
}
Binary file not shown.
3.05 KB
Binary file not shown.
189 KB
Binary file not shown.

lib_worker_1.6.2/commons-cli-1.4.jar

52.6 KB
Binary file not shown.
492 KB
Binary file not shown.
Binary file not shown.
28.3 KB
Binary file not shown.

lib_worker_1.6.2/grpc-core-1.20.0.jar

763 KB
Binary file not shown.
218 KB
Binary file not shown.
4.88 KB
Binary file not shown.
7.44 KB
Binary file not shown.

lib_worker_1.6.2/grpc-stub-1.20.0.jar

38.6 KB
Binary file not shown.

lib_worker_1.6.2/gson-2.8.5.jar

236 KB
Binary file not shown.

lib_worker_1.6.2/guava-26.0-jre.jar

2.61 MB
Binary file not shown.
8.58 KB
Binary file not shown.
Binary file not shown.

lib_worker_1.6.2/jna-5.3.0.jar

1.44 MB
Binary file not shown.
2.5 MB
Binary file not shown.

lib_worker_1.6.2/jsr305-3.0.2.jar

19.5 KB
Binary file not shown.
272 KB
Binary file not shown.
309 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
575 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
320 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
1.36 MB
Binary file not shown.

package-pipeline.ps1

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
param (
2+
[string]$buildNumber = $env:APPVEYOR_BUILD_NUMBER
3+
)
4+
5+
# A function that checks exit codes and fails script if an error is found
6+
function StopOnFailedExecution {
7+
if ($LastExitCode)
8+
{
9+
exit $LastExitCode
10+
}
11+
}
12+
Write-Host "Building azure-functions-java-worker"
13+
cmd.exe /c '.\mvnBuild.bat'
14+
StopOnFailedExecution
15+
16+
Write-Host "Creating nuget package Microsoft.Azure.Functions.JavaWorker"
17+
Write-Host "buildNumber: " $buildNumber
18+
Get-Command nuget
19+
StopOnFailedExecution
20+
remove-item pkg -Recurse -ErrorAction Ignore
21+
mkdir pkg
22+
Get-ChildItem -Path .\target\* -Include 'azure*' -Exclude '*shaded.jar','*tests.jar' | %{ Copy-Item $_.FullName .\pkg\azure-functions-java-worker.jar }
23+
StopOnFailedExecution
24+
copy-item ./worker.config.json pkg
25+
copy-item ./tools/AzureFunctionsJavaWorker.nuspec pkg/
26+
Copy-Item ".\lib_worker_1.6.2" pkg\lib -Recurse
27+
set-location pkg
28+
nuget pack -Properties version=$buildNumber
29+
set-location ..

package.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Get-ChildItem -Path .\target\* -Include 'azure*' -Exclude '*shaded.jar' | %{ Cop
2323
StopOnFailedExecution
2424
copy-item ./worker.config.json pkg
2525
copy-item ./tools/AzureFunctionsJavaWorker.nuspec pkg/
26+
Copy-Item ".\lib_worker_1.6.2" pkg\lib -Recurse
2627
set-location pkg
2728
nuget pack -Properties version=$buildNumber
2829
set-location ..

pom.xml

+54-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.microsoft.azure.functions</groupId>
66
<artifactId>azure-functions-java-worker</artifactId>
7-
<version>1.6.2</version>
7+
<version>1.7.1</version>
88
<packaging>jar</packaging>
99
<parent>
1010
<groupId>com.microsoft.maven</groupId>
@@ -174,7 +174,7 @@
174174
</plugin>
175175
<plugin>
176176
<artifactId>maven-shade-plugin</artifactId>
177-
<version>3.2.0</version>
177+
<version>3.2.4</version>
178178
<executions>
179179
<execution>
180180
<phase>package</phase>
@@ -184,14 +184,15 @@
184184
<configuration>
185185
<transformers>
186186
<transformer
187-
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
187+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
188188
<mainClass>com.microsoft.azure.functions.worker.Application</mainClass>
189189
<manifestEntries>
190190
<Implementation-Title>${project.name}</Implementation-Title>
191191
<Implementation-Version>${project.version}</Implementation-Version>
192192
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
193193
</manifestEntries>
194194
</transformer>
195+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
195196
</transformers>
196197
<filters>
197198
<filter>
@@ -203,6 +204,56 @@
203204
</excludes>
204205
</filter>
205206
</filters>
207+
<relocations>
208+
<relocation combine.children="append">
209+
<pattern>com.google</pattern>
210+
<shadedPattern>com.microsoft.azure.functions.shaded.com.google</shadedPattern>
211+
</relocation>
212+
<relocation combine.children="append">
213+
<pattern>com.sun</pattern>
214+
<shadedPattern>com.microsoft.azure.functions.shaded.com.sun</shadedPattern>
215+
</relocation>
216+
<relocation combine.children="append">
217+
<pattern>android</pattern>
218+
<shadedPattern>com.microsoft.azure.functions.shaded.android</shadedPattern>
219+
</relocation>
220+
<relocation combine.children="append">
221+
<pattern>google</pattern>
222+
<shadedPattern>com.microsoft.azure.functions.shaded.google</shadedPattern>
223+
</relocation>
224+
<relocation combine.children="append">
225+
<pattern>identity</pattern>
226+
<shadedPattern>com.microsoft.azure.functions.shaded.identity</shadedPattern>
227+
</relocation>
228+
<relocation combine.children="append">
229+
<pattern>shared</pattern>
230+
<shadedPattern>com.microsoft.azure.functions.shaded.shared</shadedPattern>
231+
</relocation>
232+
<relocation combine.children="append">
233+
<pattern>org</pattern>
234+
<shadedPattern>com.microsoft.azure.functions.shaded.org</shadedPattern>
235+
</relocation>
236+
<relocation combine.children="append">
237+
<pattern>io.netty</pattern>
238+
<shadedPattern>com.microsoft.azure.functions.shaded.io.netty</shadedPattern>
239+
</relocation>
240+
<relocation combine.children="append">
241+
<pattern>io.perfmark</pattern>
242+
<shadedPattern>com.microsoft.azure.functions.shaded.io.perfmark</shadedPattern>
243+
</relocation>
244+
<relocation combine.children="append">
245+
<pattern>io.grpc</pattern>
246+
<shadedPattern>com.microsoft.azure.functions.shaded.io.grpc</shadedPattern>
247+
</relocation>
248+
<relocation combine.children="append">
249+
<pattern>javax.annotation</pattern>
250+
<shadedPattern>com.microsoft.azure.functions.shaded.javax.annotation</shadedPattern>
251+
</relocation>
252+
<relocation combine.children="append">
253+
<pattern>io.opencensus</pattern>
254+
<shadedPattern>com.microsoft.azure.functions.shaded.io.opencensus</shadedPattern>
255+
</relocation>
256+
</relocations>
206257
</configuration>
207258
</execution>
208259
</executions>

setup-tests-pipeline.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ if(!$skipCliDownload)
3636
Write-Host "Copying azure-functions-java-worker to Functions Host workers directory...."
3737
Get-ChildItem -Path .\target\* -Include 'azure*' -Exclude '*shaded.jar','*tests.jar' | %{ Copy-Item $_.FullName ".\Azure.Functions.Cli\workers\java\azure-functions-java-worker.jar" }
3838
Copy-Item ".\worker.config.json" ".\Azure.Functions.Cli\workers\java"
39-
39+
Copy-Item ".\lib_worker_1.6.2" ".\Azure.Functions.Cli\workers\java\lib" -Recurse

setup-tests.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ if(!$skipCliDownload)
4444
Write-Host "Copying azure-functions-java-worker to Functions Host workers directory...."
4545
Get-ChildItem -Path .\target\* -Include 'azure*' -Exclude '*shaded.jar','*tests.jar' | %{ Copy-Item $_.FullName ".\Azure.Functions.Cli\workers\java\azure-functions-java-worker.jar" }
4646
Copy-Item ".\worker.config.json" ".\Azure.Functions.Cli\workers\java"
47+
Copy-Item ".\lib_worker_1.6.2" ".\Azure.Functions.Cli\workers\java\lib" -Recurse
4748

4849
Write-Host "Building endtoendtests...."
4950
$Env:Path = $Env:Path+";$currDir\Azure.Functions.Cli"

src/main/java/com/microsoft/azure/functions/worker/Constants.java

+2
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
public final class Constants {
77
private Constants(){}
88
public final static String TRIGGER_METADATA_DOLLAR_REQUEST_KEY = "$request";
9+
public final static String FUNCTIONS_WORKER_DIRECTORY = "FUNCTIONS_WORKER_DIRECTORY";
10+
public final static String JAVA_REVERSE_LIB_LOADING = "JAVA_REVERSE_LIB_LOADING";
911
}

src/main/java/com/microsoft/azure/functions/worker/broker/JavaFunctionBroker.java

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package com.microsoft.azure.functions.worker.broker;
22

33
import java.io.File;
4+
import java.io.FileFilter;
45
import java.io.IOException;
56
import java.net.URL;
67
import java.util.*;
78
import java.util.concurrent.ConcurrentHashMap;
9+
import java.util.logging.Level;
810

911
import com.microsoft.azure.functions.rpc.messages.*;
1012
import com.microsoft.azure.functions.worker.Constants;
13+
import com.microsoft.azure.functions.worker.WorkerLogManager;
1114
import com.microsoft.azure.functions.worker.binding.BindingDataStore;
1215
import com.microsoft.azure.functions.worker.description.FunctionMethodDescriptor;
1316
import com.microsoft.azure.functions.worker.reflect.ClassLoaderProvider;
1417

18+
import org.apache.commons.lang3.SystemUtils;
1519
import org.apache.commons.lang3.exception.ExceptionUtils;
1620
import org.apache.commons.lang3.tuple.ImmutablePair;
1721

@@ -87,14 +91,48 @@ private void addSearchPathsToClassLoader(FunctionMethodDescriptor function) thro
8791
function.getLibDirectory().ifPresent(d -> registerWithClassLoaderProvider(d));
8892
}
8993

90-
private void registerWithClassLoaderProvider(File libDirectory) {
94+
void registerWithClassLoaderProvider(File libDirectory) {
9195
try {
92-
classLoaderProvider.addDirectory(libDirectory);
96+
if(SystemUtils.IS_JAVA_1_8) {
97+
String workerLibPath = System.getenv(Constants.FUNCTIONS_WORKER_DIRECTORY) + "/lib";
98+
String javaReverseLibLoading = System.getenv(Constants.JAVA_REVERSE_LIB_LOADING);
99+
File workerLib = new File(workerLibPath);
100+
if(javaReverseLibLoading != null && javaReverseLibLoading.toLowerCase().equals("true")) {
101+
if(checkLibFolder(workerLib, workerLibPath, "CLIENT_LIB_FIRST")) {
102+
classLoaderProvider.addDirectory(libDirectory);
103+
classLoaderProvider.addDirectory(workerLib);
104+
}
105+
} else {
106+
if(checkLibFolder(workerLib, workerLibPath, "WORKER_LIB_FIRST")) {
107+
classLoaderProvider.addDirectory(workerLib);
108+
classLoaderProvider.addDirectory(libDirectory);
109+
}
110+
}
111+
} else {
112+
classLoaderProvider.addDirectory(libDirectory);
113+
}
93114
} catch (Exception ex) {
94115
ExceptionUtils.rethrow(ex);
95116
}
96117
}
97118

119+
boolean checkLibFolder(File workerLib, String workerLibPath, String status) throws Exception{
120+
if(!workerLib.exists()) {
121+
throw new Exception("Error loading worker jars, for "+ status +", from path: " + workerLibPath);
122+
} else {
123+
File[] jarFiles = workerLib.listFiles(new FileFilter() {
124+
@Override
125+
public boolean accept(File file) {
126+
return file.isFile() && file.getName().endsWith(".jar");
127+
}
128+
});
129+
if(jarFiles.length == 0) {
130+
throw new Exception("Error loading worker jars, for "+ status +", from path: " + workerLibPath + ". Jars size is zero");
131+
}
132+
}
133+
return true;
134+
}
135+
98136
private final Map<String, ImmutablePair<String, JavaMethodExecutor>> methods;
99137
private final ClassLoaderProvider classLoaderProvider;
100138
}

0 commit comments

Comments
 (0)