Skip to content

Commit bc7da01

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 39ba223 commit bc7da01

File tree

4 files changed

+1667
-1426
lines changed

4 files changed

+1667
-1426
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extensions:
2424

2525
To run this sample:
2626

27-
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).
27+
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).
2828

2929
git clone https://github.com/Azure-Samples/compute-java-manage-vmss-in-availability-zones.git
3030

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

3535
## More information ##
3636

37-
[http://azure.com/java](http://azure.com/java)
37+
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).
3838

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

4143
---
4244

pom.xml

Lines changed: 15 additions & 19 deletions
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.ManageZonalVirtualMachineScaleSet</mainClass>
18+
<mainClass>com.azure.resourcemanager.compute.samples.ManageZonalVirtualMachineScaleSet</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.ManageZonalVirtualMachineScaleSet.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.compute.samples.ManageZonalVirtualMachineScaleSet.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>
Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
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.management.AzureEnvironment;
9+
import com.azure.identity.DefaultAzureCredentialBuilder;
10+
import com.azure.resourcemanager.AzureResourceManager;
11+
import com.azure.resourcemanager.compute.models.KnownLinuxVirtualMachineImage;
12+
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSet;
13+
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetSkuTypes;
14+
import com.azure.resourcemanager.network.models.LoadBalancer;
15+
import com.azure.resourcemanager.network.models.LoadBalancerSkuType;
16+
import com.azure.resourcemanager.network.models.Network;
17+
import com.azure.resourcemanager.network.models.PublicIpAddress;
18+
import com.azure.resourcemanager.network.models.PublicIPSkuType;
19+
import com.azure.resourcemanager.network.models.TransportProtocol;
20+
import com.azure.resourcemanager.resources.models.ResourceGroup;
21+
import com.azure.resourcemanager.resources.fluentcore.arm.AvailabilityZoneId;
22+
import com.azure.core.management.Region;
23+
import com.azure.core.management.profile.AzureProfile;
24+
import com.azure.resourcemanager.samples.Utils;
625

7-
package com.microsoft.azure.management.compute.samples;
8-
9-
import com.microsoft.azure.management.Azure;
10-
import com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage;
11-
import com.microsoft.azure.management.compute.VirtualMachineScaleSet;
12-
import com.microsoft.azure.management.compute.VirtualMachineScaleSetSkuTypes;
13-
import com.microsoft.azure.management.network.LoadBalancer;
14-
import com.microsoft.azure.management.network.LoadBalancerSkuType;
15-
import com.microsoft.azure.management.network.Network;
16-
import com.microsoft.azure.management.network.PublicIPAddress;
17-
import com.microsoft.azure.management.network.PublicIPSkuType;
18-
import com.microsoft.azure.management.network.TransportProtocol;
19-
import com.microsoft.azure.management.resources.ResourceGroup;
20-
import com.microsoft.azure.management.resources.fluentcore.arm.AvailabilityZoneId;
21-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
22-
import com.microsoft.azure.management.samples.Utils;
23-
import com.microsoft.rest.LogLevel;
24-
25-
import java.io.File;
2626
import java.util.ArrayList;
2727
import java.util.List;
2828

