Skip to content

Commit 14306f7

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 2806a1a commit 14306f7

File tree

5 files changed

+1669
-1425
lines changed

5 files changed

+1669
-1425
lines changed

README.md

Lines changed: 5 additions & 3 deletions
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-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

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.DeployUsingARMTemplate</mainClass>
18+
<mainClass>com.azure.resourcemanager.resources.samples.DeployUsingARMTemplate</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.DeployUsingARMTemplate.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.resources.samples.DeployUsingARMTemplate.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/DeployUsingARMTemplate.java renamed to src/main/java/com/azure/resourcemanager/resources/samples/DeployUsingARMTemplate.java

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
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.http.rest.PagedIterable;
9+
import com.azure.core.management.AzureEnvironment;
10+
import com.azure.identity.DefaultAzureCredentialBuilder;
11+
import com.azure.resourcemanager.AzureResourceManager;
12+
import com.azure.resourcemanager.resources.models.Deployment;
13+
import com.azure.resourcemanager.resources.models.DeploymentMode;
14+
import com.azure.resourcemanager.resources.models.DeploymentOperation;
15+
import com.azure.core.management.Region;
16+
import com.azure.core.management.profile.AzureProfile;
17+
import com.azure.resourcemanager.samples.Utils;
918
import com.fasterxml.jackson.core.JsonProcessingException;
1019
import com.fasterxml.jackson.databind.JsonNode;
1120
import com.fasterxml.jackson.databind.ObjectMapper;
1221
import com.fasterxml.jackson.databind.node.ObjectNode;
13-
import com.microsoft.azure.PagedList;
14-
import com.microsoft.azure.management.Azure;
15-
import com.microsoft.azure.management.resources.Deployment;
16-
import com.microsoft.azure.management.resources.DeploymentMode;
17-
import com.microsoft.azure.management.resources.DeploymentOperation;
18-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
19-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
20-
import com.microsoft.rest.LogLevel;
21-
22-
import java.io.File;
22+
2323
import java.io.IOException;
2424
import java.io.InputStream;
2525

