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

Commit fa536cb

Browse files
committed
changes for 1.1.0
1 parent e05b453 commit fa536cb

File tree

6 files changed

+2250
-14
lines changed

6 files changed

+2250
-14
lines changed

.gitignore

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# Compiled class file
21
*.class
32

4-
# Log file
5-
*.log
6-
7-
# BlueJ files
8-
*.ctxt
3+
# Auth filed
4+
*.auth
5+
*.azureauth
96

107
# Mobile Tools for Java (J2ME)
118
.mtj.tmp/
@@ -14,9 +11,40 @@
1411
*.jar
1512
*.war
1613
*.ear
17-
*.zip
18-
*.tar.gz
19-
*.rar
2014

21-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
22-
hs_err_pid*
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

Lines changed: 11 additions & 0 deletions
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-documentdb-and-configure-firewall/) whether it was helpful or not.
10+
- Submit issues through [issue tracker](https://github.com/Azure-Samples/cosmosdb-java-create-documentdb-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.

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1-
# Contributing
2-
3-
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 [[email protected]](mailto:[email protected]) with any additional questions or comments.
1+
---
2+
services: Documentdb
3+
platforms: java
4+
author: alvadb
5+
---
6+
7+
#Getting Started with Documentdb - Create Document DB With IP Range - in Java #
8+
9+
10+
Azure DocumentDB sample for high availability.
11+
- Create a DocumentDB configured with IP range filter
12+
- Delete the DocumentDB.
13+
14+
15+
## Running this Sample ##
16+
17+
To run this sample:
18+
19+
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-sdk-for-java/blob/master/AUTH.md).
20+
21+
git clone https://github.com/Azure-Samples/cosmosdb-java-create-documentdb-and-configure-firewall.git
22+
23+
cd cosmosdb-java-create-documentdb-and-configure-firewall
24+
25+
mvn clean compile exec:java
26+
27+
## More information ##
28+
29+
[http://azure.com/java] (http://azure.com/java)
30+
31+
If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212)
32+
33+
---
34+
35+
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 [[email protected]](mailto:[email protected]) with any additional questions or comments.

pom.xml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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-documentdb-and-configure-firewall</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<name>CreateDocumentDBWithIPRange.java</name>
9+
<description></description>
10+
<url>https://github.com/Azure/cosmosdb-java-create-documentdb-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.documentdb.samples.CreateDocumentDBWithIPRange</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.documentdb.samples.CreateDocumentDBWithIPRange.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.1.0</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>commons-net</groupId>
60+
<artifactId>commons-net</artifactId>
61+
<version>3.3</version>
62+
</dependency>
63+
</dependencies>
64+
</project>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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.documentdb.samples;
8+
9+
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
10+
import com.microsoft.azure.management.Azure;
11+
import com.microsoft.azure.management.documentdb.DatabaseAccountKind;
12+
import com.microsoft.azure.management.documentdb.DocumentDBAccount;
13+
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
14+
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
15+
import com.microsoft.azure.management.samples.Utils;
16+
import com.microsoft.rest.LogLevel;
17+
18+
import java.io.File;
19+
20+
/**
21+
* Azure DocumentDB sample for high availability.
22+
* - Create a DocumentDB configured with IP range filter
23+
* - Delete the DocumentDB.
24+
*/
25+
public final class CreateDocumentDBWithIPRange {
26+
/**
27+
* Main function which runs the actual sample.
28+
* @param azure instance of the azure client
29+
* @param clientId client id
30+
* @return true if sample runs successfully
31+
*/
32+
public static boolean runSample(Azure azure, String clientId) {
33+
final String docDBName = SdkContext.randomResourceName("docDb", 10);
34+
final String rgName = SdkContext.randomResourceName("rgNEMV", 24);
35+
36+
try {
37+
//============================================================
38+
// Create a DocumentDB
39+
40+
System.out.println("Creating a DocumentDB...");
41+
DocumentDBAccount documentDBAccount = azure.documentDBs().define(docDBName)
42+
.withRegion(Region.US_EAST)
43+
.withNewResourceGroup(rgName)
44+
.withKind(DatabaseAccountKind.GLOBAL_DOCUMENT_DB)
45+
.withSessionConsistency()
46+
.withWriteReplication(Region.US_WEST)
47+
.withReadReplication(Region.US_CENTRAL)
48+
.withIpRangeFilter("13.91.6.132,13.91.6.1/24")
49+
.create();
50+
51+
System.out.println("Created DocumentDB");
52+
Utils.print(documentDBAccount);
53+
54+
//============================================================
55+
// Delete DocumentDB
56+
System.out.println("Deleting the DocumentDB");
57+
azure.documentDBs().deleteById(documentDBAccount.id());
58+
System.out.println("Deleted the DocumentDB");
59+
60+
return true;
61+
} catch (Exception e) {
62+
System.err.println(e.getMessage());
63+
} finally {
64+
try {
65+
System.out.println("Deleting resource group: " + rgName);
66+
azure.resourceGroups().deleteByName(rgName);
67+
System.out.println("Deleted resource group: " + rgName);
68+
} catch (NullPointerException npe) {
69+
System.out.println("Did not create any resources in Azure. No clean up is necessary");
70+
} catch (Exception g) {
71+
g.printStackTrace();
72+
}
73+
}
74+
75+
return false;
76+
}
77+
78+
/**
79+
* Main entry point.
80+
* @param args the parameters
81+
*/
82+
public static void main(String[] args) {
83+
try {
84+
85+
//=============================================================
86+
// Authenticate
87+
88+
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
89+
90+
Azure azure = Azure.configure()
91+
.withLogLevel(LogLevel.BASIC)
92+
.authenticate(credFile)
93+
.withDefaultSubscription();
94+
95+
// Print selected subscription
96+
System.out.println("Selected subscription: " + azure.subscriptionId());
97+
98+
runSample(azure, ApplicationTokenCredentials.fromFile(credFile).clientId());
99+
} catch (Exception e) {
100+
System.out.println(e.getMessage());
101+
e.printStackTrace();
102+
}
103+
}
104+
105+
private CreateDocumentDBWithIPRange() {
106+
}
107+
}

0 commit comments

Comments
 (0)