From cc2c81429291239973a91d00296d10ac1461102c Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 20 Nov 2023 14:28:19 +0800 Subject: [PATCH 01/17] test case --- .../appservice/FunctionAppsTests.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) 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 31bfbda04e46..920b239f464d 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 @@ -16,6 +16,8 @@ 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.resources.fluentcore.arm.ResourceId; +import com.azure.resourcemanager.resources.models.ResourceGroup; import com.azure.resourcemanager.test.utils.TestUtilities; import com.azure.core.management.Region; import com.azure.core.management.profile.AzureProfile; @@ -466,6 +468,40 @@ public void canCreateAndUpdateFunctionAppWithContainerSize() { Assertions.assertEquals(128, functionDeploymentSlot.containerSize()); } + @Test + public void canCreateAndUpdateFunctionAppOnACA() { + Region region = Region.US_WEST; + ResourceGroup resourceGroup = appServiceManager.resourceManager() + .resourceGroups() + .define(rgName1) + .withRegion(region) + .create(); + String managedEnvironmentName = createAcaEnvironment(region, resourceGroup); + webappName1 = generateRandomResourceName("java-function-", 20); + FunctionApp functionApp = appServiceManager + .functionApps() + .define(webappName1) + .withRegion(region) + .withExistingResourceGroup(resourceGroup) + .withManagedEnvironmentName(managedEnvironmentName) + .withMaxReplicas(10) + .withMinReplicas(3) + .withBuiltInImage(FunctionRuntimeStack.JAVA_17) + .create(); + + Assertions.assertEquals(managedEnvironmentName, new ResourceId(functionApp.managedEnvironmentId()).name()); + 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 void assertRunning(FunctionApp functionApp) { if (!isPlaybackMode()) { // wait From 1b8810fbbd2102d84e81816d614b5283178c77a3 Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 20 Nov 2023 14:34:41 +0800 Subject: [PATCH 02/17] pom.xml --- .../azure-resourcemanager-appservice/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml b/sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml index 8c0e0e6efb4c..bf02f572144d 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 + From 6a4f325e63283c45fdc10c6c3731407779545e2b Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 20 Nov 2023 15:40:50 +0800 Subject: [PATCH 03/17] interfaces --- .../appservice/models/FunctionApp.java | 33 ++++++++++++++++--- .../appservice/FunctionAppsTests.java | 14 +++++++- 2 files changed, 42 insertions(+), 5 deletions(-) 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 7392983d1a20..04d9c6775f0d 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,12 @@ public interface FunctionApp extends FunctionAppBasic, WebAppBase, Updatable syncTriggersAsync(); + String managedEnvironmentId(); + + Integer maxReplicas(); + + Integer minReplicas(); + /************************************************************** * Fluent interfaces to provision a Function App **************************************************************/ @@ -310,6 +317,10 @@ interface WithNewAppServicePlan { * @return the next stage of the definition */ WithDockerContainerImage withNewLinuxAppServicePlan(Creatable appServicePlanCreatable); + + WithManagedEnvironmentOrDockerContainerImage withManagedEnvironmentId(String managedEnvironmentId); + + WithManagedEnvironmentOrDockerContainerImage withManagedEnvironmentName(String managedEnvironmentName); } /** @@ -397,6 +408,7 @@ interface WithCreate DefinitionStages.WithStorageAccount, DefinitionStages.WithRuntimeVersion, DefinitionStages.WithDailyUsageQuota, + DefinitionStages.WithManagedEnvironmentOrDockerContainerImage, WebAppBase.DefinitionStages.WithCreate { } @@ -485,6 +497,12 @@ interface WithDockerContainerImage { WithCredentials withPrivateRegistryImage(String imageAndTag, String serverUrl); } + interface WithManagedEnvironmentOrDockerContainerImage extends WithDockerContainerImage { + WithManagedEnvironmentOrDockerContainerImage withMaxReplicas(int maxReplicas); + + WithManagedEnvironmentOrDockerContainerImage withMinReplicas(int minReplicas); + } + /** A function app definition allowing docker registry credentials to be set. */ interface WithCredentials { /** @@ -728,6 +746,12 @@ interface WithCredentials { */ Update withCredentials(String username, String password); } + + interface WithManagedEnvironment { + Update withMaxReplicas(int maxReplicas); + + Update withMinReplicas(int minReplicas); + } } /** The template for a function app update operation, containing all the settings that can be modified. */ @@ -738,6 +762,7 @@ interface Update UpdateStages.WithStorageAccount, UpdateStages.WithDailyUsageQuota, UpdateStages.WithDockerContainerImage, - UpdateStages.WithCredentials { + UpdateStages.WithCredentials, + UpdateStages.WithManagedEnvironment { } } 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 920b239f464d..eac7351ff372 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 @@ -7,6 +7,7 @@ import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.Response; import com.azure.core.management.exception.ManagementException; +import com.azure.resourcemanager.appcontainers.ContainerAppsApiManager; import com.azure.resourcemanager.appservice.models.AppServicePlan; import com.azure.resourcemanager.appservice.models.AppSetting; import com.azure.resourcemanager.appservice.models.FunctionApp; @@ -46,6 +47,7 @@ public class FunctionAppsTests extends AppServiceTest { private String storageAccountName1 = ""; protected StorageManager storageManager; + protected ContainerAppsApiManager containerAppsApiManager; @Override protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) { @@ -489,7 +491,7 @@ public void canCreateAndUpdateFunctionAppOnACA() { .withBuiltInImage(FunctionRuntimeStack.JAVA_17) .create(); - Assertions.assertEquals(managedEnvironmentName, new ResourceId(functionApp.managedEnvironmentId()).name()); + Assertions.assertEquals(managedEnvironmentName, ResourceId.fromString(functionApp.managedEnvironmentId()).name()); Assertions.assertEquals(10, functionApp.maxReplicas()); Assertions.assertEquals(3, functionApp.minReplicas()); @@ -502,6 +504,16 @@ public void canCreateAndUpdateFunctionAppOnACA() { Assertions.assertEquals(5, functionApp.minReplicas()); } + private String createAcaEnvironment(Region region, ResourceGroup resourceGroup) { + String managedEnvironmentName = generateRandomResourceName("jvacam", 15); + containerAppsApiManager.managedEnvironments() + .define(managedEnvironmentName) + .withRegion(region) + .withExistingResourceGroup(resourceGroup.name()) + .create(); + return managedEnvironmentName; + } + private void assertRunning(FunctionApp functionApp) { if (!isPlaybackMode()) { // wait From 0ad55b82f3280c7d9c61b3d41e53c8b280d51356 Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 20 Nov 2023 16:47:26 +0800 Subject: [PATCH 04/17] javadocs --- .../appservice/models/FunctionApp.java | 81 ++++++++++++++++--- 1 file changed, 71 insertions(+), 10 deletions(-) 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 04d9c6775f0d..5b4e867c6f54 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 @@ -124,8 +124,19 @@ 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 {@link DefinitionStages.WithDockerContainerImage#} + */ String managedEnvironmentId(); + /** + * Retrieves + * + * @return + */ Integer maxReplicas(); Integer minReplicas(); @@ -317,10 +328,6 @@ interface WithNewAppServicePlan { * @return the next stage of the definition */ WithDockerContainerImage withNewLinuxAppServicePlan(Creatable appServicePlanCreatable); - - WithManagedEnvironmentOrDockerContainerImage withManagedEnvironmentId(String managedEnvironmentId); - - WithManagedEnvironmentOrDockerContainerImage withManagedEnvironmentName(String managedEnvironmentName); } /** @@ -408,7 +415,8 @@ interface WithCreate DefinitionStages.WithStorageAccount, DefinitionStages.WithRuntimeVersion, DefinitionStages.WithDailyUsageQuota, - DefinitionStages.WithManagedEnvironmentOrDockerContainerImage, + DefinitionStages.WithManagedEnvironment, + WithScaleRulesOrDockerContainerImage, WebAppBase.DefinitionStages.WithCreate { } @@ -497,10 +505,50 @@ interface WithDockerContainerImage { WithCredentials withPrivateRegistryImage(String imageAndTag, String serverUrl); } - interface WithManagedEnvironmentOrDockerContainerImage extends WithDockerContainerImage { - WithManagedEnvironmentOrDockerContainerImage withMaxReplicas(int maxReplicas); + /** 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); - WithManagedEnvironmentOrDockerContainerImage withMinReplicas(int minReplicas); + /** + * Specifies the name of the Azure Container Apps environment + * to deploy the Function App on. The environment must be in the same resource group as the Function App. + *

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 managedEnvironmentName name of the Azure Container Apps environment + * @return the next stage of the definition + */ + WithScaleRulesOrDockerContainerImage withManagedEnvironmentName(String managedEnvironmentName); + } + + /** 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. */ @@ -747,9 +795,22 @@ interface WithCredentials { Update withCredentials(String username, String password); } - interface WithManagedEnvironment { + /** 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); } } @@ -763,6 +824,6 @@ interface Update UpdateStages.WithDailyUsageQuota, UpdateStages.WithDockerContainerImage, UpdateStages.WithCredentials, - UpdateStages.WithManagedEnvironment { + UpdateStages.WithManagedEnvironmentScaleRules { } } From f4d728fa8020a2a600b82ed7aa035b6771381d46 Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Fri, 1 Dec 2023 16:21:13 +0800 Subject: [PATCH 05/17] interface interface adjust interface adjust --- .../appservice/models/FunctionApp.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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 5b4e867c6f54..bfa58f9c6fb9 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 @@ -128,17 +128,22 @@ public interface FunctionApp extends FunctionAppBasic, WebAppBase, Updatable { } @@ -824,6 +829,6 @@ interface Update UpdateStages.WithDailyUsageQuota, UpdateStages.WithDockerContainerImage, UpdateStages.WithCredentials, - UpdateStages.WithManagedEnvironmentScaleRules { + UpdateStages.WithManagedEnvironmentScaleRules { } } From 1fe4defbc0cc8393793a09d33c34da5953a6d5df Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Fri, 1 Dec 2023 14:30:48 +0800 Subject: [PATCH 06/17] implementation imports --- .../implementation/FunctionAppImpl.java | 242 +++++++++++++++++- .../implementation/WebAppsClientImpl.java | 4 +- .../appservice/FunctionAppsTests.java | 24 +- 3 files changed, 253 insertions(+), 17 deletions(-) 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 81a1d3cd25d3..9a13458582d5 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 @@ -13,20 +13,32 @@ import com.azure.core.annotation.Post; import com.azure.core.annotation.Put; import com.azure.core.annotation.ServiceInterface; +import com.azure.core.http.HttpHeader; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.HttpMethod; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; 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.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; 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.fluent.models.StringDictionaryInner; import com.azure.resourcemanager.appservice.models.AppServicePlan; import com.azure.resourcemanager.appservice.models.FunctionApp; import com.azure.resourcemanager.appservice.models.FunctionAuthenticationPolicy; @@ -38,6 +50,7 @@ import com.azure.resourcemanager.appservice.models.PricingTier; import com.azure.resourcemanager.appservice.models.SkuDescription; import com.azure.resourcemanager.appservice.models.SkuName; +import com.azure.resourcemanager.resources.fluentcore.arm.ResourceUtils; import com.azure.resourcemanager.resources.fluentcore.model.Creatable; import com.azure.resourcemanager.resources.fluentcore.model.Indexable; import com.azure.resourcemanager.resources.fluentcore.policy.AuthenticationPolicy; @@ -55,10 +68,12 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; +import java.time.Duration; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; /** The implementation for FunctionApp. */ class FunctionAppImpl @@ -171,6 +186,39 @@ 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 updateInner(SitePatchResourceInner siteUpdate) { + if (isFunctionAppOnACA()) { + return pollResult( + this.manager() + .serviceClient() + .getWebApps() + .updateWithResponseAsync(resourceGroupName(), name(), siteUpdate), + SiteInner.class + ); + } else { + return super.updateInner(siteUpdate); + } + } + @Override Mono submitAppSettings() { if (storageAccountCreatable != null && this.taskResult(storageAccountCreatable.key()) != null) { @@ -178,6 +226,24 @@ Mono submitAppSettings() { } 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; + })); } else { return Flux .concat( @@ -209,16 +275,92 @@ Mono submitAppSettings() { Mono .fromCallable( () -> { - currentStorageAccount = storageAccountToSet; - storageAccountToSet = null; - storageAccountCreatable = null; + resetStorageInfo(); return this; })); } } + private void resetStorageInfo() { + currentStorageAccount = storageAccountToSet; + storageAccountToSet = null; + storageAccountCreatable = null; + } + + @Override + Mono updateAppSettings(StringDictionaryInner appSettings) { + if (isFunctionAppOnACA()) { + return pollResult( + this.manager() + .serviceClient() + .getWebApps() + .updateApplicationSettingsWithResponseAsync(resourceGroupName(), name(), appSettings), + StringDictionaryInner.class + ); + } else { + return super.updateAppSettings(appSettings); + } + } + + @Override + Mono createOrUpdateSiteConfig(SiteConfigResourceInner siteConfig) { + if (isFunctionAppOnACA()) { + return pollResult( + this.manager() + .serviceClient() + .getWebApps() + .createOrUpdateConfigurationWithResponseAsync(resourceGroupName(), name(), siteConfig), + SiteConfigResourceInner.class); + } else { + return super.createOrUpdateSiteConfig(siteConfig); + } + } + + private Mono pollResult(Mono> responseMono, Class responseBodyType) { + return responseMono.flatMap((Function, Mono>) response -> { + if (response.getStatusCode() == 200) { + return Mono.just(response.getValue()); + } else if (response.getStatusCode() == 202) { + HttpHeader locationHeader = response.getHeaders().get(HttpHeaderName.LOCATION); + if (locationHeader == null) { + return Mono.error(new IllegalStateException("\"Location\" header is null")); + } + String locationUrl = locationHeader.getValue(); + SerializerAdapter serializerAdapter = ((WebSiteManagementClientImpl) manager().serviceClient()).getSerializerAdapter(); + return Flux.interval(Duration.ZERO, ResourceManagerUtils.InternalRuntimeContext.getDelayDuration(manager().serviceClient().getDefaultPollInterval())) + .flatMap(ignored -> manager().httpPipeline().send(new HttpRequest(HttpMethod.GET, locationUrl))) + .takeUntil(pollResponse -> { + if (pollResponse.getStatusCode() == 200) { + return true; + } else if (pollResponse.getStatusCode() == 202) { + return false; + } else { + throw new IllegalStateException(String.format("Poll response status: %d.", response.getStatusCode())); + } + }) + .last() + .flatMap((Function>) httpResponse -> { + try { + return Mono.just( + serializerAdapter.deserialize( + httpResponse.getBodyAsBinaryData().toBytes(), + responseBodyType, + SerializerEncoding.JSON)); + } catch (IOException e) { + return Mono.error(e); + } + }); + } else { + throw new IllegalStateException(String.format("createOrUpdateConfiguration response status: %d.", response.getStatusCode())); + } + }); + } + @Override public OperatingSystem operatingSystem() { + if (isFunctionAppOnACA()) { + return OperatingSystem.LINUX; + } return (innerModel().reserved() == null || !innerModel().reserved()) ? OperatingSystem.WINDOWS : OperatingSystem.LINUX; } @@ -513,6 +655,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 +740,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 +784,57 @@ 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 withManagedEnvironmentName(String managedEnvironmentName) { + if (CoreUtils.isNullOrEmpty(managedEnvironmentName)) { + throw new IllegalArgumentException("managedEnvironmentName for Function App must not be null."); + } + return withManagedEnvironmentId(ResourceUtils.constructResourceId( + this.manager().subscriptionId(), + resourceGroupName(), + "Microsoft.App", + "managedEnvironments", + managedEnvironmentName, + "" + )); + } + + @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 6e9ebe4e6989..03184aaeed1e 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 @@ -370,7 +370,7 @@ 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, @PathParam("resourceGroupName") String resourceGroupName, @PathParam("name") String name, @@ -634,7 +634,7 @@ 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, @PathParam("resourceGroupName") String resourceGroupName, @PathParam("name") String name, 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 eac7351ff372..1fd91ff271bd 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,9 @@ 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.appservice.models.AppServicePlan; import com.azure.resourcemanager.appservice.models.AppSetting; @@ -18,24 +20,22 @@ import com.azure.resourcemanager.appservice.models.PricingTier; import com.azure.resourcemanager.appservice.models.SkuName; import com.azure.resourcemanager.resources.fluentcore.arm.ResourceId; -import com.azure.resourcemanager.resources.models.ResourceGroup; -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.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.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 = ""; @@ -61,6 +61,7 @@ protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile rgName2 = generateRandomResourceName("javacsmrg", 20); storageManager = buildManager(StorageManager.class, httpPipeline, profile); + containerAppsApiManager = ContainerAppsApiManager.authenticate(httpPipeline, profile); super.initializeClients(httpPipeline, profile); } @@ -472,7 +473,7 @@ public void canCreateAndUpdateFunctionAppWithContainerSize() { @Test public void canCreateAndUpdateFunctionAppOnACA() { - Region region = Region.US_WEST; + Region region = Region.US_EAST; ResourceGroup resourceGroup = appServiceManager.resourceManager() .resourceGroups() .define(rgName1) @@ -488,7 +489,7 @@ public void canCreateAndUpdateFunctionAppOnACA() { .withManagedEnvironmentName(managedEnvironmentName) .withMaxReplicas(10) .withMinReplicas(3) - .withBuiltInImage(FunctionRuntimeStack.JAVA_17) + .withPublicDockerHubImage("mcr.microsoft.com/azure-functions/dotnet7-quickstart-demo:1.0") .create(); Assertions.assertEquals(managedEnvironmentName, ResourceId.fromString(functionApp.managedEnvironmentId()).name()); @@ -510,6 +511,7 @@ private String createAcaEnvironment(Region region, ResourceGroup resourceGroup) .define(managedEnvironmentName) .withRegion(region) .withExistingResourceGroup(resourceGroup.name()) + .withZoneRedundant(false) .create(); return managedEnvironmentName; } From d218ad94ce6c74f3110b3963c355d40a2d03c2f6 Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Fri, 1 Dec 2023 16:40:26 +0800 Subject: [PATCH 07/17] assets.json --- .../azure-resourcemanager-appservice/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/assets.json b/sdk/resourcemanager/azure-resourcemanager-appservice/assets.json index 97cad2500283..196e013b6736 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_e835fadf70" } From d53b990134269978324cf4ccfc228c2027fea38b Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Fri, 1 Dec 2023 16:43:53 +0800 Subject: [PATCH 08/17] changelog --- .../azure-resourcemanager-appservice/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md b/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md index abef519a029b..3e5cc108fb5d 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` and `withManagedEnvironmentName` for `FunctionApp`. + - Supported `withMaxReplica` and `withMinReplica` for `FunctionApp`. + ### Breaking Changes ### Bugs Fixed From 6b3abcc078c690ef08069bc6fb6601407cdf618d Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Fri, 1 Dec 2023 16:51:02 +0800 Subject: [PATCH 09/17] update note --- sdk/resourcemanager/api-specs.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/api-specs.json b/sdk/resourcemanager/api-specs.json index edcaa94dd3d0..5d34c9f9c5d1 100644 --- a/sdk/resourcemanager/api-specs.json +++ b/sdk/resourcemanager/api-specs.json @@ -10,7 +10,7 @@ "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'" + "note": "Add expected status code '202' to 'updateApplicationSettings' and 'createOrUpdateConfiguration' in 'WebAppsClientImpl'" }, "appservice-hybrid": { "dir": "../resourcemanagerhybrid/azure-resourcemanager-appservice", From efdee8f6a9d6e1adcff5205956ae1e8de807c46d Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 4 Dec 2023 12:05:16 +0800 Subject: [PATCH 10/17] regen --- .../appservice/fluent/WebAppsClient.java | 207 +++++++++- .../implementation/WebAppsClientImpl.java | 387 ++++++++++++++++-- ...ppsCreateOrUpdateConfigurationSamples.java | 3 +- ...bAppsUpdateApplicationSettingsSamples.java | 4 +- .../generated/WebAppsUpdateSamples.java | 2 +- 5 files changed, 547 insertions(+), 56 deletions(-) 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 6508eb8e04a8..87180a633c32 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/WebAppsClientImpl.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/WebAppsClientImpl.java index 03184aaeed1e..c81b11411218 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, @@ -372,7 +372,7 @@ Mono> listConfigurations(@HostParam("$hos @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/config/appsettings") @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, @@ -636,7 +636,7 @@ Mono> getConfiguration(@HostParam("$host") Str @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/config/web") @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/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 200f1da9b939..87e5e530003a 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 9fdb4e3eee1f..1b06430af3ca 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 358a0f4aaa40..d9acf7315999 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); From 81158920106f8854baa7f59690d9601e15d25598 Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 4 Dec 2023 13:18:14 +0800 Subject: [PATCH 11/17] fix compilation after regen --- .../implementation/FunctionAppImpl.java | 95 ------------------- 1 file changed, 95 deletions(-) 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 9a13458582d5..3237f3c4419a 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 @@ -13,24 +13,16 @@ import com.azure.core.annotation.Post; import com.azure.core.annotation.Put; import com.azure.core.annotation.ServiceInterface; -import com.azure.core.http.HttpHeader; -import com.azure.core.http.HttpHeaderName; -import com.azure.core.http.HttpMethod; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; -import com.azure.core.http.HttpRequest; -import com.azure.core.http.HttpResponse; import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.http.rest.PagedIterable; -import com.azure.core.http.rest.Response; 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.core.util.serializer.SerializerAdapter; -import com.azure.core.util.serializer.SerializerEncoding; import com.azure.resourcemanager.appservice.AppServiceManager; import com.azure.resourcemanager.appservice.fluent.models.HostKeysInner; import com.azure.resourcemanager.appservice.fluent.models.SiteConfigInner; @@ -38,7 +30,6 @@ 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.fluent.models.StringDictionaryInner; import com.azure.resourcemanager.appservice.models.AppServicePlan; import com.azure.resourcemanager.appservice.models.FunctionApp; import com.azure.resourcemanager.appservice.models.FunctionAuthenticationPolicy; @@ -68,12 +59,10 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; -import java.time.Duration; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Function; /** The implementation for FunctionApp. */ class FunctionAppImpl @@ -204,21 +193,6 @@ Mono submitSite(SitePatchResourceInner siteUpdate) { } } - @Override - Mono updateInner(SitePatchResourceInner siteUpdate) { - if (isFunctionAppOnACA()) { - return pollResult( - this.manager() - .serviceClient() - .getWebApps() - .updateWithResponseAsync(resourceGroupName(), name(), siteUpdate), - SiteInner.class - ); - } else { - return super.updateInner(siteUpdate); - } - } - @Override Mono submitAppSettings() { if (storageAccountCreatable != null && this.taskResult(storageAccountCreatable.key()) != null) { @@ -287,75 +261,6 @@ private void resetStorageInfo() { storageAccountCreatable = null; } - @Override - Mono updateAppSettings(StringDictionaryInner appSettings) { - if (isFunctionAppOnACA()) { - return pollResult( - this.manager() - .serviceClient() - .getWebApps() - .updateApplicationSettingsWithResponseAsync(resourceGroupName(), name(), appSettings), - StringDictionaryInner.class - ); - } else { - return super.updateAppSettings(appSettings); - } - } - - @Override - Mono createOrUpdateSiteConfig(SiteConfigResourceInner siteConfig) { - if (isFunctionAppOnACA()) { - return pollResult( - this.manager() - .serviceClient() - .getWebApps() - .createOrUpdateConfigurationWithResponseAsync(resourceGroupName(), name(), siteConfig), - SiteConfigResourceInner.class); - } else { - return super.createOrUpdateSiteConfig(siteConfig); - } - } - - private Mono pollResult(Mono> responseMono, Class responseBodyType) { - return responseMono.flatMap((Function, Mono>) response -> { - if (response.getStatusCode() == 200) { - return Mono.just(response.getValue()); - } else if (response.getStatusCode() == 202) { - HttpHeader locationHeader = response.getHeaders().get(HttpHeaderName.LOCATION); - if (locationHeader == null) { - return Mono.error(new IllegalStateException("\"Location\" header is null")); - } - String locationUrl = locationHeader.getValue(); - SerializerAdapter serializerAdapter = ((WebSiteManagementClientImpl) manager().serviceClient()).getSerializerAdapter(); - return Flux.interval(Duration.ZERO, ResourceManagerUtils.InternalRuntimeContext.getDelayDuration(manager().serviceClient().getDefaultPollInterval())) - .flatMap(ignored -> manager().httpPipeline().send(new HttpRequest(HttpMethod.GET, locationUrl))) - .takeUntil(pollResponse -> { - if (pollResponse.getStatusCode() == 200) { - return true; - } else if (pollResponse.getStatusCode() == 202) { - return false; - } else { - throw new IllegalStateException(String.format("Poll response status: %d.", response.getStatusCode())); - } - }) - .last() - .flatMap((Function>) httpResponse -> { - try { - return Mono.just( - serializerAdapter.deserialize( - httpResponse.getBodyAsBinaryData().toBytes(), - responseBodyType, - SerializerEncoding.JSON)); - } catch (IOException e) { - return Mono.error(e); - } - }); - } else { - throw new IllegalStateException(String.format("createOrUpdateConfiguration response status: %d.", response.getStatusCode())); - } - }); - } - @Override public OperatingSystem operatingSystem() { if (isFunctionAppOnACA()) { From 1ab016dc64ce7b9ee3570f7790ba44f7e2deaa59 Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 4 Dec 2023 13:29:19 +0800 Subject: [PATCH 12/17] drop withManagedEnvironmentName fix test fix test --- .../CHANGELOG.md | 2 +- .../implementation/FunctionAppImpl.java | 16 ---------- .../appservice/models/FunctionApp.java | 12 -------- .../appservice/AppServiceTest.java | 2 +- .../appservice/FunctionAppsTests.java | 30 ++++++++++++++----- 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md b/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md index 3e5cc108fb5d..d2aa4702e29a 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md @@ -5,7 +5,7 @@ ### Features Added - Supported Function App in Azure Container Apps environment. - - Supported `withManagedEnvironmentId` and `withManagedEnvironmentName` for `FunctionApp`. + - Supported `withManagedEnvironmentId` or `FunctionApp`. - Supported `withMaxReplica` and `withMinReplica` for `FunctionApp`. ### Breaking Changes 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 3237f3c4419a..ea802cea67e9 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 @@ -41,7 +41,6 @@ import com.azure.resourcemanager.appservice.models.PricingTier; import com.azure.resourcemanager.appservice.models.SkuDescription; import com.azure.resourcemanager.appservice.models.SkuName; -import com.azure.resourcemanager.resources.fluentcore.arm.ResourceUtils; import com.azure.resourcemanager.resources.fluentcore.model.Creatable; import com.azure.resourcemanager.resources.fluentcore.model.Indexable; import com.azure.resourcemanager.resources.fluentcore.policy.AuthenticationPolicy; @@ -698,21 +697,6 @@ public FunctionAppImpl withManagedEnvironmentId(String managedEnvironmentId) { return this; } - @Override - public FunctionAppImpl withManagedEnvironmentName(String managedEnvironmentName) { - if (CoreUtils.isNullOrEmpty(managedEnvironmentName)) { - throw new IllegalArgumentException("managedEnvironmentName for Function App must not be null."); - } - return withManagedEnvironmentId(ResourceUtils.constructResourceId( - this.manager().subscriptionId(), - resourceGroupName(), - "Microsoft.App", - "managedEnvironments", - managedEnvironmentName, - "" - )); - } - @Override public FunctionAppImpl withMaxReplicas(int maxReplicas) { if (siteConfig == null) { 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 bfa58f9c6fb9..9d75a8580c74 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 @@ -523,18 +523,6 @@ interface WithManagedEnvironment { * @return the next stage of the definition */ WithScaleRulesOrDockerContainerImage withManagedEnvironmentId(String managedEnvironmentId); - - /** - * Specifies the name of the Azure Container Apps environment - * to deploy the Function App on. The environment must be in the same resource group as the Function App. - *

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 managedEnvironmentName name of the Azure Container Apps environment - * @return the next stage of the definition - */ - WithScaleRulesOrDockerContainerImage withManagedEnvironmentName(String managedEnvironmentName); } /** A function app definition allowing scale rules to be specified for Function Apps hosted on Azure Container Apps. */ 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 85e0e9903c98..a8c1600cbc62 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 1fd91ff271bd..020ba5b01437 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 @@ -10,6 +10,7 @@ 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; @@ -19,18 +20,19 @@ 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.resources.fluentcore.arm.ResourceId; 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.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; @@ -61,7 +63,21 @@ protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile rgName2 = generateRandomResourceName("javacsmrg", 20); storageManager = buildManager(StorageManager.class, httpPipeline, profile); - containerAppsApiManager = ContainerAppsApiManager.authenticate(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); } @@ -479,20 +495,20 @@ public void canCreateAndUpdateFunctionAppOnACA() { .define(rgName1) .withRegion(region) .create(); - String managedEnvironmentName = createAcaEnvironment(region, resourceGroup); + String managedEnvironmentId = createAcaEnvironment(region, resourceGroup); webappName1 = generateRandomResourceName("java-function-", 20); FunctionApp functionApp = appServiceManager .functionApps() .define(webappName1) .withRegion(region) .withExistingResourceGroup(resourceGroup) - .withManagedEnvironmentName(managedEnvironmentName) + .withManagedEnvironmentId(managedEnvironmentId) .withMaxReplicas(10) .withMinReplicas(3) .withPublicDockerHubImage("mcr.microsoft.com/azure-functions/dotnet7-quickstart-demo:1.0") .create(); - Assertions.assertEquals(managedEnvironmentName, ResourceId.fromString(functionApp.managedEnvironmentId()).name()); + Assertions.assertEquals(managedEnvironmentId, functionApp.managedEnvironmentId()); Assertions.assertEquals(10, functionApp.maxReplicas()); Assertions.assertEquals(3, functionApp.minReplicas()); @@ -507,13 +523,13 @@ public void canCreateAndUpdateFunctionAppOnACA() { private String createAcaEnvironment(Region region, ResourceGroup resourceGroup) { String managedEnvironmentName = generateRandomResourceName("jvacam", 15); - containerAppsApiManager.managedEnvironments() + ManagedEnvironment managedEnvironment = containerAppsApiManager.managedEnvironments() .define(managedEnvironmentName) .withRegion(region) .withExistingResourceGroup(resourceGroup.name()) .withZoneRedundant(false) .create(); - return managedEnvironmentName; + return managedEnvironment.id(); } private void assertRunning(FunctionApp functionApp) { From a37d58e3820b314afbcdaef5515c9fdbe5362f67 Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 4 Dec 2023 13:30:02 +0800 Subject: [PATCH 13/17] assets.json --- .../azure-resourcemanager-appservice/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/assets.json b/sdk/resourcemanager/azure-resourcemanager-appservice/assets.json index 196e013b6736..96d6661168bb 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_e835fadf70" + "Tag": "java/resourcemanager/azure-resourcemanager-appservice_3c0a63fc34" } From 645893ab78d531ea680286b256ac9d9c032c817d Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 4 Dec 2023 14:51:48 +0800 Subject: [PATCH 14/17] update note in api-specs.json --- sdk/resourcemanager/api-specs.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/resourcemanager/api-specs.json b/sdk/resourcemanager/api-specs.json index 5d34c9f9c5d1..026fae0557b7 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 expected status code '202' to 'updateApplicationSettings' and 'createOrUpdateConfiguration' in 'WebAppsClientImpl'" + "args": "--tag=package-2023-01 --add-inner=AppServiceCertificate --remove-inner=CsmDeploymentStatus --name-for-ungrouped-operations=ResourceProvider" }, "appservice-hybrid": { "dir": "../resourcemanagerhybrid/azure-resourcemanager-appservice", From 016b8de3717a3a64e4ec680555f883fa29ad4711 Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 4 Dec 2023 14:59:16 +0800 Subject: [PATCH 15/17] update pom.xml for dependency update --- sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml b/sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml index bf02f572144d..bee9222ef44b 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml @@ -142,7 +142,7 @@ com.azure.resourcemanager azure-resourcemanager-appcontainers - 1.0.0-beta.6 + 1.0.0-beta.6 test From b7b12cf46d7428647feb4ca592414efc3d54fc30 Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Mon, 4 Dec 2023 15:38:12 +0800 Subject: [PATCH 16/17] nit, fix changelog.md --- .../azure-resourcemanager-appservice/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md b/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md index d2aa4702e29a..b9eef123bd82 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md @@ -5,7 +5,7 @@ ### Features Added - Supported Function App in Azure Container Apps environment. - - Supported `withManagedEnvironmentId` or `FunctionApp`. + - Supported `withManagedEnvironmentId` for `FunctionApp`. - Supported `withMaxReplica` and `withMinReplica` for `FunctionApp`. ### Breaking Changes From 5ef196c24f9b5a8de759145f4970d0f6cd0a696c Mon Sep 17 00:00:00 2001 From: XiaofeiCao Date: Tue, 5 Dec 2023 12:04:55 +0800 Subject: [PATCH 17/17] update according to comments --- .../implementation/FunctionAppImpl.java | 47 ++++++------------- 1 file changed, 14 insertions(+), 33 deletions(-) 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 ea802cea67e9..2f088c72a83f 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 @@ -199,7 +199,7 @@ Mono submitAppSettings() { } if (storageAccountToSet == null) { return super.submitAppSettings(); - } else if (isFunctionAppOnACA()) { + } else { return storageAccountToSet .getKeysAsync() .flatMap(storageAccountKeys -> { @@ -209,28 +209,9 @@ Mono submitAppSettings() { manager().environment()); addAppSettingIfNotModified(SETTING_WEB_JOBS_STORAGE, connectionString); addAppSettingIfNotModified(SETTING_WEB_JOBS_DASHBOARD, connectionString); - return FunctionAppImpl.super.submitAppSettings(); - }).then( - Mono - .fromCallable( - () -> { - resetStorageInfo(); - return this; - })); - } 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); + if (!isFunctionAppOnACA()) { + return this.manager().appServicePlans().getByIdAsync(this.appServicePlanId()) + .flatMap(appServicePlan -> { if (appServicePlan == null || isConsumptionOrPremiumAppServicePlan(appServicePlan.pricingTier())) { @@ -242,27 +223,27 @@ Mono submitAppSettings() { .randomResourceName(name(), 32)); } return FunctionAppImpl.super.submitAppSettings(); - })) - .last() - .then( + }); + } else { + return FunctionAppImpl.super.submitAppSettings(); + } + }).then( Mono .fromCallable( () -> { - resetStorageInfo(); + currentStorageAccount = storageAccountToSet; + storageAccountToSet = null; + storageAccountCreatable = null; return this; })); } } - private void resetStorageInfo() { - currentStorageAccount = storageAccountToSet; - storageAccountToSet = null; - storageAccountCreatable = null; - } - @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())