Skip to content

Commit

Permalink
mgmt, support function app on ACA (#37890)
Browse files Browse the repository at this point in the history
* test case

* pom.xml

* interfaces

* javadocs

* interface

interface adjust

interface adjust

* implementation

imports

* assets.json

* changelog

* update note

* regen

* fix compilation after regen

* drop withManagedEnvironmentName

fix test

fix test

* assets.json

* update note in api-specs.json

* update pom.xml for dependency update

* nit, fix changelog.md

* update according to comments
  • Loading branch information
XiaofeiCao authored Dec 5, 2023
1 parent 3c906c6 commit 1a75d51
Show file tree
Hide file tree
Showing 13 changed files with 840 additions and 91 deletions.
3 changes: 1 addition & 2 deletions sdk/resourcemanager/api-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"dir": "azure-resourcemanager-appservice",
"source": "specification/web/resource-manager/readme.md",
"package": "com.azure.resourcemanager.appservice",
"args": "--tag=package-2023-01 --add-inner=AppServiceCertificate --remove-inner=CsmDeploymentStatus --name-for-ungrouped-operations=ResourceProvider",
"note": "Add status code '200' to 'syncFunctionTriggers' and 'syncFunctionTriggersSlot'"
"args": "--tag=package-2023-01 --add-inner=AppServiceCertificate --remove-inner=CsmDeploymentStatus --name-for-ungrouped-operations=ResourceProvider"
},
"appservice-hybrid": {
"dir": "../resourcemanagerhybrid/azure-resourcemanager-appservice",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### Features Added

- Supported Function App in Azure Container Apps environment.
- Supported `withManagedEnvironmentId` for `FunctionApp`.
- Supported `withMaxReplica` and `withMinReplica` for `FunctionApp`.

### Breaking Changes

### Bugs Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/resourcemanager/azure-resourcemanager-appservice",
"Tag": "java/resourcemanager/azure-resourcemanager-appservice_4acbe354d9"
"Tag": "java/resourcemanager/azure-resourcemanager-appservice_3c0a63fc34"
}
6 changes: 6 additions & 0 deletions sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@
<version>1.7.36</version> <!-- {x-version-update;org.slf4j:slf4j-simple;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-appcontainers</artifactId>
<version>1.0.0-beta.6</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-appcontainers;dependency} -->
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.management.serializer.SerializerFactory;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.UrlBuilder;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.appservice.AppServiceManager;
import com.azure.resourcemanager.appservice.fluent.models.HostKeysInner;
import com.azure.resourcemanager.appservice.fluent.models.SiteConfigInner;
import com.azure.resourcemanager.appservice.fluent.models.SiteConfigResourceInner;
import com.azure.resourcemanager.appservice.fluent.models.SiteInner;
import com.azure.resourcemanager.appservice.fluent.models.SiteLogsConfigInner;
import com.azure.resourcemanager.appservice.fluent.models.SitePatchResourceInner;
import com.azure.resourcemanager.appservice.models.AppServicePlan;
import com.azure.resourcemanager.appservice.models.FunctionApp;
import com.azure.resourcemanager.appservice.models.FunctionAuthenticationPolicy;
Expand Down Expand Up @@ -171,6 +174,24 @@ public FunctionAppImpl withLatestRuntimeVersion() {
return withRuntimeVersion("latest");
}

@Override
Mono<SiteInner> submitSite(SiteInner site) {
if (isFunctionAppOnACA()) {
return createOrUpdateInner(site);
} else {
return super.submitSite(site);
}
}

@Override
Mono<SiteInner> submitSite(SitePatchResourceInner siteUpdate) {
if (isFunctionAppOnACA()) {
return updateInner(siteUpdate);
} else {
return super.submitSite(siteUpdate);
}
}

