Skip to content

Commit 8cb3375

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent c264dd8 commit 8cb3375

File tree

4 files changed

+1665
-1421
lines changed

4 files changed

+1665
-1421
lines changed

Diff for: README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extensions:
1919

2020
To run this sample:
2121

22-
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).
22+
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).
2323

2424
git clone https://github.com/Azure-Samples/resources-java-deploy-virtual-machine-with-managed-disks-using-arm-template.git
2525

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

3030
## More information ##
3131

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

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

3638
---
3739

Diff for: 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.resources.samples.DeployVirtualMachineUsingARMTemplate</mainClass>
18+
<mainClass>com.azure.resourcemanager.resources.samples.DeployVirtualMachineUsingARMTemplate</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.DeployVirtualMachineUsingARMTemplate.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.resources.samples.DeployVirtualMachineUsingARMTemplate.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>

Diff for: src/main/java/com/microsoft/azure/management/resources/samples/DeployVirtualMachineUsingARMTemplate.java renamed to src/main/java/com/azure/resourcemanager/resources/samples/DeployVirtualMachineUsingARMTemplate.java

+50-50
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
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-
package com.microsoft.azure.management.resources.samples;
7-
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.azure.resourcemanager.resources.samples;
4+
5+
import com.azure.core.credential.TokenCredential;
6+
import com.azure.core.http.policy.HttpLogDetailLevel;
7+
import com.azure.core.management.AzureEnvironment;
8+
import com.azure.identity.DefaultAzureCredentialBuilder;
9+
import com.azure.resourcemanager.AzureResourceManager;
10+
import com.azure.core.management.Region;
11+
import com.azure.core.management.profile.AzureProfile;
12+
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
13+
import com.azure.resourcemanager.resources.models.Deployment;
14+
import com.azure.resourcemanager.resources.models.DeploymentMode;
15+
import com.azure.resourcemanager.samples.Utils;
816
import com.fasterxml.jackson.core.JsonProcessingException;
917
import com.fasterxml.jackson.databind.JsonNode;
1018
import com.fasterxml.jackson.databind.ObjectMapper;
1119
import com.fasterxml.jackson.databind.node.ObjectNode;
12-
import com.microsoft.azure.management.Azure;
13-
import com.microsoft.azure.management.resources.Deployment;
14-
import com.microsoft.azure.management.resources.DeploymentMode;
15-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
16-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
17-
import com.microsoft.rest.LogLevel;
18-
19-
import java.io.File;
20+
2021
import java.io.IOException;
2122
import java.io.InputStream;
23+
import java.time.Duration;
2224

