Skip to content

Commit ce262e6

Browse files
committed
Release azure-resourcemanager 2.1.0
1 parent ae09436 commit ce262e6

File tree

4 files changed

+1013
-706
lines changed

4 files changed

+1013
-706
lines changed

README.md

+5-3
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/aci-java-create-container-groups.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

+15-19
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.containerinstance.samples.ManageContainerInstanceWithMultipleContainerImages</mainClass>
18+
<mainClass>com.azure.resourcemanager.containerinstance.samples.ManageContainerInstanceWithMultipleContainerImages</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.containerinstance.samples.ManageContainerInstanceWithMultipleContainerImages.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.containerinstance.samples.ManageContainerInstanceWithMultipleContainerImages.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.1.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.2.0</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>
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
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-
*/
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
63

7-
package com.microsoft.azure.management.containerinstance.samples;
4+
package com.azure.resourcemanager.containerinstance.samples;
85

9-
import com.microsoft.azure.management.Azure;
10-
import com.microsoft.azure.management.containerinstance.ContainerGroup;
11-
import com.microsoft.azure.management.containerinstance.ContainerGroupRestartPolicy;
12-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
13-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
14-
import com.microsoft.azure.management.samples.Utils;
15-
import com.microsoft.rest.LogLevel;
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.containerinstance.models.ContainerGroup;
12+
import com.azure.resourcemanager.containerinstance.models.ContainerGroupRestartPolicy;
13+
import com.azure.core.management.Region;
14+
import com.azure.core.management.profile.AzureProfile;
15+
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
16+
import com.azure.resourcemanager.samples.Utils;
1617

17-
import java.io.File;
18+
import java.time.Duration;
1819

1920
/**
2021
* Azure Container Instance sample for managing container instances.
@@ -28,20 +29,20 @@ public class ManageContainerInstanceWithMultipleContainerImages {
2829
/**
2930
* Main function which runs the actual sample.
3031
*
31-
* @param azure instance of the azure client
32+
* @param azureResourceManager instance of the azure client
3233
* @return true if sample runs successfully
3334
*/
34-
public static boolean runSample(Azure azure) {
35-
final String rgName = SdkContext.randomResourceName("rgACI", 15);
36-
final String aciName = SdkContext.randomResourceName("acisample", 20);
35+
public static boolean runSample(AzureResourceManager azureResourceManager) {
36+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgACI", 15);
37+
final String aciName = Utils.randomResourceName(azureResourceManager, "acisample", 20);
3738
final String containerImageName1 = "microsoft/aci-helloworld";
3839
final String containerImageName2 = "microsoft/aci-tutorial-sidecar";
3940

4041
try {
4142
//=============================================================
4243
// Create a container group with two container instances
4344

44-
ContainerGroup containerGroup = azure.containerGroups().define(aciName)
45+
ContainerGroup containerGroup = azureResourceManager.containerGroups().define(aciName)
4546
.withRegion(Region.US_WEST)
4647
.withNewResourceGroup(rgName)
4748
.withLinux()
@@ -70,40 +71,36 @@ public static boolean runSample(Azure azure) {
7071

7172
// warm up
7273
System.out.println("Warming up " + containerGroup.ipAddress());
73-
Utils.curl("http://" + containerGroup.ipAddress());
74-
SdkContext.sleep(15000);
74+
Utils.sendGetRequest("http://" + containerGroup.ipAddress());
75+
ResourceManagerUtils.sleep(Duration.ofSeconds(15));
7576
System.out.println("CURLing " + containerGroup.ipAddress());
76-
System.out.println(Utils.curl("http://" + containerGroup.ipAddress()));
77+
System.out.println(Utils.sendGetRequest("http://" + containerGroup.ipAddress()));
7778

7879
//=============================================================
7980
// Check the container instance logs
8081

8182
String logContent = containerGroup.getLogContent(aciName + "-1");
82-
System.out.format("Logs for container instance: %s\n%s", aciName + "-1", logContent);
83+
System.out.format("Logs for container instance: %s%n%s", aciName + "-1", logContent);
8384
logContent = containerGroup.getLogContent(aciName + "-2");
84-
System.out.format("Logs for container instance: %s\n%s", aciName + "-2", logContent);
85+
System.out.format("Logs for container instance: %s%n%s", aciName + "-2", logContent);
8586

8687
//=============================================================
8788
// Remove the container group
8889

89-
azure.containerGroups().deleteById(containerGroup.id());
90+
azureResourceManager.containerGroups().deleteById(containerGroup.id());
9091

9192
return true;
92-
} catch (Exception f) {
93-
System.out.println(f.getMessage());
94-
f.printStackTrace();
9593
} finally {
9694
try {
9795
System.out.println("Deleting Resource Group: " + rgName);
98-
azure.resourceGroups().beginDeleteByName(rgName);
96+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
9997
System.out.println("Deleted Resource Group: " + rgName);
10098
} catch (NullPointerException npe) {
10199
System.out.println("Did not create any resources in Azure. No clean up is necessary");
102100
} catch (Exception g) {
103101
g.printStackTrace();
104102
}
105103
}
106-
return false;
107104
}
108105

109106
/**
@@ -116,17 +113,21 @@ public static void main(String[] args) {
116113
//=============================================================
117114
// Authenticate
118115

119-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
116+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
117+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
118+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
119+
.build();
120120

121-
Azure azure = Azure.configure()
122-
.withLogLevel(LogLevel.BODY)
123-
.authenticate(credFile)
121+
AzureResourceManager azureResourceManager = AzureResourceManager
122+
.configure()
123+
.withLogLevel(HttpLogDetailLevel.BASIC)
124+
.authenticate(credential, profile)
124125
.withDefaultSubscription();
125126

126127
// Print selected subscription
127-
System.out.println("Selected subscription: " + azure.subscriptionId());
128+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
128129

129-
runSample(azure);
130+
runSample(azureResourceManager);
130131
} catch (Exception e) {
131132
System.out.println(e.getMessage());
132133
e.printStackTrace();

0 commit comments

Comments
 (0)