@@ -37,28 +37,27 @@
3737
public final class ManageZonalVirtualMachineScaleSet {
3838
/**
3939
* Main function which runs the actual sample.
40-
* @param azure instance of the azure client
40+
* @param azureResourceManager instance of the azure client
4141
* @return true if sample runs successfully
4242
*/
43-
public static boolean runSample(Azure azure) {
43+
public static boolean runSample(AzureResourceManager azureResourceManager) {
4444
final Region region = Region.US_EAST2;
45-
final String rgName = Utils.createRandomName("rgCOMV");
46-
final String loadBalancerName = Utils.createRandomName("extlb");
45+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgCOMV", 15);
46+
final String loadBalancerName = Utils.randomResourceName(azureResourceManager, "extlb", 15);
4747
final String publicIPName = "pip-" + loadBalancerName;
4848
final String frontendName = loadBalancerName + "-FE1";
4949
final String backendPoolName1 = loadBalancerName + "-BAP1";
5050
final String backendPoolName2 = loadBalancerName + "-BAP2";
5151
final String natPoolName1 = loadBalancerName + "-INP1";
5252
final String natPoolName2 = loadBalancerName + "-INP2";
53-
final String vmssName1 = Utils.createRandomName("vmss1");
54-
final String vmssName2 = Utils.createRandomName("vmss2");
53+
final String vmssName1 = Utils.randomResourceName(azureResourceManager, "vmss1", 15);
54+
final String vmssName2 = Utils.randomResourceName(azureResourceManager, "vmss2", 15);
5555

5656
final String userName = "tirekicker";
57-
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
58-
final String password = "12NewPA23w0rd!";
57+
final String password = Utils.password();
5958

6059
try {
61-
ResourceGroup resourceGroup = azure.resourceGroups()
60+
ResourceGroup resourceGroup = azureResourceManager.resourceGroups()
6261
.define(rgName)
6362
.withRegion(region)
6463
.create();
@@ -68,7 +67,7 @@ public static boolean runSample(Azure azure) {
6867

6968
System.out.println("Creating a zone resilient public ip address");
7069

71-
PublicIPAddress publicIPAddress = azure.publicIPAddresses()
70+
PublicIpAddress publicIPAddress = azureResourceManager.publicIpAddresses()
7271
.define(publicIPName)
7372
.withRegion(region)
7473
.withExistingResourceGroup(resourceGroup)
@@ -87,7 +86,7 @@ public static boolean runSample(Azure azure) {
8786

8887
System.out.println("Creating a zone resilient load balancer");
8988

90-
LoadBalancer loadBalancer = azure.loadBalancers()
89+
LoadBalancer loadBalancer = azureResourceManager.loadBalancers()
9190
.define(loadBalancerName)
9291
.withRegion(region)
9392
.withExistingResourceGroup(resourceGroup)
@@ -122,7 +121,7 @@ public static boolean runSample(Azure azure) {
122121
.attach()
123122
// Explicitly define the frontend
124123
.definePublicFrontend(frontendName)
125-
.withExistingPublicIPAddress(publicIPAddress) // Frontend with PIP means internet-facing load-balancer
124+
.withExistingPublicIpAddress(publicIPAddress) // Frontend with PIP means internet-facing load-balancer
126125
.attach()
127126
// Add two probes one per rule
128127
.defineHttpProbe("httpProbe")
@@ -148,7 +147,7 @@ public static boolean runSample(Azure azure) {
148147

149148
System.out.println("Creating network for virtual machine scale sets");
150149

151-
Network network = azure
150+
Network network = azureResourceManager
152151
.networks()
153152
.define("vmssvnet")
154153
.withRegion(region)
@@ -167,7 +166,7 @@ public static boolean runSample(Azure azure) {
167166

168167
// HTTP goes to this virtual machine scale set
169168
//
170-
VirtualMachineScaleSet virtualMachineScaleSet1 = azure.virtualMachineScaleSets()
169+
VirtualMachineScaleSet virtualMachineScaleSet1 = azureResourceManager.virtualMachineScaleSets()
171170
.define(vmssName1)
172171
.withRegion(region)
173172
.withExistingResourceGroup(resourceGroup)
@@ -183,7 +182,7 @@ public static boolean runSample(Azure azure) {
183182
.withAvailabilityZone(AvailabilityZoneId.ZONE_1)
184183
.create();
185184

186-
System.out.println("Created zone aware virtual machine scale set");
185+
System.out.println("Created zone aware virtual machine scale set: " + virtualMachineScaleSet1.id());
187186

188187
//=============================================================
189188
// Create a zone aware virtual machine scale set
@@ -192,7 +191,7 @@ public static boolean runSample(Azure azure) {
192191

193192
// HTTPS goes to this virtual machine scale set
194193
//
195-
VirtualMachineScaleSet virtualMachineScaleSet2 = azure.virtualMachineScaleSets()
194+
VirtualMachineScaleSet virtualMachineScaleSet2 = azureResourceManager.virtualMachineScaleSets()
196195
.define(vmssName2)
197196
.withRegion(region)
198197
.withExistingResourceGroup(resourceGroup)
@@ -208,26 +207,20 @@ public static boolean runSample(Azure azure) {
208207
.withAvailabilityZone(AvailabilityZoneId.ZONE_1)
209208
.create();
210209

211-
System.out.println("Created zone aware virtual machine scale set");
210+
System.out.println("Created zone aware virtual machine scale set: " + virtualMachineScaleSet2.id());
212211

213212
return true;
214-
} catch (Exception f) {
215-
216-
System.out.println(f.getMessage());
217-
f.printStackTrace();
218-
219213
} finally {
220214
try {
221215
System.out.println("Deleting Resource Group: " + rgName);
222-
azure.resourceGroups().deleteByName(rgName);
216+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
223217
System.out.println("Deleted Resource Group: " + rgName);
224218
} catch (NullPointerException npe) {
225219
System.out.println("Did not create any resources in Azure. No clean up is necessary");
226220
} catch (Exception g) {
227221
g.printStackTrace();
228222
}
229223
}
230-
return false;
231224
}
232225

233226
/**
@@ -240,17 +233,21 @@ public static void main(String[] args) {
240233
//=============================================================
241234
// Authenticate
242235

243-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
236+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
237+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
238+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
239+
.build();
244240

245-
Azure azure = Azure.configure()
246-
.withLogLevel(LogLevel.BODY_AND_HEADERS)
247-
.authenticate(credFile)
248-
.withDefaultSubscription();
241+
AzureResourceManager azureResourceManager = AzureResourceManager
242+
.configure()
243+
.withLogLevel(HttpLogDetailLevel.BASIC)
244+
.authenticate(credential, profile)
245+
.withDefaultSubscription();
249246

250247
// Print selected subscription
251-
System.out.println("Selected subscription: " + azure.subscriptionId());
248+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
252249

253-
runSample(azure);
250+
runSample(azureResourceManager);
254251
} catch (Exception e) {
255252
System.out.println(e.getMessage());
256253
e.printStackTrace();

0 commit comments

Comments
 (0)