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

mgmt, support function app on ACA #37890

Merged
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"
}
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,13 +174,49 @@ 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) {
storageAccountToSet = this.taskResult(storageAccountCreatable.key());
}
if (storageAccountToSet == null) {
return super.submitAppSettings();
} else if (isFunctionAppOnACA()) {
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);
return FunctionAppImpl.super.submitAppSettings();
}).then(
Mono
.fromCallable(
() -> {
resetStorageInfo();
return this;
}));
XiaofeiCao marked this conversation as resolved.
Show resolved Hide resolved
} else {
return Flux
.concat(
Expand Down Expand Up @@ -209,16 +248,23 @@ Mono<Indexable> submitAppSettings() {
Mono
.fromCallable(
() -> {
currentStorageAccount = storageAccountToSet;
storageAccountToSet = null;
storageAccountCreatable = null;
resetStorageInfo();
return this;
}));
}
}

private void resetStorageInfo() {
currentStorageAccount = storageAccountToSet;
storageAccountToSet = null;
storageAccountCreatable = null;
}

@Override
public OperatingSystem operatingSystem() {
if (isFunctionAppOnACA()) {
return OperatingSystem.LINUX;
XiaofeiCao marked this conversation as resolved.
Show resolved Hide resolved
}
return (innerModel().reserved() == null || !innerModel().reserved())
? OperatingSystem.WINDOWS : OperatingSystem.LINUX;
}
Expand Down Expand Up @@ -513,6 +559,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 +644,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 +688,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