2325
/**
2426
* Azure Resource sample for deploying virtual machine with managed disk using an ARM template.
@@ -27,14 +29,15 @@ public class DeployVirtualMachineUsingARMTemplate {
2729

2830
/**
2931
* Main function which runs the actual sample.
30-
* @param azure instance of the azure client
32+
*
33+
* @param azureResourceManager instance of the azure client
3134
* @return true if sample runs successfully
3235
*/
33-
public static boolean runSample(Azure azure) {
34-
final String rgName = SdkContext.randomResourceName("rgRSAT", 24);
35-
final String deploymentName = SdkContext.randomResourceName("dpRSAT", 24);
36+
public static boolean runSample(AzureResourceManager azureResourceManager) throws IOException, IllegalAccessException {
37+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgRSAT", 24);
38+
final String deploymentName = Utils.randomResourceName(azureResourceManager, "dpRSAT", 24);
3639
try {
37-
String templateJson = DeployVirtualMachineUsingARMTemplate.getTemplate();
40+
String templateJson = DeployVirtualMachineUsingARMTemplate.getTemplate(azureResourceManager);
3841

3942
System.out.println(templateJson);
4043

@@ -43,7 +46,7 @@ public static boolean runSample(Azure azure) {
4346

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

46-
azure.resourceGroups().define(rgName)
49+
azureResourceManager.resourceGroups().define(rgName)
4750
.withRegion(Region.US_WEST)
4851
.create();
4952

@@ -56,43 +59,37 @@ public static boolean runSample(Azure azure) {
5659

5760
System.out.println("Starting a deployment for an Azure Virtual Machine with managed disks: " + deploymentName);
5861

59-
azure.deployments().define(deploymentName)
62+
azureResourceManager.deployments().define(deploymentName)
6063
.withExistingResourceGroup(rgName)
6164
.withTemplate(templateJson)
6265
.withParameters("{}")
6366
.withMode(DeploymentMode.INCREMENTAL)
6467
.create();
6568

6669
System.out.println("Started a deployment for an Azure Virtual Machine with managed disks: " + deploymentName);
67-
Deployment deployment = azure.deployments().getByResourceGroup(rgName, deploymentName);
70+
Deployment deployment = azureResourceManager.deployments().getByResourceGroup(rgName, deploymentName);
6871
System.out.println("Current deployment status : " + deployment.provisioningState());
6972

7073
while (!(deployment.provisioningState().equalsIgnoreCase("Succeeded")
7174
|| deployment.provisioningState().equalsIgnoreCase("Failed")
7275
|| deployment.provisioningState().equalsIgnoreCase("Cancelled"))) {
73-
SdkContext.sleep(10000);
74-
deployment = azure.deployments().getByResourceGroup(rgName, deploymentName);
76+
ResourceManagerUtils.sleep(Duration.ofSeconds(10));
77+
deployment = azureResourceManager.deployments().getByResourceGroup(rgName, deploymentName);
7578
System.out.println("Current deployment status : " + deployment.provisioningState());
7679
}
7780
return true;
78-
} catch (Exception f) {
79-
80-
System.out.println(f.getMessage());
81-
f.printStackTrace();
82-
8381
} finally {
8482

8583
try {
8684
System.out.println("Deleting Resource Group: " + rgName);
87-
azure.resourceGroups().beginDeleteByName(rgName);
85+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
8886
System.out.println("Deleted Resource Group: " + rgName);
8987
} catch (NullPointerException npe) {
9088
System.out.println("Did not create any resources in Azure. No clean up is necessary");
9189
} catch (Exception g) {
9290
g.printStackTrace();
9391
}
9492
}
95-
return false;
9693
}
9794

9895
/**
@@ -106,36 +103,39 @@ public static void main(String[] args) {
106103
//=================================================================
107104
// Authenticate
108105

109-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
106+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
107+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
108+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
109+
.build();
110110

111-
Azure azure = Azure.configure()
112-
.withLogLevel(LogLevel.BODY_AND_HEADERS)
113-
.authenticate(credFile)
114-
.withDefaultSubscription();
111+
AzureResourceManager azureResourceManager = AzureResourceManager
112+
.configure()
113+
.withLogLevel(HttpLogDetailLevel.BASIC)
114+
.authenticate(credential, profile)
115+
.withDefaultSubscription();
115116

116-
runSample(azure);
117+
runSample(azureResourceManager);
117118
} catch (Exception e) {
118119
System.out.println(e.getMessage());
119120
e.printStackTrace();
120121
}
121122
}
122123

123-
private static String getTemplate() throws IllegalAccessException, JsonProcessingException, IOException {
124+
private static String getTemplate(AzureResourceManager azureResourceManager) throws IllegalAccessException, JsonProcessingException, IOException {
124125
final String adminUsername = "tirekicker";
125-
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
126-
final String adminPassword = "12NewPA$$w0rd!";
127-
final String osDiskName = SdkContext.randomResourceName("osdisk-", 24);
126+
final String adminPassword = Utils.password();
127+
final String osDiskName = Utils.randomResourceName(azureResourceManager, "osdisk-", 24);
128128

129-
final InputStream embeddedTemplate;
130-
embeddedTemplate = DeployVirtualMachineUsingARMTemplate.class.getResourceAsStream("/virtualMachineWithManagedDisksTemplate.json");
129+
try (InputStream embeddedTemplate = DeployVirtualMachineUsingARMTemplate.class.getResourceAsStream("/virtualMachineWithManagedDisksTemplate.json")) {
131130

132-
final ObjectMapper mapper = new ObjectMapper();
133-
final JsonNode tmp = mapper.readTree(embeddedTemplate);
131+
final ObjectMapper mapper = new ObjectMapper();
132+
final JsonNode tmp = mapper.readTree(embeddedTemplate);
134133

135-
DeployVirtualMachineUsingARMTemplate.validateAndAddFieldValue("string", adminUsername, "adminUsername", null, tmp);
136-
DeployVirtualMachineUsingARMTemplate.validateAndAddFieldValue("string", adminPassword, "adminPassword", null, tmp);
137-
DeployVirtualMachineUsingARMTemplate.validateAndAddFieldValue("string", osDiskName, "osDiskName", null, tmp);
138-
return tmp.toString();
134+
DeployVirtualMachineUsingARMTemplate.validateAndAddFieldValue("string", adminUsername, "adminUsername", null, tmp);
135+
DeployVirtualMachineUsingARMTemplate.validateAndAddFieldValue("string", adminPassword, "adminPassword", null, tmp);
136+
DeployVirtualMachineUsingARMTemplate.validateAndAddFieldValue("string", osDiskName, "osDiskName", null, tmp);
137+
return tmp.toString();
138+
}
139139
}
140140

141141
private static void validateAndAddFieldValue(String type, String fieldValue, String fieldName, String errorMessage,

0 commit comments

Comments
 (0)