Skip to content

Commit

Permalink
mgmt, support functionapp java17 (Azure#29994)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Aug 18, 2022
1 parent 0a48859 commit 44184a3
Show file tree
Hide file tree
Showing 6 changed files with 610 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
- Supported Java SE 17 in `FunctionRuntimeStack` for `FunctionApp`.

## 2.17.0 (2022-07-25)

Expand Down
2 changes: 2 additions & 0 deletions sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
--add-opens com.azure.resourcemanager.resources/com.azure.resourcemanager.resources=ALL-UNNAMED
--add-opens com.azure.resourcemanager.resources/com.azure.resourcemanager.resources.fluentcore.arm=ALL-UNNAMED
--add-opens com.azure.resourcemanager.storage/com.azure.resourcemanager.storage=ALL-UNNAMED

--add-opens com.azure.core/com.azure.core.implementation.util=ALL-UNNAMED
</javaModulesSurefireArgLine>
<revapi.skip>true</revapi.skip>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class FunctionRuntimeStack {
public static final FunctionRuntimeStack JAVA_11 = new FunctionRuntimeStack("java", "~3",
"java|11");

/** JAVA 17. */
public static final FunctionRuntimeStack JAVA_17 = new FunctionRuntimeStack("java", "~4",
"java|17");

private final String runtime;
private final String version;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.azure.core.http.HttpPipeline;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.management.exception.ManagementException;
import com.azure.resourcemanager.appservice.models.AppServicePlan;
import com.azure.resourcemanager.appservice.models.AppSetting;
Expand All @@ -21,13 +22,12 @@
import com.azure.resourcemanager.storage.models.StorageAccount;
import com.azure.resourcemanager.storage.models.StorageAccountSkuType;
import com.azure.resourcemanager.storage.StorageManager;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.time.Duration;
import java.util.Arrays;
import java.util.Map;
import java.util.regex.Pattern;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -218,7 +218,7 @@ public void canCRUDLinuxFunctionApp() throws Exception {
.withAppSetting("WEBSITE_RUN_FROM_PACKAGE", FUNCTION_APP_PACKAGE_URL)
.create();
Assertions.assertNotNull(functionApp1);
assertLinuxJava(functionApp1, FunctionRuntimeStack.JAVA_8.getLinuxFxVersion());
assertLinuxJava(functionApp1, FunctionRuntimeStack.JAVA_8);

AppServicePlan plan1 = appServiceManager.appServicePlans().getById(functionApp1.appServicePlanId());
Assertions.assertNotNull(plan1);
Expand All @@ -228,7 +228,7 @@ public void canCRUDLinuxFunctionApp() throws Exception {
Assertions
.assertTrue(
Arrays
.asList(functionApp1.innerModel().kind().split(","))
.asList(functionApp1.innerModel().kind().split(Pattern.quote(",")))
.containsAll(Arrays.asList("linux", "functionapp")));

PagedIterable<FunctionAppBasic> functionApps = appServiceManager.functionApps().listByResourceGroup(rgName1);
Expand All @@ -247,7 +247,7 @@ public void canCRUDLinuxFunctionApp() throws Exception {
.withAppSetting("WEBSITE_RUN_FROM_PACKAGE", FUNCTION_APP_PACKAGE_URL)
.create();
Assertions.assertNotNull(functionApp2);
assertLinuxJava(functionApp2, FunctionRuntimeStack.JAVA_8.getLinuxFxVersion());
assertLinuxJava(functionApp2, FunctionRuntimeStack.JAVA_8);

AppServicePlan plan2 = appServiceManager.appServicePlans().getById(functionApp2.appServicePlanId());
Assertions.assertNotNull(plan2);
Expand All @@ -266,7 +266,7 @@ public void canCRUDLinuxFunctionApp() throws Exception {
.withAppSetting("WEBSITE_RUN_FROM_PACKAGE", FUNCTION_APP_PACKAGE_URL)
.create();
Assertions.assertNotNull(functionApp3);
assertLinuxJava(functionApp3, FunctionRuntimeStack.JAVA_8.getLinuxFxVersion());
assertLinuxJava(functionApp3, FunctionRuntimeStack.JAVA_8);

// wait for deploy
if (!isPlaybackMode()) {
Expand Down Expand Up @@ -310,8 +310,7 @@ public void canCRUDLinuxFunctionAppPremium() {
AppServicePlan plan1 = appServiceManager.appServicePlans().getById(functionApp1.appServicePlanId());
Assertions.assertNotNull(plan1);
Assertions.assertEquals(new PricingTier(SkuName.ELASTIC_PREMIUM.toString(), "EP1"), plan1.pricingTier());
Assertions.assertTrue(plan1.innerModel().reserved());
assertLinuxJava(functionApp1, FunctionRuntimeStack.JAVA_8.getLinuxFxVersion());
assertLinuxJava(functionApp1, FunctionRuntimeStack.JAVA_8);

// wait for deploy
if (!isPlaybackMode()) {
Expand Down Expand Up @@ -352,36 +351,81 @@ public void canCRUDLinuxFunctionAppPremiumDocker() {
public void canCRUDLinuxFunctionAppJava11() throws Exception {
rgName2 = null;

String runtimeVersion = "~4";

// function app with consumption plan
FunctionApp functionApp1 = appServiceManager.functionApps().define(webappName1)
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName1)
.withNewLinuxConsumptionPlan()
.withBuiltInImage(FunctionRuntimeStack.JAVA_11)
.withRuntimeVersion(runtimeVersion)
.withHttpsOnly(true)
.withAppSetting("WEBSITE_RUN_FROM_PACKAGE", FUNCTION_APP_PACKAGE_URL)
.create();
Assertions.assertNotNull(functionApp1);
assertLinuxJava(functionApp1, FunctionRuntimeStack.JAVA_11, runtimeVersion);

assertRunning(functionApp1);
}

@Test
public void canCRUDLinuxFunctionAppJava17() throws Exception {
rgName2 = null;

// function app with consumption plan
FunctionApp functionApp1 = appServiceManager.functionApps().define(webappName1)
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName1)
.withNewLinuxConsumptionPlan()
.withBuiltInImage(FunctionRuntimeStack.JAVA_17)
.withHttpsOnly(true)
.withAppSetting("WEBSITE_RUN_FROM_PACKAGE", FUNCTION_APP_PACKAGE_URL)
.create();
Assertions.assertNotNull(functionApp1);
assertLinuxJava(functionApp1, FunctionRuntimeStack.JAVA_11.getLinuxFxVersion());
assertLinuxJava(functionApp1, FunctionRuntimeStack.JAVA_17);

assertRunning(functionApp1);
}

private void assertRunning(FunctionApp functionApp) {
if (!isPlaybackMode()) {
// wait
ResourceManagerUtils.sleep(Duration.ofMinutes(1));

String name = "linux_function_app";
Response<String> response = curl("https://" + functionApp.defaultHostname()
+ "/api/HttpTrigger-Java?name=" + name);
Assertions.assertEquals(200, response.getStatusCode());
String body = response.getValue();
Assertions.assertNotNull(body);
Assertions.assertTrue(body.contains("Hello, " + name));
}
}

private static Map<String, AppSetting> assertLinuxJava(FunctionApp functionApp, FunctionRuntimeStack stack) {
return assertLinuxJava(functionApp, stack, null);
}

private static Map<String, AppSetting> assertLinuxJava(FunctionApp functionApp, String linuxFxVersion) {
Assertions.assertEquals(linuxFxVersion, functionApp.linuxFxVersion());
private static Map<String, AppSetting> assertLinuxJava(FunctionApp functionApp, FunctionRuntimeStack stack,
String runtimeVersion) {
Assertions.assertEquals(stack.getLinuxFxVersion(), functionApp.linuxFxVersion());
Assertions
.assertTrue(
Arrays
.asList(functionApp.innerModel().kind().split(","))
.asList(functionApp.innerModel().kind().split(Pattern.quote(",")))
.containsAll(Arrays.asList("linux", "functionapp")));
Assertions.assertTrue(functionApp.innerModel().reserved());

Map<String, AppSetting> appSettings = functionApp.getAppSettings();
Assertions.assertNotNull(appSettings);
Assertions.assertNotNull(appSettings.get(KEY_AZURE_WEB_JOBS_STORAGE));
Assertions
.assertEquals(FunctionRuntimeStack.JAVA_8.runtime(), appSettings.get(KEY_FUNCTIONS_WORKER_RUNTIME).value());
Assertions
.assertEquals(
FunctionRuntimeStack.JAVA_8.version(), appSettings.get(KEY_FUNCTIONS_EXTENSION_VERSION).value());
Assertions.assertEquals(
stack.runtime(),
appSettings.get(KEY_FUNCTIONS_WORKER_RUNTIME).value());
Assertions.assertEquals(
runtimeVersion == null ? stack.version() : runtimeVersion,
appSettings.get(KEY_FUNCTIONS_EXTENSION_VERSION).value());

return appSettings;
}
Expand Down Expand Up @@ -429,16 +473,4 @@ private static FunctionAppResource getStorageAccount(StorageManager storageManag

return resource;
}

private static String readLine(InputStream in) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
int c;
for (c = in.read(); c != '\n' && c >= 0; c = in.read()) {
stream.write(c);
}
if (c == -1 && stream.size() == 0) {
return null;
}
return stream.toString("UTF-8");
}
}
Loading

0 comments on commit 44184a3

Please sign in to comment.