From c44022c3595b359939fa7fad3a18926d7f7cec43 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Tue, 17 Dec 2024 10:09:06 +0800 Subject: [PATCH] Register provider via policy Part seven --- ...viceFabricManagedClustersManagerTests.java | 34 +++---------------- .../TrafficControllerManagerTests.java | 10 +++--- .../sphere/AzureSphereManagerTests.java | 10 +++--- .../StorageMoverManagerTests.java | 12 ++++--- .../webpubsub/WebPubSubManagerTests.java | 10 +++--- 5 files changed, 30 insertions(+), 46 deletions(-) diff --git a/sdk/servicefabricmanagedclusters/azure-resourcemanager-servicefabricmanagedclusters/src/test/java/com/azure/resourcemanager/servicefabricmanagedclusters/ServiceFabricManagedClustersManagerTests.java b/sdk/servicefabricmanagedclusters/azure-resourcemanager-servicefabricmanagedclusters/src/test/java/com/azure/resourcemanager/servicefabricmanagedclusters/ServiceFabricManagedClustersManagerTests.java index cb6bd4dc5ebe9..e662038f54915 100644 --- a/sdk/servicefabricmanagedclusters/azure-resourcemanager-servicefabricmanagedclusters/src/test/java/com/azure/resourcemanager/servicefabricmanagedclusters/ServiceFabricManagedClustersManagerTests.java +++ b/sdk/servicefabricmanagedclusters/azure-resourcemanager-servicefabricmanagedclusters/src/test/java/com/azure/resourcemanager/servicefabricmanagedclusters/ServiceFabricManagedClustersManagerTests.java @@ -15,17 +15,13 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; -import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils; -import com.azure.resourcemanager.resources.models.Provider; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.servicefabricmanagedclusters.models.ManagedCluster; import com.azure.resourcemanager.servicefabricmanagedclusters.models.Sku; import com.azure.resourcemanager.servicefabricmanagedclusters.models.SkuName; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.time.Duration; -import java.util.Arrays; -import java.util.List; import java.util.Random; import java.util.UUID; @@ -42,16 +38,15 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - serviceFabricManagedClustersManager = ServiceFabricManagedClustersManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); - canRegisterProviders(Arrays.asList("Microsoft.ServiceFabric")); + serviceFabricManagedClustersManager = ServiceFabricManagedClustersManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); @@ -110,23 +105,4 @@ public void testCreateManagedCluster() { private static String randomPadding() { return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000)); } - - /** - * Check and register service resources - * - * @param providerNamespaces the resource provider names - */ - private void canRegisterProviders(List providerNamespaces) { - providerNamespaces.forEach(providerNamespace -> { - Provider provider = resourceManager.providers().getByName(providerNamespace); - if (!"Registered".equalsIgnoreCase(provider.registrationState()) - && !"Registering".equalsIgnoreCase(provider.registrationState())) { - provider = resourceManager.providers().register(providerNamespace); - } - while (!"Registered".equalsIgnoreCase(provider.registrationState())) { - ResourceManagerUtils.sleep(Duration.ofSeconds(5)); - provider = resourceManager.providers().getByName(provider.namespace()); - } - }); - } } diff --git a/sdk/servicenetworking/azure-resourcemanager-servicenetworking/src/test/java/com/azure/resourcemanager/servicenetworking/TrafficControllerManagerTests.java b/sdk/servicenetworking/azure-resourcemanager-servicenetworking/src/test/java/com/azure/resourcemanager/servicenetworking/TrafficControllerManagerTests.java index 5214c6be6228a..68b15e8267fa3 100644 --- a/sdk/servicenetworking/azure-resourcemanager-servicenetworking/src/test/java/com/azure/resourcemanager/servicenetworking/TrafficControllerManagerTests.java +++ b/sdk/servicenetworking/azure-resourcemanager-servicenetworking/src/test/java/com/azure/resourcemanager/servicenetworking/TrafficControllerManagerTests.java @@ -15,6 +15,7 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.servicenetworking.models.TrafficController; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - trafficControllerManager = TrafficControllerManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + trafficControllerManager = TrafficControllerManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/sphere/azure-resourcemanager-sphere/src/test/java/com/azure/resourcemanager/sphere/AzureSphereManagerTests.java b/sdk/sphere/azure-resourcemanager-sphere/src/test/java/com/azure/resourcemanager/sphere/AzureSphereManagerTests.java index ad1deba3c3b57..a18645c49e9cc 100644 --- a/sdk/sphere/azure-resourcemanager-sphere/src/test/java/com/azure/resourcemanager/sphere/AzureSphereManagerTests.java +++ b/sdk/sphere/azure-resourcemanager-sphere/src/test/java/com/azure/resourcemanager/sphere/AzureSphereManagerTests.java @@ -15,6 +15,7 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.sphere.models.Catalog; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -35,15 +36,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - azureSphereManager = AzureSphereManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + azureSphereManager = AzureSphereManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/storagemover/azure-resourcemanager-storagemover/src/test/java/com/azure/resourcemanager/storagemover/StorageMoverManagerTests.java b/sdk/storagemover/azure-resourcemanager-storagemover/src/test/java/com/azure/resourcemanager/storagemover/StorageMoverManagerTests.java index 08e641677dcd0..8211480ee8e3a 100644 --- a/sdk/storagemover/azure-resourcemanager-storagemover/src/test/java/com/azure/resourcemanager/storagemover/StorageMoverManagerTests.java +++ b/sdk/storagemover/azure-resourcemanager-storagemover/src/test/java/com/azure/resourcemanager/storagemover/StorageMoverManagerTests.java @@ -15,6 +15,7 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.storagemover.models.StorageMover; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -23,7 +24,7 @@ public class StorageMoverManagerTests extends TestProxyTestBase { private static final Random RANDOM = new Random(); - private static final Region REGION = Region.create("eastus2euap", "East US 2 EUAP"); + private static final Region REGION = Region.US_EAST2; private String resourceGroupName = "rg" + randomPadding(); private StorageMoverManager storageMoverManager; private ResourceManager resourceManager; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - storageMoverManager = StorageMoverManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + storageMoverManager = StorageMoverManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/webpubsub/azure-resourcemanager-webpubsub/src/test/java/com/azure/resourcemanager/webpubsub/WebPubSubManagerTests.java b/sdk/webpubsub/azure-resourcemanager-webpubsub/src/test/java/com/azure/resourcemanager/webpubsub/WebPubSubManagerTests.java index cade90cba06d7..d0305fa4c0f15 100644 --- a/sdk/webpubsub/azure-resourcemanager-webpubsub/src/test/java/com/azure/resourcemanager/webpubsub/WebPubSubManagerTests.java +++ b/sdk/webpubsub/azure-resourcemanager-webpubsub/src/test/java/com/azure/resourcemanager/webpubsub/WebPubSubManagerTests.java @@ -15,6 +15,7 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.webpubsub.models.ResourceSku; import com.azure.resourcemanager.webpubsub.models.WebPubSubResource; import com.azure.resourcemanager.webpubsub.models.WebPubSubSkuTier; @@ -37,15 +38,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - webPubSubManager = WebPubSubManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + webPubSubManager = WebPubSubManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup);