Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgmt, samples, migrate test-proxy #36129

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/resourcemanager/azure-resourcemanager-samples",
"Tag": "java/resourcemanager/azure-resourcemanager-samples_5e94215958"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import com.azure.resourcemanager.network.models.VirtualMachineScaleSetNicIpConfiguration;
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.samples.Utils;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -219,6 +221,12 @@ public static boolean runSample(AzureResourceManager azureResourceManager) {
.withNewDataDisk(100, 1, CachingTypes.READ_WRITE)
.withNewDataDisk(100, 2, CachingTypes.READ_WRITE, StorageAccountTypes.STANDARD_LRS)
.withCapacity(3)
.create();

// VM may take some time to init its pkgs
ResourceManagerUtils.sleep(Duration.ofMinutes(1));

virtualMachineScaleSet.update()
// Use a VM extension to install Apache Web servers
.defineNewExtension("CustomScriptForLinux")
.withPublisher("Microsoft.OSTCExtensions")
Expand All @@ -228,7 +236,7 @@ public static boolean runSample(AzureResourceManager azureResourceManager) {
.withPublicSetting("fileUris", fileUris)
.withPublicSetting("commandToExecute", installCommand)
.attach()
.create();
.apply();

Date t2 = new Date();
System.out.println("Created a virtual machine scale set with "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import com.azure.resourcemanager.network.models.VirtualMachineScaleSetNicIpConfiguration;
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.samples.Utils;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -222,6 +224,12 @@ public static boolean runSample(AzureResourceManager azureResourceManager) {
.withNewStorageAccount(storageAccountName2)
.withNewStorageAccount(storageAccountName3)
.withCapacity(3)
.create();

// VM may take some time to init its pkgs
ResourceManagerUtils.sleep(Duration.ofMinutes(1));

virtualMachineScaleSet.update()
// Use a VM extension to install Apache Web servers
.defineNewExtension("CustomScriptForLinux")
.withPublisher("Microsoft.OSTCExtensions")
Expand All @@ -231,7 +239,7 @@ public static boolean runSample(AzureResourceManager azureResourceManager) {
.withPublicSetting("fileUris", fileUris)
.withPublicSetting("commandToExecute", installCommand)
.attach()
.create();
.apply();

Date t2 = new Date();
System.out.println("Created a virtual machine scale set with "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ManageContainerRegistryWithWebhooks {
public static boolean runSample(AzureResourceManager azureResourceManager) throws IOException, InterruptedException {
final String rgName = Utils.randomResourceName(azureResourceManager, "rgACR", 15);
final String acrName = Utils.randomResourceName(azureResourceManager, "acrsample", 20);
final Region region = Region.US_WEST_CENTRAL;
final Region region = Region.US_WEST3;
final String dockerImageName = "hello-world";
final String dockerImageTag = "latest";
final String dockerContainerName = "sample-hello";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static boolean runSample(AzureResourceManager azureResourceManager) {
.withKind(DatabaseAccountKind.GLOBAL_DOCUMENT_DB)
.withEventualConsistency()
.withWriteReplication(Region.US_EAST)
.withReadReplication(Region.US_CENTRAL)
.withReadReplication(Region.US_WEST3)
.create();

System.out.println("Created CosmosDB");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static boolean runSample(AzureResourceManager azureResourceManager) {
.withKind(DatabaseAccountKind.GLOBAL_DOCUMENT_DB)
.withSessionConsistency()
.withWriteReplication(Region.US_WEST)
.withReadReplication(Region.US_CENTRAL)
.withReadReplication(Region.US_WEST3)
.withIpRules(Arrays.asList(
new IpAddressOrRange().withIpAddressOrRange("13.91.6.132"),
new IpAddressOrRange().withIpAddressOrRange("13.91.6.1/24")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static boolean runSample(AzureResourceManager azureResourceManager) {
.withKind(DatabaseAccountKind.MONGO_DB)
.withEventualConsistency()
.withWriteReplication(Region.US_WEST)
.withReadReplication(Region.US_CENTRAL)
.withReadReplication(Region.US_WEST3)
.create();

System.out.println("Created CosmosDB");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static boolean runSample(AzureResourceManager azureResourceManager) {
.withKind(DatabaseAccountKind.GLOBAL_DOCUMENT_DB)
.withSessionConsistency()
.withWriteReplication(Region.US_WEST)
.withReadReplication(Region.US_CENTRAL)
.withReadReplication(Region.US_WEST3)
.create();

System.out.println("Created CosmosDB");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static boolean runSample(AzureResourceManager azureResourceManager) {
.withKind(DatabaseAccountKind.MONGO_DB)
.withEventualConsistency()
.withWriteReplication(Region.US_WEST)
.withReadReplication(Region.US_CENTRAL)
.withReadReplication(Region.US_WEST3)
.create();

System.out.println("Created a DocumentDb instance.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;

/**
* This sample shows examples of configuring Activity Log Alerts for potential security breach or risk notifications.
Expand Down Expand Up @@ -97,7 +98,7 @@ public static boolean runSample(AzureResourceManager azureResourceManager) {
// for near real time monitoring.
ResourceManagerUtils.sleep(Duration.ofMinutes(6));

OffsetDateTime recordDateTime = OffsetDateTime.parse("2020-08-03T16:34:27.009944500+08:00");
OffsetDateTime recordDateTime = OffsetDateTime.now().truncatedTo(ChronoUnit.DAYS);
// get activity logs for the same period.
PagedIterable<EventData> logs = azureResourceManager.activityLogs().defineQuery()
.startingFrom(recordDateTime.minusDays(7))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import com.azure.resourcemanager.compute.models.VirtualMachine;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.network.models.ApplicationGateway;
import com.azure.resourcemanager.network.models.ApplicationGatewaySkuName;
import com.azure.resourcemanager.network.models.ApplicationGatewayTier;
import com.azure.resourcemanager.network.models.Network;
import com.azure.resourcemanager.network.models.PublicIPSkuType;
import com.azure.resourcemanager.network.models.PublicIpAddress;
import com.azure.resourcemanager.resources.models.ResourceGroup;
import com.azure.core.management.Region;
Expand Down Expand Up @@ -115,6 +118,8 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw
PublicIpAddress publicIPAddress = azureResourceManager.publicIpAddresses().define(pipName)
.withRegion(Region.US_EAST)
.withExistingResourceGroup(rgName)
.withSku(PublicIPSkuType.STANDARD)
.withStaticIP()
.create();

System.out.println("Created a public IP address");
Expand Down Expand Up @@ -159,7 +164,9 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw
.define(String.format("%s-%d", linuxVMNamePrefix, j))
.withRegion(regions[i])
.withExistingResourceGroup(resourceGroup)
.withLeafDomainLabel(String.format("%s-%d", linuxVMNamePrefix, j));
.withLeafDomainLabel(String.format("%s-%d", linuxVMNamePrefix, j))
.withSku(PublicIPSkuType.STANDARD)
.withStaticIP();

publicIpCreatableKeys[i][j] = publicIPAddressCreatable.key();

Expand Down Expand Up @@ -243,6 +250,8 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw
.toBackendIPAddress(ipAddresses[0][3])
.attach()

.withTier(ApplicationGatewayTier.WAF_V2)
.withSize(ApplicationGatewaySkuName.WAF_V2)
.withExistingPublicIpAddress(publicIPAddress)
.create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public final class ManageNetworkWatcher {
* @return true if sample runs successfully
*/
public static boolean runSample(AzureResourceManager azureResourceManager) {
final Region region = Region.US_NORTH_CENTRAL;
final Region region = Region.US_WEST3;
final String nwName = Utils.randomResourceName(azureResourceManager, "nw", 8);

final String userName = "tirekicker";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import com.azure.resourcemanager.network.models.ApplicationGateway;
import com.azure.core.management.Region;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.network.models.ApplicationGatewaySkuName;
import com.azure.resourcemanager.network.models.ApplicationGatewayTier;
import com.azure.resourcemanager.network.models.PublicIPSkuType;
import com.azure.resourcemanager.network.models.PublicIpAddress;
import com.azure.resourcemanager.samples.Utils;

import java.io.File;
Expand Down Expand Up @@ -70,6 +74,14 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw
System.out.println("Creating an application gateway... (this can take about 20 min)");
long t1 = System.currentTimeMillis();

final String pipName = Utils.randomResourceName(azureResourceManager, "pip" + "-", 18);
PublicIpAddress publicIPAddress = azureResourceManager.publicIpAddresses().define(pipName)
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName)
.withSku(PublicIPSkuType.STANDARD)
.withStaticIP()
.create();

ApplicationGateway applicationGateway = azureResourceManager.applicationGateways().define("myFirstAppGateway")
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName)
Expand All @@ -84,7 +96,10 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw
.toBackendIPAddress("11.1.1.3")
.toBackendIPAddress("11.1.1.4")
.attach()
.withNewPublicIpAddress()

.withTier(ApplicationGatewayTier.WAF_V2)
.withSize(ApplicationGatewaySkuName.WAF_V2)
.withExistingPublicIpAddress(publicIPAddress)
.create();

long t2 = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public void testListVirtualMachineExtensionImages() {
Assertions.assertTrue(ListVirtualMachineExtensionImages.runSample(azureResourceManager));
}

// record too large, playback takes 30+ seconds
@Test
@DoNotRecord(skipInPlayback = true)
public void testListVirtualMachineImages() {
Assertions.assertTrue(ListVirtualMachineImages.runSample(azureResourceManager));
}
Expand Down Expand Up @@ -195,6 +197,7 @@ public void testCreateVirtualMachineEncryptedUsingCustomerManagedKey() {
Assertions.assertTrue(CreateVirtualMachineEncryptedUsingCustomerManagedKey.runSample(azureResourceManager, clientId));
}

@DoNotRecord(skipInPlayback = true)
@Test
public void testCloneVirtualMachineToNewRegion() {
Assertions.assertTrue(CloneVirtualMachineToNewRegion.runSample(azureResourceManager));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.resourcemanager.samples;

import com.azure.core.test.annotation.DoNotRecord;
import com.azure.resourcemanager.cosmos.samples.CreateCosmosDBTableWithVirtualNetworkRule;
import com.azure.resourcemanager.cosmos.samples.CreateCosmosDBWithEventualConsistency;
import com.azure.resourcemanager.cosmos.samples.CreateCosmosDBWithIPRange;
Expand All @@ -13,6 +14,9 @@

public class CosmosDBTests extends SamplesTestBase {

// Most this error in runtime
// Sorry, we are currently experiencing high demand in Central US region, and cannot fulfill your request at this time ###.

@Test
public void testCreateCosmosDBWithEventualConsistency() {
// Skip test in "playback" mode due to HTTP calls made outside of the management plane which can not be recorded at this time
Expand All @@ -39,6 +43,8 @@ public void testCreateCosmosDBWithKindMongoDB() {
}
}

// it uses lots of read replication regions
@DoNotRecord(skipInPlayback = true)
@Test
public void testManageHACosmosDB() {
// Skip test in "playback" mode due to HTTP calls made outside of the management plane which can not be recorded at this time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
import com.azure.resourcemanager.authorization.samples.ManageUsersGroupsAndRoles;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider;
import com.azure.resourcemanager.test.ResourceManagerTestBase;
import com.azure.resourcemanager.test.ResourceManagerTestProxyTestBase;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.time.temporal.ChronoUnit;
import java.util.List;

public class GraphRbacTests extends ResourceManagerTestBase {
public class GraphRbacTests extends ResourceManagerTestProxyTestBase {
private AzureResourceManager azureResourceManager;
private AzureProfile profile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.azure.resourcemanager.samples;


import com.azure.core.test.annotation.DoNotRecord;
import com.azure.resourcemanager.monitor.samples.AutoscaleSettingsBasedOnPerformanceOrSchedule;
import com.azure.resourcemanager.monitor.samples.QueryMetricsAndActivityLogs;
import com.azure.resourcemanager.monitor.samples.SecurityBreachOrRiskActivityLogAlerts;
Expand All @@ -23,6 +24,8 @@ public void testQueryMetricsAndActivityLogs() throws IOException {
}
}

// Require latest date as query parameter
@DoNotRecord(skipInPlayback = true)
@Test
public void testSecurityBreachOrRiskActivityLogAlerts() {
Assertions.assertTrue(SecurityBreachOrRiskActivityLogAlerts.runSample(azureResourceManager));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,30 @@
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.test.models.TestProxySanitizer;
import com.azure.core.test.models.TestProxySanitizerType;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider;
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
import com.azure.resourcemanager.test.ResourceManagerTestBase;
import com.azure.resourcemanager.test.ResourceManagerTestProxyTestBase;
import com.azure.resourcemanager.test.utils.TestDelayProvider;
import com.azure.resourcemanager.test.utils.TestIdentifierProvider;

import java.time.temporal.ChronoUnit;
import java.util.List;

public class SamplesTestBase extends ResourceManagerTestBase {
public class SamplesTestBase extends ResourceManagerTestProxyTestBase {
protected AzureResourceManager azureResourceManager;

public SamplesTestBase() {
addSanitizers(
// Search key
new TestProxySanitizer("$.key", null, REDACTED_VALUE, TestProxySanitizerType.BODY_KEY),
new TestProxySanitizer("$.value[*].key", null, REDACTED_VALUE, TestProxySanitizerType.BODY_KEY)
);
}

@Override
protected HttpPipeline buildHttpPipeline(
TokenCredential credential,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

package com.azure.resourcemanager.samples;

import com.azure.core.test.annotation.DoNotRecord;
import com.azure.resourcemanager.search.samples.ManageSearchService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SearchSampleTests extends SamplesTestBase {

// secret in URL on API deleteQueryKey
@DoNotRecord(skipInPlayback = true)
@Test
public void testManageSearchService() {
Assertions.assertTrue(ManageSearchService.runSample(azureResourceManager));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.resourcemanager.samples;

import com.azure.core.test.annotation.DoNotRecord;
import com.azure.resourcemanager.sql.samples.ManageSqlDatabase;
import com.azure.resourcemanager.sql.samples.ManageSqlDatabaseInElasticPool;
import com.azure.resourcemanager.sql.samples.ManageSqlDatabasesAcrossDifferentDataCenters;
Expand Down Expand Up @@ -53,17 +54,17 @@ public void testManageSqlVirtualNetworkRules() {
Assertions.assertTrue(ManageSqlVirtualNetworkRules.runSample(azureResourceManager));
}

// Skip test in "playback" mode due to HTTP calls made outside of the management plane which can not be recorded at this time
@DoNotRecord(skipInPlayback = true)
@Test
public void testManageSqlImportExportDatabase() {
// Skip test in "playback" mode due to HTTP calls made outside of the management plane which can not be recorded at this time
if (!isPlaybackMode()) {
Assertions.assertTrue(ManageSqlImportExportDatabase.runSample(azureResourceManager));
}
Assertions.assertTrue(ManageSqlImportExportDatabase.runSample(azureResourceManager));
}

// This test can take significant time to run since it depends on the availability of certain resources on the service side.
@DoNotRecord(skipInPlayback = true)
@Test
public void testManageSqlWithRecoveredOrRestoredDatabase() {
// This test can take significant time to run since it depends on the availability of certain resources on the service side.
Assertions.assertTrue(ManageSqlWithRecoveredOrRestoredDatabase.runSample(azureResourceManager));
}

Expand Down
Loading