Skip to content
This repository was archived by the owner on Jun 15, 2026. It is now read-only.

Commit 696373d

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 80861c3 commit 696373d

4 files changed

Lines changed: 1670 additions & 1424 deletions

File tree

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ languages:
55
products:
66
- azure
77
extensions:
8-
services: virtual-network
8+
services: Network
99
platforms: java
1010
---
1111

1212
# Getting Started with Network - Manage Express Route - in Java #
1313

1414

1515
Azure Network sample for managing express route circuits.
16-
- Create Express Route circuit
17-
- Create Express Route circuit peering. Please note: express route circuit should be provisioned by connectivity provider before this step.
18-
- Adding authorization to express route circuit
19-
- Create virtual network to be associated with virtual network gateway
20-
- Create virtual network gateway
21-
- Create virtual network gateway connection
16+
- Create Express Route circuit
17+
- Create Express Route circuit peering. Please note: express route circuit should be provisioned by connectivity provider before this step.
18+
- Adding authorization to express route circuit
19+
- Create virtual network to be associated with virtual network gateway
20+
- Create virtual network gateway
21+
- Create virtual network gateway connection
2222

2323

2424
## Running this Sample ##
2525

2626
To run this sample:
2727

28-
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).
28+
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).
2929

3030
git clone https://github.com/Azure-Samples/network-java-manage-express-route.git
3131

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

3636
## More information ##
3737

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

40-
If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212)
40+
Start to develop applications with Java on Azure [here](http://azure.com/java).
41+
42+
If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212).
4143

4244
---
4345

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.network.samples.ManageExpressRoute</mainClass>
18+
<mainClass>com.azure.resourcemanager.network.samples.ManageExpressRoute</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.network.samples.ManageExpressRoute.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.network.samples.ManageExpressRoute.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>

src/main/java/com/microsoft/azure/management/network/samples/ManageExpressRoute.java renamed to src/main/java/com/azure/resourcemanager/network/samples/ManageExpressRoute.java

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
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-
package com.microsoft.azure.management.network.samples;
7-
8-
import com.microsoft.azure.management.Azure;
9-
import com.microsoft.azure.management.network.ExpressRouteCircuit;
10-
import com.microsoft.azure.management.network.ExpressRouteCircuitSkuType;
11-
import com.microsoft.azure.management.network.Network;
12-
import com.microsoft.azure.management.network.VirtualNetworkGateway;
13-
import com.microsoft.azure.management.network.VirtualNetworkGatewaySkuName;
14-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
15-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
16-
import com.microsoft.rest.LogLevel;
17-
18-
import java.io.File;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.azure.resourcemanager.network.samples;
4+
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.network.models.ExpressRouteCircuit;
12+
import com.azure.resourcemanager.network.models.ExpressRouteCircuitSkuType;
13+
import com.azure.resourcemanager.network.models.Network;
14+
import com.azure.resourcemanager.network.models.VirtualNetworkGateway;
15+
import com.azure.resourcemanager.network.models.VirtualNetworkGatewaySkuName;
16+
import com.azure.core.management.Region;
17+
import com.azure.core.management.profile.AzureProfile;
18+
import com.azure.resourcemanager.samples.Utils;
1919

