Skip to content

Commit ded7d05

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent d54f961 commit ded7d05

File tree

4 files changed

+1663
-1431
lines changed

4 files changed

+1663
-1431
lines changed

README.md

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

2727
To run this sample:
2828

29-
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).
29+
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).
3030

3131
git clone https://github.com/Azure-Samples/app-service-java-manage-web-apps-with-custom-domains.git
3232

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

3737
## More information ##
3838

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

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

4345
---
4446

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.appservice.samples.ManageWebAppWithDomainSsl</mainClass>
18+
<mainClass>com.azure.resourcemanager.appservice.samples.ManageWebAppWithDomainSsl</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.appservice.samples.ManageWebAppWithDomainSsl.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.appservice.samples.ManageWebAppWithDomainSsl.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: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +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-
7-
package com.microsoft.azure.management.appservice.samples;
8-
9-
import com.microsoft.azure.management.Azure;
10-
import com.microsoft.azure.management.appservice.AppServiceDomain;
11-
import com.microsoft.azure.management.appservice.AppServicePlan;
12-
import com.microsoft.azure.management.appservice.CustomHostNameDnsRecordType;
13-
import com.microsoft.azure.management.appservice.PricingTier;
14-
import com.microsoft.azure.management.appservice.WebApp;
15-
import com.microsoft.azure.management.resources.fluentcore.arm.CountryIsoCode;
16-
import com.microsoft.azure.management.resources.fluentcore.arm.CountryPhoneCode;
17-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
18-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
19-
import com.microsoft.azure.management.samples.Utils;
20-
import com.microsoft.rest.LogLevel;
21-
import okhttp3.OkHttpClient;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.appservice.samples;
5+
6+
import com.azure.core.credential.TokenCredential;
7+
import com.azure.core.management.AzureEnvironment;
8+
import com.azure.identity.DefaultAzureCredentialBuilder;
9+
import com.azure.resourcemanager.AzureResourceManager;
10+
import com.azure.resourcemanager.appservice.models.AppServiceDomain;
11+
import com.azure.resourcemanager.appservice.models.AppServicePlan;
12+
import com.azure.resourcemanager.appservice.models.CustomHostnameDnsRecordType;
13+
import com.azure.resourcemanager.appservice.models.PricingTier;
14+
import com.azure.resourcemanager.appservice.models.WebApp;
15+
import com.azure.resourcemanager.resources.fluentcore.arm.CountryIsoCode;
16+
import com.azure.resourcemanager.resources.fluentcore.arm.CountryPhoneCode;
17+
import com.azure.core.management.Region;
18+
import com.azure.core.management.profile.AzureProfile;
19+
import com.azure.resourcemanager.samples.Utils;
20+
import com.azure.core.http.policy.HttpLogDetailLevel;
2221

2322
import java.io.File;
24-
import java.util.concurrent.TimeUnit;
23+
import java.io.IOException;
2524

