Skip to content

Commit b249a5e

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 29ed8f2 commit b249a5e

File tree

4 files changed

+1650
-1408
lines changed

4 files changed

+1650
-1408
lines changed

README.md

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

2323
To run this sample:
2424

25-
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).
25+
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).
2626

2727
git clone https://github.com/Azure-Samples/managed-disk-java-convert-existing-virtual-machines-to-use-managed-disks.git
2828

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

3333
## More information ##
3434

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

37-
If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212)
37+
Start to develop applications with Java on Azure [here](http://azure.com/java).
38+
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).
3840

3941
---
4042

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.ConvertVirtualMachineToManagedDisks</mainClass>
18+
<mainClass>com.azure.resourcemanager.compute.samples.ConvertVirtualMachineToManagedDisks</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.ConvertVirtualMachineToManagedDisks.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.compute.samples.ConvertVirtualMachineToManagedDisks.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: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
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-
*/
6-
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.VirtualMachine;
12-
import com.microsoft.azure.management.compute.VirtualMachineSizeTypes;
13-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
14-
import com.microsoft.azure.management.samples.Utils;
15-
import com.microsoft.rest.LogLevel;
16-
import java.io.File;
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.VirtualMachine;
13+
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
14+
import com.azure.core.management.Region;
15+
import com.azure.core.management.profile.AzureProfile;
16+
import com.azure.resourcemanager.samples.Utils;
1717

1818
/**
1919
* Azure Compute sample for managing virtual machines -
@@ -26,24 +26,23 @@ public final class ConvertVirtualMachineToManagedDisks {
2626
/**
2727
* Main function which runs the actual sample.
2828
*
29-
* @param azure instance of the azure client
29+
* @param azureResourceManager instance of the azure client
3030
* @return true if sample runs successfully
3131
*/
32-
public static boolean runSample(Azure azure) {
33-
final String linuxVMName = Utils.createRandomName("VM1");
34-
final String rgName = Utils.createRandomName("rgCOMV");
32+
public static boolean runSample(AzureResourceManager azureResourceManager) {
33+
final String linuxVMName = Utils.randomResourceName(azureResourceManager, "VM1", 15);
34+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgCOMV", 15);
3535
final String userName = "tirekicker";
36-
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
37-
final String password = "12NewPA$$w0rd!";
38-
final Region region = Region.US_WEST_CENTRAL;
36+
final String password = Utils.password();
37+
final Region region = Region.US_WEST;
3938

4039
try {
4140
//=============================================================
4241
// Create a Linux VM using a PIR image with un-managed OS and data disks
4342

4443
System.out.println("Creating an un-managed Linux VM");
4544

46-
VirtualMachine linuxVM = azure.virtualMachines().define(linuxVMName)
45+
VirtualMachine linuxVM = azureResourceManager.virtualMachines().define(linuxVMName)
4746
.withRegion(region)
4847
.withNewResourceGroup(rgName)
4948
.withNewPrimaryNetwork("10.0.0.0/28")
@@ -86,22 +85,17 @@ public static boolean runSample(Azure azure) {
8685
Utils.print(linuxVM);
8786

8887
return true;
89-
} catch (Exception f) {
90-
System.out.println(f.getMessage());
91-
f.printStackTrace();
9288
} finally {
9389
try {
9490
System.out.println("Deleting Resource Group: " + rgName);
95-
azure.resourceGroups().deleteByName(rgName);
91+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
9692
System.out.println("Deleted Resource Group: " + rgName);
9793
} catch (NullPointerException npe) {
9894
System.out.println("Did not create any resources in Azure. No clean up is necessary");
9995
} catch (Exception g) {
10096
g.printStackTrace();
10197
}
10298
}
103-
104-
return false;
10599
}
106100

107101
/**
@@ -113,17 +107,21 @@ public static void main(String[] args) {
113107
//=============================================================
114108
// Authenticate
115109

116-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
110+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
111+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
112+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
113+
.build();
117114

118-
Azure azure = Azure.configure()
119-
.withLogLevel(LogLevel.BODY)
120-
.authenticate(credFile)
121-
.withDefaultSubscription();
115+
AzureResourceManager azureResourceManager = AzureResourceManager
116+
.configure()
117+
.withLogLevel(HttpLogDetailLevel.BASIC)
118+
.authenticate(credential, profile)
119+
.withDefaultSubscription();
122120

123121
// Print selected subscription
124-
System.out.println("Selected subscription: " + azure.subscriptionId());
122+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
125123

126-
runSample(azure);
124+
runSample(azureResourceManager);
127125
} catch (Exception e) {
128126
System.out.println(e.getMessage());
129127
e.printStackTrace();

0 commit comments

Comments
 (0)