Skip to content

Commit 39a69ce

Browse files
committed
Release azure-resourcemanager 2.1.0
1 parent 80d55c4 commit 39a69ce

File tree

6 files changed

+1138
-829
lines changed

6 files changed

+1138
-829
lines changed

README.md

+5-3
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-deploy-image-from-acr-to-linux.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

+24-23
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.ManageLinuxWebAppWithContainerRegistry</mainClass>
18+
<mainClass>com.azure.resourcemanager.appservice.samples.ManageLinuxWebAppWithContainerRegistry</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.ManageLinuxWebAppWithContainerRegistry.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.appservice.samples.ManageLinuxWebAppWithContainerRegistry.java</mainClass>
4445
</manifest>
4546
</archive>
4647
</configuration>
@@ -51,39 +52,39 @@
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.1.0</version>
5758
</dependency>
5859
<dependency>
59-
<groupId>commons-net</groupId>
60-
<artifactId>commons-net</artifactId>
61-
<version>3.3</version>
60+
<groupId>com.azure</groupId>
61+
<artifactId>azure-identity</artifactId>
62+
<version>1.2.0</version>
6263
</dependency>
6364
<dependency>
64-
<groupId>commons-lang</groupId>
65-
<artifactId>commons-lang</artifactId>
66-
<version>2.6</version>
65+
<groupId>com.jcraft</groupId>
66+
<artifactId>jsch</artifactId>
67+
<version>0.1.55</version>
6768
</dependency>
6869
<dependency>
69-
<groupId>org.apache.commons</groupId>
70-
<artifactId>commons-lang3</artifactId>
71-
<version>3.7</version>
70+
<groupId>commons-net</groupId>
71+
<artifactId>commons-net</artifactId>
72+
<version>3.6</version>
7273
</dependency>
7374
<dependency>
74-
<groupId>com.jcraft</groupId>
75-
<artifactId>jsch</artifactId>
76-
<version>0.1.55</version>
75+
<groupId>com.github.docker-java</groupId>
76+
<artifactId>docker-java</artifactId>
77+
<version>3.2.1</version>
7778
</dependency>
7879
<dependency>
7980
<groupId>com.github.cverges.expect4j</groupId>
8081
<artifactId>expect4j</artifactId>
8182
<version>1.6</version>
8283
</dependency>
8384
<dependency>
84-
<groupId>com.github.docker-java</groupId>
85-
<artifactId>docker-java</artifactId>
86-
<version>3.0.6</version>
85+
<groupId>com.github.spotbugs</groupId>
86+
<artifactId>spotbugs-annotations</artifactId>
87+
<version>4.0.2</version>
8788
</dependency>
8889
</dependencies>
8990
</project>
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
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-
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.identity.DefaultAzureCredentialBuilder;
10+
import com.azure.resourcemanager.AzureResourceManager;
11+
import com.azure.resourcemanager.appservice.models.PricingTier;
12+
import com.azure.resourcemanager.appservice.models.WebApp;
13+
import com.azure.resourcemanager.containerregistry.models.AccessKeyType;
14+
import com.azure.resourcemanager.containerregistry.models.Registry;
15+
import com.azure.resourcemanager.containerregistry.models.RegistryCredentials;
16+
import com.azure.core.management.Region;
17+
import com.azure.core.management.profile.AzureProfile;
18+
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
19+
import com.azure.resourcemanager.samples.DockerUtils;
20+
import com.azure.resourcemanager.samples.Utils;
921
import com.github.dockerjava.api.DockerClient;
1022
import com.github.dockerjava.api.command.CreateContainerResponse;
23+
import com.github.dockerjava.api.command.PullImageResultCallback;
1124
import com.github.dockerjava.api.exception.NotFoundException;
25+
import com.github.dockerjava.api.model.AuthConfig;
1226
import com.github.dockerjava.api.model.Image;
13-
import com.github.dockerjava.core.command.PullImageResultCallback;
1427
import com.github.dockerjava.core.command.PushImageResultCallback;
15-
import com.microsoft.azure.management.Azure;
16-
import com.microsoft.azure.management.appservice.PricingTier;
17-
import com.microsoft.azure.management.appservice.WebApp;
18-
import com.microsoft.azure.management.containerregistry.AccessKeyType;
19-
import com.microsoft.azure.management.containerregistry.Registry;
20-
import com.microsoft.azure.management.containerregistry.RegistryCredentials;
21-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
22-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
23-
import com.microsoft.azure.management.samples.DockerUtils;
24-
import com.microsoft.azure.management.samples.Utils;
25-
import com.microsoft.rest.LogLevel;
26-
import okhttp3.OkHttpClient;
27-
import okhttp3.Request;
28-
29-
import java.io.File;
28+
3029
import java.io.IOException;
30+
import java.time.Duration;
3131
import java.util.Date;
3232
import java.util.List;
33-
import java.util.concurrent.TimeUnit;
3433

