|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | +// Code generated by Microsoft (R) AutoRest Code Generator. |
| 4 | + |
| 5 | +package com.azure.resourcemanager.hdinsight; |
| 6 | + |
| 7 | +import com.azure.core.http.policy.HttpLogDetailLevel; |
| 8 | +import com.azure.core.http.policy.HttpLogOptions; |
| 9 | +import com.azure.core.management.AzureEnvironment; |
| 10 | +import com.azure.core.management.Region; |
| 11 | +import com.azure.core.management.profile.AzureProfile; |
| 12 | +import com.azure.core.test.TestBase; |
| 13 | +import com.azure.core.test.annotation.DoNotRecord; |
| 14 | +import com.azure.identity.DefaultAzureCredentialBuilder; |
| 15 | +import com.azure.resourcemanager.hdinsight.models.ClusterCreateProperties; |
| 16 | +import com.azure.resourcemanager.hdinsight.models.ClusterDefinition; |
| 17 | +import com.azure.resourcemanager.hdinsight.models.ComputeProfile; |
| 18 | +import com.azure.resourcemanager.hdinsight.models.HardwareProfile; |
| 19 | +import com.azure.resourcemanager.hdinsight.models.LinuxOperatingSystemProfile; |
| 20 | +import com.azure.resourcemanager.hdinsight.models.OSType; |
| 21 | +import com.azure.resourcemanager.hdinsight.models.OsProfile; |
| 22 | +import com.azure.resourcemanager.hdinsight.models.Role; |
| 23 | +import com.azure.resourcemanager.hdinsight.models.StorageAccount; |
| 24 | +import com.azure.resourcemanager.hdinsight.models.StorageProfile; |
| 25 | +import com.azure.resourcemanager.hdinsight.models.Tier; |
| 26 | +import com.azure.resourcemanager.hdinsight.models.VirtualNetworkProfile; |
| 27 | +import com.azure.resourcemanager.network.NetworkManager; |
| 28 | +import com.azure.resourcemanager.network.models.Network; |
| 29 | +import com.azure.resourcemanager.network.models.Subnet; |
| 30 | +import com.azure.resourcemanager.storage.StorageManager; |
| 31 | +import com.azure.resourcemanager.storage.models.PublicAccess; |
| 32 | +import com.google.common.collect.ImmutableList; |
| 33 | +import com.google.common.collect.ImmutableMap; |
| 34 | +import org.junit.jupiter.api.Test; |
| 35 | + |
| 36 | +import java.util.Random; |
| 37 | + |
| 38 | +public class HdInsightTests extends TestBase { |
| 39 | + |
| 40 | + private static final Region REGION = Region.US_EAST2; |
| 41 | + |
| 42 | + @Test |
| 43 | + @DoNotRecord(skipInPlayback = true) |
| 44 | + public void clusterTest() { |
| 45 | + StorageManager storageManager = StorageManager |
| 46 | + .authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); |
| 47 | + |
| 48 | + NetworkManager networkManager = NetworkManager |
| 49 | + .authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); |
| 50 | + |
| 51 | + HDInsightManager manager = HDInsightManager |
| 52 | + .configure().withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) |
| 53 | + .authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); |
| 54 | + |
| 55 | + String resourceGroupName = "rg" + randomPadding(); |
| 56 | + String storageAccountName = "sa" + randomPadding(); |
| 57 | + |
| 58 | + storageManager.resourceManager().resourceGroups().define(resourceGroupName) |
| 59 | + .withRegion(REGION) |
| 60 | + .create(); |
| 61 | + |
| 62 | + try { |
| 63 | + // network |
| 64 | + Network network = networkManager.networks().define("vn1") |
| 65 | + .withRegion(REGION) |
| 66 | + .withExistingResourceGroup(resourceGroupName) |
| 67 | + .withAddressSpace("10.0.0.0/24") |
| 68 | + .withSubnet("default", "10.0.0.0/24") |
| 69 | + .create(); |
| 70 | + Subnet subnet = network.subnets().values().iterator().next(); |
| 71 | + |
| 72 | + // storage account |
| 73 | + com.azure.resourcemanager.storage.models.StorageAccount storageAccount = storageManager.storageAccounts().define(storageAccountName) |
| 74 | + .withRegion(REGION) |
| 75 | + .withExistingResourceGroup(resourceGroupName) |
| 76 | + .create(); |
| 77 | + final String storageAccountKey = storageAccount.getKeys().iterator().next().value(); |
| 78 | + |
| 79 | + // container |
| 80 | + final String containerName = "hdinsight"; |
| 81 | + storageManager.blobContainers().defineContainer(containerName) |
| 82 | + .withExistingBlobService(resourceGroupName, storageAccountName) |
| 83 | + .withPublicAccess(PublicAccess.NONE) |
| 84 | + .create(); |
| 85 | + |
| 86 | + // cluster |
| 87 | + manager.clusters().define("cluster" + randomPadding()) |
| 88 | + .withExistingResourceGroup(resourceGroupName) |
| 89 | + .withRegion(REGION) |
| 90 | + .withProperties(new ClusterCreateProperties() |
| 91 | + .withClusterVersion("3.6") |
| 92 | + .withOsType(OSType.LINUX) |
| 93 | + .withTier(Tier.STANDARD) |
| 94 | + .withClusterDefinition(new ClusterDefinition() |
| 95 | + .withKind("Spark") |
| 96 | + .withConfigurations(ImmutableMap.of( |
| 97 | + "gateway", ImmutableMap.of( |
| 98 | + "restAuthCredential.isEnabled", "true", |
| 99 | + "restAuthCredential.username", "admin", |
| 100 | + "restAuthCredential.password", "Pa$s" + randomPadding() |
| 101 | + ))) |
| 102 | + ) |
| 103 | + .withComputeProfile(new ComputeProfile() |
| 104 | + .withRoles(ImmutableList.of( |
| 105 | + new Role().withName("headnode") |
| 106 | + .withTargetInstanceCount(2) |
| 107 | + .withHardwareProfile(new HardwareProfile() |
| 108 | + .withVmSize("Large") |
| 109 | + ) |
| 110 | + .withOsProfile(new OsProfile() |
| 111 | + .withLinuxOperatingSystemProfile( |
| 112 | + new LinuxOperatingSystemProfile() |
| 113 | + .withUsername("sshuser") |
| 114 | + .withPassword("Pa$s" + randomPadding()) |
| 115 | + ) |
| 116 | + ) |
| 117 | + .withVirtualNetworkProfile(new VirtualNetworkProfile() |
| 118 | + .withId(network.id()) |
| 119 | + .withSubnet(subnet.id()) |
| 120 | + ), |
| 121 | + new Role().withName("workernode") |
| 122 | + .withTargetInstanceCount(3) |
| 123 | + .withHardwareProfile(new HardwareProfile() |
| 124 | + .withVmSize("Large") |
| 125 | + ) |
| 126 | + .withOsProfile(new OsProfile() |
| 127 | + .withLinuxOperatingSystemProfile( |
| 128 | + new LinuxOperatingSystemProfile() |
| 129 | + .withUsername("sshuser") |
| 130 | + .withPassword("Pa$s" + randomPadding()) |
| 131 | + ) |
| 132 | + ) |
| 133 | + .withVirtualNetworkProfile(new VirtualNetworkProfile() |
| 134 | + .withId(network.id()) |
| 135 | + .withSubnet(subnet.id()) |
| 136 | + ) |
| 137 | + )) |
| 138 | + ) |
| 139 | + .withStorageProfile(new StorageProfile() |
| 140 | + .withStorageaccounts(ImmutableList.of( |
| 141 | + new StorageAccount() |
| 142 | + .withName(storageAccountName + ".blob.core.windows.net") |
| 143 | + .withKey(storageAccountKey) |
| 144 | + .withContainer(containerName) |
| 145 | + .withIsDefault(true) |
| 146 | + )) |
| 147 | + )) |
| 148 | + .create(); |
| 149 | + } finally { |
| 150 | + storageManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroupName); |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + private static final Random RANDOM = new Random(); |
| 155 | + |
| 156 | + private static String randomPadding() { |
| 157 | + return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000)); |
| 158 | + } |
| 159 | +} |
0 commit comments