Skip to content

Commit

Permalink
mgmt, hdinsight sample in readme from test (#21675)
Browse files Browse the repository at this point in the history
* add embedme tag

* generate example in readme
  • Loading branch information
weidongxu-microsoft authored May 20, 2021
1 parent 8812296 commit ff6fe4e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 5 deletions.
90 changes: 90 additions & 0 deletions sdk/hdinsight/azure-resourcemanager-hdinsight/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions sdk/hdinsight/azure-resourcemanager-hdinsight/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.6.2</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<scope>test</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
Expand All @@ -82,7 +82,6 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -60,6 +62,7 @@ public void clusterTest() {
.create();

try {
// @embedmeStart
// network
Network network = networkManager.networks().define("vn1")
.withRegion(REGION)
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit ff6fe4e

Please sign in to comment.