From 1a75d51b2c751ae021f4897e0e3ae799a15db1b0 Mon Sep 17 00:00:00 2001 From: Xiaofei Cao <92354331+XiaofeiCao@users.noreply.github.com> Date: Tue, 5 Dec 2023 14:00:42 +0800 Subject: [PATCH] mgmt, support function app on ACA (#37890) * 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 --- sdk/resourcemanager/api-specs.json | 3 +- .../CHANGELOG.md | 4 + .../assets.json | 2 +- .../azure-resourcemanager-appservice/pom.xml | 6 + .../appservice/fluent/WebAppsClient.java | 207 +++++++++- .../implementation/FunctionAppImpl.java | 138 ++++++- .../implementation/WebAppsClientImpl.java | 391 ++++++++++++++++-- .../appservice/models/FunctionApp.java | 87 +++- .../appservice/AppServiceTest.java | 2 +- .../appservice/FunctionAppsTests.java | 82 +++- ...ppsCreateOrUpdateConfigurationSamples.java | 3 +- ...bAppsUpdateApplicationSettingsSamples.java | 4 +- .../generated/WebAppsUpdateSamples.java | 2 +- 13 files changed, 840 insertions(+), 91 deletions(-) diff --git a/sdk/resourcemanager/api-specs.json b/sdk/resourcemanager/api-specs.json index edcaa94dd3d0e..026fae0557b77 100644 --- a/sdk/resourcemanager/api-specs.json +++ b/sdk/resourcemanager/api-specs.json @@ -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", diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md b/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md index abef519a029b1..b9eef123bd827 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md @@ -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 diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/assets.json b/sdk/resourcemanager/azure-resourcemanager-appservice/assets.json index 97cad25002837..96d6661168bb8 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/assets.json +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/assets.json @@ -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" } diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml b/sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml index b2df3a16fa870..e5bed146ebe6b 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml @@ -139,6 +139,12 @@ 1.7.36 test + + com.azure.resourcemanager + azure-resourcemanager-appcontainers + 1.0.0-beta.6 + test + diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/fluent/WebAppsClient.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/fluent/WebAppsClient.java index 6508eb8e04a85..87180a633c327 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/fluent/WebAppsClient.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/fluent/WebAppsClient.java @@ -508,9 +508,67 @@ Response deleteWithResponse(String resourceGroupName, String name, Boolean * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - Mono> updateWithResponseAsync(String resourceGroupName, String name, + Mono>> updateWithResponseAsync(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope); + /** + * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * Description for Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Unique name of the app to create or update. To create or update a deployment slot, use the {slot} + * parameter. + * @param siteEnvelope A JSON representation of the app properties. See example. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is + * rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of a web app, a mobile app backend, or an API app. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + PollerFlux, SiteInner> beginUpdateAsync(String resourceGroupName, String name, + SitePatchResourceInner siteEnvelope); + + /** + * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * Description for Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Unique name of the app to create or update. To create or update a deployment slot, use the {slot} + * parameter. + * @param siteEnvelope A JSON representation of the app properties. See example. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is + * rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of a web app, a mobile app backend, or an API app. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, SiteInner> beginUpdate(String resourceGroupName, String name, + SitePatchResourceInner siteEnvelope); + + /** + * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * Description for Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Unique name of the app to create or update. To create or update a deployment slot, use the {slot} + * parameter. + * @param siteEnvelope A JSON representation of the app properties. See example. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is + * rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of a web app, a mobile app backend, or an API app. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, SiteInner> beginUpdate(String resourceGroupName, String name, + SitePatchResourceInner siteEnvelope, Context context); + /** * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. * @@ -538,16 +596,14 @@ Mono> updateWithResponseAsync(String resourceGroupName, Stri * @param name Unique name of the app to create or update. To create or update a deployment slot, use the {slot} * parameter. * @param siteEnvelope A JSON representation of the app properties. See example. - * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is * rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a web app, a mobile app backend, or an API app along with {@link Response}. + * @return a web app, a mobile app backend, or an API app. */ @ServiceMethod(returns = ReturnType.SINGLE) - Response updateWithResponse(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope, - Context context); + SiteInner update(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope); /** * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. @@ -558,6 +614,7 @@ Response updateWithResponse(String resourceGroupName, String name, Si * @param name Unique name of the app to create or update. To create or update a deployment slot, use the {slot} * parameter. * @param siteEnvelope A JSON representation of the app properties. See example. + * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is * rejected by server. @@ -565,7 +622,7 @@ Response updateWithResponse(String resourceGroupName, String name, Si * @return a web app, a mobile app backend, or an API app. */ @ServiceMethod(returns = ReturnType.SINGLE) - SiteInner update(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope); + SiteInner update(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope, Context context); /** * Analyze a custom hostname. @@ -1601,8 +1658,63 @@ CsmPublishingCredentialsPoliciesEntityInner updateScmAllowed(String resourceGrou * @return string dictionary resource along with {@link Response} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - Mono> updateApplicationSettingsWithResponseAsync(String resourceGroupName, - String name, StringDictionaryInner appSettings); + Mono>> updateApplicationSettingsWithResponseAsync(String resourceGroupName, String name, + StringDictionaryInner appSettings); + + /** + * Replaces the application settings of an app. + * + * Description for Replaces the application settings of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param appSettings Application settings of the app. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is + * rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of string dictionary resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + PollerFlux, StringDictionaryInner> + beginUpdateApplicationSettingsAsync(String resourceGroupName, String name, StringDictionaryInner appSettings); + + /** + * Replaces the application settings of an app. + * + * Description for Replaces the application settings of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param appSettings Application settings of the app. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is + * rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of string dictionary resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, StringDictionaryInner> + beginUpdateApplicationSettings(String resourceGroupName, String name, StringDictionaryInner appSettings); + + /** + * Replaces the application settings of an app. + * + * Description for Replaces the application settings of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param appSettings Application settings of the app. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is + * rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of string dictionary resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, StringDictionaryInner> beginUpdateApplicationSettings( + String resourceGroupName, String name, StringDictionaryInner appSettings, Context context); /** * Replaces the application settings of an app. @@ -1630,16 +1742,15 @@ Mono updateApplicationSettingsAsync(String resourceGroupN * @param resourceGroupName Name of the resource group to which the resource belongs. * @param name Name of the app. * @param appSettings Application settings of the app. - * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is * rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return string dictionary resource along with {@link Response}. + * @return string dictionary resource. */ @ServiceMethod(returns = ReturnType.SINGLE) - Response updateApplicationSettingsWithResponse(String resourceGroupName, String name, - StringDictionaryInner appSettings, Context context); + StringDictionaryInner updateApplicationSettings(String resourceGroupName, String name, + StringDictionaryInner appSettings); /** * Replaces the application settings of an app. @@ -1649,6 +1760,7 @@ Response updateApplicationSettingsWithResponse(String res * @param resourceGroupName Name of the resource group to which the resource belongs. * @param name Name of the app. * @param appSettings Application settings of the app. + * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is * rejected by server. @@ -1657,7 +1769,7 @@ Response updateApplicationSettingsWithResponse(String res */ @ServiceMethod(returns = ReturnType.SINGLE) StringDictionaryInner updateApplicationSettings(String resourceGroupName, String name, - StringDictionaryInner appSettings); + StringDictionaryInner appSettings, Context context); /** * Gets the application settings of an app. @@ -3592,8 +3704,63 @@ Response getConfigurationWithResponse(String resourceGr * @return web app configuration ARM resource along with {@link Response} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - Mono> createOrUpdateConfigurationWithResponseAsync(String resourceGroupName, - String name, SiteConfigResourceInner siteConfig); + Mono>> createOrUpdateConfigurationWithResponseAsync(String resourceGroupName, String name, + SiteConfigResourceInner siteConfig); + + /** + * Updates the configuration of an app. + * + * Description for Updates the configuration of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param siteConfig JSON representation of a SiteConfig object. See example. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is + * rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of web app configuration ARM resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + PollerFlux, SiteConfigResourceInner> beginCreateOrUpdateConfigurationAsync( + String resourceGroupName, String name, SiteConfigResourceInner siteConfig); + + /** + * Updates the configuration of an app. + * + * Description for Updates the configuration of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param siteConfig JSON representation of a SiteConfig object. See example. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is + * rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of web app configuration ARM resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, SiteConfigResourceInner> + beginCreateOrUpdateConfiguration(String resourceGroupName, String name, SiteConfigResourceInner siteConfig); + + /** + * Updates the configuration of an app. + * + * Description for Updates the configuration of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param siteConfig JSON representation of a SiteConfig object. See example. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is + * rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of web app configuration ARM resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, SiteConfigResourceInner> beginCreateOrUpdateConfiguration( + String resourceGroupName, String name, SiteConfigResourceInner siteConfig, Context context); /** * Updates the configuration of an app. @@ -3621,16 +3788,15 @@ Mono createOrUpdateConfigurationAsync(String resourceGr * @param resourceGroupName Name of the resource group to which the resource belongs. * @param name Name of the app. * @param siteConfig JSON representation of a SiteConfig object. See example. - * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is * rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return web app configuration ARM resource along with {@link Response}. + * @return web app configuration ARM resource. */ @ServiceMethod(returns = ReturnType.SINGLE) - Response createOrUpdateConfigurationWithResponse(String resourceGroupName, String name, - SiteConfigResourceInner siteConfig, Context context); + SiteConfigResourceInner createOrUpdateConfiguration(String resourceGroupName, String name, + SiteConfigResourceInner siteConfig); /** * Updates the configuration of an app. @@ -3640,6 +3806,7 @@ Response createOrUpdateConfigurationWithResponse(String * @param resourceGroupName Name of the resource group to which the resource belongs. * @param name Name of the app. * @param siteConfig JSON representation of a SiteConfig object. See example. + * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws com.azure.resourcemanager.appservice.models.DefaultErrorResponseErrorException thrown if the request is * rejected by server. @@ -3648,7 +3815,7 @@ Response createOrUpdateConfigurationWithResponse(String */ @ServiceMethod(returns = ReturnType.SINGLE) SiteConfigResourceInner createOrUpdateConfiguration(String resourceGroupName, String name, - SiteConfigResourceInner siteConfig); + SiteConfigResourceInner siteConfig, Context context); /** * Updates the configuration of an app. diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/FunctionAppImpl.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/FunctionAppImpl.java index 81a1d3cd25d31..2f088c72a83f5 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/FunctionAppImpl.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/FunctionAppImpl.java @@ -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; @@ -171,6 +174,24 @@ public FunctionAppImpl withLatestRuntimeVersion() { return withRuntimeVersion("latest"); } + @Override + Mono submitSite(SiteInner site) { + if (isFunctionAppOnACA()) { + return createOrUpdateInner(site); + } else { + return super.submitSite(site); + } + } + + @Override + Mono submitSite(SitePatchResourceInner siteUpdate) { + if (isFunctionAppOnACA()) { + return updateInner(siteUpdate); + } else { + return super.submitSite(siteUpdate); + } + } + @Override Mono submitAppSettings() { if (storageAccountCreatable != null && this.taskResult(storageAccountCreatable.key()) != null) { @@ -179,19 +200,18 @@ Mono 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())) { @@ -203,9 +223,11 @@ Mono submitAppSettings() { .randomResourceName(name(), 32)); } return FunctionAppImpl.super.submitAppSettings(); - })) - .last() - .then( + }); + } else { + return FunctionAppImpl.super.submitAppSettings(); + } + }).then( Mono .fromCallable( () -> { @@ -219,6 +241,11 @@ Mono 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; } @@ -513,6 +540,27 @@ public Mono 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 streamApplicationLogsAsync() { return functionService @@ -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 createAsync() { if (this.isInCreateMode()) { - if (innerModel().serverFarmId() == null) { + if (innerModel().serverFarmId() == null && !isFunctionAppOnACA()) { withNewConsumptionPlan(); } if (currentStorageAccount == null && storageAccountToSet == null && storageAccountCreatable == null) { @@ -601,6 +669,42 @@ public Mono 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 { diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/WebAppsClientImpl.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/WebAppsClientImpl.java index 6e9ebe4e69895..c81b114112186 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/WebAppsClientImpl.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/WebAppsClientImpl.java @@ -227,7 +227,7 @@ Mono> delete(@HostParam("$host") String endpoint, @Patch("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}") @ExpectedResponses({ 200, 202 }) @UnexpectedResponseExceptionType(DefaultErrorResponseErrorException.class) - Mono> update(@HostParam("$host") String endpoint, + Mono>> update(@HostParam("$host") String endpoint, @PathParam("resourceGroupName") String resourceGroupName, @PathParam("name") String name, @PathParam("subscriptionId") String subscriptionId, @QueryParam("api-version") String apiVersion, @BodyParam("application/json") SitePatchResourceInner siteEnvelope, @HeaderParam("Accept") String accept, @@ -370,9 +370,9 @@ Mono> listConfigurations(@HostParam("$hos @Headers({ "Content-Type: application/json" }) @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/config/appsettings") - @ExpectedResponses({ 200 }) + @ExpectedResponses({ 200, 202 }) @UnexpectedResponseExceptionType(DefaultErrorResponseErrorException.class) - Mono> updateApplicationSettings(@HostParam("$host") String endpoint, + Mono>> updateApplicationSettings(@HostParam("$host") String endpoint, @PathParam("resourceGroupName") String resourceGroupName, @PathParam("name") String name, @PathParam("subscriptionId") String subscriptionId, @QueryParam("api-version") String apiVersion, @BodyParam("application/json") StringDictionaryInner appSettings, @HeaderParam("Accept") String accept, @@ -634,9 +634,9 @@ Mono> getConfiguration(@HostParam("$host") Str @Headers({ "Content-Type: application/json" }) @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/config/web") - @ExpectedResponses({ 200 }) + @ExpectedResponses({ 200, 202 }) @UnexpectedResponseExceptionType(DefaultErrorResponseErrorException.class) - Mono> createOrUpdateConfiguration(@HostParam("$host") String endpoint, + Mono>> createOrUpdateConfiguration(@HostParam("$host") String endpoint, @PathParam("resourceGroupName") String resourceGroupName, @PathParam("name") String name, @PathParam("subscriptionId") String subscriptionId, @QueryParam("api-version") String apiVersion, @BodyParam("application/json") SiteConfigResourceInner siteConfig, @HeaderParam("Accept") String accept, @@ -5628,7 +5628,7 @@ public void delete(String resourceGroupName, String name) { * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> updateWithResponseAsync(String resourceGroupName, String name, + public Mono>> updateWithResponseAsync(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope) { if (this.client.getEndpoint() == null) { return Mono.error( @@ -5674,7 +5674,7 @@ public Mono> updateWithResponseAsync(String resourceGroupNam * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - private Mono> updateWithResponseAsync(String resourceGroupName, String name, + private Mono>> updateWithResponseAsync(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope, Context context) { if (this.client.getEndpoint() == null) { return Mono.error( @@ -5702,6 +5702,93 @@ private Mono> updateWithResponseAsync(String resourceGroupNa this.client.getApiVersion(), siteEnvelope, accept, context); } + /** + * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * Description for Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Unique name of the app to create or update. To create or update a deployment slot, use the {slot} + * parameter. + * @param siteEnvelope A JSON representation of the app properties. See example. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of a web app, a mobile app backend, or an API app. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux, SiteInner> beginUpdateAsync(String resourceGroupName, String name, + SitePatchResourceInner siteEnvelope) { + Mono>> mono = updateWithResponseAsync(resourceGroupName, name, siteEnvelope); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), SiteInner.class, + SiteInner.class, this.client.getContext()); + } + + /** + * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * Description for Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Unique name of the app to create or update. To create or update a deployment slot, use the {slot} + * parameter. + * @param siteEnvelope A JSON representation of the app properties. See example. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of a web app, a mobile app backend, or an API app. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, SiteInner> beginUpdateAsync(String resourceGroupName, String name, + SitePatchResourceInner siteEnvelope, Context context) { + context = this.client.mergeContext(context); + Mono>> mono = updateWithResponseAsync(resourceGroupName, name, siteEnvelope, context); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), SiteInner.class, + SiteInner.class, context); + } + + /** + * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * Description for Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Unique name of the app to create or update. To create or update a deployment slot, use the {slot} + * parameter. + * @param siteEnvelope A JSON representation of the app properties. See example. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of a web app, a mobile app backend, or an API app. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, SiteInner> beginUpdate(String resourceGroupName, String name, + SitePatchResourceInner siteEnvelope) { + return this.beginUpdateAsync(resourceGroupName, name, siteEnvelope).getSyncPoller(); + } + + /** + * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * Description for Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Unique name of the app to create or update. To create or update a deployment slot, use the {slot} + * parameter. + * @param siteEnvelope A JSON representation of the app properties. See example. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of a web app, a mobile app backend, or an API app. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, SiteInner> beginUpdate(String resourceGroupName, String name, + SitePatchResourceInner siteEnvelope, Context context) { + return this.beginUpdateAsync(resourceGroupName, name, siteEnvelope, context).getSyncPoller(); + } + /** * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. * @@ -5718,8 +5805,8 @@ private Mono> updateWithResponseAsync(String resourceGroupNa */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono updateAsync(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope) { - return updateWithResponseAsync(resourceGroupName, name, siteEnvelope) - .flatMap(res -> Mono.justOrEmpty(res.getValue())); + return beginUpdateAsync(resourceGroupName, name, siteEnvelope).last() + .flatMap(this.client::getLroFinalResultOrError); } /** @@ -5735,12 +5822,13 @@ public Mono updateAsync(String resourceGroupName, String name, SitePa * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a web app, a mobile app backend, or an API app along with {@link Response}. + * @return a web app, a mobile app backend, or an API app on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response updateWithResponse(String resourceGroupName, String name, - SitePatchResourceInner siteEnvelope, Context context) { - return updateWithResponseAsync(resourceGroupName, name, siteEnvelope, context).block(); + private Mono updateAsync(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope, + Context context) { + return beginUpdateAsync(resourceGroupName, name, siteEnvelope, context).last() + .flatMap(this.client::getLroFinalResultOrError); } /** @@ -5759,7 +5847,28 @@ public Response updateWithResponse(String resourceGroupName, String n */ @ServiceMethod(returns = ReturnType.SINGLE) public SiteInner update(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope) { - return updateWithResponse(resourceGroupName, name, siteEnvelope, Context.NONE).getValue(); + return updateAsync(resourceGroupName, name, siteEnvelope).block(); + } + + /** + * Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * Description for Creates a new web, mobile, or API app in an existing resource group, or updates an existing app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Unique name of the app to create or update. To create or update a deployment slot, use the {slot} + * parameter. + * @param siteEnvelope A JSON representation of the app properties. See example. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a web app, a mobile app backend, or an API app. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SiteInner update(String resourceGroupName, String name, SitePatchResourceInner siteEnvelope, + Context context) { + return updateAsync(resourceGroupName, name, siteEnvelope, context).block(); } /** @@ -7950,7 +8059,7 @@ public PagedIterable listConfigurations(String resource * @return string dictionary resource along with {@link Response} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> updateApplicationSettingsWithResponseAsync(String resourceGroupName, + public Mono>> updateApplicationSettingsWithResponseAsync(String resourceGroupName, String name, StringDictionaryInner appSettings) { if (this.client.getEndpoint() == null) { return Mono.error( @@ -7994,7 +8103,7 @@ public Mono> updateApplicationSettingsWithRespon * @return string dictionary resource along with {@link Response} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - private Mono> updateApplicationSettingsWithResponseAsync(String resourceGroupName, + private Mono>> updateApplicationSettingsWithResponseAsync(String resourceGroupName, String name, StringDictionaryInner appSettings, Context context) { if (this.client.getEndpoint() == null) { return Mono.error( @@ -8022,6 +8131,92 @@ private Mono> updateApplicationSettingsWithRespo this.client.getSubscriptionId(), this.client.getApiVersion(), appSettings, accept, context); } + /** + * Replaces the application settings of an app. + * + * Description for Replaces the application settings of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param appSettings Application settings of the app. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of string dictionary resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux, StringDictionaryInner> + beginUpdateApplicationSettingsAsync(String resourceGroupName, String name, StringDictionaryInner appSettings) { + Mono>> mono + = updateApplicationSettingsWithResponseAsync(resourceGroupName, name, appSettings); + return this.client.getLroResult(mono, + this.client.getHttpPipeline(), StringDictionaryInner.class, StringDictionaryInner.class, + this.client.getContext()); + } + + /** + * Replaces the application settings of an app. + * + * Description for Replaces the application settings of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param appSettings Application settings of the app. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of string dictionary resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, StringDictionaryInner> beginUpdateApplicationSettingsAsync( + String resourceGroupName, String name, StringDictionaryInner appSettings, Context context) { + context = this.client.mergeContext(context); + Mono>> mono + = updateApplicationSettingsWithResponseAsync(resourceGroupName, name, appSettings, context); + return this.client.getLroResult(mono, + this.client.getHttpPipeline(), StringDictionaryInner.class, StringDictionaryInner.class, context); + } + + /** + * Replaces the application settings of an app. + * + * Description for Replaces the application settings of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param appSettings Application settings of the app. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of string dictionary resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, StringDictionaryInner> + beginUpdateApplicationSettings(String resourceGroupName, String name, StringDictionaryInner appSettings) { + return this.beginUpdateApplicationSettingsAsync(resourceGroupName, name, appSettings).getSyncPoller(); + } + + /** + * Replaces the application settings of an app. + * + * Description for Replaces the application settings of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param appSettings Application settings of the app. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of string dictionary resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, StringDictionaryInner> beginUpdateApplicationSettings( + String resourceGroupName, String name, StringDictionaryInner appSettings, Context context) { + return this.beginUpdateApplicationSettingsAsync(resourceGroupName, name, appSettings, context).getSyncPoller(); + } + /** * Replaces the application settings of an app. * @@ -8038,8 +8233,8 @@ private Mono> updateApplicationSettingsWithRespo @ServiceMethod(returns = ReturnType.SINGLE) public Mono updateApplicationSettingsAsync(String resourceGroupName, String name, StringDictionaryInner appSettings) { - return updateApplicationSettingsWithResponseAsync(resourceGroupName, name, appSettings) - .flatMap(res -> Mono.justOrEmpty(res.getValue())); + return beginUpdateApplicationSettingsAsync(resourceGroupName, name, appSettings).last() + .flatMap(this.client::getLroFinalResultOrError); } /** @@ -8054,12 +8249,13 @@ public Mono updateApplicationSettingsAsync(String resourc * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return string dictionary resource along with {@link Response}. + * @return string dictionary resource on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response updateApplicationSettingsWithResponse(String resourceGroupName, String name, + private Mono updateApplicationSettingsAsync(String resourceGroupName, String name, StringDictionaryInner appSettings, Context context) { - return updateApplicationSettingsWithResponseAsync(resourceGroupName, name, appSettings, context).block(); + return beginUpdateApplicationSettingsAsync(resourceGroupName, name, appSettings, context).last() + .flatMap(this.client::getLroFinalResultOrError); } /** @@ -8078,7 +8274,27 @@ public Response updateApplicationSettingsWithResponse(Str @ServiceMethod(returns = ReturnType.SINGLE) public StringDictionaryInner updateApplicationSettings(String resourceGroupName, String name, StringDictionaryInner appSettings) { - return updateApplicationSettingsWithResponse(resourceGroupName, name, appSettings, Context.NONE).getValue(); + return updateApplicationSettingsAsync(resourceGroupName, name, appSettings).block(); + } + + /** + * Replaces the application settings of an app. + * + * Description for Replaces the application settings of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param appSettings Application settings of the app. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return string dictionary resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public StringDictionaryInner updateApplicationSettings(String resourceGroupName, String name, + StringDictionaryInner appSettings, Context context) { + return updateApplicationSettingsAsync(resourceGroupName, name, appSettings, context).block(); } /** @@ -11956,8 +12172,8 @@ public SiteConfigResourceInner getConfiguration(String resourceGroupName, String * @return web app configuration ARM resource along with {@link Response} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> createOrUpdateConfigurationWithResponseAsync( - String resourceGroupName, String name, SiteConfigResourceInner siteConfig) { + public Mono>> createOrUpdateConfigurationWithResponseAsync(String resourceGroupName, + String name, SiteConfigResourceInner siteConfig) { if (this.client.getEndpoint() == null) { return Mono.error( new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); @@ -12000,8 +12216,8 @@ public Mono> createOrUpdateConfigurationWithRe * @return web app configuration ARM resource along with {@link Response} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - private Mono> createOrUpdateConfigurationWithResponseAsync( - String resourceGroupName, String name, SiteConfigResourceInner siteConfig, Context context) { + private Mono>> createOrUpdateConfigurationWithResponseAsync(String resourceGroupName, + String name, SiteConfigResourceInner siteConfig, Context context) { if (this.client.getEndpoint() == null) { return Mono.error( new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); @@ -12028,6 +12244,94 @@ private Mono> createOrUpdateConfigurationWithR this.client.getSubscriptionId(), this.client.getApiVersion(), siteConfig, accept, context); } + /** + * Updates the configuration of an app. + * + * Description for Updates the configuration of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param siteConfig JSON representation of a SiteConfig object. See example. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of web app configuration ARM resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux, SiteConfigResourceInner> + beginCreateOrUpdateConfigurationAsync(String resourceGroupName, String name, + SiteConfigResourceInner siteConfig) { + Mono>> mono + = createOrUpdateConfigurationWithResponseAsync(resourceGroupName, name, siteConfig); + return this.client.getLroResult(mono, + this.client.getHttpPipeline(), SiteConfigResourceInner.class, SiteConfigResourceInner.class, + this.client.getContext()); + } + + /** + * Updates the configuration of an app. + * + * Description for Updates the configuration of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param siteConfig JSON representation of a SiteConfig object. See example. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of web app configuration ARM resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, SiteConfigResourceInner> + beginCreateOrUpdateConfigurationAsync(String resourceGroupName, String name, SiteConfigResourceInner siteConfig, + Context context) { + context = this.client.mergeContext(context); + Mono>> mono + = createOrUpdateConfigurationWithResponseAsync(resourceGroupName, name, siteConfig, context); + return this.client.getLroResult(mono, + this.client.getHttpPipeline(), SiteConfigResourceInner.class, SiteConfigResourceInner.class, context); + } + + /** + * Updates the configuration of an app. + * + * Description for Updates the configuration of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param siteConfig JSON representation of a SiteConfig object. See example. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of web app configuration ARM resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, SiteConfigResourceInner> + beginCreateOrUpdateConfiguration(String resourceGroupName, String name, SiteConfigResourceInner siteConfig) { + return this.beginCreateOrUpdateConfigurationAsync(resourceGroupName, name, siteConfig).getSyncPoller(); + } + + /** + * Updates the configuration of an app. + * + * Description for Updates the configuration of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param siteConfig JSON representation of a SiteConfig object. See example. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of web app configuration ARM resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, SiteConfigResourceInner> beginCreateOrUpdateConfiguration( + String resourceGroupName, String name, SiteConfigResourceInner siteConfig, Context context) { + return this.beginCreateOrUpdateConfigurationAsync(resourceGroupName, name, siteConfig, context).getSyncPoller(); + } + /** * Updates the configuration of an app. * @@ -12044,8 +12348,8 @@ private Mono> createOrUpdateConfigurationWithR @ServiceMethod(returns = ReturnType.SINGLE) public Mono createOrUpdateConfigurationAsync(String resourceGroupName, String name, SiteConfigResourceInner siteConfig) { - return createOrUpdateConfigurationWithResponseAsync(resourceGroupName, name, siteConfig) - .flatMap(res -> Mono.justOrEmpty(res.getValue())); + return beginCreateOrUpdateConfigurationAsync(resourceGroupName, name, siteConfig).last() + .flatMap(this.client::getLroFinalResultOrError); } /** @@ -12060,12 +12364,13 @@ public Mono createOrUpdateConfigurationAsync(String res * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return web app configuration ARM resource along with {@link Response}. + * @return web app configuration ARM resource on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response createOrUpdateConfigurationWithResponse(String resourceGroupName, - String name, SiteConfigResourceInner siteConfig, Context context) { - return createOrUpdateConfigurationWithResponseAsync(resourceGroupName, name, siteConfig, context).block(); + private Mono createOrUpdateConfigurationAsync(String resourceGroupName, String name, + SiteConfigResourceInner siteConfig, Context context) { + return beginCreateOrUpdateConfigurationAsync(resourceGroupName, name, siteConfig, context).last() + .flatMap(this.client::getLroFinalResultOrError); } /** @@ -12084,7 +12389,27 @@ public Response createOrUpdateConfigurationWithResponse @ServiceMethod(returns = ReturnType.SINGLE) public SiteConfigResourceInner createOrUpdateConfiguration(String resourceGroupName, String name, SiteConfigResourceInner siteConfig) { - return createOrUpdateConfigurationWithResponse(resourceGroupName, name, siteConfig, Context.NONE).getValue(); + return createOrUpdateConfigurationAsync(resourceGroupName, name, siteConfig).block(); + } + + /** + * Updates the configuration of an app. + * + * Description for Updates the configuration of an app. + * + * @param resourceGroupName Name of the resource group to which the resource belongs. + * @param name Name of the app. + * @param siteConfig JSON representation of a SiteConfig object. See example. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws DefaultErrorResponseErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return web app configuration ARM resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SiteConfigResourceInner createOrUpdateConfiguration(String resourceGroupName, String name, + SiteConfigResourceInner siteConfig, Context context) { + return createOrUpdateConfigurationAsync(resourceGroupName, name, siteConfig, context).block(); } /** diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/FunctionApp.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/FunctionApp.java index 7392983d1a203..9d75a8580c747 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/FunctionApp.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/FunctionApp.java @@ -5,18 +5,19 @@ import com.azure.core.annotation.Fluent; import com.azure.core.http.rest.PagedIterable; +import com.azure.resourcemanager.resources.fluentcore.arm.models.GroupableResource; import com.azure.resourcemanager.resources.fluentcore.collection.SupportsListingPrivateEndpointConnection; import com.azure.resourcemanager.resources.fluentcore.collection.SupportsListingPrivateLinkResource; import com.azure.resourcemanager.resources.fluentcore.collection.SupportsUpdatingPrivateEndpointConnection; -import com.azure.resourcemanager.resources.models.ResourceGroup; -import com.azure.resourcemanager.resources.fluentcore.arm.models.GroupableResource; import com.azure.resourcemanager.resources.fluentcore.model.Creatable; import com.azure.resourcemanager.resources.fluentcore.model.Updatable; +import com.azure.resourcemanager.resources.models.ResourceGroup; import com.azure.resourcemanager.storage.models.StorageAccount; import com.azure.resourcemanager.storage.models.StorageAccountSkuType; -import java.util.Map; import reactor.core.publisher.Mono; +import java.util.Map; + /** An immutable client-side representation of an Azure Function App. */ @Fluent public interface FunctionApp extends FunctionAppBasic, WebAppBase, Updatable, @@ -123,6 +124,28 @@ public interface FunctionApp extends FunctionAppBasic, WebAppBase, Updatable syncTriggersAsync(); + /** + * Retrieve the ID of the Azure Container Apps environment that the Function App runs on. + * + * @return the ID of the Azure Container Apps environment + * @see DefinitionStages.WithManagedEnvironment#withManagedEnvironmentId(String) + */ + String managedEnvironmentId(); + + /** + * Retrieves the maximum replica count. + * + * @return the maximum replica count + */ + Integer maxReplicas(); + + /** + * Retrieves the minimum replica count. + * + * @return the minimum replica count + */ + Integer minReplicas(); + /************************************************************** * Fluent interfaces to provision a Function App **************************************************************/ @@ -397,6 +420,8 @@ interface WithCreate DefinitionStages.WithStorageAccount, DefinitionStages.WithRuntimeVersion, DefinitionStages.WithDailyUsageQuota, + DefinitionStages.WithManagedEnvironment, + DefinitionStages.WithScaleRulesOrDockerContainerImage, WebAppBase.DefinitionStages.WithCreate { } @@ -485,6 +510,40 @@ interface WithDockerContainerImage { WithCredentials withPrivateRegistryImage(String imageAndTag, String serverUrl); } + /** A function app definition allowing Azure Container App environment to be specified. */ + interface WithManagedEnvironment { + /** + * Specifies the ID of the Azure Container Apps environment + * to deploy the Function App on. + *

When your container is hosted in a Consumption + Dedicated plan structure, + * only the default Consumption plan is currently supported. Dedicated plans in this structure aren't yet supported for Functions. + * When running functions on Container Apps, you're charged only for the Container Apps usage.

+ * + * @param managedEnvironmentId ID of the Azure Container Apps environment + * @return the next stage of the definition + */ + WithScaleRulesOrDockerContainerImage withManagedEnvironmentId(String managedEnvironmentId); + } + + /** A function app definition allowing scale rules to be specified for Function Apps hosted on Azure Container Apps. */ + interface WithScaleRulesOrDockerContainerImage extends WithDockerContainerImage { + /** + * Specifies the maximum replica count. + * + * @param maxReplicas maximum replica count + * @return the next stage of the definition + */ + WithScaleRulesOrDockerContainerImage withMaxReplicas(int maxReplicas); + + /** + * Specifies the minimum replica count. + * + * @param minReplicas minimum replica count + * @return the next stage of the definition + */ + WithScaleRulesOrDockerContainerImage withMinReplicas(int minReplicas); + } + /** A function app definition allowing docker registry credentials to be set. */ interface WithCredentials { /** @@ -728,6 +787,25 @@ interface WithCredentials { */ Update withCredentials(String username, String password); } + + /** A function app update allowing scale rules to be set if hosted on Azure Container Apps environment. */ + interface WithManagedEnvironmentScaleRules { + /** + * Specifies the maximum replica count. + * + * @param maxReplicas maximum replica count + * @return the next stage of the function app update + */ + Update withMaxReplicas(int maxReplicas); + + /** + * Specifies the minimum replica count. + * + * @param minReplicas minimum replica count + * @return the next stage of the definition + */ + Update withMinReplicas(int minReplicas); + } } /** The template for a function app update operation, containing all the settings that can be modified. */ @@ -738,6 +816,7 @@ interface Update UpdateStages.WithStorageAccount, UpdateStages.WithDailyUsageQuota, UpdateStages.WithDockerContainerImage, - UpdateStages.WithCredentials { + UpdateStages.WithCredentials, + UpdateStages.WithManagedEnvironmentScaleRules { } } diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/AppServiceTest.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/AppServiceTest.java index 85e0e9903c987..a8c1600cbc62c 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/AppServiceTest.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/AppServiceTest.java @@ -47,7 +47,7 @@ /** The base for app service tests. */ public class AppServiceTest extends ResourceManagerTestProxyTestBase { - private static final ClientLogger LOGGER = new ClientLogger(AppServiceTest.class); + static final ClientLogger LOGGER = new ClientLogger(AppServiceTest.class); protected ResourceManager resourceManager; protected KeyVaultManager keyVaultManager; diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/FunctionAppsTests.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/FunctionAppsTests.java index 31bfbda04e469..020ba5b014376 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/FunctionAppsTests.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/FunctionAppsTests.java @@ -6,7 +6,11 @@ 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.Region; import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.profile.AzureProfile; +import com.azure.resourcemanager.appcontainers.ContainerAppsApiManager; +import com.azure.resourcemanager.appcontainers.models.ManagedEnvironment; import com.azure.resourcemanager.appservice.models.AppServicePlan; import com.azure.resourcemanager.appservice.models.AppSetting; import com.azure.resourcemanager.appservice.models.FunctionApp; @@ -16,23 +20,24 @@ import com.azure.resourcemanager.appservice.models.FunctionRuntimeStack; import com.azure.resourcemanager.appservice.models.PricingTier; import com.azure.resourcemanager.appservice.models.SkuName; -import com.azure.resourcemanager.test.utils.TestUtilities; -import com.azure.core.management.Region; -import com.azure.core.management.profile.AzureProfile; import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils; +import com.azure.resourcemanager.resources.models.ResourceGroup; +import com.azure.resourcemanager.storage.StorageManager; import com.azure.resourcemanager.storage.models.StorageAccount; import com.azure.resourcemanager.storage.models.StorageAccountSkuType; -import com.azure.resourcemanager.storage.StorageManager; +import com.azure.resourcemanager.test.utils.TestDelayProvider; +import com.azure.resourcemanager.test.utils.TestUtilities; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + import java.io.File; +import java.lang.reflect.Constructor; 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; - public class FunctionAppsTests extends AppServiceTest { private String rgName1 = ""; private String rgName2 = ""; @@ -44,6 +49,7 @@ public class FunctionAppsTests extends AppServiceTest { private String storageAccountName1 = ""; protected StorageManager storageManager; + protected ContainerAppsApiManager containerAppsApiManager; @Override protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) { @@ -57,6 +63,21 @@ protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile rgName2 = generateRandomResourceName("javacsmrg", 20); storageManager = buildManager(StorageManager.class, httpPipeline, profile); + // build ContainerAppsApiManager + try { + Constructor constructor = ContainerAppsApiManager.class.getDeclaredConstructor(httpPipeline.getClass(), profile.getClass(), Duration.class); + Runnable runnable = () -> constructor.setAccessible(true); + runnable.run(); + ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode())); + containerAppsApiManager = constructor.newInstance( + httpPipeline, + profile, + // Lite packages need this for playback mode, since they take defaultPollInterval directly as polling interval. + ResourceManagerUtils.InternalRuntimeContext.getDelayDuration(Duration.ofSeconds(30))); + + } catch (ReflectiveOperationException ex) { + throw LOGGER.logExceptionAsError(new RuntimeException(ex)); + } super.initializeClients(httpPipeline, profile); } @@ -466,6 +487,51 @@ public void canCreateAndUpdateFunctionAppWithContainerSize() { Assertions.assertEquals(128, functionDeploymentSlot.containerSize()); } + @Test + public void canCreateAndUpdateFunctionAppOnACA() { + Region region = Region.US_EAST; + ResourceGroup resourceGroup = appServiceManager.resourceManager() + .resourceGroups() + .define(rgName1) + .withRegion(region) + .create(); + String managedEnvironmentId = createAcaEnvironment(region, resourceGroup); + webappName1 = generateRandomResourceName("java-function-", 20); + FunctionApp functionApp = appServiceManager + .functionApps() + .define(webappName1) + .withRegion(region) + .withExistingResourceGroup(resourceGroup) + .withManagedEnvironmentId(managedEnvironmentId) + .withMaxReplicas(10) + .withMinReplicas(3) + .withPublicDockerHubImage("mcr.microsoft.com/azure-functions/dotnet7-quickstart-demo:1.0") + .create(); + + Assertions.assertEquals(managedEnvironmentId, functionApp.managedEnvironmentId()); + Assertions.assertEquals(10, functionApp.maxReplicas()); + Assertions.assertEquals(3, functionApp.minReplicas()); + + functionApp.update() + .withMaxReplicas(15) + .withMinReplicas(5) + .apply(); + + Assertions.assertEquals(15, functionApp.maxReplicas()); + Assertions.assertEquals(5, functionApp.minReplicas()); + } + + private String createAcaEnvironment(Region region, ResourceGroup resourceGroup) { + String managedEnvironmentName = generateRandomResourceName("jvacam", 15); + ManagedEnvironment managedEnvironment = containerAppsApiManager.managedEnvironments() + .define(managedEnvironmentName) + .withRegion(region) + .withExistingResourceGroup(resourceGroup.name()) + .withZoneRedundant(false) + .create(); + return managedEnvironment.id(); + } + private void assertRunning(FunctionApp functionApp) { if (!isPlaybackMode()) { // wait diff --git a/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsCreateOrUpdateConfigurationSamples.java b/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsCreateOrUpdateConfigurationSamples.java index 200f1da9b939c..87e5e530003ad 100644 --- a/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsCreateOrUpdateConfigurationSamples.java +++ b/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsCreateOrUpdateConfigurationSamples.java @@ -28,8 +28,7 @@ public final class WebAppsCreateOrUpdateConfigurationSamples { * @param azure The entry point for accessing resource management APIs in Azure. */ public static void updateSiteConfig(com.azure.resourcemanager.AzureResourceManager azure) { - azure.webApps().manager().serviceClient().getWebApps().createOrUpdateConfigurationWithResponse("testrg123", - "sitef6141", + azure.webApps().manager().serviceClient().getWebApps().createOrUpdateConfiguration("testrg123", "sitef6141", new SiteConfigResourceInner().withNumberOfWorkers(1) .withDefaultDocuments(Arrays.asList("Default.htm", "Default.html", "Default.asp", "index.htm", "index.html", "iisstart.htm", "default.aspx", "index.php", "hostingstart.html")) diff --git a/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsUpdateApplicationSettingsSamples.java b/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsUpdateApplicationSettingsSamples.java index 9fdb4e3eee1f8..1b06430af3cad 100644 --- a/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsUpdateApplicationSettingsSamples.java +++ b/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsUpdateApplicationSettingsSamples.java @@ -22,8 +22,8 @@ public final class WebAppsUpdateApplicationSettingsSamples { * @param azure The entry point for accessing resource management APIs in Azure. */ public static void updateAppSettings(com.azure.resourcemanager.AzureResourceManager azure) { - azure.webApps().manager().serviceClient().getWebApps().updateApplicationSettingsWithResponse("testrg123", - "sitef6141", new StringDictionaryInner().withProperties(mapOf("Setting1", "Value1", "Setting2", "Value2")), + azure.webApps().manager().serviceClient().getWebApps().updateApplicationSettings("testrg123", "sitef6141", + new StringDictionaryInner().withProperties(mapOf("Setting1", "Value1", "Setting2", "Value2")), com.azure.core.util.Context.NONE); } diff --git a/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsUpdateSamples.java b/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsUpdateSamples.java index 358a0f4aaa400..d9acf73159991 100644 --- a/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsUpdateSamples.java +++ b/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/generated/WebAppsUpdateSamples.java @@ -19,7 +19,7 @@ public final class WebAppsUpdateSamples { * @param azure The entry point for accessing resource management APIs in Azure. */ public static void updateWebApp(com.azure.resourcemanager.AzureResourceManager azure) { - azure.webApps().manager().serviceClient().getWebApps().updateWithResponse("testrg123", "sitef6141", + azure.webApps().manager().serviceClient().getWebApps().update("testrg123", "sitef6141", new SitePatchResourceInner().withServerFarmId( "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/testrg123/providers/Microsoft.Web/serverfarms/DefaultAsp"), com.azure.core.util.Context.NONE);