Skip to content

Commit f411eb4

Browse files
committed
Release 1.30.0
0 parents  commit f411eb4

File tree

7 files changed

+3464
-0
lines changed

7 files changed

+3464
-0
lines changed

.gitignore

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
*.class
2+
3+
# Auth filed
4+
*.auth
5+
*.azureauth
6+
7+
# Mobile Tools for Java (J2ME)
8+
.mtj.tmp/
9+
10+
# Package Files #
11+
*.jar
12+
*.war
13+
*.ear
14+
15+
# Azure Tooling #
16+
node_modules
17+
packages
18+
19+
# Eclipse #
20+
*.pydevproject
21+
.project
22+
.metadata
23+
bin/**
24+
tmp/**
25+
tmp/**/*
26+
*.tmp
27+
*.bak
28+
*.swp
29+
*~.nib
30+
local.properties
31+
.classpath
32+
.settings/
33+
.loadpath
34+
35+
# Other Tooling #
36+
.classpath
37+
.project
38+
target/
39+
.idea
40+
*.iml
41+
42+
# Mac OS #
43+
.DS_Store
44+
.DS_Store?
45+
46+
# Windows #
47+
Thumbs.db
48+
49+
# reduced pom files should not be included
50+
dependency-reduced-pom.xml

CONTRIBUTING.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Contributing to Azure samples
2+
3+
Thank you for your interest in contributing to Azure samples!
4+
5+
## Ways to contribute
6+
7+
You can contribute to [Azure samples](https://azure.microsoft.com/documentation/samples/) in a few different ways:
8+
9+
- Submit feedback on [this sample page](https://azure.microsoft.com/documentation/samples/cosmosdb-java-create-cosmosdb-and-configure-firewall/) whether it was helpful or not.
10+
- Submit issues through [issue tracker](https://github.com/Azure-Samples/cosmosdb-java-create-cosmosdb-and-configure-firewall/issues) on GitHub. We are actively monitoring the issues and improving our samples.
11+
- If you wish to make code changes to samples, or contribute something new, please follow the [GitHub Forks / Pull requests model](https://help.github.com/articles/fork-a-repo/): Fork the sample repo, make the change and propose it back by submitting a pull request.

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation. All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
page_type: sample
3+
languages:
4+
- java
5+
products:
6+
- azure
7+
extensions:
8+
- services: Cosmosdb
9+
- platforms: java
10+
---
11+
12+
# Getting Started with Cosmosdb - Create Cosmos DB With IP Range - in Java #
13+
14+
15+
Azure CosmosDB sample for high availability.
16+
- Create a CosmosDB configured with IP range filterR
17+
- Delete the CosmosDB.
18+
19+
20+
## Running this Sample ##
21+
22+
To run this sample:
23+
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).
25+
26+
git clone https://github.com/Azure-Samples/cosmosdb-java-create-cosmosdb-and-configure-firewall.git
27+
28+
cd cosmosdb-java-create-cosmosdb-and-configure-firewall
29+
30+
mvn clean compile exec:java
31+
32+
## More information ##
33+
34+
[http://azure.com/java](http://azure.com/java)
35+
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)
37+
38+
---
39+
40+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

pom.xml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.microsoft.azure</groupId>
6+
<artifactId>cosmosdb-java-create-cosmosdb-and-configure-firewall</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<name>CreateCosmosDBWithIPRange.java</name>
9+
<description></description>
10+
<url>https://github.com/Azure/cosmosdb-java-create-cosmosdb-and-configure-firewall</url>
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<groupId>org.codehaus.mojo</groupId>
15+
<artifactId>exec-maven-plugin</artifactId>
16+
<version>1.4.0</version>
17+
<configuration>
18+
<mainClass>com.microsoft.azure.management.cosmosdb.samples.CreateCosmosDBWithIPRange</mainClass>
19+
</configuration>
20+
</plugin>
21+
<plugin>
22+
<artifactId>maven-compiler-plugin</artifactId>
23+
<version>3.0</version>
24+
<configuration>
25+
<source>1.7</source>
26+
<target>1.7</target>
27+
</configuration>
28+
</plugin>
29+
<plugin>
30+
<artifactId>maven-assembly-plugin</artifactId>
31+
<executions>
32+
<execution>
33+
<phase>package</phase>
34+
<goals>
35+
<goal>attached</goal>
36+
</goals>
37+
<configuration>
38+
<descriptorRefs>
39+
<descriptorRef>jar-with-dependencies</descriptorRef>
40+
</descriptorRefs>
41+
<archive>
42+
<manifest>
43+
<mainClass>com.microsoft.azure.management.cosmosdb.samples.CreateCosmosDBWithIPRange.java</mainClass>
44+
</manifest>
45+
</archive>
46+
</configuration>
47+
</execution>
48+
</executions>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
<dependencies>
53+
<dependency>
54+
<groupId>com.microsoft.azure</groupId>
55+
<artifactId>azure</artifactId>
56+
<version>1.30.0</version>
57+
</dependency>
58+
<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>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.apache.commons</groupId>
70+
<artifactId>commons-lang3</artifactId>
71+
<version>3.7</version>
72+
</dependency>
73+
</dependencies>
74+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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;
20+
21+
/**
22+
* Azure CosmosDB sample for high availability.
23+
* - Create a CosmosDB configured with IP range filterR
24+
* - Delete the CosmosDB.
25+
*/
26+
public final class CreateCosmosDBWithIPRange {
27+
/**
28+
* Main function which runs the actual sample.
29+
* @param azure instance of the azure client
30+
* @param clientId client id
31+
* @return true if sample runs successfully
32+
*/
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);
36+
37+
try {
38+
//============================================================
39+
// Create a CosmosDB
40+
41+
System.out.println("Creating a CosmosDB...");
42+
CosmosDBAccount cosmosDBAccount = azure.cosmosDBAccounts().define(docDBName)
43+
.withRegion(Region.US_EAST)
44+
.withNewResourceGroup(rgName)
45+
.withKind(DatabaseAccountKind.GLOBAL_DOCUMENT_DB)
46+
.withSessionConsistency()
47+
.withWriteReplication(Region.US_WEST)
48+
.withReadReplication(Region.US_CENTRAL)
49+
.withIpRangeFilter("13.91.6.132,13.91.6.1/24")
50+
.create();
51+
52+
System.out.println("Created CosmosDB");
53+
Utils.print(cosmosDBAccount);
54+
55+
//============================================================
56+
// Delete CosmosDB
57+
System.out.println("Deleting the CosmosDB");
58+
// work around CosmosDB service issue returning 404 CloudException on delete operation
59+
try {
60+
azure.cosmosDBAccounts().deleteById(cosmosDBAccount.id());
61+
} catch (CloudException e) {
62+
}
63+
System.out.println("Deleted the CosmosDB");
64+
65+
return true;
66+
} catch (Exception e) {
67+
System.err.println(e.getMessage());
68+
} finally {
69+
try {
70+
System.out.println("Deleting resource group: " + rgName);
71+
azure.resourceGroups().beginDeleteByName(rgName);
72+
System.out.println("Deleted resource group: " + rgName);
73+
} catch (NullPointerException npe) {
74+
System.out.println("Did not create any resources in Azure. No clean up is necessary");
75+
} catch (Exception g) {
76+
g.printStackTrace();
77+
}
78+
}
79+
80+
return false;
81+
}
82+
83+
/**
84+
* Main entry point.
85+
* @param args the parameters
86+
*/
87+
public static void main(String[] args) {
88+
try {
89+
90+
//=============================================================
91+
// Authenticate
92+
93+
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
94+
95+
Azure azure = Azure.configure()
96+
.withLogLevel(LogLevel.BASIC)
97+
.authenticate(credFile)
98+
.withDefaultSubscription();
99+
100+
// Print selected subscription
101+
System.out.println("Selected subscription: " + azure.subscriptionId());
102+
103+
runSample(azure, ApplicationTokenCredentials.fromFile(credFile).clientId());
104+
} catch (Exception e) {
105+
System.out.println(e.getMessage());
106+
e.printStackTrace();
107+
}
108+
}
109+
110+
private CreateCosmosDBWithIPRange() {
111+
}
112+
}

0 commit comments

Comments
 (0)