3534
/**
3635
* Azure App Service sample for deploying from an Azure Container Registry.
@@ -44,18 +43,16 @@
4443
*/
4544
public class ManageLinuxWebAppWithContainerRegistry {
4645

47-
private static OkHttpClient httpClient;
48-
4946
/**
5047
* Main function which runs the actual sample.
5148
*
52-
* @param azure instance of the azure client
49+
* @param azureResourceManager instance of the azure client
5350
* @return true if sample runs successfully
5451
*/
55-
public static boolean runSample(Azure azure) {
56-
final String rgName = SdkContext.randomResourceName("rgACR", 15);
57-
final String acrName = SdkContext.randomResourceName("acrsample", 20);
58-
final String appName = SdkContext.randomResourceName("webapp", 20);
52+
public static boolean runSample(AzureResourceManager azureResourceManager) throws IOException, InterruptedException {
53+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgACR", 15);
54+
final String acrName = Utils.randomResourceName(azureResourceManager, "acrsample", 20);
55+
final String appName = Utils.randomResourceName(azureResourceManager, "webapp", 20);
5956
final String appUrl = appName + ".azurewebsites.net";
6057
final Region region = Region.US_EAST;
6158
final String dockerImageName = "tomcat";
@@ -70,7 +67,7 @@ public static boolean runSample(Azure azure) {
7067

7168
Date t1 = new Date();
7269

73-
Registry azureRegistry = azure.containerRegistries().define(acrName)
70+
Registry azureRegistry = azureResourceManager.containerRegistries().define(acrName)
7471
.withRegion(region)
7572
.withNewResourceGroup(rgName)
7673
.withBasicSku()
@@ -86,7 +83,7 @@ public static boolean runSample(Azure azure) {
8683
// Create a Docker client that will be used to push/pull images to/from the Azure Container Registry
8784

8885
RegistryCredentials acrCredentials = azureRegistry.getCredentials();
89-
DockerClient dockerClient = DockerUtils.createDockerClient(azure, rgName, region,
86+
DockerClient dockerClient = DockerUtils.createDockerClient(azureResourceManager, rgName, region,
9087
azureRegistry.loginServerUrl(), acrCredentials.username(), acrCredentials.accessKeys().get(AccessKeyType.PRIMARY));
9188

9289
//=============================================================
@@ -95,12 +92,13 @@ public static boolean runSample(Azure azure) {
9592

9693
dockerClient.pullImageCmd(dockerImageName)
9794
.withTag(dockerImageTag)
95+
.withAuthConfig(new AuthConfig())
9896
.exec(new PullImageResultCallback())
99-
.awaitSuccess();
97+
.awaitCompletion();
10098
System.out.println("List local Docker images:");
10199
List<Image> images = dockerClient.listImagesCmd().withShowAll(true).exec();
102100
for (Image image : images) {
103-
System.out.format("\tFound Docker image %s (%s)\n", image.getRepoTags()[0], image.getId());
101+
System.out.format("\tFound Docker image %s (%s)%n", image.getRepoTags()[0], image.getId());
104102
}
105103

106104
CreateContainerResponse dockerContainerInstance = dockerClient.createContainerCmd(dockerImageName + ":" + dockerImageTag)
@@ -111,9 +109,9 @@ public static boolean runSample(Azure azure) {
111109
// Commit the new container
112110

113111
String privateRepoUrl = azureRegistry.loginServerUrl() + "/samples/" + dockerContainerName;
114-
String dockerImageId = dockerClient.commitCmd(dockerContainerInstance.getId())
115-
.withRepository(privateRepoUrl)
116-
.withTag("latest").exec();
112+
dockerClient.commitCmd(dockerContainerInstance.getId())
113+
.withRepository(privateRepoUrl)
114+
.withTag("latest").exec();
117115

118116
// We can now remove the temporary container instance
119117
dockerClient.removeContainerCmd(dockerContainerInstance.getId())
@@ -139,7 +137,7 @@ public static boolean runSample(Azure azure) {
139137

140138
System.out.println("Creating web app " + appName + " in resource group " + rgName + "...");
141139

142-
WebApp app = azure.webApps().define(appName)
140+
WebApp app = azureResourceManager.webApps().define(appName)
143141
.withRegion(Region.US_WEST)
144142
.withExistingResourceGroup(rgName)
145143
.withNewLinuxPlan(PricingTier.STANDARD_S1)
@@ -153,27 +151,23 @@ public static boolean runSample(Azure azure) {
153151

154152
// warm up
155153
System.out.println("Warming up " + appUrl + "...");
156-
curl("http://" + appUrl);
157-
SdkContext.sleep(5000);
154+
Utils.sendGetRequest("http://" + appUrl);
155+
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
158156
System.out.println("CURLing " + appUrl + "...");
159-
System.out.println(curl("http://" + appUrl));
157+
System.out.println(Utils.sendGetRequest("http://" + appUrl));
160158

161159
return true;
162-
} catch (Exception f) {
163-
System.out.println(f.getMessage());
164-
f.printStackTrace();
165160
} finally {
166161
try {
167162
System.out.println("Deleting Resource Group: " + rgName);
168-
azure.resourceGroups().beginDeleteByName(rgName);
163+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
169164
System.out.println("Deleted Resource Group: " + rgName);
170165
} catch (NullPointerException npe) {
171166
System.out.println("Did not create any resources in Azure. No clean up is necessary");
172167
} catch (Exception g) {
173168
g.printStackTrace();
174169
}
175170
}
176-
return false;
177171
}
178172

179173
/**
@@ -186,33 +180,24 @@ public static void main(String[] args) {
186180
//=============================================================
187181
// Authenticate
188182

189-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
183+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
184+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
185+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
186+
.build();
190187

191-
Azure azure = Azure.configure()
192-
.withLogLevel(LogLevel.BODY)
193-
.authenticate(credFile)
194-
.withDefaultSubscription();
188+
AzureResourceManager azureResourceManager = AzureResourceManager
189+
.configure()
190+
.withLogLevel(HttpLogDetailLevel.BASIC)
191+
.authenticate(credential, profile)
192+
.withDefaultSubscription();
195193

196194
// Print selected subscription
197-
System.out.println("Selected subscription: " + azure.subscriptionId());
195+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
198196

199-
runSample(azure);
197+
runSample(azureResourceManager);
200198
} catch (Exception e) {
201199
System.out.println(e.getMessage());
202200
e.printStackTrace();
203201
}
204202
}
205-
206-
private static String curl(String url) {
207-
Request request = new Request.Builder().url(url).get().build();
208-
try {
209-
return httpClient.newCall(request).execute().body().string();
210-
} catch (IOException e) {
211-
return null;
212-
}
213-
}
214-
215-
static {
216-
httpClient = new OkHttpClient.Builder().readTimeout(1, TimeUnit.MINUTES).build();
217-
}
218-
}
203+
}

0 commit comments

Comments
 (0)