Skip to content

Commit 7ac1c78

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 4d982d7 commit 7ac1c78

File tree

5 files changed

+1671
-1425
lines changed

5 files changed

+1671
-1425
lines changed

README.md

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

2121
To run this sample:
2222

23-
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).
23+
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).
2424

2525
git clone https://github.com/Azure-Samples/resources-java-deploy-using-arm-template-with-progress.git
2626

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

3131
## More information ##
3232

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

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

3739
---
3840

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.DeployUsingARMTemplateWithProgress</mainClass>
18+
<mainClass>com.azure.resourcemanager.resources.samples.DeployUsingARMTemplateWithProgress</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.DeployUsingARMTemplateWithProgress.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.resources.samples.DeployUsingARMTemplateWithProgress.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: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
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;
8-
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.resources.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.resources.models.Deployment;
12+
import com.azure.resourcemanager.resources.models.DeploymentMode;
13+
import com.azure.core.management.Region;
14+
import com.azure.core.management.profile.AzureProfile;
15+
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
16+
import com.azure.resourcemanager.samples.Utils;
917
import com.fasterxml.jackson.core.JsonProcessingException;
1018
import com.fasterxml.jackson.databind.JsonNode;
1119
import com.fasterxml.jackson.databind.ObjectMapper;
1220
import com.fasterxml.jackson.databind.node.ObjectNode;
13-
import com.microsoft.azure.management.Azure;
14-
import com.microsoft.azure.management.resources.Deployment;
15-
import com.microsoft.azure.management.resources.DeploymentMode;
16-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
17-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
18-
import com.microsoft.rest.LogLevel;
19-
20-
import java.io.File;
21+
2122
import java.io.IOException;
2223
import java.io.InputStream;
24+
import java.time.Duration;
2325

2426
/**
2527
* Azure Resource sample for deploying resources using an ARM template and
@@ -30,21 +32,22 @@ public final class DeployUsingARMTemplateWithProgress {
3032

3133
/**
3234
* Main function which runs the actual sample.
33-
* @param azure instance of the azure client
35+
*
36+
* @param azureResourceManager instance of the azure client
3437
* @return true if sample runs successfully
3538
*/
36-
public static boolean runSample(Azure azure) {
37-
final String rgName = SdkContext.randomResourceName("rgRSAP", 24);
38-
final String deploymentName = SdkContext.randomResourceName("dpRSAP", 24);
39+
public static boolean runSample(AzureResourceManager azureResourceManager) throws IOException, IllegalAccessException {
40+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgRSAP", 24);
41+
final String deploymentName = Utils.randomResourceName(azureResourceManager, "dpRSAP", 24);
3942
try {
40-
String templateJson = DeployUsingARMTemplateWithProgress.getTemplate();
43+
String templateJson = DeployUsingARMTemplateWithProgress.getTemplate(azureResourceManager);
4144

4245
//=============================================================
4346
// Create resource group.
4447

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

47-
azure.resourceGroups().define(rgName)
50+
azureResourceManager.resourceGroups().define(rgName)
4851
.withRegion(Region.US_WEST)
4952
.create();
5053

@@ -57,7 +60,7 @@ public static boolean runSample(Azure azure) {
5760

5861
System.out.println("Starting a deployment for an Azure App Service: " + deploymentName);
5962

60-
azure.deployments().define(deploymentName)
63+
azureResourceManager.deployments().define(deploymentName)
6164
.withExistingResourceGroup(rgName)
6265
.withTemplate(templateJson)
6366
.withParameters("{}")
@@ -66,26 +69,21 @@ public static boolean runSample(Azure azure) {
6669

6770
System.out.println("Started a deployment for an Azure App Service: " + deploymentName);
6871

69-
Deployment deployment = azure.deployments().getByResourceGroup(rgName, deploymentName);
72+
Deployment deployment = azureResourceManager.deployments().getByResourceGroup(rgName, deploymentName);
7073
System.out.println("Current deployment status : " + deployment.provisioningState());
7174

7275
while (!(deployment.provisioningState().equalsIgnoreCase("Succeeded")
7376
|| deployment.provisioningState().equalsIgnoreCase("Failed")
7477
|| deployment.provisioningState().equalsIgnoreCase("Cancelled"))) {
75-
SdkContext.sleep(10000);
76-
deployment = azure.deployments().getByResourceGroup(rgName, deploymentName);
78+
ResourceManagerUtils.sleep(Duration.ofSeconds(10));
79+
deployment = azureResourceManager.deployments().getByResourceGroup(rgName, deploymentName);
7780
System.out.println("Current deployment status : " + deployment.provisioningState());
7881
}
7982
return true;
80-
} catch (Exception f) {
81-
82-
System.out.println(f.getMessage());
83-
f.printStackTrace();
84-
8583
} finally {
8684
try {
8785
System.out.println("Deleting Resource Group: " + rgName);
88-
azure.resourceGroups().beginDeleteByName(rgName);
86+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
8987
System.out.println("Deleted Resource Group: " + rgName);
9088
} catch (NullPointerException npe) {
9189
System.out.println("Did not create any resources in Azure. No clean up is necessary");
@@ -94,49 +92,53 @@ public static boolean runSample(Azure azure) {
9492
}
9593

9694
}
97-
return false;
9895
}
9996

10097
/**
10198
* Main entry point.
99+
*
102100
* @param args the parameters
103101
*/
104102
public static void main(String[] args) {
105103
try {
106104
//=================================================================
107105
// Authenticate
108106

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

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

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

123124
}
124125

125-
private static String getTemplate() throws IllegalAccessException, JsonProcessingException, IOException {
126-
final String hostingPlanName = SdkContext.randomResourceName("hpRSAT", 24);
127-
final String webappName = SdkContext.randomResourceName("wnRSAT", 24);
128-
final InputStream embeddedTemplate;
129-
embeddedTemplate = DeployUsingARMTemplateWithProgress.class.getResourceAsStream("/templateValue.json");
126+
private static String getTemplate(AzureResourceManager azureResourceManager) throws IllegalAccessException, JsonProcessingException, IOException {
127+
final String hostingPlanName = Utils.randomResourceName(azureResourceManager, "hpRSAT", 24);
128+
final String webappName = Utils.randomResourceName(azureResourceManager, "wnRSAT", 24);
130129

131-
final ObjectMapper mapper = new ObjectMapper();
132-
final JsonNode tmp = mapper.readTree(embeddedTemplate);
130+
try (InputStream embeddedTemplate = DeployUsingARMTemplateWithProgress.class.getResourceAsStream("/templateValue.json")) {
133131

134-
DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", hostingPlanName, "hostingPlanName", null, tmp);
135-
DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", webappName, "webSiteName", null, tmp);
136-
DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", "F1", "skuName", null, tmp);
137-
DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("int", "1", "skuCapacity", null, tmp);
132+
final ObjectMapper mapper = new ObjectMapper();
133+
final JsonNode tmp = mapper.readTree(embeddedTemplate);
138134

139-
return tmp.toString();
135+
DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", hostingPlanName, "hostingPlanName", null, tmp);
136+
DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", webappName, "webSiteName", null, tmp);
137+
DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", "F1", "skuName", null, tmp);
138+
DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("int", "1", "skuCapacity", null, tmp);
139+
140+
return tmp.toString();
141+
}
140142
}
141143

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

0 commit comments

Comments
 (0)