2020
/**
2121
* Azure Network sample for managing express route circuits.
22-
* - Create Express Route circuit
23-
* - Create Express Route circuit peering. Please note: express route circuit should be provisioned by connectivity provider before this step.
24-
* - Adding authorization to express route circuit
25-
* - Create virtual network to be associated with virtual network gateway
26-
* - Create virtual network gateway
27-
* - Create virtual network gateway connection
22+
* - Create Express Route circuit
23+
* - Create Express Route circuit peering. Please note: express route circuit should be provisioned by connectivity provider before this step.
24+
* - Adding authorization to express route circuit
25+
* - Create virtual network to be associated with virtual network gateway
26+
* - Create virtual network gateway
27+
* - Create virtual network gateway connection
2828
*/
2929
public final class ManageExpressRoute {
3030

3131
/**
3232
* Main function which runs the actual sample.
33-
* @param azure instance of the azure client
33+
*
34+
* @param azureResourceManager instance of the azure client
3435
* @return true if sample runs successfully
3536
*/
36-
public static boolean runSample(Azure azure) {
37+
public static boolean runSample(AzureResourceManager azureResourceManager) {
3738
final Region region = Region.US_NORTH_CENTRAL;
38-
final String rgName = SdkContext.randomResourceName("rg", 20);
39-
final String ercName = SdkContext.randomResourceName("erc", 20);
40-
final String gatewayName = SdkContext.randomResourceName("gtw", 20);
41-
final String connectionName = SdkContext.randomResourceName("con", 20);
42-
final String vnetName = SdkContext.randomResourceName("vnet", 20);
39+
final String rgName = Utils.randomResourceName(azureResourceManager, "rg", 20);
40+
final String ercName = Utils.randomResourceName(azureResourceManager, "erc", 20);
41+
final String gatewayName = Utils.randomResourceName(azureResourceManager, "gtw", 20);
42+
final String connectionName = Utils.randomResourceName(azureResourceManager, "con", 20);
43+
final String vnetName = Utils.randomResourceName(azureResourceManager, "vnet", 20);
4344

4445
try {
4546
//============================================================
4647
// create Express Route Circuit
4748
System.out.println("Creating express route circuit...");
48-
ExpressRouteCircuit erc = azure.expressRouteCircuits().define(ercName)
49+
ExpressRouteCircuit erc = azureResourceManager.expressRouteCircuits().define(ercName)
4950
.withRegion(region)
5051
.withNewResourceGroup(rgName)
5152
.withServiceProvider("Equinix")
@@ -75,7 +76,7 @@ public static boolean runSample(Azure azure) {
7576
//============================================================
7677
// Create virtual network to be associated with virtual network gateway
7778
System.out.println("Creating virtual network...");
78-
Network network = azure.networks().define(vnetName)
79+
Network network = azureResourceManager.networks().define(vnetName)
7980
.withRegion(region)
8081
.withExistingResourceGroup(rgName)
8182
.withAddressSpace("192.168.0.0/16")
@@ -86,7 +87,7 @@ public static boolean runSample(Azure azure) {
8687
//============================================================
8788
// Create virtual network gateway
8889
System.out.println("Creating virtual network gateway...");
89-
VirtualNetworkGateway vngw1 = azure.virtualNetworkGateways().define(gatewayName)
90+
VirtualNetworkGateway vngw1 = azureResourceManager.virtualNetworkGateways().define(gatewayName)
9091
.withRegion(region)
9192
.withNewResourceGroup(rgName)
9293
.withExistingNetwork(network)
@@ -106,41 +107,42 @@ public static boolean runSample(Azure azure) {
106107
System.out.println("Created virtual network gateway connection");
107108

108109
return true;
109-
} catch (Exception e) {
110-
System.err.println(e.getMessage());
111-
e.printStackTrace();
112110
} finally {
113111
try {
114112
System.out.println("Deleting Resource Group: " + rgName);
115-
azure.resourceGroups().beginDeleteByName(rgName);
113+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
116114
} catch (NullPointerException npe) {
117115
System.out.println("Did not create any resources in Azure. No clean up is necessary");
118116
} catch (Exception g) {
119117
g.printStackTrace();
120118
}
121119
}
122-
return false;
123120
}
124121

125122
/**
126123
* Main entry point.
124+
*
127125
* @param args the parameters
128126
*/
129127
public static void main(String[] args) {
130128
try {
131129
//=============================================================
132130
// Authenticate
133-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
131+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
132+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
133+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
134+
.build();
134135

135-
Azure azure = Azure.configure()
136-
.withLogLevel(LogLevel.BODY)
137-
.authenticate(credFile)
138-
.withDefaultSubscription();
136+
AzureResourceManager azureResourceManager = AzureResourceManager
137+
.configure()
138+
.withLogLevel(HttpLogDetailLevel.BASIC)
139+
.authenticate(credential, profile)
140+
.withDefaultSubscription();
139141

140142
// Print selected subscription
141-
System.out.println("Selected subscription: " + azure.subscriptionId());
143+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
142144

143-
runSample(azure);
145+
runSample(azureResourceManager);
144146
} catch (Exception e) {
145147
System.out.println(e.getMessage());
146148
e.printStackTrace();

0 commit comments

Comments
 (0)