From ff6fe4ef6c534b61d45356cd500cbc038be6b932 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 20 May 2021 16:06:32 +0800 Subject: [PATCH] mgmt, hdinsight sample in readme from test (#21675) * add embedme tag * generate example in readme --- .../azure-resourcemanager-hdinsight/README.md | 90 +++++++++++++++++++ .../azure-resourcemanager-hdinsight/pom.xml | 3 +- ...dInsightTests.java => HDInsightTests.java} | 10 ++- 3 files changed, 98 insertions(+), 5 deletions(-) rename sdk/hdinsight/azure-resourcemanager-hdinsight/src/test/java/com/azure/resourcemanager/hdinsight/{HdInsightTests.java => HDInsightTests.java} (95%) diff --git a/sdk/hdinsight/azure-resourcemanager-hdinsight/README.md b/sdk/hdinsight/azure-resourcemanager-hdinsight/README.md index ad69bcb0ff34e..06ce78f55d674 100644 --- a/sdk/hdinsight/azure-resourcemanager-hdinsight/README.md +++ b/sdk/hdinsight/azure-resourcemanager-hdinsight/README.md @@ -74,6 +74,96 @@ See [API design][design] for general introduction on design and key concepts on ## Examples +```java +// network +Network network = networkManager.networks().define("vn1") + .withRegion(REGION) + .withExistingResourceGroup(resourceGroupName) + .withAddressSpace("10.0.0.0/24") + .withSubnet("default", "10.0.0.0/24") + .create(); +Subnet subnet = network.subnets().values().iterator().next(); + +// storage account +com.azure.resourcemanager.storage.models.StorageAccount storageAccount = storageManager.storageAccounts().define(storageAccountName) + .withRegion(REGION) + .withExistingResourceGroup(resourceGroupName) + .create(); +final String storageAccountKey = storageAccount.getKeys().iterator().next().value(); + +// container +final String containerName = "hdinsight"; +storageManager.blobContainers().defineContainer(containerName) + .withExistingBlobService(resourceGroupName, storageAccountName) + .withPublicAccess(PublicAccess.NONE) + .create(); + +// cluster +manager.clusters().define("cluster" + randomPadding()) + .withExistingResourceGroup(resourceGroupName) + .withRegion(REGION) + .withProperties(new ClusterCreateProperties() + .withClusterVersion("3.6") + .withOsType(OSType.LINUX) + .withTier(Tier.STANDARD) + .withClusterDefinition(new ClusterDefinition() + .withKind("Spark") + .withConfigurations(ImmutableMap.of( + "gateway", ImmutableMap.of( + "restAuthCredential.isEnabled", "true", + "restAuthCredential.username", "admin", + "restAuthCredential.password", "Pa$s" + randomPadding() + ))) + ) + .withComputeProfile(new ComputeProfile() + .withRoles(ImmutableList.of( + new Role().withName("headnode") + .withTargetInstanceCount(2) + .withHardwareProfile(new HardwareProfile() + .withVmSize("Large") + ) + .withOsProfile(new OsProfile() + .withLinuxOperatingSystemProfile( + new LinuxOperatingSystemProfile() + .withUsername("sshuser") + .withPassword("Pa$s" + randomPadding()) + ) + ) + .withVirtualNetworkProfile(new VirtualNetworkProfile() + .withId(network.id()) + .withSubnet(subnet.id()) + ), + new Role().withName("workernode") + .withTargetInstanceCount(3) + .withHardwareProfile(new HardwareProfile() + .withVmSize("Large") + ) + .withOsProfile(new OsProfile() + .withLinuxOperatingSystemProfile( + new LinuxOperatingSystemProfile() + .withUsername("sshuser") + .withPassword("Pa$s" + randomPadding()) + ) + ) + .withVirtualNetworkProfile(new VirtualNetworkProfile() + .withId(network.id()) + .withSubnet(subnet.id()) + ) + )) + ) + .withStorageProfile(new StorageProfile() + .withStorageaccounts(ImmutableList.of( + new StorageAccount() + .withName(new URL(storageAccount.endPoints().primary().blob()).getHost()) + .withKey(storageAccountKey) + .withContainer(containerName) + .withIsDefault(true) + )) + )) + .create(); +``` + + ## Troubleshooting ## Next steps diff --git a/sdk/hdinsight/azure-resourcemanager-hdinsight/pom.xml b/sdk/hdinsight/azure-resourcemanager-hdinsight/pom.xml index 510e7f086c78e..a60f214634cbe 100644 --- a/sdk/hdinsight/azure-resourcemanager-hdinsight/pom.xml +++ b/sdk/hdinsight/azure-resourcemanager-hdinsight/pom.xml @@ -61,7 +61,7 @@ com.azure azure-core-test 1.6.2 - test + test com.azure.resourcemanager @@ -82,7 +82,6 @@ test - diff --git a/sdk/hdinsight/azure-resourcemanager-hdinsight/src/test/java/com/azure/resourcemanager/hdinsight/HdInsightTests.java b/sdk/hdinsight/azure-resourcemanager-hdinsight/src/test/java/com/azure/resourcemanager/hdinsight/HDInsightTests.java similarity index 95% rename from sdk/hdinsight/azure-resourcemanager-hdinsight/src/test/java/com/azure/resourcemanager/hdinsight/HdInsightTests.java rename to sdk/hdinsight/azure-resourcemanager-hdinsight/src/test/java/com/azure/resourcemanager/hdinsight/HDInsightTests.java index 13b4078e2ea14..45c83fc82e949 100644 --- a/sdk/hdinsight/azure-resourcemanager-hdinsight/src/test/java/com/azure/resourcemanager/hdinsight/HdInsightTests.java +++ b/sdk/hdinsight/azure-resourcemanager-hdinsight/src/test/java/com/azure/resourcemanager/hdinsight/HDInsightTests.java @@ -33,15 +33,17 @@ import com.google.common.collect.ImmutableMap; import org.junit.jupiter.api.Test; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Random; -public class HdInsightTests extends TestBase { +public class HDInsightTests extends TestBase { private static final Region REGION = Region.US_EAST2; @Test @DoNotRecord(skipInPlayback = true) - public void clusterTest() { + public void clusterTest() throws MalformedURLException { StorageManager storageManager = StorageManager .authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); @@ -60,6 +62,7 @@ public void clusterTest() { .create(); try { + // @embedmeStart // network Network network = networkManager.networks().define("vn1") .withRegion(REGION) @@ -139,13 +142,14 @@ public void clusterTest() { .withStorageProfile(new StorageProfile() .withStorageaccounts(ImmutableList.of( new StorageAccount() - .withName(storageAccountName + ".blob.core.windows.net") + .withName(new URL(storageAccount.endPoints().primary().blob()).getHost()) .withKey(storageAccountKey) .withContainer(containerName) .withIsDefault(true) )) )) .create(); + // @embedmeEnd } finally { storageManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroupName); }