@@ -31,22 +31,23 @@ public final class DeployUsingARMTemplate {
3131

3232
/**
3333
* Main function which runs the actual sample.
34-
* @param azure instance of the azure client
34+
*
35+
* @param azureResourceManager instance of the azure client
3536
* @return true if sample runs successfully
3637
*/
37-
public static boolean runSample(Azure azure) {
38-
final String rgName = SdkContext.randomResourceName("rgRSAT", 24);
39-
final String deploymentName = SdkContext.randomResourceName("dpRSAT", 24);
38+
public static boolean runSample(AzureResourceManager azureResourceManager) throws IOException, IllegalAccessException {
39+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgRSAT", 24);
40+
final String deploymentName = Utils.randomResourceName(azureResourceManager, "dpRSAT", 24);
4041
try {
41-
String templateJson = DeployUsingARMTemplate.getTemplate();
42+
String templateJson = DeployUsingARMTemplate.getTemplate(azureResourceManager);
4243

4344

4445
//=============================================================
4546
// Create resource group.
4647

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

49-
azure.resourceGroups().define(rgName)
50+
azureResourceManager.resourceGroups().define(rgName)
5051
.withRegion(Region.US_EAST2)
5152
.create();
5253

@@ -61,7 +62,7 @@ public static boolean runSample(Azure azure) {
6162
//
6263
System.out.println("Starting a deployment for an Azure App Service: " + deploymentName);
6364

64-
azure.deployments().define(deploymentName)
65+
azureResourceManager.deployments().define(deploymentName)
6566
.withExistingResourceGroup(rgName)
6667
.withTemplate(templateJson)
6768
.withParameters("{}")
@@ -70,16 +71,11 @@ public static boolean runSample(Azure azure) {
7071

7172
System.out.println("Started a deployment for an Azure App Service: " + deploymentName);
7273
return true;
73-
} catch (Exception f) {
74-
75-
System.out.println(f.getMessage());
76-
f.printStackTrace();
77-
7874
} finally {
7975
try {
80-
Deployment deployment = azure.deployments()
76+
Deployment deployment = azureResourceManager.deployments()
8177
.getByResourceGroup(rgName, deploymentName);
82-
PagedList<DeploymentOperation> operations = deployment.deploymentOperations()
78+
PagedIterable<DeploymentOperation> operations = deployment.deploymentOperations()
8379
.list();
8480

8581
for (DeploymentOperation operation : operations) {
@@ -101,7 +97,7 @@ public static boolean runSample(Azure azure) {
10197

10298
try {
10399
System.out.println("Deleting Resource Group: " + rgName);
104-
azure.resourceGroups().beginDeleteByName(rgName);
100+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
105101
System.out.println("Deleted Resource Group: " + rgName);
106102
} catch (NullPointerException npe) {
107103
System.out.println("Did not create any resources in Azure. No clean up is necessary");
@@ -110,7 +106,6 @@ public static boolean runSample(Azure azure) {
110106
}
111107

112108
}
113-
return false;
114109
}
115110

116111
/**
@@ -124,39 +119,44 @@ public static void main(String[] args) {
124119
//=================================================================
125120
// Authenticate
126121

127-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
122+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
123+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
124+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
125+
.build();
128126

129-
Azure azure = Azure.configure()
130-
.withLogLevel(LogLevel.NONE)
131-
.authenticate(credFile)
132-
.withDefaultSubscription();
127+
AzureResourceManager azureResourceManager = AzureResourceManager
128+
.configure()
129+
.withLogLevel(HttpLogDetailLevel.BASIC)
130+
.authenticate(credential, profile)
131+
.withDefaultSubscription();
133132

134-
runSample(azure);
133+
runSample(azureResourceManager);
135134
} catch (Exception e) {
136135
System.out.println(e.getMessage());
137136
e.printStackTrace();
138137
}
139138
}
140139

141-
private static String getTemplate() throws IllegalAccessException, JsonProcessingException, IOException {
142-
final String hostingPlanName = SdkContext.randomResourceName("hpRSAT", 24);
143-
final String webappName = SdkContext.randomResourceName("wnRSAT", 24);
144-
final InputStream embeddedTemplate;
145-
embeddedTemplate = DeployUsingARMTemplate.class.getResourceAsStream("/templateValue.json");
140+
private static String getTemplate(AzureResourceManager azureResourceManager) throws IllegalAccessException, JsonProcessingException, IOException {
141+
final String hostingPlanName = Utils.randomResourceName(azureResourceManager, "hpRSAT", 24);
142+
final String webappName = Utils.randomResourceName(azureResourceManager, "wnRSAT", 24);
146143

147-
final ObjectMapper mapper = new ObjectMapper();
148-
final JsonNode tmp = mapper.readTree(embeddedTemplate);
144+
try (InputStream embeddedTemplate = DeployUsingARMTemplate.class.getResourceAsStream("/templateValue.json")) {
149145

150-
DeployUsingARMTemplate.validateAndAddFieldValue("string", hostingPlanName, "hostingPlanName", null, tmp);
151-
DeployUsingARMTemplate.validateAndAddFieldValue("string", webappName, "webSiteName", null, tmp);
152-
DeployUsingARMTemplate.validateAndAddFieldValue("string", "F1", "skuName", null, tmp);
153-
DeployUsingARMTemplate.validateAndAddFieldValue("int", "1", "skuCapacity", null, tmp);
146+
final ObjectMapper mapper = new ObjectMapper();
147+
final JsonNode tmp = mapper.readTree(embeddedTemplate);
154148

155-
return tmp.toString();
149+
DeployUsingARMTemplate.validateAndAddFieldValue("string", hostingPlanName, "hostingPlanName", null, tmp);
150+
DeployUsingARMTemplate.validateAndAddFieldValue("string", webappName, "webSiteName", null, tmp);
151+
DeployUsingARMTemplate.validateAndAddFieldValue("string", "F1", "skuName", null, tmp);
152+
DeployUsingARMTemplate.validateAndAddFieldValue("int", "1", "skuCapacity", null, tmp);
153+
154+
return tmp.toString();
155+
}
156156
}
157157

158158
private static void validateAndAddFieldValue(String type, String fieldValue, String fieldName, String errorMessage,
159-
JsonNode tmp) throws IllegalAccessException {
159+
JsonNode tmp) throws IllegalAccessException {
160160
// Add count variable for loop....
161161
final ObjectMapper mapper = new ObjectMapper();
162162
final ObjectNode parameter = mapper.createObjectNode();

0 commit comments

Comments
 (0)