Skip to content

Commit 2fc6590

Browse files
authored
Initialize Java language worker in placeholder mode (#3936)
* InitializeChannelsAsync in Placeholdermode * Update Java worker - PicoHelper * Update E2E test to read environment variable * Add more tests
1 parent 75937b5 commit 2fc6590

File tree

17 files changed

+118
-77
lines changed

17 files changed

+118
-77
lines changed

sample/Java/HttpTrigger/Function.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@
1313
* Accept defaults for rest of the identifiers
1414
* Run mvn clean package
1515
*/
16-
public class Function {
16+
public class Function {
1717
@FunctionName("HttpTrigger")
18-
public HttpResponseMessage HttpTrigger(
19-
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
18+
public HttpResponseMessage run(
19+
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<Optional<String>> request,
2020
final ExecutionContext context) {
2121
context.getLogger().info("Java HTTP trigger processed a request.");
2222

2323
// Parse query parameter
2424
String query = request.getQueryParameters().get("name");
2525
String name = request.getBody().orElse(query);
26+
String readEnv = System.getenv("AzureWebJobsStorage");
2627

2728
if (name == null) {
2829
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
29-
} else {
30-
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
3130
}
31+
if (readEnv == null ) {
32+
return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR).body("AzureWebJobsStorage is empty").build();
33+
}
34+
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
3235
}
3336
}
452 Bytes
Binary file not shown.
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
{
22
"scriptFile" : "HttpTrigger-1.0-SNAPSHOT.jar",
3-
"entryPoint" : "Microsoft.Azure.WebJobs.Script.Tests.EndToEnd.Function.HttpTrigger",
3+
"entryPoint" : "Microsoft.Azure.WebJobs.Script.Tests.EndToEnd.Function.run",
44
"bindings" : [ {
55
"type" : "httpTrigger",
6-
"name" : "req",
76
"direction" : "in",
8-
"webHookType" : "NONE",
9-
"authLevel" : "anonymous",
10-
"methods" : [ "GET", "POST" ]
7+
"methods" : [ "GET", "POST" ],
8+
"name" : "req"
119
}, {
1210
"type" : "http",
13-
"name" : "$return",
14-
"direction" : "out"
11+
"direction" : "out",
12+
"name" : "$return"
1513
} ]
1614
}

src/WebJobs.Script.WebHost/Standby/StandbyManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.IO;
76
using System.Reactive.Linq;
87
using System.Threading;
98
using System.Threading.Tasks;
10-
using Microsoft.Azure.WebJobs.Script.Eventing;
119
using Microsoft.Azure.WebJobs.Script.Rpc;
1210
using Microsoft.Azure.WebJobs.Script.WebHost.Properties;
1311
using Microsoft.Extensions.Configuration;

src/WebJobs.Script/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WebJobs.Script/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,7 @@
120120
<data name="DotNetFunctionEntryPointRulesMessage" xml:space="preserve">
121121
<value>Your function must contain a single public method, a public method named 'Run', or a public method matching the name specified in the 'entryPoint' metadata property.</value>
122122
</data>
123+
<data name="LanguageWorkerChannelSpecializationTrace" xml:space="preserve">
124+
<value>Starting language worker channel specialization</value>
125+
</data>
123126
</root>

src/WebJobs.Script/Rpc/LanguageWorkerChannelManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.Azure.WebJobs.Script.Abstractions;
1010
using Microsoft.Azure.WebJobs.Script.Diagnostics;
1111
using Microsoft.Azure.WebJobs.Script.Eventing;
12+
using Microsoft.Azure.WebJobs.Script.Properties;
1213
using Microsoft.Extensions.Logging;
1314
using Microsoft.Extensions.Options;
1415

@@ -117,7 +118,7 @@ public ILanguageWorkerChannel GetChannel(string language)
117118

118119
public async Task SpecializeAsync()
119120
{
120-
_logger.LogInformation($"Starting language worker channels specialization");
121+
_logger.LogInformation(Resources.LanguageWorkerChannelSpecializationTrace);
121122
_workerRuntime = _environment.GetEnvironmentVariable(LanguageWorkerConstants.FunctionWorkerRuntimeSettingName);
122123
ILanguageWorkerChannel languageWorkerChannel = GetChannel(_workerRuntime);
123124
if (_workerRuntime != null && languageWorkerChannel != null)

src/WebJobs.Script/Rpc/RpcInitializationService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
4343
}
4444
_logger.LogInformation("Starting Rpc Initialization Service.");
4545
await InitializeRpcServerAsync();
46-
// TODO: pgopa Uncomment following after addressing issue https://github.com/Azure/azure-functions-host/issues/3872
47-
// await InitializeChannelsAsync();
46+
await InitializeChannelsAsync();
4847
}
4948

5049
public async Task StopAsync(CancellationToken cancellationToken)

src/WebJobs.Script/WebJobs.Script.csproj

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<NoWarn>NU1701</NoWarn>
3636
</PackageReference>
3737
<PackageReference Include="Microsoft.Azure.AppService.Proxy.Client" Version="2.0.6830001-df202c6c" />
38-
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="1.2.3" />
38+
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="1.2.4" />
3939
<PackageReference Include="Microsoft.Azure.Functions.NodeJsWorker" Version="1.0.0-beta7" />
4040
<PackageReference Include="Microsoft.Azure.Functions.PowerShellWorker" Version="0.1.52-alpha" />
4141
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.4" />
@@ -68,4 +68,19 @@
6868
<ProjectReference Include="..\WebJobs.Script.Grpc\WebJobs.Script.Grpc.csproj" />
6969
</ItemGroup>
7070

71+
<ItemGroup>
72+
<Compile Update="Properties\Resources.Designer.cs">
73+
<DesignTime>True</DesignTime>
74+
<AutoGen>True</AutoGen>
75+
<DependentUpon>Resources.resx</DependentUpon>
76+
</Compile>
77+
</ItemGroup>
78+
79+
<ItemGroup>
80+
<EmbeddedResource Update="Properties\Resources.resx">
81+
<Generator>ResXFileCodeGenerator</Generator>
82+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
83+
</EmbeddedResource>
84+
</ItemGroup>
85+
7186
</Project>

test/WebJobs.Script.Tests.Integration/Host/StandbyManagerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ await TestHelpers.Await(() =>
8282
Assert.Equal(2, logLines.Count(p => p.Contains("Host is in standby mode")));
8383
Assert.Equal(2, logLines.Count(p => p.Contains("Executed 'Functions.WarmUp' (Succeeded")));
8484
Assert.Equal(1, logLines.Count(p => p.Contains("Starting host specialization")));
85+
Assert.Equal(1, logLines.Count(p => p.Contains("Starting language worker channel specialization")));
8586
Assert.Equal(3, logLines.Count(p => p.Contains($"Starting Host (HostId={_expectedHostId}")));
8687
Assert.Equal(3, logLines.Count(p => p.Contains($"Loading functions metadata")));
8788
Assert.Equal(2, logLines.Count(p => p.Contains($"1 functions loaded")));

0 commit comments

Comments
 (0)