Skip to content

Commit 17e60f8

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent 8686f38 commit 17e60f8

File tree

4 files changed

+1653
-1413
lines changed

4 files changed

+1653
-1413
lines changed

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ languages:
55
products:
66
- azure
77
extensions:
8-
services: Cosmosdb
8+
services: Cosmos
99
platforms: java
1010
---
1111

12-
# Getting Started with Cosmosdb - Create Cosmos DB With IP Range - in Java #
12+
# Getting Started with Cosmos - Create Cosmos DB With IP Range - in Java #
1313

1414

1515
Azure CosmosDB sample for high availability.
@@ -21,7 +21,7 @@ extensions:
2121

2222
To run this sample:
2323

24-
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).
24+
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).
2525

2626
git clone https://github.com/Azure-Samples/cosmosdb-java-create-cosmosdb-and-configure-firewall.git
2727

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

3232
## More information ##
3333

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

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

3840
---
3941

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

+36-40
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
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.cosmosdb.samples;
8-
9-
import com.microsoft.azure.CloudException;
10-
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
11-
import com.microsoft.azure.management.Azure;
12-
import com.microsoft.azure.management.cosmosdb.DatabaseAccountKind;
13-
import com.microsoft.azure.management.cosmosdb.CosmosDBAccount;
14-
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
15-
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
16-
import com.microsoft.azure.management.samples.Utils;
17-
import com.microsoft.rest.LogLevel;
18-
19-
import java.io.File;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.cosmos.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.core.management.exception.ManagementException;
10+
import com.azure.identity.DefaultAzureCredentialBuilder;
11+
import com.azure.resourcemanager.AzureResourceManager;
12+
import com.azure.resourcemanager.cosmos.models.CosmosDBAccount;
13+
import com.azure.resourcemanager.cosmos.models.DatabaseAccountKind;
14+
import com.azure.core.management.Region;
15+
import com.azure.core.management.profile.AzureProfile;
16+
import com.azure.resourcemanager.samples.Utils;
2017

2118
/**
2219
* Azure CosmosDB sample for high availability.
@@ -26,20 +23,19 @@
2623
public final class CreateCosmosDBWithIPRange {
2724
/**
2825
* Main function which runs the actual sample.
29-
* @param azure instance of the azure client
30-
* @param clientId client id
26+
* @param azureResourceManager instance of the azure client
3127
* @return true if sample runs successfully
3228
*/
33-
public static boolean runSample(Azure azure, String clientId) {
34-
final String docDBName = SdkContext.randomResourceName("docDb", 10);
35-
final String rgName = SdkContext.randomResourceName("rgNEMV", 24);
29+
public static boolean runSample(AzureResourceManager azureResourceManager) {
30+
final String docDBName = Utils.randomResourceName(azureResourceManager, "docDb", 10);
31+
final String rgName = Utils.randomResourceName(azureResourceManager, "rgNEMV", 24);
3632

3733
try {
3834
//============================================================
3935
// Create a CosmosDB
4036

4137
System.out.println("Creating a CosmosDB...");
42-
CosmosDBAccount cosmosDBAccount = azure.cosmosDBAccounts().define(docDBName)
38+
CosmosDBAccount cosmosDBAccount = azureResourceManager.cosmosDBAccounts().define(docDBName)
4339
.withRegion(Region.US_EAST)
4440
.withNewResourceGroup(rgName)
4541
.withKind(DatabaseAccountKind.GLOBAL_DOCUMENT_DB)
@@ -55,29 +51,25 @@ public static boolean runSample(Azure azure, String clientId) {
5551
//============================================================
5652
// Delete CosmosDB
5753
System.out.println("Deleting the CosmosDB");
58-
// work around CosmosDB service issue returning 404 CloudException on delete operation
54+
// work around CosmosDB service issue returning 404 ManagementException on delete operation
5955
try {
60-
azure.cosmosDBAccounts().deleteById(cosmosDBAccount.id());
61-
} catch (CloudException e) {
56+
azureResourceManager.cosmosDBAccounts().deleteById(cosmosDBAccount.id());
57+
} catch (ManagementException e) {
6258
}
6359
System.out.println("Deleted the CosmosDB");
6460

6561
return true;
66-
} catch (Exception e) {
67-
System.err.println(e.getMessage());
6862
} finally {
6963
try {
7064
System.out.println("Deleting resource group: " + rgName);
71-
azure.resourceGroups().beginDeleteByName(rgName);
65+
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
7266
System.out.println("Deleted resource group: " + rgName);
7367
} catch (NullPointerException npe) {
7468
System.out.println("Did not create any resources in Azure. No clean up is necessary");
7569
} catch (Exception g) {
7670
g.printStackTrace();
7771
}
7872
}
79-
80-
return false;
8173
}
8274

8375
/**
@@ -90,17 +82,21 @@ public static void main(String[] args) {
9082
//=============================================================
9183
// Authenticate
9284

93-
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
85+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
86+
final TokenCredential credential = new DefaultAzureCredentialBuilder()
87+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
88+
.build();
9489

95-
Azure azure = Azure.configure()
96-
.withLogLevel(LogLevel.BASIC)
97-
.authenticate(credFile)
98-
.withDefaultSubscription();
90+
AzureResourceManager azureResourceManager = AzureResourceManager
91+
.configure()
92+
.withLogLevel(HttpLogDetailLevel.BASIC)
93+
.authenticate(credential, profile)
94+
.withDefaultSubscription();
9995

10096
// Print selected subscription
101-
System.out.println("Selected subscription: " + azure.subscriptionId());
97+
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
10298

103-
runSample(azure, ApplicationTokenCredentials.fromFile(credFile).clientId());
99+
runSample(azureResourceManager);
104100
} catch (Exception e) {
105101
System.out.println(e.getMessage());
106102
e.printStackTrace();

0 commit comments

Comments
 (0)