Skip to content

Commit 99c315b

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent d9fde04 commit 99c315b

File tree

4 files changed

+1685
-1443
lines changed

4 files changed

+1685
-1443
lines changed

README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ 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 Network Interface - in Java #
1313

1414

1515
Azure Network sample for managing network interfaces -
16-
- Create a virtual machine with multiple network interfaces
17-
- Configure a network interface
18-
- List network interfaces
19-
- Delete a network interface.
16+
- Create a virtual machine with multiple network interfaces
17+
- Configure a network interface
18+
- List network interfaces
19+
- Delete a network interface.
2020

2121

2222
## Running this Sample ##
2323

2424
To run this sample:
2525

26-
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).
26+
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).
2727

2828
git clone https://github.com/Azure-Samples/network-java-manage-network-interface.git
2929

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

3434
## More information ##
3535

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

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

4042
---
4143

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.network.samples.ManageNetworkInterface</mainClass>
18+
<mainClass>com.azure.resourcemanager.network.samples.ManageNetworkInterface</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.ManageNetworkInterface.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.network.samples.ManageNetworkInterface.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/ManageNetworkInterface.java renamed to src/main/java/com/azure/resourcemanager/network/samples/ManageNetworkInterface.java

+65-67
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
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.
3+
4+
package com.azure.resourcemanager.network.samples;
5+
6+
import com.azure.core.credential.TokenCredential;
7+
import com.azure.core.http.policy.HttpLogDetailLevel;
8+
import com.azure.core.http.rest.PagedIterable;
9+
import com.azure.core.management.AzureEnvironment;
10+
import com.azure.identity.DefaultAzureCredentialBuilder;
11+
import com.azure.resourcemanager.AzureResourceManager;
12+
import com.azure.resourcemanager.compute.models.KnownWindowsVirtualMachineImage;
13+
import com.azure.resourcemanager.compute.models.VirtualMachine;
14+
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
15+
import com.azure.resourcemanager.network.models.Network;
16+
import com.azure.resourcemanager.network.models.NetworkInterface;
17+
import com.azure.core.management.Region;
18+
import com.azure.core.management.profile.AzureProfile;
19+
import com.azure.resourcemanager.samples.Utils;
620

7-
package com.microsoft.azure.management.network.samples;
8-
9-
import com.microsoft.azure.PagedList;
10-
import com.microsoft.azure.management.Azure;
11-
import com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage;
12-
import com.microsoft.azure.management.compute.VirtualMachine;
13-
import com.microsoft.azure.management.compute.VirtualMachineSizeTypes;
14-
import com.microsoft.azure.management.network.Network;
15-
import com.microsoft.azure.management.network.NetworkInterface;
16-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
17-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
18-
import com.microsoft.azure.management.samples.Utils;
19-
import com.microsoft.rest.LogLevel;
20-
21-
import java.io.File;
2221
import java.util.Date;
2322

2423
/**
2524
* Azure Network sample for managing network interfaces -
26-
* - Create a virtual machine with multiple network interfaces
27-
* - Configure a network interface
28-
* - List network interfaces
29-
* - Delete a network interface.
25+
* - Create a virtual machine with multiple network interfaces
26+
* - Configure a network interface
27+
* - List network interfaces
28+
* - Delete a network interface.
3029
*/
3130

