Skip to content

Commit 87463da

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 0357813 commit 87463da

File tree

4 files changed

+1656
-1413
lines changed

4 files changed

+1656
-1413
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/aad-java-manage-resources-from-vm-with-msi.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.ManageStorageFromMSIEnabledVirtualMachine</mainClass>
18+
<mainClass>com.azure.resourcemanager.compute.samples.ManageStorageFromMSIEnabledVirtualMachine</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.ManageStorageFromMSIEnabledVirtualMachine.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.compute.samples.ManageStorageFromMSIEnabledVirtualMachine.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: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
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.CachingTypes;
11-
import com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage;
12-
import com.microsoft.azure.management.compute.VirtualMachine;
13-
import com.microsoft.azure.management.compute.VirtualMachineSizeTypes;
14-
import com.microsoft.azure.management.graphrbac.BuiltInRole;
15-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
16-
import com.microsoft.azure.management.samples.Utils;
17-
import com.microsoft.azure.management.storage.StorageAccount;
18-
import com.microsoft.rest.LogLevel;
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.CachingTypes;
12+
import com.azure.resourcemanager.compute.models.KnownLinuxVirtualMachineImage;
13+
import com.azure.resourcemanager.compute.models.VirtualMachine;
14+
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
15+
import com.azure.resourcemanager.authorization.models.BuiltInRole;
16+
import com.azure.core.management.Region;
17+
import com.azure.core.management.profile.AzureProfile;
18+
import com.azure.resourcemanager.samples.Utils;
19+
import com.azure.resourcemanager.storage.models.StorageAccount;
1920

20-
import java.io.File;
2121
import java.util.ArrayList;
2222
import java.util.List;
2323

@@ -33,16 +33,15 @@ public final class ManageStorageFromMSIEnabledVirtualMachine {
3333
/**
3434
* Main function which runs the actual sample.
3535
*
36-
* @param azure instance of the azure client
36+
* @param azureResourceManager instance of the azure client
3737
* @return true if sample runs successfully
3838
*/
39-
public static boolean runSample(Azure azure) {
40-
final String linuxVMName = Utils.createRandomName("VM1");
41-
final String rgName = Utils.createRandomName("rgCOMV");
42-
final String pipName = Utils.createRandomName("pip1");
39+
public static boolean runSample(AzureResourceManager azureResourceManager) {
40+
final String linuxVMName = Utils.randomResourceName(azureResourceManager, "VM1", 15);
41+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgCOMV", 15);
42+
final String pipName = Utils.randomResourceName(azureResourceManager, "pip1", 15);
4343
final String userName = "tirekicker";
44-
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
45-
final String password = "12NewPA$$w0rd!";
44+
final String password = Utils.password();
4645
final Region region = Region.US_WEST_CENTRAL;
4746

4847
final String installScript = "https://raw.githubusercontent.com/Azure/azure-libraries-for-java/master/azure-samples/src/main/resources/create_resources_with_msi.sh";
@@ -56,7 +55,7 @@ public static boolean runSample(Azure azure) {
5655

5756
System.out.println("Creating a Linux VM with MSI enabled");
5857

59-
VirtualMachine virtualMachine = azure.virtualMachines()
58+
VirtualMachine virtualMachine = azureResourceManager.virtualMachines()
6059
.define(linuxVMName)
6160
.withRegion(region)
6261
.withNewResourceGroup(rgName)
@@ -77,7 +76,7 @@ public static boolean runSample(Azure azure) {
7776

7877
// Prepare custom script t install az cli that uses MSI to create a storage account
7978
//
80-
final String stgName = Utils.createRandomName("st44");
79+
final String stgName = Utils.randomResourceName(azureResourceManager, "st44", 15);
8180
installCommand = installCommand.replace("{stgName}", stgName)
8281
.replace("{rgName}", rgName)
8382
.replace("{location}", region.name());
@@ -101,26 +100,22 @@ public static boolean runSample(Azure azure) {
101100

102101
// Retrieve the storage account created by az cli using MSI credentials
103102
//
104-
StorageAccount storageAccount = azure.storageAccounts()
103+
StorageAccount storageAccount = azureResourceManager.storageAccounts()
105104
.getByResourceGroup(rgName, stgName);
106105

107106
System.out.println("Storage account created by az cli using MSI credential");
108107
Utils.print(storageAccount);
109108
return true;
110-
} catch (Exception f) {
111-
System.out.println(f.getMessage());
112-
f.printStackTrace();
113109
} finally {
114110
try {
115111
System.out.println("Deleting Resource Group: " + rgName);
116-
azure.resourceGroups().beginDeleteByName(rgName);
112+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
117113
} catch (NullPointerException npe) {
118114
System.out.println("Did not create any resources in Azure. No clean up is necessary");
119115
} catch (Exception g) {
120116
g.printStackTrace();
121117
}
122118
}
123-
return false;
124119
}
125120

126121
/**
@@ -132,17 +127,21 @@ public static void main(String[] args) {
132127
//=============================================================
133128
// Authenticate
134129

135-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
130+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
131+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
132+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
133+
.build();
136134

137-
Azure azure = Azure.configure()
138-
.withLogLevel(LogLevel.BODY_AND_HEADERS)
139-
.authenticate(credFile)
140-
.withDefaultSubscription();
135+
AzureResourceManager azureResourceManager = AzureResourceManager
136+
.configure()
137+
.withLogLevel(HttpLogDetailLevel.BASIC)
138+
.authenticate(credential, profile)
139+
.withDefaultSubscription();
141140

142141
// Print selected subscription
143-
System.out.println("Selected subscription: " + azure.subscriptionId());
142+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
144143

145-
runSample(azure);
144+
runSample(azureResourceManager);
146145
} catch (Exception e) {
147146
System.out.println(e.getMessage());
148147
e.printStackTrace();
@@ -151,4 +150,4 @@ public static void main(String[] args) {
151150

152151
private ManageStorageFromMSIEnabledVirtualMachine() {
153152
}
154-
}
153+
}

0 commit comments

Comments
 (0)