Skip to content

Commit 250e63d

Browse files
committed
Adding sample template for private dns
1 parent 861d3c1 commit 250e63d

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

azure-samples/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@
192192
<artifactId>azure-eventhubs</artifactId>
193193
<version>1.0.0</version>
194194
</dependency>
195+
<dependency>
196+
<groupId>com.microsoft.azure.privatedns.v2018_09_01</groupId>
197+
<artifactId>azure-mgmt-privatedns</artifactId>
198+
<version>1.0.0-beta</version>
199+
</dependency>
195200
</dependencies>
196201
<build>
197202
<plugins>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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.network.samples;
8+
9+
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
10+
import com.microsoft.azure.management.Azure;
11+
import com.microsoft.azure.management.network.Network;
12+
import com.microsoft.azure.management.privatedns.v2018_09_01.implementation.privatednsManager;
13+
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
14+
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
15+
import com.microsoft.rest.LogLevel;
16+
17+
import java.io.File;
18+
19+
public class ManagePrivateDns {
20+
/**
21+
* Main function which runs the actual sample.
22+
* @param azure instance of the azure client
23+
* @param prDnsManager instance of PrivateDns client
24+
* @return true if sample runs successfully
25+
*/
26+
public static boolean runSample(Azure azure, privatednsManager prDnsManager) {
27+
final Region region = Region.US_EAST;
28+
final String rgName = SdkContext.randomResourceName("rg", 24);
29+
final String nwName = SdkContext.randomResourceName("nw", 24);
30+
31+
try {
32+
Network network = azure.networks().define(nwName)
33+
.withRegion(Region.US_EAST)
34+
.withNewResourceGroup(rgName)
35+
.withAddressSpace("10.0.0.0/27")
36+
.withSubnet("subnet1", "10.0.0.0/27")
37+
.create();
38+
//
39+
// Private DNS hybrid sample
40+
//
41+
return true;
42+
} catch (Exception e) {
43+
System.err.println(e.getMessage());
44+
e.printStackTrace();
45+
} finally {
46+
try {
47+
System.out.println("Deleting Resource Group: " + rgName);
48+
azure.resourceGroups().beginDeleteByName(rgName);
49+
} catch (NullPointerException npe) {
50+
System.out.println("Did not create any resources in Azure. No clean up is necessary");
51+
} catch (Exception g) {
52+
g.printStackTrace();
53+
}
54+
}
55+
return false;
56+
}
57+
58+
/**
59+
* Main entry point.
60+
* @param args the parameters
61+
*/
62+
public static void main(String[] args) {
63+
try {
64+
//=============================================================
65+
// Authenticate
66+
67+
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
68+
final ApplicationTokenCredentials cred = ApplicationTokenCredentials.fromFile(credFile);
69+
//
70+
Azure azure = Azure.configure()
71+
.withLogLevel(LogLevel.BODY)
72+
.authenticate(credFile)
73+
.withDefaultSubscription();
74+
privatednsManager prDnsManager = privatednsManager.authenticate(cred, cred.defaultSubscriptionId());
75+
// Print selected subscription
76+
//
77+
System.out.println("Selected subscription: " + azure.subscriptionId());
78+
//
79+
runSample(azure, prDnsManager);
80+
} catch (Exception e) {
81+
System.out.println(e.getMessage());
82+
e.printStackTrace();
83+
}
84+
}
85+
86+
private ManagePrivateDns() {
87+
}
88+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.samples;
8+
9+
import com.microsoft.azure.management.network.samples.ManagePrivateDns;
10+
import com.microsoft.azure.management.privatedns.v2018_09_01.implementation.privatednsManager;
11+
import org.junit.Assert;
12+
import org.junit.Ignore;
13+
import org.junit.Test;
14+
15+
public class PrivateDnsSampleTests extends SamplesTestBase {
16+
@Test
17+
@Ignore
18+
public void testManagePrivateDns() {
19+
privatednsManager prDnsManager = privatednsManager.authenticate(restClient, azure.subscriptionId());
20+
Assert.assertTrue(ManagePrivateDns.runSample(azure, prDnsManager));
21+
}
22+
}

azure-samples/src/test/java/com/microsoft/azure/management/samples/SamplesTestBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
public class SamplesTestBase extends TestBase {
1414
protected Azure azure;
15+
protected RestClient restClient;
1516

1617
public SamplesTestBase() {
1718
super(RunCondition.BOTH);
@@ -23,7 +24,8 @@ public SamplesTestBase(RunCondition runCondition) {
2324

2425
@Override
2526
protected void initializeClients(RestClient restClient, String defaultSubscription, String domain) {
26-
azure = Azure
27+
this.restClient = restClient;
28+
this.azure = Azure
2729
.authenticate(restClient, domain, defaultSubscription).withSubscription(defaultSubscription);
2830
}
2931

0 commit comments

Comments
 (0)