Skip to content

Commit 5e6026f

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 4c74e9d commit 5e6026f

File tree

4 files changed

+1649
-1407
lines changed

4 files changed

+1649
-1407
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/resources-java-manage-resource-group.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.resources.samples.ManageResourceGroup</mainClass>
18+
<mainClass>com.azure.resourcemanager.resources.samples.ManageResourceGroup</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.resources.samples.ManageResourceGroup.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.resources.samples.ManageResourceGroup.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>

src/main/java/com/microsoft/azure/management/resources/samples/ManageResourceGroup.java renamed to src/main/java/com/azure/resourcemanager/resources/samples/ManageResourceGroup.java

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
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.resources.samples;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
83

9-
import com.microsoft.azure.management.Azure;
10-
import com.microsoft.azure.management.resources.ResourceGroup;
11-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
12-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
13-
import com.microsoft.rest.LogLevel;
4+
package com.azure.resourcemanager.resources.samples;
145

15-
import java.io.File;
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.resources.models.ResourceGroup;
12+
import com.azure.core.management.Region;
13+
import com.azure.core.management.profile.AzureProfile;
14+
import com.azure.resourcemanager.samples.Utils;
1615

1716
/**
1817
* Azure Resource sample for managing resource groups -
@@ -26,14 +25,15 @@
2625
public final class ManageResourceGroup {
2726
/**
2827
* Main function which runs the actual sample.
29-
* @param azure instance of the azure client
28+
*
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 rgName = SdkContext.randomResourceName("rgRSMA", 24);
34-
final String rgName2 = SdkContext.randomResourceName("rgRSMA", 24);
35-
final String resourceTagName = SdkContext.randomResourceName("rgRSTN", 24);
36-
final String resourceTagValue = SdkContext.randomResourceName("rgRSTV", 24);
32+
public static boolean runSample(AzureResourceManager azureResourceManager) {
33+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgRSMA", 24);
34+
final String rgName2 = Utils.randomResourceName(azureResourceManager, "rgRSMA", 24);
35+
final String resourceTagName = Utils.randomResourceName(azureResourceManager, "rgRSTN", 24);
36+
final String resourceTagValue = Utils.randomResourceName(azureResourceManager, "rgRSTV", 24);
3737
try {
3838

3939

@@ -42,7 +42,7 @@ public static boolean runSample(Azure azure) {
4242

4343
System.out.println("Creating a resource group with name: " + rgName);
4444

45-
ResourceGroup resourceGroup = azure.resourceGroups().define(rgName)
45+
ResourceGroup resourceGroup = azureResourceManager.resourceGroups().define(rgName)
4646
.withRegion(Region.US_WEST)
4747
.create();
4848

@@ -66,7 +66,7 @@ public static boolean runSample(Azure azure) {
6666

6767
System.out.println("Creating another resource group with name: " + rgName2);
6868

69-
azure.resourceGroups().define(rgName2)
69+
azureResourceManager.resourceGroups().define(rgName2)
7070
.withRegion(Region.US_WEST)
7171
.create();
7272

@@ -78,7 +78,7 @@ public static boolean runSample(Azure azure) {
7878

7979
System.out.println("Listing all resource groups");
8080

81-
for (ResourceGroup rGroup : azure.resourceGroups().list()) {
81+
for (ResourceGroup rGroup : azureResourceManager.resourceGroups().list()) {
8282
System.out.println("Resource group: " + rGroup.name());
8383
}
8484

@@ -88,25 +88,19 @@ public static boolean runSample(Azure azure) {
8888

8989
System.out.println("Deleting resource group: " + rgName2);
9090

91-
azure.resourceGroups().beginDeleteByName(rgName2);
91+
azureResourceManager.resourceGroups().beginDeleteByName(rgName2);
9292
return true;
93-
} catch (Exception f) {
94-
95-
System.out.println(f.getMessage());
96-
f.printStackTrace();
97-
9893
} finally {
9994

10095
try {
10196
System.out.println("Deleting Resource Group: " + rgName);
102-
azure.resourceGroups().beginDeleteByName(rgName);
97+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
10398
} catch (NullPointerException npe) {
10499
System.out.println("Did not create any resources in Azure. No clean up is necessary");
105100
} catch (Exception g) {
106101
g.printStackTrace();
107102
}
108103
}
109-
return false;
110104
}
111105

112106
/**
@@ -119,14 +113,18 @@ public static void main(String[] args) {
119113
//=================================================================
120114
// Authenticate
121115

122-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
116+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
117+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
118+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
119+
.build();
123120

124-
Azure azure = Azure.configure()
125-
.withLogLevel(LogLevel.NONE)
126-
.authenticate(credFile)
127-
.withDefaultSubscription();
121+
AzureResourceManager azureResourceManager = AzureResourceManager
122+
.configure()
123+
.withLogLevel(HttpLogDetailLevel.BASIC)
124+
.authenticate(credential, profile)
125+
.withDefaultSubscription();
128126

129-
runSample(azure);
127+
runSample(azureResourceManager);
130128
} catch (Exception e) {
131129
System.out.println(e.getMessage());
132130
e.printStackTrace();

0 commit comments

Comments
 (0)