3231
public final class ManageNetworkInterface {
3332

3433
/**
3534
* Main function which runs the actual sample.
36-
* @param azure instance of the azure client
35+
*
36+
* @param azureResourceManager instance of the azure client
3737
* @return true if sample runs successfully
3838
*/
39-
public static boolean runSample(Azure azure) {
39+
public static boolean runSample(AzureResourceManager azureResourceManager) {
4040
final Region region = Region.US_NORTH_CENTRAL;
41-
final String vnetName = SdkContext.randomResourceName("vnet", 24);
42-
final String networkInterfaceName1 = SdkContext.randomResourceName("nic1", 24);
43-
final String networkInterfaceName2 = SdkContext.randomResourceName("nic2", 24);
44-
final String networkInterfaceName3 = SdkContext.randomResourceName("nic3", 24);
45-
final String publicIPAddressLeafDNS1 = SdkContext.randomResourceName("pip1", 24);
46-
final String publicIPAddressLeafDNS2 = SdkContext.randomResourceName("pip2", 24);
47-
48-
// TODO adjust the length of vm name from 8 to 24
49-
final String vmName = SdkContext.randomResourceName("vm", 8);
50-
final String rgName = SdkContext.randomResourceName("rgNEMI", 24);
41+
final String vnetName = Utils.randomResourceName(azureResourceManager, "vnet", 24);
42+
final String networkInterfaceName1 = Utils.randomResourceName(azureResourceManager, "nic1", 24);
43+
final String networkInterfaceName2 = Utils.randomResourceName(azureResourceManager, "nic2", 24);
44+
final String networkInterfaceName3 = Utils.randomResourceName(azureResourceManager, "nic3", 24);
45+
final String publicIPAddressLeafDNS1 = Utils.randomResourceName(azureResourceManager, "pip1", 24);
46+
final String publicIPAddressLeafDNS2 = Utils.randomResourceName(azureResourceManager, "pip2", 24);
47+
48+
// TODO: adjust the length of vm name from 8 to 24
49+
final String vmName = Utils.randomResourceName(azureResourceManager, "vm", 8);
50+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgNEMI", 24);
5151
final String userName = "tirekicker";
52-
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
53-
final String password = SdkContext.randomResourceName("Pa5$", 24);
52+
final String password = Utils.password();
5453
try {
5554

5655
//============================================================
@@ -60,19 +59,19 @@ public static boolean runSample(Azure azure) {
6059

6160
System.out.println("Creating a virtual network ...");
6261

63-
Network network = azure.networks().define(vnetName)
62+
Network network = azureResourceManager.networks().define(vnetName)
6463
.withRegion(region)
6564
.withNewResourceGroup(rgName)
6665
.withAddressSpace("172.16.0.0/16")
6766
.defineSubnet("Front-end")
68-
.withAddressPrefix("172.16.1.0/24")
69-
.attach()
67+
.withAddressPrefix("172.16.1.0/24")
68+
.attach()
7069
.defineSubnet("Mid-tier")
71-
.withAddressPrefix("172.16.2.0/24")
72-
.attach()
70+
.withAddressPrefix("172.16.2.0/24")
71+
.attach()
7372
.defineSubnet("Back-end")
74-
.withAddressPrefix("172.16.3.0/24")
75-
.attach()
73+
.withAddressPrefix("172.16.3.0/24")
74+
.attach()
7675
.create();
7776

7877
System.out.println("Created a virtual network: " + network.id());
@@ -81,7 +80,7 @@ public static boolean runSample(Azure azure) {
8180
System.out.println("Creating multiple network interfaces");
8281
System.out.println("Creating network interface 1");
8382

84-
NetworkInterface networkInterface1 = azure.networkInterfaces().define(networkInterfaceName1)
83+
NetworkInterface networkInterface1 = azureResourceManager.networkInterfaces().define(networkInterfaceName1)
8584
.withRegion(region)
8685
.withExistingResourceGroup(rgName)
8786
.withExistingPrimaryNetwork(network)
@@ -95,7 +94,7 @@ public static boolean runSample(Azure azure) {
9594
Utils.print(networkInterface1);
9695
System.out.println("Creating network interface 2");
9796

98-
NetworkInterface networkInterface2 = azure.networkInterfaces().define(networkInterfaceName2)
97+
NetworkInterface networkInterface2 = azureResourceManager.networkInterfaces().define(networkInterfaceName2)
9998
.withRegion(region)
10099
.withExistingResourceGroup(rgName)
101100
.withExistingPrimaryNetwork(network)
@@ -108,7 +107,7 @@ public static boolean runSample(Azure azure) {
108107

109108
System.out.println("Creating network interface 3");
110109

111-
NetworkInterface networkInterface3 = azure.networkInterfaces().define(networkInterfaceName3)
110+
NetworkInterface networkInterface3 = azureResourceManager.networkInterfaces().define(networkInterfaceName3)
112111
.withRegion(region)
113112
.withExistingResourceGroup(rgName)
114113
.withExistingPrimaryNetwork(network)
@@ -127,7 +126,7 @@ public static boolean runSample(Azure azure) {
127126

128127
Date t1 = new Date();
129128

130-
VirtualMachine vm = azure.virtualMachines().define(vmName)
129+
VirtualMachine vm = azureResourceManager.virtualMachines().define(vmName)
131130
.withRegion(region)
132131
.withExistingResourceGroup(rgName)
133132
.withExistingPrimaryNetworkInterface(networkInterface1)
@@ -162,7 +161,7 @@ public static boolean runSample(Azure azure) {
162161
// List network interfaces
163162

164163
System.out.println("Walking through network inter4faces in resource group: " + rgName);
165-
PagedList<NetworkInterface> networkInterfaces = azure.networkInterfaces().listByResourceGroup(rgName);
164+
PagedIterable<NetworkInterface> networkInterfaces = azureResourceManager.networkInterfaces().listByResourceGroup(rgName);
166165
for (NetworkInterface networkinterface : networkInterfaces) {
167166
Utils.print(networkinterface);
168167
}
@@ -173,28 +172,23 @@ public static boolean runSample(Azure azure) {
173172

174173
System.out.println("Deleting a network interface: " + networkInterface2.id());
175174
System.out.println("First, deleting the vm");
176-
azure.virtualMachines().deleteById(vm.id());
175+
azureResourceManager.virtualMachines().deleteById(vm.id());
177176
System.out.println("Second, deleting the network interface");
178-
azure.networkInterfaces().deleteById(networkInterface2.id());
177+
azureResourceManager.networkInterfaces().deleteById(networkInterface2.id());
179178
System.out.println("Deleted network interface");
180179

181180
System.out.println("============================================================");
182181
System.out.println("Remaining network interfaces are ...");
183-
networkInterfaces = azure.networkInterfaces().listByResourceGroup(rgName);
182+
networkInterfaces = azureResourceManager.networkInterfaces().listByResourceGroup(rgName);
184183
for (NetworkInterface networkinterface : networkInterfaces) {
185184
Utils.print(networkinterface);
186185
}
187186
return true;
188-
} catch (Exception f) {
189-
190-
System.out.println(f.getMessage());
191-
f.printStackTrace();
192-
193187
} finally {
194188

195189
try {
196190
System.out.println("Deleting Resource Group: " + rgName);
197-
azure.resourceGroups().deleteByName(rgName);
191+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
198192
System.out.println("Deleted Resource Group: " + rgName);
199193
} catch (NullPointerException npe) {
200194
System.out.println("Did not create any resources in Azure. No clean up is necessary");
@@ -203,11 +197,11 @@ public static boolean runSample(Azure azure) {
203197
}
204198

205199
}
206-
return false;
207200
}
208201

209202
/**
210203
* Main entry point.
204+
*
211205
* @param args the parameters
212206
*/
213207
public static void main(String[] args) {
@@ -216,17 +210,21 @@ public static void main(String[] args) {
216210
//=============================================================
217211
// Authenticate
218212

219-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
213+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
214+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
215+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
216+
.build();
220217

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

226224
// Print selected subscription
227-
System.out.println("Selected subscription: " + azure.subscriptionId());
225+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
228226

229-
runSample(azure);
227+
runSample(azureResourceManager);
230228
} catch (Exception e) {
231229
System.out.println(e.getMessage());
232230
e.printStackTrace();

0 commit comments

Comments
 (0)