page_type | languages | products | description | |||
---|---|---|---|---|---|---|
sample |
|
|
This project demonstrates how to use Java with NetApp Files SDK for Microsoft.NetApp resource provider to enable cross-region replication on NFS 4.1 Volume. |
This project demonstrates how to deploy a volume based on NFSv4.1 protocol with cross-region replication enabled using Java and Azure NetApp Files SDK.
In this sample application we perform the following operations:
-
Creation
- Primary ANF Account | Primary Capacity pool | Primary NFS v4.1 Volume
-
Secondary ANF Account | Secondary Capacity pool | Secondary NFS v.1 Data Protection Volume with referencing to the primary volume Resource ID
-
Authorize Primary volume with Secondary Volume Resource ID
If you don't already have a Microsoft Azure subscription, you can get a FREE trial account here.
- Azure Subscription
- Subscription needs to be enabled for Azure NetApp Files. For more information, please refer to this document.
- Request preview access for Azure NetApp Files cross-region replication. For more information, please refer to this document.
- This project is built upon Maven, which has to be installed in order to run the sample. Instructions on installing Maven can be found on their website here.
- The sample is written in Java 11. The Maven compiler's target Java version is therefore Java 11, and the JAVA_HOME environment variable must be set to Java 11 or a newer version.
- Resource Group created.
- Virtual Network with a delegated subnet to Microsoft.Netapp/volumes resource. For more information, please refer to Guidelines for Azure NetApp Files network planning
- For this sample console appplication work, we are using service principal based authenticate, follow these steps in order to setup authentication:
-
Within an Azure Cloud Shell session, make sure you're logged on at the subscription where you want to be associated with the service principal by default:
az account show
If this is not the correct subscription, use
az account set -s <subscription name or id>
-
Create a service principal using Azure CLI
az ad sp create-for-rbac --sdk-auth
Note: this command will automatically assign RBAC contributor role to the service principal at subscription level, you can narrow down the scope to the specific resource group where your tests will create the resources.
-
Copy the output content and paste it in a file called azureauth.json, secure it with file system permissions and save it outside the tree related of your local git repo folder so the file doesn't get commited.
-
Set an environment variable pointing to the file path you just created, here is an example with Powershell and bash: Powershell
[Environment]::SetEnvironmentVariable("AZURE_AUTH_LOCATION", "C:\sdksample\azureauth.json", "User")
Bash
export AZURE_AUTH_LOCATION=/sdksamples/azureauth.json
-
This sample project is dedicated to demonstrate how to enable cross-region replication in Azure NetApp Files for an NFSv4.1 enabled volume, similar to other examples, the authentication method is based on a service principal, this project will create two ANF Accounts in different regions with capacity pool. A single volume using Premium service level tier in the Primary ANF, and Data Protection Volume with Standard service level tier in the secondary region.
Note: The cleanup execution is disabled by default. If you want to run this end to end with the cleanup, please
- mvn install>change value of boolean variable 'shouldCleanUp' in main.java
The following table describes all files within this solution:
Folder | FileName | Description |
---|---|---|
Root\^ | main.java | Reads configuration, authenticates, executes all operations |
Root\^ | Creation.java | Class that contains all resource creation loops, following the hierarchy logic in order to successfully deploy Azure NetApp Files resources |
Root\^ | Cleanup.java | Class that performs cleanup of all artifacts that were created during this sample application. It's called when the variable shouldCleanUp in the main class is enabled |
Root\^\nfs.sdk.sample.common | CommonSdk.java | Class dedicated to nfs.sdk.sample.common operations related to ANF's SDK |
Root\^\nfs.sdk.sample.common | ResourceUriUtils.java | Class that exposes a few methods that help parsing Uri's, building new Uri's, or getting a resource name from a Uri, etc |
Root\^\nfs.sdk.sample.common | ServiceCredentialsAuth.java | A small support class for extracting and creating credentials from a File |
Root\^\nfs.sdk.sample.common | Utils.java | Class that exposes methods that help with getting the configuration object, byte conversion, etc |
Root\^\model | AzureAuthInfo.java | POJO class to hold authentication information |
\^ == src/main/java/sdk/sample |
- Clone it locally
git clone https://github.com/Azure-Samples/netappfiles-java-nfs4.1-sdk-sample.git
- Make sure you change the variables located at .netappfiles-java-crr-sdk-sample\src\main\main.java at RunAsync method.
- Change folder to .\anf-java-crr-sdk-sample
- Since we're using service principal authentication flow, make sure you have the azureauth.json and its environment variable with the path to it defined (as previously described)
- Compile the console application
mvn clean compile
- Run the console application
mvn exec:java -Dexec.mainClass="sdk.sample.main"
- [Resource limits for Azure NetApp Files](https://docs.microsoft.com/azure/azure-netapp-files/azure-netapp-files-resource-limits
- [Azure NetApp Files - Cross-Region Replication] (https://docs.microsoft.com/en-us/azure/azure-netapp-files/cross-region-replication-introduction)
- Azure Cloud Shell
- Azure NetApp Files documentation
- Download Azure SDKs