Skip to content

Commit d5792a6

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 95a420d commit d5792a6

File tree

4 files changed

+1671
-1431
lines changed

4 files changed

+1671
-1431
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extensions:
2828

2929
To run this sample:
3030

31-
Set the environment variable `AZURE_AUTH_LOCATION` with the full path for an auth file. See [how to create an auth file](https://github.com/Azure/azure-libraries-for-java/blob/master/AUTH.md).
31+
See [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/identity/azure-identity#defaultazurecredential) and prepare the authentication works best for you. For more details on authentication, please refer to [AUTH.md](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md).
3232

3333
git clone https://github.com/Azure-Samples/compute-java-manage-virtual-machine-scale-set-with-unmanaged-disks.git
3434

@@ -38,9 +38,11 @@ Set the environment variable `AZURE_AUTH_LOCATION` with the full path for an aut
3838

3939
## More information ##
4040

41-
[http://azure.com/java](http://azure.com/java)
41+
For general documentation as well as quickstarts on how to use Azure Management Libraries for Java, please see [here](https://aka.ms/azsdk/java/mgmt).
4242

43-
If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212)
43+
Start to develop applications with Java on Azure [here](http://azure.com/java).
44+
45+
If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212).
4446

4547
---
4648

pom.xml

+15-19
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
<artifactId>exec-maven-plugin</artifactId>
1616
<version>1.4.0</version>
1717
<configuration>
18-
<mainClass>com.microsoft.azure.management.compute.samples.ManageVirtualMachineScaleSetWithUnmanagedDisks</mainClass>
18+
<mainClass>com.azure.resourcemanager.compute.samples.ManageVirtualMachineScaleSetWithUnmanagedDisks</mainClass>
19+
<cleanupDaemonThreads>false</cleanupDaemonThreads>
1920
</configuration>
2021
</plugin>
2122
<plugin>
2223
<artifactId>maven-compiler-plugin</artifactId>
23-
<version>3.0</version>
24+
<version>3.8.1</version>
2425
<configuration>
25-
<source>1.7</source>
26-
<target>1.7</target>
26+
<source>1.8</source>
27+
<target>1.8</target>
2728
</configuration>
2829
</plugin>
2930
<plugin>
@@ -40,7 +41,7 @@
4041
</descriptorRefs>
4142
<archive>
4243
<manifest>
43-
<mainClass>com.microsoft.azure.management.compute.samples.ManageVirtualMachineScaleSetWithUnmanagedDisks.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.compute.samples.ManageVirtualMachineScaleSetWithUnmanagedDisks.java</mainClass>
4445
</manifest>
4546
</archive>
4647
</configuration>
@@ -51,24 +52,19 @@
5152
</build>
5253
<dependencies>
5354
<dependency>
54-
<groupId>com.microsoft.azure</groupId>
55-
<artifactId>azure</artifactId>
56-
<version>1.36.3</version>
55+
<groupId>com.azure.resourcemanager</groupId>
56+
<artifactId>azure-resourcemanager</artifactId>
57+
<version>2.0.0</version>
5758
</dependency>
5859
<dependency>
59-
<groupId>commons-net</groupId>
60-
<artifactId>commons-net</artifactId>
61-
<version>3.3</version>
62-
</dependency>
63-
<dependency>
64-
<groupId>commons-lang</groupId>
65-
<artifactId>commons-lang</artifactId>
66-
<version>2.6</version>
60+
<groupId>com.azure</groupId>
61+
<artifactId>azure-identity</artifactId>
62+
<version>1.1.3</version>
6763
</dependency>
6864
<dependency>
69-
<groupId>org.apache.commons</groupId>
70-
<artifactId>commons-lang3</artifactId>
71-
<version>3.7</version>
65+
<groupId>commons-net</groupId>
66+
<artifactId>commons-net</artifactId>
67+
<version>3.6</version>
7268
</dependency>
7369
</dependencies>
7470
</project>
+56-60
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
/**
2-
* Copyright (c) Microsoft Corporation. All rights reserved.
3-
* Licensed under the MIT License. See License.txt in the project root for
4-
* license information.
5-
*/
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.compute.samples;
5+
6+
import com.azure.core.credential.TokenCredential;
7+
import com.azure.core.http.policy.HttpLogDetailLevel;
8+
import com.azure.core.http.rest.PagedIterable;
9+
import com.azure.core.management.AzureEnvironment;
10+
import com.azure.identity.DefaultAzureCredentialBuilder;
11+
import com.azure.resourcemanager.AzureResourceManager;
12+
import com.azure.resourcemanager.compute.models.ImageReference;
13+
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVM;
14+
import com.azure.resourcemanager.network.models.LoadBalancerInboundNatRule;
15+
import com.azure.resourcemanager.network.models.Network;
16+
import com.azure.resourcemanager.network.models.PublicIpAddress;
17+
import com.azure.resourcemanager.network.models.LoadBalancer;
18+
import com.azure.resourcemanager.network.models.TransportProtocol;
19+
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSet;
20+
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetSkuTypes;
21+
import com.azure.resourcemanager.network.models.VirtualMachineScaleSetNetworkInterface;
22+
import com.azure.resourcemanager.network.models.VirtualMachineScaleSetNicIpConfiguration;
23+
import com.azure.core.management.Region;
24+
import com.azure.core.management.profile.AzureProfile;
25+
import com.azure.resourcemanager.samples.Utils;
626

7-
package com.microsoft.azure.management.compute.samples;
8-
9-
import com.microsoft.azure.PagedList;
10-
import com.microsoft.azure.management.Azure;
11-
import com.microsoft.azure.management.compute.ImageReference;
12-
import com.microsoft.azure.management.compute.VirtualMachineScaleSetVM;
13-
import com.microsoft.azure.management.network.LoadBalancerInboundNatRule;
14-
import com.microsoft.azure.management.network.Network;
15-
import com.microsoft.azure.management.network.PublicIPAddress;
16-
import com.microsoft.azure.management.network.LoadBalancer;
17-
import com.microsoft.azure.management.network.TransportProtocol;
18-
import com.microsoft.azure.management.compute.VirtualMachineScaleSet;
19-
import com.microsoft.azure.management.compute.VirtualMachineScaleSetSkuTypes;
20-
import com.microsoft.azure.management.network.VirtualMachineScaleSetNetworkInterface;
21-
import com.microsoft.azure.management.network.VirtualMachineScaleSetNicIPConfiguration;
22-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
23-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
24-
import com.microsoft.azure.management.samples.Utils;
25-
import com.microsoft.rest.LogLevel;
26-
27-
import java.io.File;
2827
import java.util.ArrayList;
2928
import java.util.Date;
3029
import java.util.List;
@@ -45,14 +44,14 @@ public final class ManageVirtualMachineScaleSetWithUnmanagedDisks {
4544

4645
/**
4746
* Main function which runs the actual sample.
48-
* @param azure instance of the azure client
47+
* @param azureResourceManager instance of the azure client
4948
* @return true if sample runs successfully
5049
*/
51-
public static boolean runSample(Azure azure) {
50+
public static boolean runSample(AzureResourceManager azureResourceManager) {
5251
final Region region = Region.US_EAST2;
53-
final String rgName = SdkContext.randomResourceName("rgCOVS", 15);
54-
final String vnetName = SdkContext.randomResourceName("vnet", 24);
55-
final String loadBalancerName1 = SdkContext.randomResourceName("intlb" + "-", 18);
52+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgCOVS", 15);
53+
final String vnetName = Utils.randomResourceName(azureResourceManager, "vnet", 24);
54+
final String loadBalancerName1 = Utils.randomResourceName(azureResourceManager, "intlb" + "-", 18);
5655
final String publicIpName = "pip-" + loadBalancerName1;
5756
final String frontendName = loadBalancerName1 + "-FE1";
5857
final String backendPoolName1 = loadBalancerName1 + "-BAP1";
@@ -65,10 +64,10 @@ public static boolean runSample(Azure azure) {
6564
final String natPool50XXto22 = "natPool50XXto22";
6665
final String natPool60XXto23 = "natPool60XXto23";
6766

68-
final String vmssName = SdkContext.randomResourceName("vmss", 24);
69-
final String storageAccountName1 = SdkContext.randomResourceName("stg1", 24);
70-
final String storageAccountName2 = SdkContext.randomResourceName("stg2", 24);
71-
final String storageAccountName3 = SdkContext.randomResourceName("stg3", 24);
67+
final String vmssName = Utils.randomResourceName(azureResourceManager, "vmss", 24);
68+
final String storageAccountName1 = Utils.randomResourceName(azureResourceManager, "stg1", 24);
69+
final String storageAccountName2 = Utils.randomResourceName(azureResourceManager, "stg2", 24);
70+
final String storageAccountName3 = Utils.randomResourceName(azureResourceManager, "stg3", 24);
7271

7372
final String userName = "tirekicker";
7473
final String sshKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCfSPC2K7LZcFKEO+/t3dzmQYtrJFZNxOsbVgOVKietqHyvmYGHEC0J2wPdAqQ/63g/hhAEFRoyehM+rbeDri4txB3YFfnOK58jqdkyXzupWqXzOrlKY4Wz9SKjjN765+dqUITjKRIaAip1Ri137szRg71WnrmdP3SphTRlCx1Bk2nXqWPsclbRDCiZeF8QOTi4JqbmJyK5+0UqhqYRduun8ylAwKKQJ1NJt85sYIHn9f1Rfr6Tq2zS0wZ7DHbZL+zB5rSlAr8QyUdg/GQD+cmSs6LvPJKL78d6hMGk84ARtFo4A79ovwX/Fj01znDQkU6nJildfkaolH2rWFG/qttD [email protected]";
@@ -82,7 +81,7 @@ public static boolean runSample(Azure azure) {
8281
// Create a virtual network with a frontend subnet
8382
System.out.println("Creating virtual network with a frontend subnet ...");
8483

85-
Network network = azure.networks().define(vnetName)
84+
Network network = azureResourceManager.networks().define(vnetName)
8685
.withRegion(region)
8786
.withNewResourceGroup(rgName)
8887
.withAddressSpace("172.16.0.0/16")
@@ -99,7 +98,7 @@ public static boolean runSample(Azure azure) {
9998
// Create a public IP address
10099
System.out.println("Creating a public IP address...");
101100

102-
PublicIPAddress publicIPAddress = azure.publicIPAddresses().define(publicIpName)
101+
PublicIpAddress publicIPAddress = azureResourceManager.publicIpAddresses().define(publicIpName)
103102
.withRegion(region)
104103
.withExistingResourceGroup(rgName)
105104
.withLeafDomainLabel(publicIpName)
@@ -134,7 +133,7 @@ public static boolean runSample(Azure azure) {
134133
+ " balancer to a port for a specific virtual machine in the backend address pool\n"
135134
+ " - this provides direct VM connectivity for SSH to port 22 and TELNET to port 23");
136135

137-
LoadBalancer loadBalancer1 = azure.loadBalancers().define(loadBalancerName1)
136+
LoadBalancer loadBalancer1 = azureResourceManager.loadBalancers().define(loadBalancerName1)
138137
.withRegion(region)
139138
.withExistingResourceGroup(rgName)
140139

@@ -171,7 +170,7 @@ public static boolean runSample(Azure azure) {
171170

172171
// Explicitly define the frontend
173172
.definePublicFrontend(frontendName)
174-
.withExistingPublicIPAddress(publicIPAddress)
173+
.withExistingPublicIpAddress(publicIPAddress)
175174
.attach()
176175

177176
// Add two probes one per rule
@@ -206,7 +205,7 @@ public static boolean runSample(Azure azure) {
206205
.withSku("18.04-LTS")
207206
.withVersion("latest");
208207

209-
VirtualMachineScaleSet virtualMachineScaleSet = azure.virtualMachineScaleSets().define(vmssName)
208+
VirtualMachineScaleSet virtualMachineScaleSet = azureResourceManager.virtualMachineScaleSets().define(vmssName)
210209
.withRegion(region)
211210
.withExistingResourceGroup(rgName)
212211
.withSku(VirtualMachineScaleSetSkuTypes.STANDARD_D3_V2)
@@ -241,13 +240,13 @@ public static boolean runSample(Azure azure) {
241240
System.out.println();
242241

243242
// Print virtual machine scale set details
244-
// Utils.print(virtualMachineScaleSet);
243+
// ResourceManagerUtils.print(virtualMachineScaleSet);
245244

246245
//=============================================================
247246
// List virtual machine scale set network interfaces
248247

249248
System.out.println("Listing scale set network interfaces ...");
250-
PagedList<VirtualMachineScaleSetNetworkInterface> vmssNics = virtualMachineScaleSet.listNetworkInterfaces();
249+
PagedIterable<VirtualMachineScaleSetNetworkInterface> vmssNics = virtualMachineScaleSet.listNetworkInterfaces();
251250
for (VirtualMachineScaleSetNetworkInterface vmssNic : vmssNics) {
252251
System.out.println(vmssNic.id());
253252
}
@@ -259,10 +258,10 @@ public static boolean runSample(Azure azure) {
259258
for (VirtualMachineScaleSetVM instance : virtualMachineScaleSet.virtualMachines().list()) {
260259
System.out.println("Scale set virtual machine instance #" + instance.instanceId());
261260
System.out.println(instance.id());
262-
PagedList<VirtualMachineScaleSetNetworkInterface> networkInterfaces = instance.listNetworkInterfaces();
261+
PagedIterable<VirtualMachineScaleSetNetworkInterface> networkInterfaces = instance.listNetworkInterfaces();
263262
// Pick the first NIC
264-
VirtualMachineScaleSetNetworkInterface networkInterface = networkInterfaces.get(0);
265-
for (VirtualMachineScaleSetNicIPConfiguration ipConfig :networkInterface.ipConfigurations().values()) {
263+
VirtualMachineScaleSetNetworkInterface networkInterface = networkInterfaces.iterator().next();
264+
for (VirtualMachineScaleSetNicIpConfiguration ipConfig :networkInterface.ipConfigurations().values()) {
266265
if (ipConfig.isPrimary()) {
267266
List<LoadBalancerInboundNatRule> natRules = ipConfig.listAssociatedLoadBalancerInboundNatRules();
268267
for (LoadBalancerInboundNatRule natRule : natRules) {
@@ -315,23 +314,17 @@ public static boolean runSample(Azure azure) {
315314
System.out.println("re-started virtual machine scale set");
316315

317316
return true;
318-
} catch (Exception f) {
319-
320-
System.out.println(f.getMessage());
321-
f.printStackTrace();
322-
323317
} finally {
324318
try {
325319
System.out.println("Deleting Resource Group: " + rgName);
326-
azure.resourceGroups().deleteByName(rgName);
320+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
327321
System.out.println("Deleted Resource Group: " + rgName);
328322
} catch (NullPointerException npe) {
329323
System.out.println("Did not create any resources in Azure. No clean up is necessary");
330324
} catch (Exception g) {
331325
g.printStackTrace();
332326
}
333327
}
334-
return false;
335328
}
336329

337330
/**
@@ -345,18 +338,21 @@ public static void main(String[] args) {
345338
//=============================================================
346339
// Authenticate
347340

348-
System.out.println(System.getenv("AZURE_AUTH_LOCATION"));
349-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
341+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
342+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
343+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
344+
.build();
350345

351-
Azure azure = Azure.configure()
352-
.withLogLevel(LogLevel.BASIC)
353-
.authenticate(credFile)
354-
.withDefaultSubscription();
346+
AzureResourceManager azureResourceManager = AzureResourceManager
347+
.configure()
348+
.withLogLevel(HttpLogDetailLevel.BASIC)
349+
.authenticate(credential, profile)
350+
.withDefaultSubscription();
355351

356352
// Print selected subscription
357-
System.out.println("Selected subscription: " + azure.subscriptionId());
353+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
358354

359-
runSample(azure);
355+
runSample(azureResourceManager);
360356

361357
} catch (Exception e) {
362358
System.out.println(e.getMessage());

0 commit comments

Comments
 (0)