Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Commit a608a77

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 834f402 commit a608a77

File tree

4 files changed

+1675
-1447
lines changed

4 files changed

+1675
-1447
lines changed

README.md

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

2525
To run this sample:
2626

27-
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).
27+
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).
2828

2929
git clone https://github.com/Azure-Samples/app-service-java-configure-deployment-sources-for-web-apps-on-linux.git
3030

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

3535
## More information ##
3636

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

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

4143
---
4244

pom.xml

Lines changed: 16 additions & 20 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.ManageLinuxWebAppSourceControl</mainClass>
18+
<mainClass>com.azure.resourcemanager.appservice.samples.ManageLinuxWebAppSourceControl</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.ManageLinuxWebAppSourceControl.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.appservice.samples.ManageLinuxWebAppSourceControl.java</mainClass>
4445
</manifest>
4546
</archive>
4647
</configuration>
@@ -51,29 +52,24 @@
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>
58+
</dependency>
59+
<dependency>
60+
<groupId>com.azure</groupId>
61+
<artifactId>azure-identity</artifactId>
62+
<version>1.1.3</version>
5763
</dependency>
5864
<dependency>
5965
<groupId>commons-net</groupId>
6066
<artifactId>commons-net</artifactId>
61-
<version>3.3</version>
67+
<version>3.6</version>
6268
</dependency>
6369
<dependency>
6470
<groupId>org.eclipse.jgit</groupId>
6571
<artifactId>org.eclipse.jgit</artifactId>
66-
<version>4.5.0.201609210915-r</version>
67-
</dependency>
68-
<dependency>
69-
<groupId>commons-lang</groupId>
70-
<artifactId>commons-lang</artifactId>
71-
<version>2.6</version>
72-
</dependency>
73-
<dependency>
74-
<groupId>org.apache.commons</groupId>
75-
<artifactId>commons-lang3</artifactId>
76-
<version>3.7</version>
72+
<version>4.5.7.201904151645-r</version>
7773
</dependency>
7874
</dependencies>
7975
</project>
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
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.AppServicePlan;
11-
import com.microsoft.azure.management.appservice.PricingTier;
12-
import com.microsoft.azure.management.appservice.PublishingProfile;
13-
import com.microsoft.azure.management.appservice.RuntimeStack;
14-
import com.microsoft.azure.management.appservice.WebApp;
15-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
16-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
17-
import com.microsoft.azure.management.samples.Utils;
18-
import com.microsoft.rest.LogLevel;
19-
import okhttp3.OkHttpClient;
20-
import okhttp3.Request;
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.AppServicePlan;
11+
import com.azure.resourcemanager.appservice.models.PricingTier;
12+
import com.azure.resourcemanager.appservice.models.PublishingProfile;
13+
import com.azure.resourcemanager.appservice.models.RuntimeStack;
14+
import com.azure.resourcemanager.appservice.models.WebApp;
15+
import com.azure.core.management.Region;
16+
import com.azure.core.management.profile.AzureProfile;
17+
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
18+
import com.azure.resourcemanager.samples.Utils;
19+
import com.azure.core.http.policy.HttpLogDetailLevel;
2120
import org.eclipse.jgit.api.Git;
2221
import org.eclipse.jgit.api.PushCommand;
22+
import org.eclipse.jgit.api.errors.GitAPIException;
2323
import org.eclipse.jgit.transport.RefSpec;
2424
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
2525

2626
import java.io.File;
27-
import java.io.IOException;
28-
import java.util.concurrent.TimeUnit;
27+
import java.time.Duration;
28+
2929