@Override
Mono<Indexable> submitAppSettings() {
if (storageAccountCreatable != null && this.taskResult(storageAccountCreatable.key()) != null) {
Expand All @@ -179,19 +200,18 @@ Mono<Indexable> submitAppSettings() {
if (storageAccountToSet == null) {
return super.submitAppSettings();
} else {
return Flux
.concat(
storageAccountToSet
.getKeysAsync()
.map(storageAccountKeys -> storageAccountKeys.get(0))
.zipWith(
this.manager().appServicePlans().getByIdAsync(this.appServicePlanId()),
(StorageAccountKey storageAccountKey, AppServicePlan appServicePlan) -> {
String connectionString = ResourceManagerUtils
.getStorageConnectionString(storageAccountToSet.name(), storageAccountKey.value(),
manager().environment());
addAppSettingIfNotModified(SETTING_WEB_JOBS_STORAGE, connectionString);
addAppSettingIfNotModified(SETTING_WEB_JOBS_DASHBOARD, connectionString);
return storageAccountToSet
.getKeysAsync()
.flatMap(storageAccountKeys -> {
StorageAccountKey key = storageAccountKeys.get(0);
String connectionString = ResourceManagerUtils
.getStorageConnectionString(storageAccountToSet.name(), key.value(),
manager().environment());
addAppSettingIfNotModified(SETTING_WEB_JOBS_STORAGE, connectionString);
addAppSettingIfNotModified(SETTING_WEB_JOBS_DASHBOARD, connectionString);
if (!isFunctionAppOnACA()) {
return this.manager().appServicePlans().getByIdAsync(this.appServicePlanId())
.flatMap(appServicePlan -> {
if (appServicePlan == null
|| isConsumptionOrPremiumAppServicePlan(appServicePlan.pricingTier())) {

Expand All @@ -203,9 +223,11 @@ Mono<Indexable> submitAppSettings() {
.randomResourceName(name(), 32));
}
return FunctionAppImpl.super.submitAppSettings();
}))
.last()
.then(
});
} else {
return FunctionAppImpl.super.submitAppSettings();
}
}).then(
Mono
.fromCallable(
() -> {
Expand All @@ -219,6 +241,11 @@ Mono<Indexable> submitAppSettings() {

@Override
public OperatingSystem operatingSystem() {
if (isFunctionAppOnACA()) {
// TODO(xiaofei) Current Function App on ACA only supports LINUX containers.
// This logic will change after service supports Windows containers.
return OperatingSystem.LINUX;
}
return (innerModel().reserved() == null || !innerModel().reserved())
? OperatingSystem.WINDOWS : OperatingSystem.LINUX;
}
Expand Down Expand Up @@ -513,6 +540,27 @@ public Mono<Void> syncTriggersAsync() {
});
}

@Override
public String managedEnvironmentId() {
return innerModel().managedEnvironmentId();
}

@Override
public Integer maxReplicas() {
if (this.siteConfig == null) {
return null;
}
return this.siteConfig.functionAppScaleLimit();
}

@Override
public Integer minReplicas() {
if (this.siteConfig == null) {
return null;
}
return this.siteConfig.minimumElasticInstanceCount();
}

@Override
public Flux<String> streamApplicationLogsAsync() {
return functionService
Expand Down Expand Up @@ -577,10 +625,30 @@ public void zipDeploy(InputStream zipFile, long length) {
zipDeployAsync(zipFile, length).block();
}

@Override
public void beforeGroupCreateOrUpdate() {
// special handling for Function App on ACA
if (isFunctionAppOnACA()) {
adaptForFunctionAppOnACA();
}
super.beforeGroupCreateOrUpdate();
}

private void adaptForFunctionAppOnACA() {
this.innerModel().withReserved(null);
if (this.siteConfig != null) {
SiteConfigInner siteConfigInner = new SiteConfigInner();
siteConfigInner.withLinuxFxVersion(this.siteConfig.linuxFxVersion());
siteConfigInner.withMinimumElasticInstanceCount(this.siteConfig.minimumElasticInstanceCount());
siteConfigInner.withFunctionAppScaleLimit(this.siteConfig.functionAppScaleLimit());
this.innerModel().withSiteConfig(siteConfigInner);
}
}

@Override
public Mono<FunctionApp> createAsync() {
if (this.isInCreateMode()) {
if (innerModel().serverFarmId() == null) {
if (innerModel().serverFarmId() == null && !isFunctionAppOnACA()) {
withNewConsumptionPlan();
}
if (currentStorageAccount == null && storageAccountToSet == null && storageAccountCreatable == null) {
Expand All @@ -601,6 +669,42 @@ public Mono<Void> afterPostRunAsync(final boolean isGroupFaulted) {
return super.afterPostRunAsync(isGroupFaulted);
}

@Override
public FunctionAppImpl withManagedEnvironmentId(String managedEnvironmentId) {
this.innerModel().withManagedEnvironmentId(managedEnvironmentId);
if (!CoreUtils.isNullOrEmpty(managedEnvironmentId)) {
this.innerModel().withKind("functionapp,linux,container,azurecontainerapps");
}
return this;
}

@Override
public FunctionAppImpl withMaxReplicas(int maxReplicas) {
if (siteConfig == null) {
siteConfig = new SiteConfigResourceInner();
}
siteConfig.withFunctionAppScaleLimit(maxReplicas);
return this;
}

@Override
public FunctionAppImpl withMinReplicas(int minReplicas) {
if (siteConfig == null) {
siteConfig = new SiteConfigResourceInner();
}
siteConfig.withMinimumElasticInstanceCount(minReplicas);
return this;
}

/**
* Whether this Function App is on Azure Container Apps environment.
*
* @return whether this Function App is on Azure Container Apps environment
*/
private boolean isFunctionAppOnACA() {
return !CoreUtils.isNullOrEmpty(this.innerModel().managedEnvironmentId());
}

@Host("{$host}")
@ServiceInterface(name = "FunctionService")
private interface FunctionService {
Expand Down
Loading

0 comments on commit 1a75d51

Please sign in to comment.