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

Commit d58c506

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 1812257 commit d58c506

File tree

5 files changed

+1838
-1640
lines changed

5 files changed

+1838
-1640
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-async.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.ManageWebAppSourceControlAsync</mainClass>
18+
<mainClass>com.azure.resourcemanager.appservice.samples.ManageWebAppSourceControlAsync</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.ManageWebAppSourceControlAsync.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.appservice.samples.ManageWebAppSourceControlAsync.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>
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
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.http.policy.HttpLogDetailLevel;
8+
import com.azure.core.management.AzureEnvironment;
9+
import com.azure.core.management.profile.AzureProfile;
10+
import com.azure.identity.DefaultAzureCredentialBuilder;
11+
import com.azure.resourcemanager.AzureResourceManager;
12+
import com.azure.resourcemanager.appservice.models.JavaVersion;
13+
import com.azure.resourcemanager.appservice.models.PricingTier;
14+
import com.azure.resourcemanager.appservice.models.WebContainer;
15+
import com.azure.core.management.Region;
16+
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
17+
import com.azure.resourcemanager.samples.Utils;
18+
import org.eclipse.jgit.api.Git;
19+
import org.eclipse.jgit.api.PushCommand;
20+
import org.eclipse.jgit.api.errors.GitAPIException;
21+
import org.eclipse.jgit.transport.RefSpec;
22+
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
23+
import reactor.core.publisher.Flux;
24+
25+
import java.io.File;
26+
import java.time.Duration;
27+
28+
29+
/**
30+
* Azure App Service basic sample for managing web apps.
31+
* - Create 4 web apps under the same new app service plan:
32+
* - Deploy to 1 using FTP
33+
* - Deploy to 2 using local Git repository
34+
* - Deploy to 3 using a publicly available Git repository
35+
* - Deploy to 4 using a GitHub repository with continuous integration
36+
*/
37+
public final class ManageWebAppSourceControlAsync {
38+
39+
/**
40+
* Main function which runs the actual sample.
41+
* @param azureResourceManager instance of the azure client
42+
* @return true if sample runs successfully
43+
*/
44+
public static boolean runSample(final AzureResourceManager azureResourceManager) {
45+
// New resources
46+
final String suffix = ".azurewebsites.net";
47+
final String app1Name = Utils.randomResourceName(azureResourceManager, "webapp1-", 20);
48+
final String app2Name = Utils.randomResourceName(azureResourceManager, "webapp2-", 20);
49+
final String app3Name = Utils.randomResourceName(azureResourceManager, "webapp3-", 20);
50+
final String app4Name = Utils.randomResourceName(azureResourceManager, "webapp4-", 20);
51+
final String app1Url = app1Name + suffix;
52+
final String app2Url = app2Name + suffix;
53+
final String app3Url = app3Name + suffix;
54+
final String app4Url = app4Name + suffix;
55+
final String planName = Utils.randomResourceName(azureResourceManager, "jplan_", 15);
56+
final String rgName = Utils.randomResourceName(azureResourceManager, "rg1NEMV_", 24);
57+
58+
try {
59+
60+
61+
//============================================================
62+
// Create a web app with a new app service plan
63+
64+
System.out.println("Creating web app " + app1Name + " in resource group " + rgName + "...");
65+
66+
Flux<?> app1Observable = azureResourceManager.webApps().define(app1Name)
67+
.withRegion(Region.US_WEST)
68+
.withNewResourceGroup(rgName)
69+
.withNewWindowsPlan(PricingTier.STANDARD_S1)
70+
.withJavaVersion(JavaVersion.JAVA_8_NEWEST)
71+
.withWebContainer(WebContainer.TOMCAT_8_0_NEWEST)
72+
.createAsync()
73+
.flatMapMany(app -> {
74+
System.out.println("Created web app " + app.name());
75+
return Flux.merge(
76+
Flux.just(app),
77+
app.getPublishingProfileAsync()
78+
.map(publishingProfile -> {
79+
System.out.println("Deploying helloworld.war to " + app1Name + " through FTP...");
80+
Utils.uploadFileViaFtp(publishingProfile,
81+
"helloworld.war",
82+
ManageWebAppSourceControlAsync.class.getResourceAsStream("/helloworld.war"));
83+
84+
System.out.println("Deployment helloworld.war to web app " + app1Name + " completed");
85+
return publishingProfile;
86+
}));
87+
});
88+
89+
System.out.println("Creating another web app " + app2Name + " in resource group " + rgName + "...");
90+
System.out.println("Creating another web app " + app3Name + "...");
91+
System.out.println("Creating another web app " + app4Name + "...");
92+
93+
Flux<?> app234Observable = azureResourceManager.appServicePlans()
94+
.getByResourceGroupAsync(rgName, planName)
95+
.flatMapMany(plan -> {
96+
return Flux.merge(
97+
azureResourceManager.webApps().define(app2Name)
98+
.withExistingWindowsPlan(plan)
99+
.withExistingResourceGroup(rgName)
100+
.withLocalGitSourceControl()
101+
.withJavaVersion(JavaVersion.JAVA_8_NEWEST)
102+
.withWebContainer(WebContainer.TOMCAT_8_0_NEWEST)
103+
.createAsync(),
104+
azureResourceManager.webApps().define(app3Name)
105+
.withExistingWindowsPlan(plan)
106+
.withNewResourceGroup(rgName)
107+
.defineSourceControl()
108+
.withPublicGitRepository(
109+
"https://github.com/Azure-Samples/app-service-web-dotnet-get-started")
110+
.withBranch("master")
111+
.attach()
112+
.createAsync(),
113+
azureResourceManager.webApps()
114+
.define(app4Name)
115+
.withExistingWindowsPlan(plan)
116+
.withExistingResourceGroup(rgName)
117+
// Uncomment the following lines to turn on 4th scenario
118+
//.defineSourceControl()
119+
// .withContinuouslyIntegratedGitHubRepository("username", "reponame")
120+
// .withBranch("master")
121+
// .withGitHubAccessToken("YOUR GITHUB PERSONAL TOKEN")
122+
// .attach()
123+
.createAsync());
124+
}).flatMap(app -> {
125+
System.out.println("Created web app " + app.name());
126+
if (!app.name().equals(app2Name)) {
127+
return Flux.just(app);
128+
}
129+
// for the second web app Deploy a local Tomcat
130+
return app.getPublishingProfileAsync()
131+
.map(profile -> {
132+
System.out.println("Deploying a local Tomcat source to " + app2Name + " through Git...");
133+
Git git = null;
134+
try {
135+
git = Git
136+
.init()
137+
.setDirectory(new File(
138+
ManageWebAppSourceControlAsync.class.getResource(
139+
"/azure-samples-appservice-helloworld/")
140+
.getPath()))
141+
.call();
142+
git.add().addFilepattern(".").call();
143+
git.commit().setMessage("Initial commit").call();
144+
PushCommand command = git.push();
145+
command.setRemote(profile.gitUrl());
146+
command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(profile.gitUsername(), profile.gitPassword()));
147+
command.setRefSpecs(new RefSpec("master:master"));
148+
command.setForce(true);
149+
command.call();
150+
} catch (GitAPIException e) {
151+
e.printStackTrace();
152+
}
153+
System.out.println("Deployment to web app " + app2Name + " completed");
154+
return profile;
155+
});
156+
});
157+
158+
Flux.merge(app1Observable, app234Observable).blockLast();
159+
160+
// warm up
161+
System.out.println("Warming up " + app1Url + "/helloworld...");
162+
Utils.sendGetRequest("http://" + app1Url + "/helloworld/");
163+
System.out.println("Warming up " + app2Url + "/helloworld...");
164+
Utils.sendGetRequest("http://" + app2Url + "/helloworld/");
165+
System.out.println("Warming up " + app3Url + "...");
166+
Utils.sendGetRequest("http://" + app3Url);
167+
System.out.println("Warming up " + app4Url + "...");
168+
Utils.sendGetRequest("http://" + app4Url);
169+
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
170+
System.out.println("CURLing " + app1Url + "/helloworld...");
171+
System.out.println(Utils.sendGetRequest("http://" + app1Url + "/helloworld/"));
172+
System.out.println("CURLing " + app2Url + "/helloworld...");
173+
System.out.println(Utils.sendGetRequest("http://" + app2Url + "/helloworld/"));
174+
System.out.println("CURLing " + app3Url + "...");
175+
System.out.println(Utils.sendGetRequest("http://" + app3Url));
176+
System.out.println("CURLing " + app4Url + "...");
177+
System.out.println(Utils.sendGetRequest("http://" + app4Url));
178+
179+
return true;
180+
} finally {
181+
try {
182+
System.out.println("Deleting Resource Group: " + rgName);
183+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
184+
System.out.println("Deleted Resource Group: " + rgName);
185+
} catch (NullPointerException npe) {
186+
System.out.println("Did not create any resources in Azure. No clean up is necessary");
187+
} catch (Exception g) {
188+
g.printStackTrace();
189+
}
190+
}
191+
}
192+
/**
193+
* Main entry point.
194+
* @param args the parameters
195+
*/
196+
public static void main(String[] args) {
197+
try {
198+
199+
//=============================================================
200+
// Authenticate
201+
202+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
203+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
204+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
205+
.build();
206+
207+
AzureResourceManager azureResourceManager = AzureResourceManager
208+
.configure()
209+
.withLogLevel(HttpLogDetailLevel.BASIC)
210+
.authenticate(credential, profile)
211+
.withDefaultSubscription();
212+
213+
// Print selected subscription
214+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
215+
216+
runSample(azureResourceManager);
217+
} catch (Exception e) {
218+
System.out.println(e.getMessage());
219+
e.printStackTrace();
220+
}
221+
}
222+
}

0 commit comments

Comments
 (0)