3030
/**
3131
* Azure App Service basic sample for managing web apps.
@@ -37,25 +37,23 @@
3737
*/
3838
public final class ManageLinuxWebAppSourceControl {
3939

40-
private static OkHttpClient httpClient;
41-
4240
/**
4341
* Main function which runs the actual sample.
44-
* @param azure instance of the azure client
42+
* @param azureResourceManager instance of the azure client
4543
* @return true if sample runs successfully
4644
*/
47-
public static boolean runSample(Azure azure) {
45+
public static boolean runSample(AzureResourceManager azureResourceManager) throws GitAPIException {
4846
// New resources
4947
final String suffix = ".azurewebsites.net";
50-
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
51-
final String app2Name = SdkContext.randomResourceName("webapp2-", 20);
52-
final String app3Name = SdkContext.randomResourceName("webapp3-", 20);
53-
final String app4Name = SdkContext.randomResourceName("webapp4-", 20);
48+
final String app1Name = Utils.randomResourceName(azureResourceManager, "webapp1-", 20);
49+
final String app2Name = Utils.randomResourceName(azureResourceManager, "webapp2-", 20);
50+
final String app3Name = Utils.randomResourceName(azureResourceManager, "webapp3-", 20);
51+
final String app4Name = Utils.randomResourceName(azureResourceManager, "webapp4-", 20);
5452
final String app1Url = app1Name + suffix;
5553
final String app2Url = app2Name + suffix;
5654
final String app3Url = app3Name + suffix;
5755
final String app4Url = app4Name + suffix;
58-
final String rgName = SdkContext.randomResourceName("rg1NEMV_", 24);
56+
final String rgName = Utils.randomResourceName(azureResourceManager, "rg1NEMV_", 24);
5957

6058
try {
6159

@@ -65,7 +63,7 @@ public static boolean runSample(Azure azure) {
6563

6664
System.out.println("Creating web app " + app1Name + " in resource group " + rgName + "...");
6765

68-
WebApp app1 = azure.webApps().define(app1Name)
66+
WebApp app1 = azureResourceManager.webApps().define(app1Name)
6967
.withRegion(Region.US_WEST)
7068
.withNewResourceGroup(rgName)
7169
.withNewLinuxPlan(PricingTier.STANDARD_S1)
@@ -80,24 +78,24 @@ public static boolean runSample(Azure azure) {
8078

8179
System.out.println("Deploying helloworld.war to " + app1Name + " through FTP...");
8280

83-
Utils.uploadFileToWebApp(app1.getPublishingProfile(), "helloworld.war", ManageLinuxWebAppSourceControl.class.getResourceAsStream("/helloworld.war"));
81+
Utils.uploadFileViaFtp(app1.getPublishingProfile(), "helloworld.war", ManageLinuxWebAppSourceControl.class.getResourceAsStream("/helloworld.war"));
8482

8583
System.out.println("Deployment helloworld.war to web app " + app1.name() + " completed");
8684
Utils.print(app1);
8785

8886
// warm up
8987
System.out.println("Warming up " + app1Url + "/helloworld...");
90-
curl("http://" + app1Url + "/helloworld");
91-
SdkContext.sleep(5000);
88+
Utils.sendGetRequest("http://" + app1Url + "/helloworld/");
89+
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
9290
System.out.println("CURLing " + app1Url + "/helloworld...");
93-
System.out.println(curl("http://" + app1Url + "/helloworld"));
91+
System.out.println(Utils.sendGetRequest("http://" + app1Url + "/helloworld/"));
9492

9593
//============================================================
9694
// Create a second web app with local git source control
9795

9896
System.out.println("Creating another web app " + app2Name + " in resource group " + rgName + "...");
99-
AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
100-
WebApp app2 = azure.webApps().define(app2Name)
97+
AppServicePlan plan = azureResourceManager.appServicePlans().getById(app1.appServicePlanId());
98+
WebApp app2 = azureResourceManager.webApps().define(app2Name)
10199
.withExistingLinuxPlan(plan)
102100
.withExistingResourceGroup(rgName)
103101
.withBuiltInImage(RuntimeStack.TOMCAT_8_5_JRE8)
@@ -131,16 +129,16 @@ public static boolean runSample(Azure azure) {
131129

132130
// warm up
133131
System.out.println("Warming up " + app2Url + "/helloworld...");
134-
curl("http://" + app2Url + "/helloworld");
135-
SdkContext.sleep(5000);
132+
Utils.sendGetRequest("http://" + app2Url + "/helloworld/");
133+
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
136134
System.out.println("CURLing " + app2Url + "/helloworld...");
137-
System.out.println(curl("http://" + app2Url + "/helloworld"));
135+
System.out.println(Utils.sendGetRequest("http://" + app2Url + "/helloworld/"));
138136

139137
//============================================================
140138
// Create a 3rd web app with a public GitHub repo in Azure-Samples
141139

142140
System.out.println("Creating another web app " + app3Name + "...");
143-
WebApp app3 = azure.webApps().define(app3Name)
141+
WebApp app3 = azureResourceManager.webApps().define(app3Name)
144142
.withExistingLinuxPlan(plan)
145143
.withNewResourceGroup(rgName)
146144
.withBuiltInImage(RuntimeStack.TOMCAT_8_5_JRE8)
@@ -155,16 +153,16 @@ public static boolean runSample(Azure azure) {
155153

156154
// warm up
157155
System.out.println("Warming up " + app3Url + "...");
158-
curl("http://" + app3Url);
159-
SdkContext.sleep(5000);
156+
Utils.sendGetRequest("http://" + app3Url);
157+
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
160158
System.out.println("CURLing " + app3Url + "...");
161-
System.out.println(curl("http://" + app3Url));
159+
System.out.println(Utils.sendGetRequest("http://" + app3Url));
162160

163161
//============================================================
164162
// Create a 4th web app with a personal GitHub repo and turn on continuous integration
165163

166164
System.out.println("Creating another web app " + app4Name + "...");
167-
WebApp app4 = azure.webApps()
165+
WebApp app4 = azureResourceManager.webApps()
168166
.define(app4Name)
169167
.withExistingLinuxPlan(plan)
170168
.withExistingResourceGroup(rgName)
@@ -182,27 +180,23 @@ public static boolean runSample(Azure azure) {
182180

183181
// warm up
184182
System.out.println("Warming up " + app4Url + "...");
185-
curl("http://" + app4Url);
186-
SdkContext.sleep(5000);
183+
Utils.sendGetRequest("http://" + app4Url);
184+
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
187185
System.out.println("CURLing " + app4Url + "...");
188-
System.out.println(curl("http://" + app4Url));
186+
System.out.println(Utils.sendGetRequest("http://" + app4Url));
189187

190188
return true;
191-
} catch (Exception e) {
192-
System.err.println(e.getMessage());
193-
e.printStackTrace();
194189
} finally {
195190
try {
196191
System.out.println("Deleting Resource Group: " + rgName);
197-
azure.resourceGroups().beginDeleteByName(rgName);
192+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
198193
System.out.println("Deleted Resource Group: " + rgName);
199194
} catch (NullPointerException npe) {
200195
System.out.println("Did not create any resources in Azure. No clean up is necessary");
201196
} catch (Exception g) {
202197
g.printStackTrace();
203198
}
204199
}
205-
return false;
206200
}
207201
/**
208202
* Main entry point.
@@ -214,34 +208,24 @@ public static void main(String[] args) {
214208
//=============================================================
215209
// Authenticate
216210

217-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
211+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
212+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
213+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
214+
.build();
218215

219-
Azure azure = Azure
220-
.configure()
221-
.withLogLevel(LogLevel.BASIC)
222-
.authenticate(credFile)
223-
.withDefaultSubscription();
216+
AzureResourceManager azureResourceManager = AzureResourceManager
217+
.configure()
218+
.withLogLevel(HttpLogDetailLevel.BASIC)
219+
.authenticate(credential, profile)
220+
.withDefaultSubscription();
224221

225222
// Print selected subscription
226-
System.out.println("Selected subscription: " + azure.subscriptionId());
223+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
227224

228-
runSample(azure);
225+
runSample(azureResourceManager);
229226
} catch (Exception e) {
230227
System.out.println(e.getMessage());
231228
e.printStackTrace();
232229
}
233230
}
234-
235-
private static String curl(String url) {
236-
Request request = new Request.Builder().url(url).get().build();
237-
try {
238-
return httpClient.newCall(request).execute().body().string();
239-
} catch (IOException e) {
240-
return null;
241-
}
242-
}
243-
244-
static {
245-
httpClient = new OkHttpClient.Builder().readTimeout(1, TimeUnit.MINUTES).build();
246-
}
247231
}

0 commit comments

Comments
 (0)