2625
/**
2726
* Azure App Service sample for managing web apps.
@@ -35,29 +34,26 @@
3534
*/
3635
public final class ManageWebAppWithDomainSsl {
3736

38-
private static OkHttpClient httpClient;
39-
4037
/**
4138
* Main function which runs the actual sample.
42-
* @param azure instance of the azure client
39+
* @param azureResourceManager instance of the azure client
4340
* @return true if sample runs successfully
4441
*/
45-
public static boolean runSample(Azure azure) {
42+
public static boolean runSample(AzureResourceManager azureResourceManager) throws IOException {
4643
// New resources
47-
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
48-
final String app2Name = SdkContext.randomResourceName("webapp2-", 20);
49-
final String rgName = SdkContext.randomResourceName("rgNEMV_", 24);
50-
final String domainName = SdkContext.randomResourceName("jsdkdemo-", 20) + ".com";
51-
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
52-
final String certPassword = "StrongPass!12";
44+
final String app1Name = Utils.randomResourceName(azureResourceManager, "webapp1-", 20);
45+
final String app2Name = Utils.randomResourceName(azureResourceManager, "webapp2-", 20);
46+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgNEMV_", 24);
47+
final String domainName = Utils.randomResourceName(azureResourceManager, "jsdkdemo-", 20) + ".com";
48+
final String certPassword = Utils.password();
5349

5450
try {
5551
//============================================================
5652
// Create a web app with a new app service plan
5753

5854
System.out.println("Creating web app " + app1Name + "...");
5955

60-
WebApp app1 = azure.webApps().define(app1Name)
56+
WebApp app1 = azureResourceManager.webApps().define(app1Name)
6157
.withRegion(Region.US_WEST)
6258
.withNewResourceGroup(rgName)
6359
.withNewWindowsPlan(PricingTier.STANDARD_S1)
@@ -70,8 +66,8 @@ public static boolean runSample(Azure azure) {
7066
// Create a second web app with the same app service plan
7167

7268
System.out.println("Creating another web app " + app2Name + "...");
73-
AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
74-
WebApp app2 = azure.webApps().define(app2Name)
69+
AppServicePlan plan = azureResourceManager.appServicePlans().getById(app1.appServicePlanId());
70+
WebApp app2 = azureResourceManager.webApps().define(app2Name)
7571
.withExistingWindowsPlan(plan)
7672
.withExistingResourceGroup(rgName)
7773
.create();
@@ -84,7 +80,7 @@ public static boolean runSample(Azure azure) {
8480

8581
System.out.println("Purchasing a domain " + domainName + "...");
8682

87-
AppServiceDomain domain = azure.appServices().domains().define(domainName)
83+
AppServiceDomain domain = azureResourceManager.appServiceDomains().define(domainName)
8884
.withExistingResourceGroup(rgName)
8985
.defineRegistrantContact()
9086
.withFirstName("Jon")
@@ -113,7 +109,7 @@ public static boolean runSample(Azure azure) {
113109
.defineHostnameBinding()
114110
.withAzureManagedDomain(domain)
115111
.withSubDomain(app1Name)
116-
.withDnsRecordType(CustomHostNameDnsRecordType.CNAME)
112+
.withDnsRecordType(CustomHostnameDnsRecordType.CNAME)
117113
.attach()
118114
.apply();
119115

@@ -123,8 +119,8 @@ public static boolean runSample(Azure azure) {
123119
//============================================================
124120
// Create a self-singed SSL certificate
125121

126-
String pfxPath = ManageWebAppWithDomainSsl.class.getResource("/").getPath() + "webapp_" + ManageWebAppWithDomainSsl.class.getSimpleName().toLowerCase() + ".pfx";
127-
String cerPath = ManageWebAppWithDomainSsl.class.getResource("/").getPath() + "webapp_" + ManageWebAppWithDomainSsl.class.getSimpleName().toLowerCase() + ".cer";
122+
String pfxPath = ManageWebAppWithDomainSsl.class.getResource("/").getPath() + "webapp_" + domainName + ".pfx";
123+
String cerPath = ManageWebAppWithDomainSsl.class.getResource("/").getPath() + "webapp_" + domainName + ".cer";
128124

129125
System.out.println("Creating a self-signed certificate " + pfxPath + "...");
130126

@@ -155,7 +151,7 @@ public static boolean runSample(Azure azure) {
155151
.withManagedHostnameBindings(domain, app2Name)
156152
.defineSslBinding()
157153
.forHostname(app2Name + "." + domainName)
158-
.withExistingCertificate(app1.hostNameSslStates().get(app1Name + "." + domainName).thumbprint())
154+
.withExistingCertificate(app1.hostnameSslStates().get(app1Name + "." + domainName).thumbprint())
159155
.withSniBasedSsl()
160156
.attach()
161157
.apply();
@@ -164,56 +160,48 @@ public static boolean runSample(Azure azure) {
164160
Utils.print(app2);
165161

166162
return true;
167-
} catch (Exception e) {
168-
System.err.println(e.getMessage());
169-
e.printStackTrace();
170163
} finally {
171164
try {
172165
System.out.println("Deleting Resource Group: " + rgName);
173-
azure.resourceGroups().deleteByName(rgName);
166+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
174167
System.out.println("Deleted Resource Group: " + rgName);
175168
} catch (NullPointerException npe) {
176169
System.out.println("Did not create any resources in Azure. No clean up is necessary");
177170
} catch (Exception g) {
178171
g.printStackTrace();
179172
}
180173
}
181-
182-
return false;
183174
}
184175
/**
185176
* Main entry point.
186177
* @param args the parameters
187178
*/
188179
public static void main(String[] args) {
189180

190-
191181
try {
192182

193183
//=============================================================
194184
// Authenticate
195185

196-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
186+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
187+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
188+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
189+
.build();
197190

198-
Azure azure = Azure.configure()
199-
.withLogLevel(LogLevel.BODY)
200-
.authenticate(credFile)
201-
.withDefaultSubscription();
191+
AzureResourceManager azureResourceManager = AzureResourceManager
192+
.configure()
193+
.withLogLevel(HttpLogDetailLevel.BASIC)
194+
.authenticate(credential, profile)
195+
.withDefaultSubscription();
202196

203197
// Print selected subscription
204-
System.out.println("Selected subscription: " + azure.subscriptionId());
198+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
205199

206-
runSample(azure);
200+
runSample(azureResourceManager);
207201

208202
} catch (Exception e) {
209203
System.out.println(e.getMessage());
210204
e.printStackTrace();
211205
}
212206
}
213-
214-
static {
215-
httpClient = new OkHttpClient.Builder().readTimeout(1, TimeUnit.MINUTES).build();
216-
}
217-
218-
219207
}

0 commit comments

Comments
 (0)