Skip to content

Commit 863877d

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 5d616d0 commit 863877d

File tree

4 files changed

+1666
-1433
lines changed

4 files changed

+1666
-1433
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-on-linux-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.ManageLinuxWebAppWithDomainSsl</mainClass>
18+
<mainClass>com.azure.resourcemanager.appservice.samples.ManageLinuxWebAppWithDomainSsl</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.ManageLinuxWebAppWithDomainSsl.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.appservice.samples.ManageLinuxWebAppWithDomainSsl.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: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +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.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.RuntimeStack;
15-
import com.microsoft.azure.management.appservice.WebApp;
16-
import com.microsoft.azure.management.resources.fluentcore.arm.CountryIsoCode;
17-
import com.microsoft.azure.management.resources.fluentcore.arm.CountryPhoneCode;
18-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
19-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
20-
import com.microsoft.azure.management.samples.Utils;
21-
import com.microsoft.rest.LogLevel;
22-
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.RuntimeStack;
15+
import com.azure.resourcemanager.appservice.models.WebApp;
16+
import com.azure.resourcemanager.resources.fluentcore.arm.CountryIsoCode;
17+
import com.azure.resourcemanager.resources.fluentcore.arm.CountryPhoneCode;
18+
import com.azure.core.management.Region;
19+
import com.azure.core.management.profile.AzureProfile;
20+
import com.azure.resourcemanager.samples.Utils;
21+
import com.azure.core.http.policy.HttpLogDetailLevel;
2322

2423
import java.io.File;
25-
import java.util.concurrent.TimeUnit;
24+
import java.io.IOException;
2625

2726
/**
2827
* Azure App Service sample for managing web apps.
@@ -36,33 +35,30 @@
3635
*/
3736
public final class ManageLinuxWebAppWithDomainSsl {
3837

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

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

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

61-
WebApp app1 = azure.webApps().define(app1Name)
57+
WebApp app1 = azureResourceManager.webApps().define(app1Name)
6258
.withRegion(Region.US_WEST)
6359
.withNewResourceGroup(rgName)
6460
.withNewLinuxPlan(PricingTier.STANDARD_S1)
65-
.withBuiltInImage(RuntimeStack.NODEJS_6_9)
61+
.withBuiltInImage(RuntimeStack.NODEJS_10_LTS)
6662
.create();
6763

6864
System.out.println("Created web app " + app1.name());
@@ -72,11 +68,11 @@ public static boolean runSample(Azure azure) {
7268
// Create a second web app with the same app service plan
7369

7470
System.out.println("Creating another web app " + app2Name + "...");
75-
AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
76-
WebApp app2 = azure.webApps().define(app2Name)
71+
AppServicePlan plan = azureResourceManager.appServicePlans().getById(app1.appServicePlanId());
72+
WebApp app2 = azureResourceManager.webApps().define(app2Name)
7773
.withExistingLinuxPlan(plan)
7874
.withExistingResourceGroup(rgName)
79-
.withBuiltInImage(RuntimeStack.NODEJS_6_9)
75+
.withBuiltInImage(RuntimeStack.NODEJS_10_LTS)
8076
.create();
8177

8278
System.out.println("Created web app " + app2.name());
@@ -87,7 +83,7 @@ public static boolean runSample(Azure azure) {
8783

8884
System.out.println("Purchasing a domain " + domainName + "...");
8985

90-
AppServiceDomain domain = azure.appServices().domains().define(domainName)
86+
AppServiceDomain domain = azureResourceManager.appServiceDomains().define(domainName)
9187
.withExistingResourceGroup(rgName)
9288
.defineRegistrantContact()
9389
.withFirstName("Jon")
@@ -116,7 +112,7 @@ public static boolean runSample(Azure azure) {
116112
.defineHostnameBinding()
117113
.withAzureManagedDomain(domain)
118114
.withSubDomain(app1Name)
119-
.withDnsRecordType(CustomHostNameDnsRecordType.CNAME)
115+
.withDnsRecordType(CustomHostnameDnsRecordType.CNAME)
120116
.attach()
121117
.apply();
122118

@@ -126,8 +122,8 @@ public static boolean runSample(Azure azure) {
126122
//============================================================
127123
// Create a self-singed SSL certificate
128124

129-
String pfxPath = ManageLinuxWebAppWithDomainSsl.class.getResource("/").getPath() + "webapp_" + ManageLinuxWebAppWithDomainSsl.class.getSimpleName().toLowerCase() + ".pfx";
130-
String cerPath = ManageLinuxWebAppWithDomainSsl.class.getResource("/").getPath() + "webapp_" + ManageLinuxWebAppWithDomainSsl.class.getSimpleName().toLowerCase() + ".cer";
125+
String pfxPath = ManageLinuxWebAppWithDomainSsl.class.getResource("/").getPath() + "webapp_" + domainName + ".pfx";
126+
String cerPath = ManageLinuxWebAppWithDomainSsl.class.getResource("/").getPath() + "webapp_" + domainName + ".cer";
131127

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

@@ -158,7 +154,7 @@ public static boolean runSample(Azure azure) {
158154
.withManagedHostnameBindings(domain, app2Name)
159155
.defineSslBinding()
160156
.forHostname(app2Name + "." + domainName)
161-
.withExistingCertificate(app1.hostNameSslStates().get(app1Name + "." + domainName).thumbprint())
157+
.withExistingCertificate(app1.hostnameSslStates().get(app1Name + "." + domainName).thumbprint())
162158
.withSniBasedSsl()
163159
.attach()
164160
.apply();
@@ -167,22 +163,17 @@ public static boolean runSample(Azure azure) {
167163
Utils.print(app2);
168164

169165
return true;
170-
} catch (Exception e) {
171-
System.err.println(e.getMessage());
172-
e.printStackTrace();
173166
} finally {
174167
try {
175168
System.out.println("Deleting Resource Group: " + rgName);
176-
azure.resourceGroups().deleteByName(rgName);
169+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
177170
System.out.println("Deleted Resource Group: " + rgName);
178171
} catch (NullPointerException npe) {
179172
System.out.println("Did not create any resources in Azure. No clean up is necessary");
180173
} catch (Exception g) {
181174
g.printStackTrace();
182175
}
183176
}
184-
185-
return false;
186177
}
187178
/**
188179
* Main entry point.
@@ -196,27 +187,25 @@ public static void main(String[] args) {
196187
//=============================================================
197188
// Authenticate
198189

199-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
190+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
191+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
192+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
193+
.build();
200194

201-
Azure azure = Azure.configure()
202-
.withLogLevel(LogLevel.BODY_AND_HEADERS)
203-
.authenticate(credFile)
204-
.withDefaultSubscription();
195+
AzureResourceManager azureResourceManager = AzureResourceManager
196+
.configure()
197+
.withLogLevel(HttpLogDetailLevel.BASIC)
198+
.authenticate(credential, profile)
199+
.withDefaultSubscription();
205200

206201
// Print selected subscription
207-
System.out.println("Selected subscription: " + azure.subscriptionId());
202+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
208203

209-
runSample(azure);
204+
runSample(azureResourceManager);
210205

211206
} catch (Exception e) {
212207
System.out.println(e.getMessage());
213208
e.printStackTrace();
214209
}
215210
}
216-
217-
static {
218-
httpClient = new OkHttpClient.Builder().readTimeout(1, TimeUnit.MINUTES).build();
219-
}
220-
221-
222211
}

0 commit comments

Comments
 (0)